diff --git a/src/main/java/com/progwml6/natura/common/gui/client/FurnaceGui.java b/src/main/java/com/progwml6/natura/common/gui/client/FurnaceGui.java index f3ad79c5..f3a69680 100644 --- a/src/main/java/com/progwml6/natura/common/gui/client/FurnaceGui.java +++ b/src/main/java/com/progwml6/natura/common/gui/client/FurnaceGui.java @@ -28,6 +28,17 @@ public FurnaceGui(InventoryPlayer playerInv, IInventory furnaceInv) this.tileFurnace = furnaceInv; } + /** + * Draws the screen and all the components in it. + */ + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) + { + this.drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + this.renderHoveredToolTip(mouseX, mouseY); + } + /** * Draw the foreground layer for the GuiContainer (everything in front of the items) */ diff --git a/src/main/java/com/progwml6/natura/common/gui/client/WorkbenchGui.java b/src/main/java/com/progwml6/natura/common/gui/client/WorkbenchGui.java index 026e5360..b9baa340 100644 --- a/src/main/java/com/progwml6/natura/common/gui/client/WorkbenchGui.java +++ b/src/main/java/com/progwml6/natura/common/gui/client/WorkbenchGui.java @@ -1,11 +1,18 @@ package com.progwml6.natura.common.gui.client; -import com.progwml6.natura.common.gui.common.WorkbenchContainer; +import java.io.IOException; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiButtonImage; import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.gui.recipebook.GuiRecipeBook; +import net.minecraft.client.gui.recipebook.IRecipeShownListener; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ClickType; +import net.minecraft.inventory.ContainerWorkbench; +import net.minecraft.inventory.Slot; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -13,10 +20,16 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) -public class WorkbenchGui extends GuiContainer +public class WorkbenchGui extends GuiContainer implements IRecipeShownListener { private static final ResourceLocation CRAFTING_TABLE_GUI_TEXTURES = new ResourceLocation("textures/gui/container/crafting_table.png"); + private GuiButtonImage recipeButton; + + private final GuiRecipeBook recipeBookGui; + + private boolean widthTooNarrow; + public WorkbenchGui(InventoryPlayer playerInv, World worldIn) { this(playerInv, worldIn, BlockPos.ORIGIN); @@ -24,7 +37,57 @@ public WorkbenchGui(InventoryPlayer playerInv, World worldIn) public WorkbenchGui(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition) { - super(new WorkbenchContainer(playerInv, worldIn, blockPosition)); + super(new ContainerWorkbench(playerInv, worldIn, blockPosition)); + this.recipeBookGui = new GuiRecipeBook(); + } + + /** + * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the + * window resizes, the buttonList is cleared beforehand. + */ + @Override + public void initGui() + { + super.initGui(); + this.widthTooNarrow = this.width < 379; + this.recipeBookGui.init(this.width, this.height, this.mc, this.widthTooNarrow, this.inventorySlots, ((ContainerWorkbench) this.inventorySlots).craftMatrix); + this.guiLeft = this.recipeBookGui.updateScreenPosition(this.widthTooNarrow, this.width, this.xSize); + this.recipeButton = new GuiButtonImage(10, this.guiLeft + 5, this.height / 2 - 49, 20, 18, 0, 168, 19, CRAFTING_TABLE_GUI_TEXTURES); + this.buttonList.add(this.recipeButton); + } + + /** + * Called from the main game loop to update the screen. + */ + @Override + public void updateScreen() + { + super.updateScreen(); + this.recipeBookGui.tick(); + } + + /** + * Draws the screen and all the components in it. + */ + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) + { + this.drawDefaultBackground(); + + if (this.recipeBookGui.isVisible() && this.widthTooNarrow) + { + this.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY); + this.recipeBookGui.render(mouseX, mouseY, partialTicks); + } + else + { + this.recipeBookGui.render(mouseX, mouseY, partialTicks); + super.drawScreen(mouseX, mouseY, partialTicks); + this.recipeBookGui.renderGhostRecipe(this.guiLeft, this.guiTop, true, partialTicks); + } + + this.renderHoveredToolTip(mouseX, mouseY); + this.recipeBookGui.renderTooltip(this.guiLeft, this.guiTop, mouseX, mouseY); } /** @@ -33,8 +96,8 @@ public WorkbenchGui(InventoryPlayer playerInv, World worldIn, BlockPos blockPosi @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - this.fontRenderer.drawString(I18n.format("container.crafting", new Object[0]), 28, 6, 4210752); - this.fontRenderer.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); + this.fontRenderer.drawString(I18n.format("container.crafting"), 28, 6, 4210752); + this.fontRenderer.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); } /** @@ -45,8 +108,94 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(CRAFTING_TABLE_GUI_TEXTURES); - int i = (this.width - this.xSize) / 2; + int i = this.guiLeft; int j = (this.height - this.ySize) / 2; this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize); } + + /** + * Test if the 2D point is in a rectangle (relative to the GUI). Args : rectX, rectY, rectWidth, rectHeight, pointX, + * pointY + */ + @Override + protected boolean isPointInRegion(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY) + { + return (!this.widthTooNarrow || !this.recipeBookGui.isVisible()) && super.isPointInRegion(rectX, rectY, rectWidth, rectHeight, pointX, pointY); + } + + /** + * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton + */ + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException + { + if (!this.recipeBookGui.mouseClicked(mouseX, mouseY, mouseButton)) + { + if (!this.widthTooNarrow || !this.recipeBookGui.isVisible()) + { + super.mouseClicked(mouseX, mouseY, mouseButton); + } + } + } + + @Override + protected boolean hasClickedOutside(int p_193983_1_, int p_193983_2_, int p_193983_3_, int p_193983_4_) + { + boolean flag = p_193983_1_ < p_193983_3_ || p_193983_2_ < p_193983_4_ || p_193983_1_ >= p_193983_3_ + this.xSize || p_193983_2_ >= p_193983_4_ + this.ySize; + return this.recipeBookGui.hasClickedOutside(p_193983_1_, p_193983_2_, this.guiLeft, this.guiTop, this.xSize, this.ySize) && flag; + } + + /** + * Called by the controls from the buttonList when activated. (Mouse pressed for buttons) + */ + @Override + protected void actionPerformed(GuiButton button) throws IOException + { + if (button.id == 10) + { + this.recipeBookGui.initVisuals(this.widthTooNarrow, ((ContainerWorkbench) this.inventorySlots).craftMatrix); + this.recipeBookGui.toggleVisibility(); + this.guiLeft = this.recipeBookGui.updateScreenPosition(this.widthTooNarrow, this.width, this.xSize); + this.recipeButton.setPosition(this.guiLeft + 5, this.height / 2 - 49); + } + } + + /** + * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of + * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code) + */ + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException + { + if (!this.recipeBookGui.keyPressed(typedChar, keyCode)) + { + super.keyTyped(typedChar, keyCode); + } + } + + /** + * Called when the mouse is clicked over a slot or outside the gui. + */ + @Override + protected void handleMouseClick(Slot slotIn, int slotId, int mouseButton, ClickType type) + { + super.handleMouseClick(slotIn, slotId, mouseButton, type); + this.recipeBookGui.slotClicked(slotIn); + } + + @Override + public void recipesUpdated() + { + this.recipeBookGui.recipesUpdated(); + } + + /** + * Called when the screen is unloaded. Used to disable keyboard repeat events + */ + @Override + public void onGuiClosed() + { + this.recipeBookGui.removed(); + super.onGuiClosed(); + } } diff --git a/src/main/java/com/progwml6/natura/common/gui/common/FurnaceContainer.java b/src/main/java/com/progwml6/natura/common/gui/common/FurnaceContainer.java index 4580e7c1..6dfd6a75 100644 --- a/src/main/java/com/progwml6/natura/common/gui/common/FurnaceContainer.java +++ b/src/main/java/com/progwml6/natura/common/gui/common/FurnaceContainer.java @@ -113,10 +113,6 @@ public boolean canInteractWith(EntityPlayer playerIn) /** * Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player * inventory and the other inventory(s). - * - * @param playerIn Player that interacted with this {@code Container}. - * @param index Index of the {@link Slot}. This index is relative to the list of slots in this {@code Container}, - * {@link #inventorySlots}. */ @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) diff --git a/src/main/java/com/progwml6/natura/common/gui/common/WorkbenchContainer.java b/src/main/java/com/progwml6/natura/common/gui/common/WorkbenchContainer.java index 6f7e2365..7eb46a2a 100644 --- a/src/main/java/com/progwml6/natura/common/gui/common/WorkbenchContainer.java +++ b/src/main/java/com/progwml6/natura/common/gui/common/WorkbenchContainer.java @@ -33,7 +33,6 @@ public WorkbenchContainer(InventoryPlayer playerInventory, World worldIn, BlockP this.world = worldIn; this.pos = posIn; this.player = playerInventory.player; - this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35)); for (int i = 0; i < 3; ++i) @@ -56,8 +55,6 @@ public WorkbenchContainer(InventoryPlayer playerInventory, World worldIn, BlockP { this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142)); } - - this.onCraftMatrixChanged(this.craftMatrix); } /** diff --git a/src/main/java/com/progwml6/natura/nether/block/furnace/BlockNetherrackFurnace.java b/src/main/java/com/progwml6/natura/nether/block/furnace/BlockNetherrackFurnace.java index d31a0b63..ea95d7b3 100644 --- a/src/main/java/com/progwml6/natura/nether/block/furnace/BlockNetherrackFurnace.java +++ b/src/main/java/com/progwml6/natura/nether/block/furnace/BlockNetherrackFurnace.java @@ -130,24 +130,27 @@ public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, switch (enumfacing) { case WEST: - worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); - worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); + worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D); + worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D); break; case EAST: - worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); - worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); + worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D); + worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D); break; case NORTH: - worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D, new int[0]); - worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D, new int[0]); + worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D); + worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D); break; case SOUTH: - worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D, new int[0]); - worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D, new int[0]); + worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D); + worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D); } } } + /** + * Called when the block is right clicked by a player. + */ @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { diff --git a/src/main/java/com/progwml6/natura/nether/block/furnace/tile/TileEntityNetherrackFurnace.java b/src/main/java/com/progwml6/natura/nether/block/furnace/tile/TileEntityNetherrackFurnace.java index d16e5697..2095728f 100644 --- a/src/main/java/com/progwml6/natura/nether/block/furnace/tile/TileEntityNetherrackFurnace.java +++ b/src/main/java/com/progwml6/natura/nether/block/furnace/tile/TileEntityNetherrackFurnace.java @@ -310,12 +310,23 @@ private boolean canSmelt() else { ItemStack itemstack1 = this.furnaceItemStacks.get(2); + if (itemstack1.isEmpty()) + { return true; - if (!itemstack1.isItemEqual(itemstack)) + } + else if (!itemstack1.isItemEqual(itemstack)) + { return false; - int result = itemstack1.getCount() + itemstack.getCount(); - return result <= getInventoryStackLimit() && result <= itemstack1.getMaxStackSize(); // Forge fix: make furnace respect stack sizes in furnace recipes + } + else if (itemstack1.getCount() + itemstack.getCount() <= this.getInventoryStackLimit() && itemstack1.getCount() + itemstack.getCount() <= itemstack1.getMaxStackSize()) // Forge fix: make furnace respect stack sizes in furnace recipes + { + return true; + } + else + { + return itemstack1.getCount() + itemstack.getCount() <= itemstack.getMaxStackSize(); // Forge fix: make furnace respect stack sizes in furnace recipes + } } } } @@ -361,14 +372,93 @@ public static int getItemBurnTime(ItemStack stack) } else { + int burnTime = net.minecraftforge.event.ForgeEventFactory.getItemBurnTime(stack); + if (burnTime >= 0) + return burnTime; Item item = stack.getItem(); - if (!item.getRegistryName().getResourceDomain().equals("minecraft")) + + if (item == Item.getItemFromBlock(Blocks.WOODEN_SLAB)) + { + return 150; + } + else if (item == Item.getItemFromBlock(Blocks.WOOL)) + { + return 100; + } + else if (item == Item.getItemFromBlock(Blocks.CARPET)) { - int burnTime = net.minecraftforge.fml.common.registry.GameRegistry.getFuelValue(stack); - if (burnTime != 0) - return burnTime; + return 67; + } + else if (item == Item.getItemFromBlock(Blocks.LADDER)) + { + return 300; + } + else if (item == Item.getItemFromBlock(Blocks.WOODEN_BUTTON)) + { + return 100; + } + else if (Block.getBlockFromItem(item).getDefaultState().getMaterial() == Material.WOOD) + { + return 300; + } + else if (item == Item.getItemFromBlock(Blocks.COAL_BLOCK)) + { + return 16000; + } + else if (item instanceof ItemTool && "WOOD".equals(((ItemTool) item).getToolMaterialName())) + { + return 200; + } + else if (item instanceof ItemSword && "WOOD".equals(((ItemSword) item).getToolMaterialName())) + { + return 200; + } + else if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe) item).getMaterialName())) + { + return 200; + } + else if (item == Items.STICK) + { + return 100; + } + else if (item != Items.BOW && item != Items.FISHING_ROD) + { + if (item == Items.SIGN) + { + return 200; + } + else if (item == Items.COAL) + { + return 1600; + } + else if (item == Items.LAVA_BUCKET) + { + return 20000; + } + else if (item != Item.getItemFromBlock(Blocks.SAPLING) && item != Items.BOWL) + { + if (item == Items.BLAZE_ROD) + { + return 2400; + } + else if (item instanceof ItemDoor && item != Items.IRON_DOOR) + { + return 200; + } + else + { + return item instanceof ItemBoat ? 400 : 0; + } + } + else + { + return 100; + } + } + else + { + return 300; } - return item == Item.getItemFromBlock(Blocks.WOODEN_SLAB) ? 150 : (item == Item.getItemFromBlock(Blocks.WOOL) ? 100 : (item == Item.getItemFromBlock(Blocks.CARPET) ? 67 : (item == Item.getItemFromBlock(Blocks.LADDER) ? 300 : (item == Item.getItemFromBlock(Blocks.WOODEN_BUTTON) ? 100 : (Block.getBlockFromItem(item).getDefaultState().getMaterial() == Material.WOOD ? 300 : (item == Item.getItemFromBlock(Blocks.COAL_BLOCK) ? 16000 : (item instanceof ItemTool && "WOOD".equals(((ItemTool) item).getToolMaterialName()) ? 200 : (item instanceof ItemSword && "WOOD".equals(((ItemSword) item).getToolMaterialName()) ? 200 : (item instanceof ItemHoe && "WOOD".equals(((ItemHoe) item).getMaterialName()) ? 200 : (item == Items.STICK ? 100 : (item != Items.BOW && item != Items.FISHING_ROD ? (item == Items.SIGN ? 200 : (item == Items.COAL ? 1600 : (item == Items.LAVA_BUCKET ? 20000 : (item != Item.getItemFromBlock(Blocks.SAPLING) && item != Items.BOWL ? (item == Items.BLAZE_ROD ? 2400 : (item instanceof ItemDoor && item != Items.IRON_DOOR ? 200 : (item instanceof ItemBoat ? 400 : 0))) : 100)))) : 300))))))))))); } } @@ -383,7 +473,14 @@ public static boolean isItemFuel(ItemStack stack) @Override public boolean isUsableByPlayer(EntityPlayer player) { - return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64.0D; + if (this.world.getTileEntity(this.pos) != this) + { + return false; + } + else + { + return player.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64.0D; + } } @Override @@ -421,7 +518,14 @@ else if (index != 1) @Override public int[] getSlotsForFace(EnumFacing side) { - return side == EnumFacing.DOWN ? SLOTS_BOTTOM : (side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES); + if (side == EnumFacing.DOWN) + { + return SLOTS_BOTTOM; + } + else + { + return side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES; + } } /**