Support for facades with metadata >= 16 by using NBT
This commit is contained in:
parent
7a320cbba0
commit
8933df795a
3 changed files with 32 additions and 17 deletions
|
@ -12,6 +12,7 @@ import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
@ -43,8 +44,8 @@ public class ItemFacade extends ItemBuildCraft {
|
||||||
@Override
|
@Override
|
||||||
public String getItemDisplayName(ItemStack itemstack) {
|
public String getItemDisplayName(ItemStack itemstack) {
|
||||||
String name = super.getItemDisplayName(itemstack);
|
String name = super.getItemDisplayName(itemstack);
|
||||||
int decodedBlockId = ItemFacade.getBlockId(itemstack.getItemDamage());
|
int decodedBlockId = ItemFacade.getBlockId(itemstack);
|
||||||
int decodedMeta = ItemFacade.getMetaData(itemstack.getItemDamage());
|
int decodedMeta = ItemFacade.getMetaData(itemstack);
|
||||||
if (decodedBlockId < Block.blocksList.length && Block.blocksList[decodedBlockId] != null && Block.blocksList[decodedBlockId].getRenderType() == 31) {
|
if (decodedBlockId < Block.blocksList.length && Block.blocksList[decodedBlockId] != null && Block.blocksList[decodedBlockId].getRenderType() == 31) {
|
||||||
decodedMeta &= 0x3;
|
decodedMeta &= 0x3;
|
||||||
}
|
}
|
||||||
|
@ -87,8 +88,8 @@ public class ItemFacade extends ItemBuildCraft {
|
||||||
pipeTile.dropFacade(ForgeDirection.VALID_DIRECTIONS[side]);
|
pipeTile.dropFacade(ForgeDirection.VALID_DIRECTIONS[side]);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (((TileGenericPipe) tile).addFacade(ForgeDirection.values()[side], ItemFacade.getBlockId(stack.getItemDamage()),
|
if (((TileGenericPipe) tile).addFacade(ForgeDirection.values()[side], ItemFacade.getBlockId(stack),
|
||||||
ItemFacade.getMetaData(stack.getItemDamage()))) {
|
ItemFacade.getMetaData(stack))) {
|
||||||
if (!player.capabilities.isCreativeMode) {
|
if (!player.capabilities.isCreativeMode) {
|
||||||
stack.stackSize--;
|
stack.stackSize--;
|
||||||
}
|
}
|
||||||
|
@ -141,12 +142,14 @@ public class ItemFacade extends ItemBuildCraft {
|
||||||
return metaData & 0xF | ((blockId & 0xFFF) << 4);
|
return metaData & 0xF | ((blockId & 0xFFF) << 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMetaData(int encoded) {
|
public static int getMetaData(ItemStack stack) {
|
||||||
return encoded & 0x0000F;
|
if(stack.hasTagCompound() && stack.getTagCompound().hasKey("meta"))
|
||||||
|
return stack.getTagCompound().getInteger("meta");
|
||||||
|
return stack.getItemDamage() & 0x0000F;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getBlockId(int encoded) {
|
public static int getBlockId(ItemStack stack) {
|
||||||
return ((encoded & 0xFFF0) >>> 4);
|
return ((stack.getItemDamage() & 0xFFF0) >>> 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -156,19 +159,23 @@ public class ItemFacade extends ItemBuildCraft {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addFacade(ItemStack itemStack) {
|
public static void addFacade(ItemStack itemStack) {
|
||||||
allFacades.add(new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage())));
|
ItemStack facade = getStack(itemStack.itemID, itemStack.getItemDamage());
|
||||||
|
allFacades.add(facade);
|
||||||
|
|
||||||
|
ItemStack facade6 = facade.copy();
|
||||||
|
facade6.stackSize = 6;
|
||||||
|
|
||||||
// 3 Structurepipes + this block makes 6 facades
|
// 3 Structurepipes + this block makes 6 facades
|
||||||
AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] { new ItemStack(BuildCraftTransport.pipeStructureCobblestone, 3), itemStack },
|
AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] { new ItemStack(BuildCraftTransport.pipeStructureCobblestone, 3), itemStack },
|
||||||
8000, new ItemStack(BuildCraftTransport.facadeItem, 6, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage()))));
|
8000, facade6));
|
||||||
if (itemStack.itemID < Block.blocksList.length && Block.blocksList[itemStack.itemID] != null) {
|
if (itemStack.itemID < Block.blocksList.length && Block.blocksList[itemStack.itemID] != null) {
|
||||||
Block bl = Block.blocksList[itemStack.itemID];
|
Block bl = Block.blocksList[itemStack.itemID];
|
||||||
|
|
||||||
// Special handling for logs
|
// Special handling for logs
|
||||||
if (bl.getRenderType() == 31) {
|
if (bl.getRenderType() == 31) {
|
||||||
ItemStack mainLog = new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage()));
|
ItemStack mainLog = getStack(itemStack.itemID, itemStack.getItemDamage());
|
||||||
ItemStack rotLog1 = new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage() | 4));
|
ItemStack rotLog1 = getStack(itemStack.itemID, itemStack.getItemDamage() | 4);
|
||||||
ItemStack rotLog2 = new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage() | 8));
|
ItemStack rotLog2 = getStack(itemStack.itemID, itemStack.getItemDamage() | 8);
|
||||||
allFacades.add(rotLog1);
|
allFacades.add(rotLog1);
|
||||||
allFacades.add(rotLog2);
|
allFacades.add(rotLog2);
|
||||||
CoreProxy.proxy.addShapelessRecipe(rotLog1, new Object[] { mainLog });
|
CoreProxy.proxy.addShapelessRecipe(rotLog1, new Object[] { mainLog });
|
||||||
|
@ -191,4 +198,12 @@ public class ItemFacade extends ItemBuildCraft {
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ItemStack getStack(int blockID, int metadata) {
|
||||||
|
ItemStack stack = new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(blockID, 0));
|
||||||
|
NBTTagCompound nbt = new NBTTagCompound("tag");
|
||||||
|
nbt.setInteger("meta", metadata);
|
||||||
|
stack.setTagCompound(nbt);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -604,7 +604,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dropFacadeItem(ForgeDirection direction){
|
private void dropFacadeItem(ForgeDirection direction){
|
||||||
Utils.dropItems(worldObj, new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()])), this.xCoord, this.yCoord, this.zCoord);
|
Utils.dropItems(worldObj, ItemFacade.getStack(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()]), this.xCoord, this.yCoord, this.zCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropFacade(ForgeDirection direction) {
|
public void dropFacade(ForgeDirection direction) {
|
||||||
|
|
|
@ -18,8 +18,8 @@ public class FacadeItemRenderer implements IItemRenderer {
|
||||||
|
|
||||||
private void renderFacadeItem(RenderBlocks render, ItemStack item, float translateX, float translateY, float translateZ) {
|
private void renderFacadeItem(RenderBlocks render, ItemStack item, float translateX, float translateY, float translateZ) {
|
||||||
|
|
||||||
int decodedMeta = ItemFacade.getMetaData(item.getItemDamage());
|
int decodedMeta = ItemFacade.getMetaData(item);
|
||||||
int decodedBlockId = ItemFacade.getBlockId(item.getItemDamage());
|
int decodedBlockId = ItemFacade.getBlockId(item);
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.instance;
|
Tessellator tessellator = Tessellator.instance;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue