Résolu Flower Pot
-
Salutation, voilà j’ai un problème dans la création de mon pot de fleur plutôt perturbant… Tout marche correctement (la fleur est correctement positionné dans le pot de fleur, il la drop correctement, etc…) Mais voilà quand je déco / reco ou quitte / recharge la map la fleur ne se trouve pas “graphiquement” dans le pot de fleur (donc affiche un pot de fleur vide) mais quand je casse le block il drop bien la fleur en question.
Après un “debug massif” j’ai remarqué que “int p_149915_2_” de
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
indique constamment 0 quand je rejoins le monde avec des pots de fleurs, je ne sais pas si cela vient de là mais je trouve ça quand même un peu louche.
La Class du Block
public class BlockFlowerPotShunayte extends BlockContainer { public BlockFlowerPotShunayte() { super(Material.circuits); this.setBlockBoundsForItemRender(); } public void setBlockBoundsForItemRender() { float f = 0.375F; float f1 = f / 2.0F; this.setBlockBounds(0.5F - f1, 0.0F, 0.5F - f1, 0.5F + f1, f, 0.5F + f1); } public boolean isOpaqueCube() { return false; } @SideOnly(Side.CLIENT) public int getRenderType() { return ClientProxy.flowerPotShunayteId; } public boolean renderAsNormalBlock() { return false; } public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { ItemStack itemstack = p_149727_5_.inventory.getCurrentItem(); if(itemstack != null && itemstack.getItem() instanceof ItemBlock) { TileEntityFlowerPotShunayte TileEntityFlowerPotShunayte = this.func_149929_e(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_); if(TileEntityFlowerPotShunayte != null) { if(TileEntityFlowerPotShunayte.getFlowerPotItem() != null) { return false; } else { Block block = Block.getBlockFromItem(itemstack.getItem()); if(!this.func_149928_a(block, itemstack.getItemDamage())) { return false; } else { TileEntityFlowerPotShunayte.func_145964_a(itemstack.getItem(), itemstack.getItemDamage()); TileEntityFlowerPotShunayte.markDirty(); if(!p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_, p_149727_4_, itemstack.getItemDamage(), 2)) { p_149727_1_.markBlockForUpdate(p_149727_2_, p_149727_3_, p_149727_4_); } if(!p_149727_5_.capabilities.isCreativeMode && –itemstack.stackSize <= 0) { p_149727_5_.inventory.setInventorySlotContents(p_149727_5_.inventory.currentItem, (ItemStack)null); } return true; } } } else { return false; } } else { return false; } } private boolean func_149928_a(Block p_149928_1_, int p_149928_2_) { return p_149928_1_ != BlockShunayte.bleuet && p_149928_1_ != BlockShunayte.millepertuis && p_149928_1_ != BlockShunayte.marguerite && p_149928_1_ != BlockShunayte.jonguille && p_149928_1_ != BlockShunayte.petunia && p_149928_1_ != BlockShunayte.geranium && p_149928_1_ != BlockShunayte.saplingShunayte && p_149928_1_ != BlockShunayte.saplingShunayte2 ? p_149928_1_ == Blocks.tallgrass && p_149928_2_ == 2 : true; } @SideOnly(Side.CLIENT) public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) { TileEntityFlowerPotShunayte TileEntityFlowerPotShunayte = this.func_149929_e(p_149694_1_, p_149694_2_, p_149694_3_, p_149694_4_); return TileEntityFlowerPotShunayte != null && TileEntityFlowerPotShunayte.getFlowerPotItem() != null ? TileEntityFlowerPotShunayte.getFlowerPotItem() : ItemShunayte.flowerPotShunayte; } private TileEntityFlowerPotShunayte func_149929_e(World p_149929_1_, int p_149929_2_, int p_149929_3_, int p_149929_4_) { TileEntity tileentity = p_149929_1_.getTileEntity(p_149929_2_, p_149929_3_, p_149929_4_); return tileentity != null && tileentity instanceof TileEntityFlowerPotShunayte ? (TileEntityFlowerPotShunayte)tileentity : null; } public int getDamageValue(World p_149643_1_, int p_149643_2_, int p_149643_3_, int p_149643_4_) { TileEntityFlowerPotShunayte TileEntityFlowerPotShunayte = this.func_149929_e(p_149643_1_, p_149643_2_, p_149643_3_, p_149643_4_); return TileEntityFlowerPotShunayte != null && TileEntityFlowerPotShunayte.getFlowerPotItem() != null ? TileEntityFlowerPotShunayte.getFlowerPotData() : 0; } @SideOnly(Side.CLIENT) public boolean isFlowerPot() { return true; } public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) { return super.canPlaceBlockAt(par1World, par2, par3, par4) && par1World.doesBlockHaveSolidTopSurface(par1World, par2, par3 - 1, par4); } public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { if(!par1World.doesBlockHaveSolidTopSurface(par1World, par2, par3 - 1, par4)) { this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0); par1World.setBlockToAir(par2, par3, par4); } } public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) { super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_); } public void onBlockHarvested(World p_149681_1_, int p_149681_2_, int p_149681_3_, int p_149681_4_, int p_149681_5_, EntityPlayer p_149681_6_) { super.onBlockHarvested(p_149681_1_, p_149681_2_, p_149681_3_, p_149681_4_, p_149681_5_, p_149681_6_); if(p_149681_6_.capabilities.isCreativeMode) { TileEntityFlowerPotShunayte tileEntityFlowerPotShunayte = this.func_149929_e(p_149681_1_, p_149681_2_, p_149681_3_, p_149681_4_); if(tileEntityFlowerPotShunayte != null) { tileEntityFlowerPotShunayte.func_145964_a(Item.getItemById(0), 0); } } } public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { return ItemShunayte.flowerPotShunayte; } public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { Block object = null; byte b0 = 0; switch(p_149915_2_) { case 1: object = BlockShunayte.bleuet; break; case 2: object = BlockShunayte.millepertuis; break; case 3: object = BlockShunayte.marguerite; break; case 4: object = BlockShunayte.jonguille; break; case 5: object = BlockShunayte.petunia; break; case 6: object = BlockShunayte.geranium; break; case 7: object = BlockShunayte.saplingShunayte; b0 = 0; break; case 8: object = BlockShunayte.saplingShunayte; b0 = 1; break; case 9: object = BlockShunayte.saplingShunayte; b0 = 2; break; case 10: object = BlockShunayte.saplingShunayte; b0 = 3; break; case 11: object = BlockShunayte.saplingShunayte2; b0 = 0; break; case 12: object = BlockShunayte.saplingShunayte2; b0 = 1; break; case 13: object = BlockShunayte.saplingShunayte2; b0 = 2; break; } System.out.println("[DEBUG BLOCK] : " + p_149915_2_ + " | " + object + " | " + b0); return new TileEntityFlowerPotShunayte(Item.getItemFromBlock(object), b0); } @Override public ArrayList<itemstack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<itemstack> ret = super.getDrops(world, x, y, z, metadata, fortune); TileEntityFlowerPotShunayte te = this.func_149929_e(world, x, y, z); if(te != null && te.getFlowerPotItem() != null) ret.add(new ItemStack(te.getFlowerPotItem(), 1, te.getFlowerPotData())); return ret; } @Override public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { if(willHarvest) return true; return super.removedByPlayer(world, player, x, y, z, willHarvest); } @Override public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) { super.harvestBlock(world, player, x, y, z, meta); world.setBlockToAir(x, y, z); } }
Le TileEntity
public class TileEntityFlowerPotShunayte extends TileEntity { private Item flowerPotItem; private int flowerPotData; public TileEntityFlowerPotShunayte() {} public TileEntityFlowerPotShunayte(Item p_i45442_1_, int p_i45442_2_) { this.flowerPotItem = p_i45442_1_; this.flowerPotData = p_i45442_2_; } public void writeToNBT(NBTTagCompound p_145841_1_) { super.writeToNBT(p_145841_1_); p_145841_1_.setInteger("Item", Item.getIdFromItem(this.flowerPotItem)); p_145841_1_.setInteger("Data", this.flowerPotData); } public void readFromNBT(NBTTagCompound p_145839_1_) { super.readFromNBT(p_145839_1_); this.flowerPotItem = Item.getItemById(p_145839_1_.getInteger("Item")); this.flowerPotData = p_145839_1_.getInteger("Data"); } /** * Overriden in a sign to provide the text. */ public Packet getDescriptionPacket() { NBTTagCompound nbttagcompound = new NBTTagCompound(); this.writeToNBT(nbttagcompound); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 5, nbttagcompound); } public void func_145964_a(Item p_145964_1_, int p_145964_2_) { this.flowerPotItem = p_145964_1_; this.flowerPotData = p_145964_2_; } public Item getFlowerPotItem() { return this.flowerPotItem; } public int getFlowerPotData() { return this.flowerPotData; } }
Le rendu
public boolean renderBlockFlowerpotShunayte(BlockFlowerPotShunayte p_147752_1_, int p_147752_2_, int p_147752_3_, int p_147752_4_, IBlockAccess par5, RenderBlocks par6) { par6.renderStandardBlock(p_147752_1_, p_147752_2_, p_147752_3_, p_147752_4_); Tessellator tessellator = Tessellator.instance; tessellator.setBrightness(p_147752_1_.getMixedBrightnessForBlock(par6.blockAccess, p_147752_2_, p_147752_3_, p_147752_4_)); int l = p_147752_1_.colorMultiplier(par6.blockAccess, p_147752_2_, p_147752_3_, p_147752_4_); IIcon iicon = par6.getBlockIconFromSide(p_147752_1_, 0); float f = (float)(l >> 16 & 255) / 255.0F; float f1 = (float)(l >> 8 & 255) / 255.0F; float f2 = (float)(l & 255) / 255.0F; float f3; if(EntityRenderer.anaglyphEnable) { f3 = (f * 30.0F + f1 * 59.0F + f2 * 11.0F) / 100.0F; float f4 = (f * 30.0F + f1 * 70.0F) / 100.0F; float f5 = (f * 30.0F + f2 * 70.0F) / 100.0F; f = f3; f1 = f4; f2 = f5; } tessellator.setColorOpaque_F(f, f1, f2); f3 = 0.1865F; par6.renderFaceXPos(p_147752_1_, (double)((float)p_147752_2_ - 0.5F + f3), (double)p_147752_3_, (double)p_147752_4_, iicon); par6.renderFaceXNeg(p_147752_1_, (double)((float)p_147752_2_ + 0.5F - f3), (double)p_147752_3_, (double)p_147752_4_, iicon); par6.renderFaceZPos(p_147752_1_, (double)p_147752_2_, (double)p_147752_3_, (double)((float)p_147752_4_ - 0.5F + f3), iicon); par6.renderFaceZNeg(p_147752_1_, (double)p_147752_2_, (double)p_147752_3_, (double)((float)p_147752_4_ + 0.5F - f3), iicon); par6.renderFaceYPos(p_147752_1_, (double)p_147752_2_, (double)((float)p_147752_3_ - 0.5F + f3 + 0.1875F), (double)p_147752_4_, par6.getBlockIcon(Blocks.dirt)); TileEntity tileentity = par6.blockAccess.getTileEntity(p_147752_2_, p_147752_3_, p_147752_4_); if(tileentity != null && tileentity instanceof TileEntityFlowerPotShunayte) { Item item = ((TileEntityFlowerPotShunayte)tileentity).getFlowerPotItem(); int i1 = ((TileEntityFlowerPotShunayte)tileentity).getFlowerPotData(); if(item instanceof ItemBlock) { Block block = Block.getBlockFromItem(item); int j1 = block.getRenderType(); float f6 = 0.0F; float f7 = 4.0F; float f8 = 0.0F; tessellator.addTranslation(f6 / 16.0F, f7 / 16.0F, f8 / 16.0F); l = block.colorMultiplier(par6.blockAccess, p_147752_2_, p_147752_3_, p_147752_4_); if(l != 16777215) { f = (float)(l >> 16 & 255) / 255.0F; f1 = (float)(l >> 8 & 255) / 255.0F; f2 = (float)(l & 255) / 255.0F; tessellator.setColorOpaque_F(f, f1, f2); } if(j1 == 1) { par6.drawCrossedSquares(par6.getBlockIconFromSideAndMetadata(block, 0, i1), (double)p_147752_2_, (double)p_147752_3_, (double)p_147752_4_, 0.75F); } else if(j1 == 13) { par6.renderAllFaces = true; float f9 = 0.125F; par6.setRenderBounds((double)(0.5F - f9), 0.0D, (double)(0.5F - f9), (double)(0.5F + f9), 0.25D, (double)(0.5F + f9)); par6.renderStandardBlock(block, p_147752_2_, p_147752_3_, p_147752_4_); par6.setRenderBounds((double)(0.5F - f9), 0.25D, (double)(0.5F - f9), (double)(0.5F + f9), 0.5D, (double)(0.5F + f9)); par6.renderStandardBlock(block, p_147752_2_, p_147752_3_, p_147752_4_); par6.setRenderBounds((double)(0.5F - f9), 0.5D, (double)(0.5F - f9), (double)(0.5F + f9), 0.75D, (double)(0.5F + f9)); par6.renderStandardBlock(block, p_147752_2_, p_147752_3_, p_147752_4_); par6.renderAllFaces = false; par6.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); } } tessellator.addTranslation(-f6 / 16.0F, -f7 / 16.0F, -f8 / 16.0F); } return true; }
-
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.readFromNBT(pkt.func_148857_g()); }
À mettre dans la classe du tile entity.
-
…… C’est donc un oubli complétement idiot ! >< le pire c’est que j’avais rajouté au tout début et que je les supprimé pour je sais plus quel raison… Merci à toi !