Fixed Peat Bog and Humus texture issues

Closes #174
This commit is contained in:
mezz committed 2014-09-08 23:32:39 -07:00
1 parent 476576ae55
commit 42d80acb51
4 files changed
+76 -43

No files matched your search

@@ -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<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
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;
}
}
@@ -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);
}
}
@@ -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);