diff --git a/.gitignore b/.gitignore index 32258774f..a0abcab4a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ !/build.gradle !/build.xml !/gradlew -!/gradlew.bat \ No newline at end of file +!/gradlew.bat +.DS_Store diff --git a/src/main/java/forestry/core/gadgets/BlockBase.java b/src/main/java/forestry/core/gadgets/BlockBase.java index 8e5c47f6d..3fee9ff6f 100755 --- a/src/main/java/forestry/core/gadgets/BlockBase.java +++ b/src/main/java/forestry/core/gadgets/BlockBase.java @@ -24,6 +24,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; @@ -101,6 +102,25 @@ public class BlockBase extends BlockForestry { return definitions.get(metadata); } + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { + MachineDefinition definition = definitions.get(world.getBlockMetadata(x, y, z)); + if (definition == null) { + return super.getCollisionBoundingBoxFromPool(world, x, y, z); + } + return definition.getBoundingBox(x, y, z); + } + + @Override + @SideOnly(Side.CLIENT) + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { + MachineDefinition definition = definitions.get(world.getBlockMetadata(x, y, z)); + if (definition == null) { + return super.getCollisionBoundingBoxFromPool(world, x, y, z); + } + return definition.getBoundingBox(x, y, z); + } + /* CREATIVE INVENTORY */ @SuppressWarnings("rawtypes") @SideOnly(Side.CLIENT) diff --git a/src/main/java/forestry/core/gadgets/MachineDefinition.java b/src/main/java/forestry/core/gadgets/MachineDefinition.java index 26a0b18f9..2d7107608 100755 --- a/src/main/java/forestry/core/gadgets/MachineDefinition.java +++ b/src/main/java/forestry/core/gadgets/MachineDefinition.java @@ -22,6 +22,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -35,7 +36,6 @@ import cpw.mods.fml.relauncher.SideOnly; import forestry.core.interfaces.IBlockRenderer; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; -import forestry.core.render.TileRendererIndex; public class MachineDefinition { @@ -46,6 +46,8 @@ public class MachineDefinition { private final int meta; public final IBlockRenderer renderer; + + private float minX, minY, minZ, maxX, maxY, maxZ; /* CRAFTING */ public IRecipe[] recipes; @@ -67,6 +69,12 @@ public class MachineDefinition { faceMap[i] = 0; } + minX = 0; + minY = 0; + minZ = 0; + maxX = 1; + maxY = 1; + maxZ = 1; } public Block getBlock() { @@ -80,6 +88,16 @@ public class MachineDefinition { public void setBlock(Block block) { this.block = block; } + + public MachineDefinition setBoundingBox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) { + this.minX = minX; + this.minY = minY; + this.minZ = minZ; + this.maxX = maxX; + this.maxY = maxY; + this.maxZ = maxZ; + return this; + } public void register() { registerTileEntity(); @@ -97,6 +115,10 @@ public class MachineDefinition { } } } + + public AxisAlignedBB getBoundingBox(int x, int y, int z) { + return AxisAlignedBB.getBoundingBox(x + minX, y + minY, z + minZ, x + maxX, y + maxY, z + maxZ); + } /** * Registers the tile entity with MC. diff --git a/src/main/java/forestry/core/gadgets/TileNaturalistChest.java b/src/main/java/forestry/core/gadgets/TileNaturalistChest.java index e284d6f0b..ff084eb72 100755 --- a/src/main/java/forestry/core/gadgets/TileNaturalistChest.java +++ b/src/main/java/forestry/core/gadgets/TileNaturalistChest.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.core.gadgets; +import java.io.IOException; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -19,9 +21,15 @@ import forestry.core.GuiHandler; import forestry.core.config.Config; import forestry.core.gui.IPagedInventory; import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; public abstract class TileNaturalistChest extends TileBase implements IPagedInventory { private final int guiID; + public float lidAngle; + public float prevLidAngle; + private int numPlayersUsing; + private static float lidAngleVariationPerTick = 0.1F; public TileNaturalistChest(ISpeciesRoot speciesRoot, int guiId) { setInternalInventory(new NaturalistInventoryAdapter(this, speciesRoot)); @@ -29,6 +37,44 @@ public abstract class TileNaturalistChest extends TileBase implements IPagedInve this.guiID = guiId; } + @Override + protected void updateClientSide() { + update(); + } + + @Override + protected void updateServerSide() { + update(); + } + + private void update() { + prevLidAngle = lidAngle; + + if (numPlayersUsing > 0 && lidAngle == 0.0F) { + playLidSound("random.chestopen"); + } + + if (numPlayersUsing == 0 && lidAngle > 0.0F || numPlayersUsing > 0 && lidAngle < 1.0F) { + float oldAngle = lidAngle; + + if (numPlayersUsing > 0) { + lidAngle += lidAngleVariationPerTick; + } else { + lidAngle -= lidAngleVariationPerTick; + } + + lidAngle = Math.max(Math.min(lidAngle, 1), 0); + + if (lidAngle < 0.5F && oldAngle >= 0.5F) { + playLidSound("random.chestclosed"); + } + } + } + + private void playLidSound(String sound) { + worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, sound, 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); + } + @Override public void openGui(EntityPlayer player) { player.openGui(ForestryAPI.instance, guiID, player.worldObj, xCoord, yCoord, zCoord); @@ -39,6 +85,18 @@ public abstract class TileNaturalistChest extends TileBase implements IPagedInve player.openGui(ForestryAPI.instance, GuiHandler.encodeGuiData(guiID, page), player.worldObj, xCoord, yCoord, zCoord); } + @Override + public void writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + data.writeInt(numPlayersUsing); + } + + @Override + public void readData(DataInputStreamForestry data) throws IOException { + super.readData(data); + numPlayersUsing = data.readInt(); + } + private static class NaturalistInventoryAdapter extends TileInventoryAdapter { private final ISpeciesRoot speciesRoot; @@ -56,5 +114,20 @@ public abstract class TileNaturalistChest extends TileBase implements IPagedInve public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { return true; } + + @Override + public void openInventory() { + tile.numPlayersUsing++; + tile.setNeedsNetworkUpdate(); + } + + @Override + public void closeInventory() { + tile.numPlayersUsing--; + if (tile.numPlayersUsing < 0) { + tile.numPlayersUsing = 0; + } + tile.setNeedsNetworkUpdate(); + } } } diff --git a/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java b/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java index 69b42038c..2c1134918 100755 --- a/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java +++ b/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java @@ -21,6 +21,7 @@ public class ContainerNaturalistInventory extends ContainerTile defaultPlantableFlowers = new HashMap(); @Override - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"unchecked"}) protected void setupAPI() { super.setupAPI(); @@ -208,7 +209,7 @@ public class PluginApiculture extends ForestryPlugin { MinecraftForge.EVENT_BUS.register(this); - ForestryBlock.apiculture.registerBlock(new BlockBase(Material.iron), ItemForestryBlock.class, "apiculture"); + ForestryBlock.apiculture.registerBlock(new BlockBase(Material.iron, true), ItemForestryBlock.class, "apiculture"); ForestryBlock.apiculture.block().setCreativeTab(Tabs.tabApiculture); ForestryBlock.apiculture.block().setHarvestLevel("axe", 0); @@ -222,7 +223,7 @@ public class PluginApiculture extends ForestryPlugin { 'C', ForestryItem.impregnatedCasing)) .setFaces(0, 1, 2, 2, 4, 4, 0, 7)); - definitionChest = ((BlockBase) ForestryBlock.apiculture.block()).addDefinition(new MachineDefinition(Defaults.DEFINITION_APIARISTCHEST_META, "forestry.ApiaristChest", TileApiaristChest.class, + definitionChest = ((BlockBase) ForestryBlock.apiculture.block()).addDefinition(new MachineDefinition(Defaults.DEFINITION_APIARISTCHEST_META, "forestry.ApiaristChest", TileApiaristChest.class, new RenderNaturalistChest("apiaristchest"), ShapedRecipeCustom.createShapedRecipe(ForestryBlock.apiculture.getItemStack(1, Defaults.DEFINITION_APIARISTCHEST_META), " # ", "XYX", @@ -230,7 +231,7 @@ public class PluginApiculture extends ForestryPlugin { '#', "blockGlass", 'X', "beeComb", 'Y', "chestWood")) - .setFaces(0, 1, 2, 3, 4, 4)); + .setBoundingBox(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F)); definitionBeehouse = ((BlockBase) ForestryBlock.apiculture.block()).addDefinition(new MachineDefinition(Defaults.DEFINITION_BEEHOUSE_META, "forestry.Beehouse", TileBeehouse.class, ShapedRecipeCustom.createShapedRecipe(ForestryBlock.apiculture.getItemStack(1, Defaults.DEFINITION_BEEHOUSE_META), diff --git a/src/main/java/forestry/plugins/PluginArboriculture.java b/src/main/java/forestry/plugins/PluginArboriculture.java index 3f9d2bd6a..33e2a7426 100644 --- a/src/main/java/forestry/plugins/PluginArboriculture.java +++ b/src/main/java/forestry/plugins/PluginArboriculture.java @@ -92,6 +92,7 @@ import forestry.core.items.ItemForestryBlock; import forestry.core.items.ItemFruit.EnumFruit; import forestry.core.network.IPacketHandler; import forestry.core.proxy.Proxies; +import forestry.core.render.RenderNaturalistChest; import forestry.core.utils.RecipeUtil; import forestry.core.utils.ShapedRecipeCustom; import forestry.core.utils.ShapelessRecipeCustom; @@ -183,11 +184,11 @@ public class PluginArboriculture extends ForestryPlugin { ForestryBlock.pods.registerBlock(new BlockFruitPod(), ItemForestryBlock.class, "pods"); // Machines - ForestryBlock.arboriculture.registerBlock(new BlockBase(Material.iron), ItemForestryBlock.class, "arboriculture"); + ForestryBlock.arboriculture.registerBlock(new BlockBase(Material.iron, true), ItemForestryBlock.class, "arboriculture"); ForestryBlock.arboriculture.block().setCreativeTab(Tabs.tabArboriculture); definitionChest = ((BlockBase) ForestryBlock.arboriculture.block()).addDefinition(new MachineDefinition(Defaults.DEFINITION_ARBCHEST_META, - "forestry.ArbChest", TileArboristChest.class, + "forestry.ArbChest", TileArboristChest.class, new RenderNaturalistChest("arbchest"), ShapedRecipeCustom.createShapedRecipe(ForestryBlock.arboriculture.getItemStack(1, Defaults.DEFINITION_ARBCHEST_META), " # ", "XYX", @@ -195,7 +196,7 @@ public class PluginArboriculture extends ForestryPlugin { '#', "blockGlass", 'X', "treeSapling", 'Y', "chestWood")) - .setFaces(0, 1, 2, 3, 4, 4, 0, 7)); + .setBoundingBox(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F)); // Init rendering proxy.initializeRendering(); diff --git a/src/main/java/forestry/plugins/PluginLepidopterology.java b/src/main/java/forestry/plugins/PluginLepidopterology.java index 83929b2f6..3fca030fe 100755 --- a/src/main/java/forestry/plugins/PluginLepidopterology.java +++ b/src/main/java/forestry/plugins/PluginLepidopterology.java @@ -15,8 +15,6 @@ import java.util.EnumSet; import java.util.Locale; import net.minecraft.block.material.Material; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.item.crafting.CraftingManager; import net.minecraftforge.oredict.RecipeSorter; @@ -46,6 +44,7 @@ import forestry.core.genetics.Branch; import forestry.core.genetics.alleles.Allele; import forestry.core.items.ItemForestryBlock; import forestry.core.proxy.Proxies; +import forestry.core.render.RenderNaturalistChest; import forestry.core.utils.ShapedRecipeCustom; import forestry.core.utils.Utils; import forestry.lepidopterology.ButterflySpawner; @@ -85,7 +84,7 @@ public class PluginLepidopterology extends ForestryPlugin { @Override public void preInit() { - ForestryBlock.lepidopterology.registerBlock(new BlockBase(Material.iron), ItemForestryBlock.class, "lepidopterology"); + ForestryBlock.lepidopterology.registerBlock(new BlockBase(Material.iron, true), ItemForestryBlock.class, "lepidopterology"); ForestryBlock.lepidopterology.block().setCreativeTab(Tabs.tabLepidopterology); createAlleles(); @@ -125,7 +124,7 @@ public class PluginLepidopterology extends ForestryPlugin { registerTemplates(); BlockBase lepidopterology = ((BlockBase) ForestryBlock.lepidopterology.block()); - MachineDefinition definitionChest = lepidopterology.addDefinition((new MachineDefinition(Defaults.DEFINITION_LEPICHEST_META, "forestry.LepiChest", TileLepidopteristChest.class, + MachineDefinition definitionChest = lepidopterology.addDefinition(new MachineDefinition(Defaults.DEFINITION_LEPICHEST_META, "forestry.LepiChest", TileLepidopteristChest.class, new RenderNaturalistChest("lepichest"), ShapedRecipeCustom.createShapedRecipe( ForestryBlock.lepidopterology.getItemStack(1, Defaults.DEFINITION_LEPICHEST_META), " # ", @@ -134,7 +133,7 @@ public class PluginLepidopterology extends ForestryPlugin { '#', "blockGlass", 'X', ForestryItem.butterflyGE.getItemStack(1, Defaults.WILDCARD), 'Y', "chestWood")) - .setFaces(0, 1, 2, 3, 4, 4, 0, 7))); + .setBoundingBox(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F)); definitionChest.register(); ((ITreeRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees")).registerLeafTickHandler(new ButterflySpawner()); diff --git a/src/main/resources/assets/forestry/textures/blocks/apiaristchest.1.png b/src/main/resources/assets/forestry/textures/blocks/apiaristchest.1.png deleted file mode 100755 index 9f19f52e1..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/apiaristchest.1.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/apiaristchest.2.png b/src/main/resources/assets/forestry/textures/blocks/apiaristchest.2.png deleted file mode 100755 index 1ed13f0f8..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/apiaristchest.2.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/apiaristchest.3.png b/src/main/resources/assets/forestry/textures/blocks/apiaristchest.3.png deleted file mode 100755 index b36e50a6f..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/apiaristchest.3.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/apiaristchest.4.png b/src/main/resources/assets/forestry/textures/blocks/apiaristchest.4.png deleted file mode 100755 index 1ed13f0f8..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/apiaristchest.4.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/apiaristchest.png b/src/main/resources/assets/forestry/textures/blocks/apiaristchest.png new file mode 100644 index 000000000..9cfeadb3f Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/apiaristchest.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/arbchest.1.png b/src/main/resources/assets/forestry/textures/blocks/arbchest.1.png deleted file mode 100755 index a19bdb551..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/arbchest.1.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/arbchest.2.png b/src/main/resources/assets/forestry/textures/blocks/arbchest.2.png deleted file mode 100755 index 7c6bbfb6b..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/arbchest.2.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/arbchest.3.png b/src/main/resources/assets/forestry/textures/blocks/arbchest.3.png deleted file mode 100755 index c9c1b36e7..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/arbchest.3.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/arbchest.4.png b/src/main/resources/assets/forestry/textures/blocks/arbchest.4.png deleted file mode 100755 index 7c6bbfb6b..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/arbchest.4.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/arbchest.7.png b/src/main/resources/assets/forestry/textures/blocks/arbchest.7.png deleted file mode 100755 index 0a9d451d4..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/arbchest.7.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/arbchest.png b/src/main/resources/assets/forestry/textures/blocks/arbchest.png new file mode 100644 index 000000000..cda43debb Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/arbchest.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/lepichest.1.png b/src/main/resources/assets/forestry/textures/blocks/lepichest.1.png deleted file mode 100755 index fb503ed9b..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/lepichest.1.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/lepichest.2.png b/src/main/resources/assets/forestry/textures/blocks/lepichest.2.png deleted file mode 100755 index a749b0127..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/lepichest.2.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/lepichest.3.png b/src/main/resources/assets/forestry/textures/blocks/lepichest.3.png deleted file mode 100755 index d1082185a..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/lepichest.3.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/lepichest.4.png b/src/main/resources/assets/forestry/textures/blocks/lepichest.4.png deleted file mode 100755 index a749b0127..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/lepichest.4.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/lepichest.7.png b/src/main/resources/assets/forestry/textures/blocks/lepichest.7.png deleted file mode 100755 index ec8aa3c97..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/lepichest.7.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/lepichest.png b/src/main/resources/assets/forestry/textures/blocks/lepichest.png new file mode 100644 index 000000000..c5dfc0988 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/lepichest.png differ