From 979516f069a5bfc6a5eeb174b763087d8f50c75f Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 23 Sep 2014 20:25:05 -0700 Subject: [PATCH 1/6] Farms radius is now (width of central structure * 3) instead of (width + 1) --- src/main/java/forestry/farming/gadgets/TileFarmPlain.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/forestry/farming/gadgets/TileFarmPlain.java b/src/main/java/forestry/farming/gadgets/TileFarmPlain.java index d1572b5aa..9bbf6b73e 100755 --- a/src/main/java/forestry/farming/gadgets/TileFarmPlain.java +++ b/src/main/java/forestry/farming/gadgets/TileFarmPlain.java @@ -273,8 +273,9 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable // System.out.println(String.format("Adding %s to %s", potential.size(), direction)); // Set the maximum allowed extent. - if (potential.size() + 1 > allowedExtent) - allowedExtent = potential.size() + 1; + int size = potential.size() * 3; + if (size > allowedExtent) + allowedExtent = size; targets.put(direction, potential.toArray(new FarmTarget[0])); } From 23c30c77459139103410d76912037dbd59c18f18 Mon Sep 17 00:00:00 2001 From: mezz Date: Wed, 24 Sep 2014 04:48:17 -0700 Subject: [PATCH 2/6] #216 Make Forestry Leaves inherit from and rely on Vanilla Leaves --- .../arboriculture/gadgets/BlockLeaves.java | 355 ------------------ .../gadgets/ForestryBlockLeaves.java | 245 ++++++++++++ .../arboriculture/gadgets/TileLeaves.java | 10 + .../render/LeavesRenderingHandler.java | 4 +- .../forestry/plugins/PluginArboriculture.java | 4 +- 5 files changed, 259 insertions(+), 359 deletions(-) delete mode 100755 src/main/java/forestry/arboriculture/gadgets/BlockLeaves.java create mode 100644 src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockLeaves.java b/src/main/java/forestry/arboriculture/gadgets/BlockLeaves.java deleted file mode 100755 index f0052ec42..000000000 --- a/src/main/java/forestry/arboriculture/gadgets/BlockLeaves.java +++ /dev/null @@ -1,355 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture.gadgets; - -import java.util.ArrayList; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.world.ColorizerFoliage; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraftforge.common.util.ForgeDirection; - -import forestry.api.arboriculture.EnumGermlingType; -import forestry.api.arboriculture.IToolGrafter; -import forestry.api.arboriculture.ITree; -import forestry.api.core.IToolScoop; -import forestry.api.lepidopterology.EnumFlutterType; -import forestry.api.lepidopterology.IButterfly; -import forestry.arboriculture.items.ItemLeavesBlock; -import forestry.core.config.ForestryBlock; -import forestry.core.config.Defaults; -import forestry.core.proxy.Proxies; -import forestry.core.render.TextureManager; -import forestry.core.utils.StackUtils; -import forestry.plugins.PluginArboriculture; -import forestry.plugins.PluginLepidopterology; - -public class BlockLeaves extends BlockTreeContainer { - - int[] adjacentTreeBlocks; - - public BlockLeaves() { - super(Material.leaves); - this.setTickRandomly(true); - this.setHardness(0.2F); - this.setLightOpacity(1); - this.setStepSound(soundTypeGrass); - } - - public static TileLeaves getLeafTile(IBlockAccess world, int x, int y, int z) { - TileEntity tile = world.getTileEntity(x, y, z); - if (!(tile instanceof TileLeaves)) - return null; - - return (TileLeaves) tile; - } - - @Override - public TileEntity createNewTileEntity(World world, int meta) { - return new TileLeaves(); - } - - /* DROP HANDLING */ - @Override - public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { - int metadata = world.getBlockMetadata(x, y, z); - - if (Proxies.common.isSimulating(world) && canHarvestBlock(player, metadata)) { - - ItemStack held = player.inventory.getCurrentItem(); - if (held != null && held.getItem() instanceof IToolGrafter) { - float saplingModifier = 1.0f; - saplingModifier = ((IToolGrafter) held.getItem()).getSaplingModifier(held, world, player, x, y, z); - held.damageItem(1, player); - if(held.stackSize <= 0) - player.destroyCurrentEquippedItem(); - - spawnLeafDrops(world, x, y, z, metadata, saplingModifier, false); - } - } - - return world.setBlockToAir(x, y, z); - } - - @Override - public void breakBlock(World world, int x, int y, int z, Block block, int metadata) { - - byte offset = 1; - int shift = offset + 1; - - if (world.checkChunksExist(x - shift, y - shift, z - shift, x + shift, y + shift, z + shift)) - for (int i = -offset; i <= offset; ++i) - for (int j = -offset; j <= offset; ++j) - for (int k = -offset; k <= offset; ++k) { - Block neighborBlock = world.getBlock(x + i, y + j, z + k); - neighborBlock.beginLeavesDecay(world, x + i, y + j, z + k); - } - - spawnLeafDrops(world, x, y, z, metadata, 1.0f, true); - super.breakBlock(world, x, y, z, block, metadata); - } - - @Override - public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { - return StackUtils.EMPTY_STACK_LIST; - } - - private void removeLeaves(World world, int x, int y, int z) { - this.spawnLeafDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 1.0f, true); - world.setBlockToAir(x, y, z); - } - - private void spawnLeafDrops(World world, int x, int y, int z, int metadata, float saplingModifier, boolean doFruitDrop) { - for (ItemStack drop : getLeafDrop(world, x, y, z, metadata, saplingModifier, doFruitDrop)) - if (drop != null) - StackUtils.dropItemStackAsEntity(drop, world, x, y, z); - } - - private ArrayList getLeafDrop(World world, int x, int y, int z, int metadata, float saplingModifier, boolean doFruitDrop) { - ArrayList prod = new ArrayList(); - - TileLeaves tile = getLeafTile(world, x, y, z); - if (tile == null) - return prod; - - if (tile.getTree() == null) - return prod; - - // Add saplings - ITree[] saplings = tile.getTree().getSaplings(world, x, y, z, saplingModifier); - for (ITree sapling : saplings) - if (sapling != null) - prod.add(PluginArboriculture.treeInterface.getMemberStack(sapling, EnumGermlingType.SAPLING.ordinal())); - - // Add fruits - if (doFruitDrop && tile.hasFruit()) - for (ItemStack stack : tile.getTree().produceStacks(world, x, y, z, tile.getRipeningTime())) - prod.add(stack); - - return prod; - } - - @Override - public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { - TileLeaves leaves = getLeafTile(world, x, y, z); - - NBTTagCompound nbttagcompound = new NBTTagCompound(); - leaves.getTree().writeToNBT(nbttagcompound); - - ItemLeavesBlock leavesItem = (ItemLeavesBlock)ForestryBlock.leaves.item(); - ItemStack leavesStack = new ItemStack(leavesItem); - leavesStack.setTagCompound(nbttagcompound); - - return leavesStack; - } - - /* RENDERING */ - @Override - public boolean isOpaqueCube() { - return !Proxies.render.fancyGraphicsEnabled(); - } - - @Override - public int getRenderType() { - return PluginArboriculture.modelIdLeaves; - } - - @Override - @SideOnly(Side.CLIENT) - public int getBlockColor() { - double var1 = 0.5D; - double var3 = 1.0D; - return ColorizerFoliage.getFoliageColor(var1, var3); - } - - @Override - @SideOnly(Side.CLIENT) - public int colorMultiplier(IBlockAccess world, int x, int y, int z) { - - TileLeaves leaves = getLeafTile(world, x, y, z); - if (leaves == null) - return ColorizerFoliage.getFoliageColorBasic(); - - int colour = leaves.getFoliageColour(Proxies.common.getClientInstance().thePlayer); - if (colour == PluginArboriculture.proxy.getFoliageColorBasic()) - colour = world.getBiomeGenForCoords(x, z).getBiomeFoliageColor(x, y, z); // TODO: vanilla uses a more elaborate color query - - return colour; - } - - /* ICONS */ - @SideOnly(Side.CLIENT) - private static IIcon defaultIcon; - - @SideOnly(Side.CLIENT) - @Override - public void registerBlockIcons(IIconRegister register) { - defaultIcon = TextureManager.getInstance().registerTex(register, "leaves/deciduous.fancy"); - } - - @SideOnly(Side.CLIENT) - @Override - public IIcon getIcon(int side, int metadata) { - return defaultIcon; - } - - @SideOnly(Side.CLIENT) - @Override - public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { - TileLeaves leaves = getLeafTile(world, x, y, z); - if (leaves != null) - return leaves.getIcon(Proxies.render.fancyGraphicsEnabled()); - - return defaultIcon; - } - - /* BREAKING, LEAF DECAY */ - @Override - public void updateTick(World world, int x, int y, int z, Random random) { - - super.updateTick(world, x, y, z, random); - if (!Proxies.common.isSimulating(world)) - return; - - int meta = world.getBlockMetadata(x, y, z); - - if ((meta & 8) != 0 && (meta & 4) == 0) { - byte offset = 4; - int shift = offset + 1; - byte var9 = 32; - int var10 = var9 * var9; - int var11 = var9 / 2; - - if (this.adjacentTreeBlocks == null) - this.adjacentTreeBlocks = new int[var9 * var9 * var9]; - - int var12; - - if (world.checkChunksExist(x - shift, y - shift, z - shift, x + shift, y + shift, z + shift)) { - - int var13; - int var14; - int var15; - - for (var12 = -offset; var12 <= offset; ++var12) - for (var13 = -offset; var13 <= offset; ++var13) - for (var14 = -offset; var14 <= offset; ++var14) { - Block block = world.getBlock(x + var12, y + var13, z + var14); - - if (block.canSustainLeaves(world, x + var12, y + var13, z + var14)) - this.adjacentTreeBlocks[(var12 + var11) * var10 + (var13 + var11) * var9 + var14 + var11] = 0; - else if (block.isLeaves(world, x + var12, y + var13, z + var14)) - this.adjacentTreeBlocks[(var12 + var11) * var10 + (var13 + var11) * var9 + var14 + var11] = -2; - else - this.adjacentTreeBlocks[(var12 + var11) * var10 + (var13 + var11) * var9 + var14 + var11] = -1; - } - - for (var12 = 1; var12 <= 4; ++var12) - for (var13 = -offset; var13 <= offset; ++var13) - for (var14 = -offset; var14 <= offset; ++var14) - for (var15 = -offset; var15 <= offset; ++var15) - if (this.adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + var15 + var11] == var12 - 1) { - - if (this.adjacentTreeBlocks[(var13 + var11 - 1) * var10 + (var14 + var11) * var9 + var15 + var11] == -2) - this.adjacentTreeBlocks[(var13 + var11 - 1) * var10 + (var14 + var11) * var9 + var15 + var11] = var12; - - if (this.adjacentTreeBlocks[(var13 + var11 + 1) * var10 + (var14 + var11) * var9 + var15 + var11] == -2) - this.adjacentTreeBlocks[(var13 + var11 + 1) * var10 + (var14 + var11) * var9 + var15 + var11] = var12; - - if (this.adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11 - 1) * var9 + var15 + var11] == -2) - this.adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11 - 1) * var9 + var15 + var11] = var12; - - if (this.adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11 + 1) * var9 + var15 + var11] == -2) - this.adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11 + 1) * var9 + var15 + var11] = var12; - - if (this.adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + (var15 + var11 - 1)] == -2) - this.adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + (var15 + var11 - 1)] = var12; - - if (this.adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + var15 + var11 + 1] == -2) - this.adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + var15 + var11 + 1] = var12; - } - } - - var12 = this.adjacentTreeBlocks[var11 * var10 + var11 * var9 + var11]; - - if (var12 >= 0) - world.setBlockMetadataWithNotify(x, y, z, meta & -9, Defaults.FLAG_BLOCK_SYNCH); - else - this.removeLeaves(world, x, y, z); - } - } - - @Override - public void beginLeavesDecay(World world, int x, int y, int z) { - world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) | 8, Defaults.FLAG_BLOCK_SYNCH); - } - - /* PROPERTIES */ - @Override - public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face) { - return 60; - } - - @Override - public boolean isFlammable(IBlockAccess world, int x, int y, int z, ForgeDirection face) { - return true; - } - - @Override - public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) { - if (face == ForgeDirection.DOWN) - return 20; - else if (face != ForgeDirection.UP) - return 10; - else - return 5; - } - - @Override - public boolean isLeaves(IBlockAccess world, int x, int y, int z) { - return true; - } - - @Override - public boolean onBlockActivated(World world, int x, int y, - int z, EntityPlayer player, int par6, float par7, - float par8, float par9) { - - ItemStack heldItem = player.getHeldItem(); - TileEntity tile = world.getTileEntity(x, y, z); - IButterfly caterpillar = tile instanceof TileLeaves ? ((TileLeaves) tile).getCaterpillar() : null; - if(heldItem != null && heldItem.getItem() instanceof IToolScoop - && caterpillar != null) { - StackUtils.dropItemStackAsEntity(PluginLepidopterology.butterflyInterface.getMemberStack(caterpillar, EnumFlutterType.CATERPILLAR.ordinal()), - world, x, y, z); - ((TileLeaves) tile).setCaterpillar(null); - return true; - } - - return super.onBlockActivated(world, x, y, z, player, - par6, par7, par8, par9); - } - -} diff --git a/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java b/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java new file mode 100644 index 000000000..d3676da71 --- /dev/null +++ b/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.gadgets; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.BlockNewLeaf; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraftforge.common.util.ForgeDirection; + +import forestry.api.arboriculture.EnumGermlingType; +import forestry.api.arboriculture.IToolGrafter; +import forestry.api.arboriculture.ITree; +import forestry.api.core.IToolScoop; +import forestry.api.core.Tabs; +import forestry.api.lepidopterology.EnumFlutterType; +import forestry.api.lepidopterology.IButterfly; +import forestry.core.proxy.Proxies; +import forestry.core.render.TextureManager; +import forestry.core.utils.StackUtils; +import forestry.plugins.PluginArboriculture; +import forestry.plugins.PluginLepidopterology; + +public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProvider { + + public ForestryBlockLeaves() { + this.setCreativeTab(Tabs.tabArboriculture); + } + + /* TILE ENTITY */ + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileLeaves(); + } + + public static TileLeaves getLeafTile(IBlockAccess world, int x, int y, int z) { + TileEntity tile = world.getTileEntity(x, y, z); + if (!(tile instanceof TileLeaves)) + return null; + + return (TileLeaves) tile; + } + + @SideOnly(Side.CLIENT) + @Override + public void getSubBlocks(Item item, CreativeTabs tab, List list) { + list.add(new ItemStack(item, 1, 0)); + } + + /* DROP HANDLING */ + @Override + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + + float saplingModifier = 1.0f; + int count = quantityDropped(metadata, fortune, world.rand); + + if (Proxies.common.isSimulating(world)) { + EntityPlayer player = harvesters.get(); + if (player != null) { + ItemStack held = player.inventory.getCurrentItem(); + if (held != null && held.getItem() instanceof IToolGrafter) { + saplingModifier = ((IToolGrafter) held.getItem()).getSaplingModifier(held, world, player, x, y, z); + count = 1; + held.damageItem(1, player); + if (held.stackSize <= 0) + player.destroyCurrentEquippedItem(); + } + } + } + + ArrayList ret = new ArrayList(); + + for(int i = 0; i < count; i++) { + ret.addAll(getLeafDrop(world, x, y, z, saplingModifier, fortune)); + } + return ret; + } + + + private ArrayList getLeafDrop(World world, int x, int y, int z, float saplingModifier, int fortune) { + ArrayList prod = new ArrayList(); + + TileLeaves tile = getLeafTile(world, x, y, z); + if (tile == null) + return prod; + + if (tile.getTree() == null) + return prod; + + // Add saplings + ITree[] saplings = tile.getTree().getSaplings(world, x, y, z, saplingModifier); + for (ITree sapling : saplings) + if (sapling != null) + prod.add(PluginArboriculture.treeInterface.getMemberStack(sapling, EnumGermlingType.SAPLING.ordinal())); + + // Add fruits + if (tile.hasFruit()) + for (ItemStack stack : tile.getTree().produceStacks(world, x, y, z, tile.getRipeningTime())) + prod.add(stack); + + return prod; + } + + @Override + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { + TileLeaves leaves = getLeafTile(world, x, y, z); + ITree tree = leaves.getTree(); + NBTTagCompound nbttagcompound = new NBTTagCompound(); + tree.writeToNBT(nbttagcompound); + + ItemStack itemStack = super.getPickBlock(target, world, x, y, z); + itemStack.setTagCompound(nbttagcompound); + return itemStack; + } + + @Override + public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z) { + return false; + } + + /* RENDERING */ + @Override + public boolean isOpaqueCube() { + return !Proxies.render.fancyGraphicsEnabled(); + } + + @Override + public int getRenderType() { + return PluginArboriculture.modelIdLeaves; + } + + @Override + @SideOnly(Side.CLIENT) + public int colorMultiplier(IBlockAccess world, int x, int y, int z) { + + TileLeaves leaves = getLeafTile(world, x, y, z); + if (leaves == null) + return super.colorMultiplier(world, x, y, z); + + int colour = leaves.getFoliageColour(Proxies.common.getClientInstance().thePlayer); + if (colour == PluginArboriculture.proxy.getFoliageColorBasic()) + colour = super.colorMultiplier(world, x, y, z); + + return colour; + } + + @Override + public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) { + return true; + } + + /* ICONS */ + @SideOnly(Side.CLIENT) + private static IIcon defaultIcon; + + @SideOnly(Side.CLIENT) + @Override + public void registerBlockIcons(IIconRegister register) { + defaultIcon = TextureManager.getInstance().registerTex(register, "leaves/deciduous.fancy"); + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIcon(int side, int metadata) { + return defaultIcon; + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + TileLeaves leaves = getLeafTile(world, x, y, z); + if (leaves != null) + return leaves.getIcon(Proxies.render.fancyGraphicsEnabled()); + + return defaultIcon; + } + + /* LOCALIZATION */ + @Override + public String[] func_150125_e() { + return new String[0]; + } + + /* PROPERTIES */ + @Override + public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face) { + return 60; + } + + @Override + public boolean isFlammable(IBlockAccess world, int x, int y, int z, ForgeDirection face) { + return true; + } + + @Override + public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) { + if (face == ForgeDirection.DOWN) + return 20; + else if (face != ForgeDirection.UP) + return 10; + else + return 5; + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { + + ItemStack heldItem = player.getHeldItem(); + TileEntity tile = world.getTileEntity(x, y, z); + IButterfly caterpillar = tile instanceof TileLeaves ? ((TileLeaves) tile).getCaterpillar() : null; + if(heldItem != null && (heldItem.getItem() instanceof IToolScoop) && caterpillar != null) { + ItemStack butterfly = PluginLepidopterology.butterflyInterface.getMemberStack(caterpillar, EnumFlutterType.CATERPILLAR.ordinal()); + StackUtils.dropItemStackAsEntity(butterfly, world, x, y, z); + ((TileLeaves) tile).setCaterpillar(null); + return true; + } + + return super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9); + } + +} diff --git a/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java b/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java index 83f2d81a3..274768b67 100755 --- a/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java @@ -17,6 +17,7 @@ import java.util.EnumSet; import com.mojang.authlib.GameProfile; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -309,6 +310,15 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru worldObj.func_147479_m(xCoord, yCoord, zCoord); } + /** + * Called from Chunk.setBlockIDWithMetadata, determines if this tile entity should be re-created when the ID, or Metadata changes. + * Use with caution as this will leave straggler TileEntities, or create conflicts with other TileEntities if not used properly. + **/ + @Override + public boolean shouldRefresh(Block oldBlock, Block newBlock, int oldMeta, int newMeta, World world, int x, int y, int z) { + return false; + } + /* IFRUITBEARER */ @Override public Collection pickFruit(ItemStack tool) { diff --git a/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java b/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java index 9d590001a..6b049b1b3 100755 --- a/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java +++ b/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java @@ -16,7 +16,7 @@ import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; -import forestry.arboriculture.gadgets.BlockLeaves; +import forestry.arboriculture.gadgets.ForestryBlockLeaves; import forestry.arboriculture.gadgets.TileLeaves; import forestry.core.render.OverlayRenderingHandler; import forestry.plugins.PluginArboriculture; @@ -37,7 +37,7 @@ public class LeavesRenderingHandler extends OverlayRenderingHandler { renderer.renderStandardBlock(block, x, y, z); // Render overlay for fruit leaves. - TileLeaves tile = BlockLeaves.getLeafTile(world, x, y, z); + TileLeaves tile = ForestryBlockLeaves.getLeafTile(world, x, y, z); IIcon fruitIcon = null; int fruitColor = 0xffffff; if (tile != null) { diff --git a/src/main/java/forestry/plugins/PluginArboriculture.java b/src/main/java/forestry/plugins/PluginArboriculture.java index 78d226b3b..c5dd57e33 100644 --- a/src/main/java/forestry/plugins/PluginArboriculture.java +++ b/src/main/java/forestry/plugins/PluginArboriculture.java @@ -59,7 +59,6 @@ import forestry.arboriculture.gadgets.BlockArbFence; import forestry.arboriculture.gadgets.BlockArbFence.FenceCat; import forestry.arboriculture.gadgets.BlockArbStairs; import forestry.arboriculture.gadgets.BlockFruitPod; -import forestry.arboriculture.gadgets.BlockLeaves; import forestry.arboriculture.gadgets.BlockLog; import forestry.arboriculture.gadgets.BlockLog.LogCat; import forestry.arboriculture.gadgets.BlockPlanks; @@ -67,6 +66,7 @@ import forestry.arboriculture.gadgets.BlockPlanks.PlankCat; import forestry.arboriculture.gadgets.BlockSapling; import forestry.arboriculture.gadgets.BlockSlab; import forestry.arboriculture.gadgets.BlockSlab.SlabCat; +import forestry.arboriculture.gadgets.ForestryBlockLeaves; import forestry.arboriculture.gadgets.TileArboristChest; import forestry.arboriculture.gadgets.TileFruitPod; import forestry.arboriculture.gadgets.TileLeaves; @@ -222,7 +222,7 @@ public class PluginArboriculture extends ForestryPlugin { ForestryBlock.saplingGE.registerBlock(new BlockSapling(), ItemForestryBlock.class, "saplingGE"); // Leaves - ForestryBlock.leaves.registerBlock(new BlockLeaves(), ItemLeavesBlock.class, "leaves"); + ForestryBlock.leaves.registerBlock(new ForestryBlockLeaves(), ItemLeavesBlock.class, "leaves"); // Pods ForestryBlock.pods.registerBlock(new BlockFruitPod(), ItemForestryBlock.class, "pods"); From 8c5e512172385ba90cab5898592a299624f87d53 Mon Sep 17 00:00:00 2001 From: bdew Date: Wed, 24 Sep 2014 15:27:01 +0300 Subject: [PATCH 3/6] Bees should respect the temperature/humidity provided by the bee housing --- src/main/java/forestry/apiculture/genetics/Bee.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/forestry/apiculture/genetics/Bee.java b/src/main/java/forestry/apiculture/genetics/Bee.java index bcef812a9..d4f7edcc0 100755 --- a/src/main/java/forestry/apiculture/genetics/Bee.java +++ b/src/main/java/forestry/apiculture/genetics/Bee.java @@ -231,8 +231,8 @@ public class Bee extends IndividualLiving implements IBee { && !genome.getCaveDwelling() && !housing.isSunlightSimulated()) return EnumErrorCode.NOSKY.ordinal(); - // / And finally biome check - if (!checkBiomeHazard(biome)) + // / And finally climate check + if (!checkSuitableClimate(housing.getTemperature(), housing.getHumidity())) return EnumErrorCode.INVALIDBIOME.ordinal(); return EnumErrorCode.OK.ordinal(); @@ -255,6 +255,13 @@ public class Bee extends IndividualLiving implements IBee { genome.getPrimary().getHumidity(), genome.getToleranceHumid()); } + private boolean checkSuitableClimate(EnumTemperature temperature, EnumHumidity humidity) { + + return AlleleManager.climateHelper.isWithinLimits(temperature, humidity, + genome.getPrimary().getTemperature(), genome.getToleranceTemp(), + genome.getPrimary().getHumidity(), genome.getToleranceHumid()); + } + @Override public boolean hasFlower(IBeeHousing housing) { From aaef67ae8f9e074e69272ae329a537ece07e38fa Mon Sep 17 00:00:00 2001 From: mezz Date: Wed, 24 Sep 2014 18:01:00 -0700 Subject: [PATCH 4/6] Minor cleanup in PluginApiculture --- .../forestry/plugins/PluginApiculture.java | 68 +++++++++++-------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/src/main/java/forestry/plugins/PluginApiculture.java b/src/main/java/forestry/plugins/PluginApiculture.java index a3f98a0a1..9741fa77e 100644 --- a/src/main/java/forestry/plugins/PluginApiculture.java +++ b/src/main/java/forestry/plugins/PluginApiculture.java @@ -434,14 +434,18 @@ public class PluginApiculture extends ForestryPlugin { protected void registerRecipes() { // / APIARIST'S ARMOR - Proxies.common.addRecipe(ForestryItem.apiaristHat.getItemStack(), new Object[]{"###", "# #", '#', - ForestryItem.craftingMaterial.getItemStack(1, 3)}); - Proxies.common.addRecipe(ForestryItem.apiaristChest.getItemStack(), new Object[]{"# #", "###", "###", '#', - ForestryItem.craftingMaterial.getItemStack(1, 3)}); - Proxies.common.addRecipe(ForestryItem.apiaristLegs.getItemStack(), new Object[]{"###", "# #", "# #", '#', - ForestryItem.craftingMaterial.getItemStack(1, 3)}); - Proxies.common.addRecipe(ForestryItem.apiaristBoots.getItemStack(), new Object[]{"# #", "# #", '#', - ForestryItem.craftingMaterial.getItemStack(1, 3)}); + Proxies.common.addRecipe(ForestryItem.apiaristHat.getItemStack(), + "###", "# #", + '#', ForestryItem.craftingMaterial.getItemStack(1, 3)); + Proxies.common.addRecipe(ForestryItem.apiaristChest.getItemStack(), + "# #", "###", "###", + '#', ForestryItem.craftingMaterial.getItemStack(1, 3)); + Proxies.common.addRecipe(ForestryItem.apiaristLegs.getItemStack(), + "###", "# #", "# #", + '#', ForestryItem.craftingMaterial.getItemStack(1, 3)); + Proxies.common.addRecipe(ForestryItem.apiaristBoots.getItemStack(), + "# #", "# #", + '#', ForestryItem.craftingMaterial.getItemStack(1, 3)); // / HABITAT LOCATOR //Proxies.common.addRecipe(ForestryItem.biomeFinder.getItemStack(), @@ -501,17 +505,17 @@ public class PluginApiculture extends ForestryPlugin { 'S', Items.string); // FOOD STUFF - if (ForestryItem.honeyedSlice != null) + if (ForestryItem.honeyedSlice.item() != null) Proxies.common.addRecipe(ForestryItem.honeyedSlice.getItemStack(4), "###", "#X#", "###", '#', ForestryItem.honeyDrop, 'X', Items.bread); - if (ForestryItem.honeyPot != null) + if (ForestryItem.honeyPot.item() != null) Proxies.common.addRecipe(ForestryItem.honeyPot.getItemStack(1), "# #", " X ", "# #", '#', ForestryItem.honeyDrop, 'X', ForestryItem.waxCapsule); - if (ForestryItem.ambrosia != null) + if (ForestryItem.ambrosia.item() != null) Proxies.common.addRecipe(ForestryItem.ambrosia.getItemStack(), "#Y#", "XXX", "###", '#', ForestryItem.honeydew, @@ -524,13 +528,18 @@ public class PluginApiculture extends ForestryPlugin { // / BITUMINOUS PEAT Proxies.common.addRecipe(ForestryItem.bituminousPeat.getItemStack(), - new Object[]{" # ", "XYX", " # ", '#', "dustAsh", 'X', ForestryItem.peat, 'Y', - ForestryItem.propolis}); + " # ", "XYX", " # ", + '#', "dustAsh", + 'X', ForestryItem.peat, + 'Y', ForestryItem.propolis); // / TORCHES Proxies.common.addRecipe(new ItemStack(Blocks.torch, 3), - new Object[]{" # ", " # ", " Y ", '#', ForestryItem.beeswax, 'Y', "stickWood"}); - Proxies.common.addRecipe(ForestryItem.craftingMaterial.getItemStack(1, 1), new Object[]{"# #", " # ", "# #", '#', - ForestryItem.propolis.getItemStack(1, 2)}); + " # ", " # ", " Y ", + '#', ForestryItem.beeswax, + 'Y', "stickWood"); + Proxies.common.addRecipe(ForestryItem.craftingMaterial.getItemStack(1, 1), + "# #", " # ", "# #", + '#', ForestryItem.propolis.getItemStack(1, 2)); // / CANDLES RecipeManagers.carpenterManager.addRecipe(30, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 600), null, ForestryBlock.candle.getItemStack(24), @@ -617,15 +626,17 @@ public class PluginApiculture extends ForestryPlugin { // / CARPENTER RecipeManagers.carpenterManager.addRecipe(100, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 2000), null, ForestryItem.beealyzer.getItemStack(), - new Object[]{"X#X", "X#X", "RDR", '#', Blocks.glass_pane, 'X', "ingotTin", 'R', - Items.redstone, 'D', Items.diamond}); - RecipeManagers.carpenterManager.addRecipe( - 50, - LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, 500), - null, - ForestryItem.craftingMaterial.getItemStack(1, 6), - new Object[]{" J ", "###", "WPW", '#', "plankWood", 'J', ForestryItem.royalJelly, - 'W', ForestryItem.beeswax, 'P', ForestryItem.pollen}); + "X#X", "X#X", "RDR", + '#', Blocks.glass_pane, + 'X', "ingotTin", + 'R', Items.redstone, + 'D', Items.diamond); + RecipeManagers.carpenterManager.addRecipe(50, LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, 500), null, ForestryItem.craftingMaterial.getItemStack(1, 6), + " J ", "###", "WPW", + '#', "plankWood", + 'J', ForestryItem.royalJelly, + 'W', ForestryItem.beeswax, + 'P', ForestryItem.pollen); // / CENTRIFUGE // Honey combs @@ -1207,7 +1218,7 @@ public class PluginApiculture extends ForestryPlugin { ((BlockCandle) ForestryBlock.candle.block()).addItemToLightingList(value.getItem()); else Logger.getLogger("Forestry").log(Level.WARNING, - "Recieved an invalid 'add-candle-lighting-id' request from mod %s. Please contact the author and report this issue.", + "Received an invalid 'add-candle-lighting-id' request from mod %s. Please contact the author and report this issue.", message.getSender()); return true; } else if (message.key.equals("add-alveary-slab") && message.isStringMessage()) @@ -1216,11 +1227,14 @@ public class PluginApiculture extends ForestryPlugin { if (block == null || block == Blocks.air) Logger.getLogger("Forestry").log(Level.WARNING, - "Recieved an invalid 'add-alveary-slab' request from mod %s. Please contact the author and report this issue.", + "Received an invalid 'add-alveary-slab' request from mod %s. Please contact the author and report this issue.", message.getSender()); else StructureLogicAlveary.slabBlocks.add(block); } catch (Exception e) { + Logger.getLogger("Forestry").log(Level.WARNING, + "Received an invalid 'add-alveary-slab' request from mod %s. Please contact the author and report this issue.", + message.getSender()); } return super.processIMCMessage(message); } From b2feb8b4c4f631d12595139dd1f4101962b66d31 Mon Sep 17 00:00:00 2001 From: mezz Date: Thu, 25 Sep 2014 02:14:02 -0700 Subject: [PATCH 5/6] #216 Add 3D leaf item rendering, allow shearing, allow creative access --- .../gadgets/ForestryBlockLeaves.java | 74 ++++++-- .../arboriculture/gadgets/TileLeaves.java | 11 +- .../arboriculture/genetics/TreeHelper.java | 11 +- .../arboriculture/items/ItemLeavesBlock.java | 20 ++- .../proxy/ClientProxyArboriculture.java | 1 + .../render/LeavesRenderingHandler.java | 166 +++++++++++++++++- .../forestry/core/render/TextureManager.java | 2 + 7 files changed, 251 insertions(+), 34 deletions(-) diff --git a/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java b/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java index d3676da71..2ae803b07 100644 --- a/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java +++ b/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java @@ -17,6 +17,7 @@ import net.minecraft.block.BlockNewLeaf; import net.minecraft.block.ITileEntityProvider; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -65,41 +66,68 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv return (TileLeaves) tile; } + private static NBTTagCompound getTagCompoundForTree(IBlockAccess world, int x, int y, int z) { + TileLeaves leaves = getLeafTile(world, x, y, z); + ITree tree = leaves.getTree(); + + NBTTagCompound nbttagcompound = new NBTTagCompound(); + if (tree == null) + return nbttagcompound; + + tree.writeToNBT(nbttagcompound); + return nbttagcompound; + } + @SideOnly(Side.CLIENT) @Override public void getSubBlocks(Item item, CreativeTabs tab, List list) { - list.add(new ItemStack(item, 1, 0)); + + for (ITree tree : PluginArboriculture.treeInterface.getIndividualTemplates()) { + NBTTagCompound treeNBT = new NBTTagCompound(); + tree.writeToNBT(treeNBT); + + ItemStack itemStack = new ItemStack(item, 1, 0); + itemStack.setTagCompound(treeNBT); + + list.add(itemStack); + } } /* DROP HANDLING */ + // Hack: When harvesting leaves we need to get the drops in onBlockHarvested, + // because Mojang destroys the block and tile before calling getDrops. + protected ThreadLocal> drops = new ThreadLocal>(); + @Override - public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { - + public void onBlockHarvested(World world, int x, int y, int z, int metadata, EntityPlayer player) { + int fortune = EnchantmentHelper.getFortuneModifier(player); float saplingModifier = 1.0f; - int count = quantityDropped(metadata, fortune, world.rand); if (Proxies.common.isSimulating(world)) { - EntityPlayer player = harvesters.get(); if (player != null) { ItemStack held = player.inventory.getCurrentItem(); if (held != null && held.getItem() instanceof IToolGrafter) { saplingModifier = ((IToolGrafter) held.getItem()).getSaplingModifier(held, world, player, x, y, z); - count = 1; held.damageItem(1, player); if (held.stackSize <= 0) player.destroyCurrentEquippedItem(); } } } - - ArrayList ret = new ArrayList(); - - for(int i = 0; i < count; i++) { - ret.addAll(getLeafDrop(world, x, y, z, saplingModifier, fortune)); - } - return ret; + drops.set(getLeafDrop(world, x, y, z, saplingModifier, fortune)); } + @Override + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + ArrayList ret = drops.get(); + drops.remove(); + + // leaves not harvested, get drops normally + if (ret == null) + ret = getLeafDrop(world, x, y, z, 1.0f, fortune); + + return ret; + } private ArrayList getLeafDrop(World world, int x, int y, int z, float saplingModifier, int fortune) { ArrayList prod = new ArrayList(); @@ -127,19 +155,27 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv @Override public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { - TileLeaves leaves = getLeafTile(world, x, y, z); - ITree tree = leaves.getTree(); - NBTTagCompound nbttagcompound = new NBTTagCompound(); - tree.writeToNBT(nbttagcompound); ItemStack itemStack = super.getPickBlock(target, world, x, y, z); - itemStack.setTagCompound(nbttagcompound); + NBTTagCompound treeNBT = getTagCompoundForTree(world, x, y, z); + itemStack.setTagCompound(treeNBT); return itemStack; } @Override public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z) { - return false; + return true; + } + + @Override + public ArrayList onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune) { + ArrayList ret = super.onSheared(item, world, x, y, z, fortune); + + NBTTagCompound treeNBT = getTagCompoundForTree(world, x, y, z); + for (ItemStack stack : ret) + stack.setTagCompound(treeNBT); + + return ret; } /* RENDERING */ diff --git a/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java b/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java index 274768b67..28c69d8f4 100755 --- a/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java @@ -151,9 +151,16 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru @Override public void setTree(ITree tree) { + super.setTree(tree); + if (tree.canBearFruit()) isFruitLeaf = tree.getGenome().getFruitProvider().markAsFruitLeaf(tree.getGenome(), worldObj, xCoord, yCoord, zCoord); - super.setTree(tree); + + textureIndexFancy = determineTextureIndex(true); + textureIndexPlain = determineTextureIndex(false); + textureIndexFruits = determineOverlayIndex(); + colourLeaves = determineFoliageColour(); + colourFruits = determineFruitColour(); } /* INFORMATION */ @@ -316,6 +323,8 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru **/ @Override public boolean shouldRefresh(Block oldBlock, Block newBlock, int oldMeta, int newMeta, World world, int x, int y, int z) { + if (!Block.isEqualTo(oldBlock, newBlock)) + return true; return false; } diff --git a/src/main/java/forestry/arboriculture/genetics/TreeHelper.java b/src/main/java/forestry/arboriculture/genetics/TreeHelper.java index 108801145..a6f022ff0 100755 --- a/src/main/java/forestry/arboriculture/genetics/TreeHelper.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeHelper.java @@ -208,17 +208,18 @@ public class TreeHelper extends SpeciesRoot implements ITreeRoot { if (!ForestryBlock.leaves.isBlockEqual(world, x, y, z)) return false; + TileLeaves tileLeaves = new TileLeaves(); + tileLeaves.setTree((ITree) tree.copy()); + tileLeaves.setOwner(owner); + + world.setTileEntity(x, y, z, tileLeaves); + TileEntity tile = world.getTileEntity(x, y, z); if (!(tile instanceof TileLeaves)) { world.setBlockToAir(x, y, z); return false; } - TileLeaves leaves = (TileLeaves) tile; - leaves.setTree((ITree) tree.copy()); - leaves.setOwner(owner); - world.markBlockForUpdate(x, y, z); - return true; } diff --git a/src/main/java/forestry/arboriculture/items/ItemLeavesBlock.java b/src/main/java/forestry/arboriculture/items/ItemLeavesBlock.java index da1cda956..d084da058 100644 --- a/src/main/java/forestry/arboriculture/items/ItemLeavesBlock.java +++ b/src/main/java/forestry/arboriculture/items/ItemLeavesBlock.java @@ -1,13 +1,16 @@ package forestry.arboriculture.items; +import com.mojang.authlib.GameProfile; import forestry.api.arboriculture.ITree; import forestry.arboriculture.genetics.Tree; import forestry.core.items.ItemForestryBlock; import forestry.core.utils.StringUtil; - +import forestry.plugins.PluginArboriculture; import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; +import net.minecraft.world.World; public class ItemLeavesBlock extends ItemForestryBlock { @@ -32,7 +35,11 @@ public class ItemLeavesBlock extends ItemForestryBlock { @Override public int getColorFromItemStack(ItemStack itemstack, int renderPass) { + if (!itemstack.hasTagCompound()) + return PluginArboriculture.proxy.getFoliageColorBasic(); ITree tree = getTree(itemstack); + if (tree == null) + return PluginArboriculture.proxy.getFoliageColorBasic(); return tree.getGenome().getPrimary().getLeafColour(tree); } @@ -40,4 +47,15 @@ public class ItemLeavesBlock extends ItemForestryBlock { return new Tree(itemStack.getTagCompound()); } + @Override + public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) { + if (!stack.hasTagCompound()) + return false; + ITree tree = getTree(stack); + if (tree == null) + return false; + GameProfile owner = player.getGameProfile(); + return PluginArboriculture.treeInterface.setLeaves(world, tree, owner, x, y, z); + } + } diff --git a/src/main/java/forestry/arboriculture/proxy/ClientProxyArboriculture.java b/src/main/java/forestry/arboriculture/proxy/ClientProxyArboriculture.java index 32a7954b9..1f3e27e96 100755 --- a/src/main/java/forestry/arboriculture/proxy/ClientProxyArboriculture.java +++ b/src/main/java/forestry/arboriculture/proxy/ClientProxyArboriculture.java @@ -39,6 +39,7 @@ public class ClientProxyArboriculture extends ProxyArboriculture { RenderingRegistry.registerBlockHandler(new FruitPodRenderingHandler()); MinecraftForgeClient.registerItemRenderer(ForestryBlock.stairs.item(), new StairItemRenderer()); + MinecraftForgeClient.registerItemRenderer(ForestryBlock.leaves.item(), new LeavesRenderingHandler()); } @Override diff --git a/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java b/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java index 6b049b1b3..e38de24d0 100755 --- a/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java +++ b/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java @@ -10,34 +10,46 @@ ******************************************************************************/ package forestry.arboriculture.render; +import forestry.api.arboriculture.ITree; +import forestry.arboriculture.gadgets.ForestryBlockLeaves; +import forestry.arboriculture.gadgets.TileLeaves; +import forestry.arboriculture.genetics.Tree; +import forestry.arboriculture.items.ItemLeavesBlock; +import forestry.core.proxy.Proxies; +import forestry.core.render.OverlayRenderingHandler; +import forestry.core.utils.StackUtils; +import forestry.plugins.PluginArboriculture; import net.minecraft.block.Block; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; - -import forestry.arboriculture.gadgets.ForestryBlockLeaves; -import forestry.arboriculture.gadgets.TileLeaves; -import forestry.core.render.OverlayRenderingHandler; -import forestry.plugins.PluginArboriculture; +import net.minecraftforge.client.IItemRenderer; +import org.lwjgl.opengl.GL11; /** * Ugly but serviceable renderer for leaves, taking fruits into account. */ -public class LeavesRenderingHandler extends OverlayRenderingHandler { +public class LeavesRenderingHandler extends OverlayRenderingHandler implements IItemRenderer { @Override public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { + // see IItemRenderer section below for inventory rendering } @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { + TileLeaves tile = ForestryBlockLeaves.getLeafTile(world, x, y, z); + if (tile == null || tile.getTree() == null) + return false; + // Render the plain leaf block. renderer.renderStandardBlock(block, x, y, z); // Render overlay for fruit leaves. - TileLeaves tile = ForestryBlockLeaves.getLeafTile(world, x, y, z); IIcon fruitIcon = null; int fruitColor = 0xffffff; if (tile != null) { @@ -53,7 +65,7 @@ public class LeavesRenderingHandler extends OverlayRenderingHandler { @Override public boolean shouldRender3DInInventory(int modelId) { - return false; + return true; } @Override @@ -96,4 +108,142 @@ public class LeavesRenderingHandler extends OverlayRenderingHandler { return true; } + /* IItemRenderer */ + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) { + switch (type) { + case ENTITY: + case EQUIPPED_FIRST_PERSON: + case EQUIPPED: + case INVENTORY: + return true; + default: + return false; + } + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { + return true; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + switch (type) { + case ENTITY: + renderLeafBlock((RenderBlocks) data[0], item, -0.5f, -0.5f, -0.5f); + break; + case EQUIPPED: + case EQUIPPED_FIRST_PERSON: + renderLeafBlock((RenderBlocks) data[0], item, 0f, 0.0f, 0.0f); + break; + case INVENTORY: + renderLeafBlock((RenderBlocks) data[0], item, -0.5f, -0.5f, -0.5f); + break; + default: + } + } + + private ITree getTree(ItemStack itemStack) { + return new Tree(itemStack.getTagCompound()); + } + + private void renderLeafBlock(RenderBlocks renderer, ItemStack itemStack, float x, float y, float z) { + Tessellator tessellator = Tessellator.instance; + Block block = StackUtils.getBlock(itemStack); + + if (!(itemStack.getItem() instanceof ItemLeavesBlock) || !itemStack.hasTagCompound()) + return; + + ITree tree = getTree(itemStack); + if (tree == null) + return; + + TileLeaves leaves = new TileLeaves(); + leaves.setTree(tree); + + IIcon leavesIcon = leaves.getIcon(Proxies.render.fancyGraphicsEnabled()); + int color = leaves.determineFoliageColour(); + + float r1 = (float)(color >> 16 & 255) / 255.0F; + float g1 = (float)(color >> 8 & 255) / 255.0F; + float b1 = (float)(color & 255) / 255.0F; + GL11.glColor4f(r1, g1, b1, 1.0F); + + block.setBlockBoundsForItemRender(); + renderer.setRenderBoundsFromBlock(block); + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, leavesIcon); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, leavesIcon); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, leavesIcon); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, leavesIcon); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, leavesIcon); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, leavesIcon); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + + + // add fruit + if (!leaves.hasFruit()) + return; + + leaves.addRipeness(20); + int fruitColor = leaves.determineFruitColour(); + IIcon fruitTexture = leaves.getFruitTexture(); + if (fruitTexture == null) + return; + + float r2 = (float)(fruitColor >> 16 & 255) / 255.0F; + float g2 = (float)(fruitColor >> 8 & 255) / 255.0F; + float b2 = (float)(fruitColor & 255) / 255.0F; + GL11.glColor4f(r2, g2, b2, 1.0F); + + block.setBlockBoundsForItemRender(); + renderer.setRenderBoundsFromBlock(block); + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + renderer.renderFaceYNeg(block, 0.0D, 0.0D - OVERLAY_SHIFT, 0.0D, fruitTexture); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + renderer.renderFaceYPos(block, 0.0D, 0.0D + OVERLAY_SHIFT, 0.0D, fruitTexture); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D - OVERLAY_SHIFT, fruitTexture); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D + OVERLAY_SHIFT, fruitTexture); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + renderer.renderFaceXNeg(block, 0.0D - OVERLAY_SHIFT, 0.0D, 0.0D, fruitTexture); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + renderer.renderFaceXPos(block, 0.0D + OVERLAY_SHIFT, 0.0D, 0.0D, fruitTexture); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } } diff --git a/src/main/java/forestry/core/render/TextureManager.java b/src/main/java/forestry/core/render/TextureManager.java index 00c042e69..35ee497b1 100755 --- a/src/main/java/forestry/core/render/TextureManager.java +++ b/src/main/java/forestry/core/render/TextureManager.java @@ -92,6 +92,8 @@ public class TextureManager implements ITextureManager { @Override public IIcon getIcon(short texUID) { + if (texUID < 0) + return null; if (texUID < textures.length) return textures[texUID]; From 6c6cce6957912f99848a67f368e31de4b97664b7 Mon Sep 17 00:00:00 2001 From: mezz Date: Thu, 25 Sep 2014 02:43:33 -0700 Subject: [PATCH 6/6] Fix #229 Server crash when opening mailtrader GUI --- src/main/java/forestry/mail/gui/ContainerTrader.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/forestry/mail/gui/ContainerTrader.java b/src/main/java/forestry/mail/gui/ContainerTrader.java index ea85064cb..a3eff9604 100755 --- a/src/main/java/forestry/mail/gui/ContainerTrader.java +++ b/src/main/java/forestry/mail/gui/ContainerTrader.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.mail.gui; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; @@ -78,4 +79,8 @@ public class ContainerTrader extends ContainerForestry { return machine.getAddress(); } + @Override + public boolean canInteractWith(EntityPlayer entityplayer) { + return true; + } }