Non résolu Comment créer une plante cultivable de 2 blocs de haut ?
-
J’ai essayé,
Maintenant ça me met la partie du bas en haut à la place de la partie du haut mais à son dernier stade de croissance…
La classe de mon Item en un peu plus compréhensible :
package mod.plantsandfoodpack.common; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemSeeds; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class ItemGrapesSeeds extends ItemSeeds { public ItemGrapesSeeds(Block block, Block blockground) { super(block, blockground); } public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { if(side !=1) { return false; } else { ++y; Block block = ModPlantsandFoodPack.blockGrapesCrop; if(player.canPlayerEdit(x, y, z, side, itemStack) && player.canPlayerEdit(x, y + 1, z, side, itemStack)) { if(!block.canPlaceBlockAt(world, x, y, z)) { return false; } else { world.setBlock(x, y, z, block, 0, 2); world.setBlock(x, y + 1, z, block, 8, 2); --itemStack.stackSize; return true; } } else { return false; } } } }
ce que ça donne en jeu :
J’espère que vous pourrez m’aider
-
personne ne peut m’aider… ?
-
Il faut que tu adaptes le metadata posé et la texture du bloc en fonction de metadata.
-
j’ai essayer mais ça me met toujours la texture du bas en haut !
-
Tu peux envoyer le code actuel de ton bloc ?
-
Mon bloc :
package mod.plantsandfoodpack.common; import java.util.ArrayList; import java.util.List; import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockDoublePlant; import net.minecraft.block.IGrowable; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.stats.StatList; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockGrapesCrop extends BlockCrops implements IGrowable { protected int maxGrowthStage = 5; @SideOnly(Side.CLIENT) private IIcon[] doublePlantBottomIcons; @SideOnly(Side.CLIENT) private IIcon[] doublePlantTopIcons; public BlockGrapesCrop() { setTickRandomly(true); float f = 0.5F; this.setHardness(0.0F); this.setStepSound(soundTypeGrass); this.setBlockName("grapesCrop"); disableStats(); } public int getRenderType() { return 1; } public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) { this.setBlockBounds(0F, 0F, 0F, 1F, 2F, 1F); } public int func_149885_e(IBlockAccess p_149885_1_, int p_149885_2_, int p_149885_3_, int p_149885_4_) { int l = p_149885_1_.getBlockMetadata(p_149885_2_, p_149885_3_, p_149885_4_); return !func_149887_c(l) ? l & 7 : p_149885_1_.getBlockMetadata(p_149885_2_, p_149885_3_ - 1, p_149885_4_) & 7; } @Override protected boolean canPlaceBlockOn(Block block) { return block == Blocks.farmland; } public void incrementGrowStage(World parWorld, Random parRand, int parX, int parY, int parZ) { int growStage = parWorld.getBlockMetadata(parX, parY, parZ) + MathHelper.getRandomIntegerInRange(parRand, 2, 5); if (growStage > maxGrowthStage) { growStage = maxGrowthStage; } parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2); } public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_) { return super.canPlaceBlockAt(p_149742_1_, p_149742_2_, p_149742_3_, p_149742_4_) && p_149742_1_.isAirBlock(p_149742_2_, p_149742_3_ + 1, p_149742_4_); } protected void checkAndDropBlock(World p_149855_1_, int p_149855_2_, int p_149855_3_, int p_149855_4_) { if (!this.canBlockStay(p_149855_1_, p_149855_2_, p_149855_3_, p_149855_4_)) { int l = p_149855_1_.getBlockMetadata(p_149855_2_, p_149855_3_, p_149855_4_); if (!func_149887_c(l)) { this.dropBlockAsItem(p_149855_1_, p_149855_2_, p_149855_3_, p_149855_4_, l, 0); if (p_149855_1_.getBlock(p_149855_2_, p_149855_3_ + 1, p_149855_4_) == this) { p_149855_1_.setBlock(p_149855_2_, p_149855_3_ + 1, p_149855_4_, Blocks.air, 0, 2); } } p_149855_1_.setBlock(p_149855_2_, p_149855_3_, p_149855_4_, Blocks.air, 0, 2); } } public static boolean func_149887_c(int p_149887_0_) { return (p_149887_0_ & 8) != 0; } public static int func_149890_d(int p_149890_0_) { return p_149890_0_ & 7; } @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int p_149691_1_, int metadata) { if (metadata < 0 || metadata > 5) { metadata = 5; } return func_149887_c(metadata) ? this.doublePlantBottomIcons[metadata] : this.doublePlantBottomIcons[metadata]; } @SideOnly(Side.CLIENT) public IIcon func_149888_a(boolean p_149888_1_, int metadata) { return p_149888_1_ ? this.doublePlantTopIcons[metadata] : this.doublePlantBottomIcons[metadata]; } public void func_149889_c(World p_149889_1_, int p_149889_2_, int p_149889_3_, int p_149889_4_, int p_149889_5_, int p_149889_6_) { p_149889_1_.setBlock(p_149889_2_, p_149889_3_, p_149889_4_, this, p_149889_5_, p_149889_6_); p_149889_1_.setBlock(p_149889_2_, p_149889_3_ + 1, p_149889_4_, this, 8, p_149889_6_); } public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_) { int l = ((MathHelper.floor_double((double)(p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) + 2) % 4; p_149689_1_.setBlock(p_149689_2_, p_149689_3_ + 1, p_149689_4_, this, 8 | l, 2); } 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_) { if (func_149887_c(p_149681_5_)) { if (p_149681_1_.getBlock(p_149681_2_, p_149681_3_ - 1, p_149681_4_) == this) { if (!p_149681_6_.capabilities.isCreativeMode) { int i1 = p_149681_1_.getBlockMetadata(p_149681_2_, p_149681_3_ - 1, p_149681_4_); int j1 = func_149890_d(i1); if (j1 != 3 && j1 != 2) { p_149681_1_.func_147480_a(p_149681_2_, p_149681_3_ - 1, p_149681_4_, true); } else { p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ - 1, p_149681_4_); } } else { p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ - 1, p_149681_4_); } } } else if (p_149681_6_.capabilities.isCreativeMode && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ + 1, p_149681_4_) == this) { p_149681_1_.setBlock(p_149681_2_, p_149681_3_ + 1, p_149681_4_, Blocks.air, 0, 2); } super.onBlockHarvested(p_149681_1_, p_149681_2_, p_149681_3_, p_149681_4_, p_149681_5_, p_149681_6_); } private boolean func_149886_b(World p_149886_1_, int p_149886_2_, int p_149886_3_, int p_149886_4_, int p_149886_5_, EntityPlayer p_149886_6_) { int i1 = func_149890_d(p_149886_5_); if (i1 != 3 && i1 != 2) { return false; } else { p_149886_6_.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(this)], 1); byte b0 = 1; if (i1 == 3) { b0 = 2; } return true; } } protected Item func_149866_i() { return ModPlantsandFoodPack.itemGrapesSeeds; } protected Item func_149865_P() { return ModPlantsandFoodPack.itemGrapes; } @Override public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { return p_149650_1_ == 5 ? this.func_149865_P() : this.func_149866_i(); } @Override public int quantityDropped(int meta, int fortune, Random random) { return meta == 5 ? 4 : 1; } public int getDamageValue(World p_149643_1_, int p_149643_2_, int p_149643_3_, int p_149643_4_) { int l = p_149643_1_.getBlockMetadata(p_149643_2_, p_149643_3_, p_149643_4_); return func_149887_c(l) ? func_149890_d(p_149643_1_.getBlockMetadata(p_149643_2_, p_149643_3_ - 1, p_149643_4_)) : func_149890_d(l); } @Override public boolean func_149851_a(World parWorld, int parX, int parY, int parZ, boolean p_149851_5_) { int l = this.func_149885_e(parWorld, parX, parY, parZ); return parWorld.getBlockMetadata(parX, parY, parZ) != 5; } @Override public boolean func_149852_a(World p_149852_1_, Random parRand, int p_149852_3_, int p_149852_4_, int p_149852_5_) { return true; } @SideOnly(Side.CLIENT) public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) { return this.func_149866_i(); } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister parIIconRegister) { doublePlantBottomIcons = new IIcon[maxGrowthStage+1]; doublePlantTopIcons = new IIcon[maxGrowthStage+2]; doublePlantBottomIcons[0] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_bottom_stage_0"); doublePlantBottomIcons[1] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_bottom_stage_1"); doublePlantBottomIcons[2] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_bottom_stage_2"); doublePlantBottomIcons[3] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_bottom_stage_3"); doublePlantBottomIcons[4] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_bottom_stage_4"); doublePlantBottomIcons[5] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_bottom_stage_5"); doublePlantTopIcons[0] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_top_stage_0"); doublePlantTopIcons[1] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_top_stage_1"); doublePlantTopIcons[2] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_top_stage_2"); doublePlantTopIcons[3] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_top_stage_3"); doublePlantTopIcons[4] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_top_stage_4"); doublePlantTopIcons[5] = parIIconRegister.registerIcon(ModPlantsandFoodPack.MODID + ":grapes_top_stage_5"); } @SideOnly(Side.CLIENT) public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List p_149666_3_) { for (int i = 0; i < this.doublePlantBottomIcons.length; ++i) { p_149666_3_.add(new ItemStack(p_149666_1_, 1, i)); } } @Override public void func_149853_b(World parWorld, Random parRand, int parX, int parY, int parZ) { int l = this.func_149885_e(parWorld, parX, parY, parZ); incrementGrowStage(parWorld, parRand, parX, parY, parZ); } }
-
Le problème est simple :
@Override @SideOnly(Side.CLIENT) public IIcon getIcon(int p_149691_1_, int metadata) { if (metadata < 0 || metadata > 5) { metadata = 5; } return func_149887_c(metadata) ? this.doublePlantBottomIcons[metadata] : this.doublePlantBottomIcons[metadata]; }
Tu retournes toujours ‘doublePlantBottomIcons’ (la texture du bas).
-
j’ai essayer d’en remplacer un par la texture du haut mais quand je modifie le premier, ça change rien et si je modifie le 2eme, les deux parties prennent la texture du haut…
-
…
-
personne ne sait comment m’aider ?..
-
Il faudrait que je prenne le code de mon côté pour faire des tests moi-même, mais je n’ai plus de workspace 1.7.10 et je n’ai pas du tout envie de refaire un setup (ni de dev d’ailleurs) dans cette version obsolète.
Désolé. -
ah ok…