From 42d80acb51eef333d2d58a437cfd691fb2ac923d Mon Sep 17 00:00:00 2001 From: mezz Date: Mon, 8 Sep 2014 23:32:39 -0700 Subject: [PATCH] Fixed Peat Bog and Humus texture issues Closes #174 --- lang | 2 +- .../java/forestry/core/gadgets/BlockSoil.java | 93 +++++++++++-------- .../forestry/core/items/ItemSoilBlock.java | 21 +++++ .../java/forestry/plugins/PluginCore.java | 3 +- 4 files changed, 76 insertions(+), 43 deletions(-) create mode 100644 src/main/java/forestry/core/items/ItemSoilBlock.java diff --git a/lang b/lang index 92402cb0d..1d9203714 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 92402cb0d104dd5cc25d7e720cb76487d1dc5953 +Subproject commit 1d9203714896d97a704dc36fbadc2a9196606045 diff --git a/src/main/java/forestry/core/gadgets/BlockSoil.java b/src/main/java/forestry/core/gadgets/BlockSoil.java index d475e9a55..0fba88efc 100755 --- a/src/main/java/forestry/core/gadgets/BlockSoil.java +++ b/src/main/java/forestry/core/gadgets/BlockSoil.java @@ -47,7 +47,11 @@ import forestry.core.render.TextureManager; */ public class BlockSoil extends Block { - private final int degradeDelimiter = 3; + public enum SoilType { + HUMUS, BOG_EARTH, PEAT; + } + + private static final int degradeDelimiter = 3; public BlockSoil() { super(Material.sand); @@ -66,16 +70,15 @@ public class BlockSoil extends Block { public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList ret = new ArrayList(); - int type = (metadata & 0x03); - int maturity = metadata >> 2; + SoilType type = getTypeFromMeta(metadata); - if (maturity >= this.degradeDelimiter && type == 1) { + if (type == SoilType.PEAT) { ret.add(ForestryItem.peat.getItemStack()); ret.add(new ItemStack(Blocks.dirt)); - } else if (type == 0) + } else if (type == SoilType.HUMUS) ret.add(new ItemStack(Blocks.dirt)); else - ret.add(new ItemStack(this, 1, type)); + ret.add(new ItemStack(this, 1, SoilType.BOG_EARTH.ordinal())); return ret; } @@ -91,14 +94,13 @@ public class BlockSoil extends Block { return; int meta = world.getBlockMetadata(i, j, k); - int type = (meta & 0x03); - if (type == 0) + SoilType type = getTypeFromMeta(meta); + + if (type == SoilType.HUMUS) updateTickHumus(world, i, j, k, random); - else if (type == 1) + else if (type == SoilType.BOG_EARTH) updateTickBogEarth(world, i, j, k, random); - else - Proxies.log.warning(this.getClass() + " with unknown type " + type + " encountered."); } private void updateTickHumus(World world, int i, int j, int k, Random random) { @@ -155,17 +157,17 @@ public class BlockSoil extends Block { int type = meta & 0x03; int grade = meta >> 2; - // Increment (de)gradation - grade++; + // Increment (de)gradation + grade++; - // Repackage in format TTGG - meta = (grade << 2 | type); + // Repackage in format TTGG + meta = (grade << 2 | type); - if (grade >= this.degradeDelimiter) - world.setBlock(i, j, k, Blocks.sand, 0, Defaults.FLAG_BLOCK_SYNCH); - else - world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); - world.markBlockForUpdate(i, j, k); + if (grade >= this.degradeDelimiter) + world.setBlock(i, j, k, Blocks.sand, 0, Defaults.FLAG_BLOCK_SYNCH); + else + world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); + world.markBlockForUpdate(i, j, k); } public static boolean isMoistened(World world, int x, int y, int z) { @@ -192,15 +194,15 @@ public class BlockSoil extends Block { int type = meta & 0x03; int maturity = meta >> 2; - if (maturity >= this.degradeDelimiter) - return; + if (maturity >= this.degradeDelimiter) + return; - // Increment (de)gradation - maturity++; + // Increment (de)gradation + maturity++; - meta = (maturity << 2 | type); - world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); - world.markBlockForUpdate(i, j, k); + meta = (maturity << 2 | type); + world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); + world.markBlockForUpdate(i, j, k); } @Override @@ -210,8 +212,9 @@ public class BlockSoil extends Block { return false; int meta = world.getBlockMetadata(x, y, z); + SoilType type = getTypeFromMeta(meta); - return (meta & 0x03) == 0; + return type == SoilType.HUMUS; } @Override @@ -219,6 +222,19 @@ public class BlockSoil extends Block { return false; } + public static SoilType getTypeFromMeta(int meta) { + int type = meta & 0x03; + int maturity = meta >> 2; + + if (type == 1) + if (maturity < degradeDelimiter) + return SoilType.BOG_EARTH; + else + return SoilType.PEAT; + else + return SoilType.HUMUS; + } + // / CREATIVE INVENTORY @SuppressWarnings({ "rawtypes", "unchecked" }) @Override @@ -245,21 +261,16 @@ public class BlockSoil extends Block { @Override @SideOnly(Side.CLIENT) - public IIcon getIcon(int i, int j) { + public IIcon getIcon(int side, int meta) { - int meta = j; - int type = meta & 0x0f; - int maturity = meta >> 2; + SoilType type = getTypeFromMeta(meta); - if (type == 1) - if (maturity < this.degradeDelimiter) - return iconBogEarth; - else - return iconPeat; - else if (type == 0) - return iconHumus; - else - return null; + switch (type) { + case HUMUS: return iconHumus; + case BOG_EARTH: return iconBogEarth; + case PEAT: return iconPeat; + } + return null; } } diff --git a/src/main/java/forestry/core/items/ItemSoilBlock.java b/src/main/java/forestry/core/items/ItemSoilBlock.java new file mode 100644 index 000000000..e4f5f50d1 --- /dev/null +++ b/src/main/java/forestry/core/items/ItemSoilBlock.java @@ -0,0 +1,21 @@ +package forestry.core.items; + +import forestry.core.gadgets.BlockSoil; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +public class ItemSoilBlock extends ItemForestryBlock { + + public ItemSoilBlock(Block block) { + super(block); + } + + @Override + public String getUnlocalizedName(ItemStack itemstack) { + if (this.getBlock() instanceof BlockSoil) { + BlockSoil.SoilType soilType = BlockSoil.getTypeFromMeta(itemstack.getItemDamage()); + return getBlock().getUnlocalizedName() + "." + soilType.ordinal(); + } + return super.getUnlocalizedName(itemstack); + } +} diff --git a/src/main/java/forestry/plugins/PluginCore.java b/src/main/java/forestry/plugins/PluginCore.java index 6cf7a60a0..e48d8e6ac 100755 --- a/src/main/java/forestry/plugins/PluginCore.java +++ b/src/main/java/forestry/plugins/PluginCore.java @@ -64,6 +64,7 @@ import forestry.core.items.ItemAssemblyKit; import forestry.core.items.ItemCrated; import forestry.core.items.ItemForestry; import forestry.core.items.ItemForestryBlock; +import forestry.core.items.ItemSoilBlock; import forestry.core.items.ItemForestryPickaxe; import forestry.core.items.ItemForestryShovel; import forestry.core.items.ItemFruit; @@ -111,7 +112,7 @@ public class PluginCore extends NativePlugin implements IFuelHandler { definitionEscritoire = ((BlockBase) ForestryBlock.core.block()).addDefinition(new MachineDefinition(Defaults.DEFINITION_ESCRITOIRE_META, "forestry.Escritoire", TileEscritoire.class, Proxies.render.getRenderEscritoire())); - ForestryBlock.soil.registerBlock(new BlockSoil(), ItemForestryBlock.class, "soil"); + ForestryBlock.soil.registerBlock(new BlockSoil(), ItemSoilBlock.class, "soil"); ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 0); ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 1);