Fixes #183. Give Saplings and Leaves species info for WAILA

This commit is contained in:
mezz committed 2014-09-15 16:44:49 -07:00
1 parent 5cf658fbe8
commit 69515d2f6b
8 files changed
+82 -12

No files matched your search

@@ -18,8 +18,10 @@ 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;
@@ -35,6 +37,8 @@ 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;
@@ -147,6 +151,20 @@ public class BlockLeaves extends BlockTreeContainer {
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() {
@@ -20,6 +20,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@@ -145,6 +146,12 @@ public class BlockSapling extends BlockTreeContainer {
return new ArrayList<ItemStack>();
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
TileSapling sapling = getSaplingTile(world, x, y, z);
return PluginArboriculture.treeInterface.getMemberStack(sapling.getTree(), EnumGermlingType.SAPLING.ordinal());
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
if (Proxies.common.isSimulating(world) && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
@@ -277,16 +277,16 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
/* NETWORK */
@Override
public Packet getDescriptionPacket() {
return new PacketLeafUpdate(xCoord, yCoord, zCoord, this).getPacket();
return new PacketLeafUpdate(this).getPacket();
}
@Override
public void sendNetworkUpdate() {
Proxies.net.sendNetworkPacket(new PacketLeafUpdate(xCoord, yCoord, zCoord, this), xCoord, yCoord, zCoord);
Proxies.net.sendNetworkPacket(new PacketLeafUpdate(this), xCoord, yCoord, zCoord);
}
private void sendNetworkUpdateRipening() {
Proxies.net.sendNetworkPacket(new PacketLeafUpdate(xCoord, yCoord, zCoord, determineFruitColour()), xCoord, yCoord, zCoord);
Proxies.net.sendNetworkPacket(new PacketLeafUpdate(this, determineFruitColour()), xCoord, yCoord, zCoord);
}
@Override
@@ -296,6 +296,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
if(packet.isRipeningUpdate()) {
colourFruits = packet.colourFruits;
} else {
readFromNBT(packet.getTagCompound());
isFruitLeaf = packet.isFruitLeaf();
isPollinatedState = packet.isPollinated();
textureIndexFancy = packet.textureIndexFancy;
@@ -0,0 +1,43 @@
package forestry.arboriculture.items;
import forestry.api.arboriculture.ITree;
import forestry.arboriculture.genetics.Tree;
import forestry.core.items.ItemForestryBlock;
import forestry.core.utils.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
public class ItemLeavesBlock extends ItemForestryBlock {
public ItemLeavesBlock(Block block) {
super(block);
}
@Override
public String getItemStackDisplayName(ItemStack itemstack) {
String type = StringUtil.localize("trees.grammar.leaves.type");
if (!itemstack.hasTagCompound())
return type;
ITree tree = getTree(itemstack);
String customTreeKey = "trees.custom.leaves." + tree.getGenome().getPrimary().getUnlocalizedName().replace("trees.species.","");
if(StatCollector.canTranslate("for." + customTreeKey)){
return StringUtil.localize(customTreeKey);
}
String grammar = StringUtil.localize("trees.grammar.leaves");
return grammar.replaceAll("%SPECIES", tree.getDisplayName()).replaceAll("%TYPE", type);
}
@Override
public int getColorFromItemStack(ItemStack itemstack, int renderPass) {
ITree tree = getTree(itemstack);
return tree.getGenome().getPrimary().getLeafColour(tree);
}
private ITree getTree(ItemStack itemStack) {
return new Tree(itemStack.getTagCompound());
}
}
@@ -15,10 +15,10 @@ import java.io.DataOutputStream;
import java.io.IOException;
import forestry.arboriculture.gadgets.TileLeaves;
import forestry.core.network.PacketCoordinates;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketTileNBT;
public class PacketLeafUpdate extends PacketCoordinates {
public class PacketLeafUpdate extends PacketTileNBT {
public byte isRipeningUpdate = 0;
@@ -33,8 +33,8 @@ public class PacketLeafUpdate extends PacketCoordinates {
public PacketLeafUpdate() {
}
public PacketLeafUpdate(int posX, int posY, int posZ, TileLeaves leaves) {
super(PacketIds.LEAF_UPDATE, posX, posY, posZ);
public PacketLeafUpdate(TileLeaves leaves) {
super(PacketIds.LEAF_UPDATE, leaves);
leafState = 0;
if(leaves.hasFruit())
@@ -48,8 +48,8 @@ public class PacketLeafUpdate extends PacketCoordinates {
colourFruits = leaves.determineFruitColour();
}
public PacketLeafUpdate(int posX, int posY, int posZ, int fruitColour) {
super(PacketIds.LEAF_UPDATE, posX, posY, posZ);
public PacketLeafUpdate(TileLeaves leaves, int fruitColour) {
super(PacketIds.LEAF_UPDATE, leaves);
isRipeningUpdate = 1;
colourFruits = fruitColour;
@@ -89,6 +89,7 @@ import forestry.arboriculture.genetics.TreeTemplates;
import forestry.arboriculture.genetics.TreekeepingMode;
import forestry.arboriculture.items.ItemGermlingGE;
import forestry.arboriculture.items.ItemGrafter;
import forestry.arboriculture.items.ItemLeavesBlock;
import forestry.arboriculture.items.ItemStairs;
import forestry.arboriculture.items.ItemTreealyzer;
import forestry.arboriculture.items.ItemWoodBlock;
@@ -233,7 +234,7 @@ public class PluginArboriculture extends NativePlugin implements IFuelHandler {
ForestryBlock.saplingGE.registerBlock(new BlockSapling(), ItemForestryBlock.class, "saplingGE");
// Leaves
ForestryBlock.leaves.registerBlock(new BlockLeaves(), ItemForestryBlock.class, "leaves");
ForestryBlock.leaves.registerBlock(new BlockLeaves(), ItemLeavesBlock.class, "leaves");
// Pods
ForestryBlock.pods.registerBlock(new BlockFruitPod(), ItemForestryBlock.class, "pods");