Résolu Help - Demi-dalles
-
Salut alors j’ai fait une demi-dalle en obsidienne dans mon mod mais quand je fais click droit en tenant une demi-dalle en obsi dans ma main sur n’importe quel block, tant que je fais clique droit sur la surface du haut, le bloc se transforme en double demi-dalles même si c’est un block de n’importe quoi!
ObsiSlab
:::/* */ package com.maxx.ores; /* */ /* */ import cpw.mods.fml.relauncher.Side; /* */ import cpw.mods.fml.relauncher.SideOnly; /* */ import java.util.List; /* */ import java.util.Random; /* */ import net.minecraft.block.Block; /* */ import net.minecraft.block.BlockSlab; /* */ import net.minecraft.block.material.Material; /* */ import net.minecraft.client.renderer.texture.IIconRegister; /* */ import net.minecraft.creativetab.CreativeTabs; /* */ import net.minecraft.item.Item; /* */ import net.minecraft.item.ItemStack; /* */ import net.minecraft.world.World; /* */ /* */ /* */ /* */ public class ObsiSlab /* */ extends BlockSlab /* */ { /* 21 */ public static final String[] obsiType = { "ObsiSlab" }; /* */ /* */ public ObsiSlab(boolean isdouble, Material material) /* */ { /* 25 */ super(isdouble, material); /* 26 */ setStepSound(Block.soundTypeStone); /* 27 */ setHarvestLevel("pickaxe", 3); /* 28 */ if (!this.field_150004_a) /* */ { /* 30 */ setLightOpacity(0); /* */ } /* */ } /* */ /* */ /* */ @SideOnly(Side.CLIENT) /* */ public void registerBlockIcons(IIconRegister p_149651_1_) /* */ { /* 38 */ this.blockIcon = p_149651_1_.registerIcon("minecraft:obsidian"); /* */ } /* */ /* */ @SideOnly(Side.CLIENT) /* */ private static boolean func_150003_a(Block block) /* */ { /* 44 */ return block == NewOres.blockObsiSlab; /* */ } /* */ /* */ @SideOnly(Side.CLIENT) /* */ public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) /* */ { /* 50 */ return Item.getItemFromBlock(NewOres.blockObsiSlab); /* */ } /* */ /* */ public Item getItemDropped(int metadata, Random rand, int fortune) /* */ { /* 55 */ return Item.getItemFromBlock(NewOres.blockObsiSlab); /* */ } /* */ /* */ protected ItemStack createStackedBlock(int metadata) /* */ { /* 60 */ return new ItemStack(NewOres.blockObsiSlab, 2, metadata & 0x7); /* */ } /* */ /* */ @SideOnly(Side.CLIENT) /* */ public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) /* */ { /* 66 */ if (item != Item.getItemFromBlock(NewOres.blockObsiSlabDouble)) /* */ { /* 68 */ for (int i = 0; i < obsiType.length; i++) /* */ { /* 70 */ list.add(new ItemStack(item, 1, i)); /* */ } /* */ } /* */ } /* */ /* */ /* */ public String func_150002_b(int metadata) /* */ { /* 78 */ if ((metadata < 0) || (metadata >= obsiType.length)) /* */ { /* 80 */ metadata = 0; /* */ } /* 82 */ return super.getUnlocalizedName() + "." + obsiType[metadata]; /* */ } /* */ }
:::
ItemMySlab
:::/* */ package com.maxx.ores; /* */ /* */ import cpw.mods.fml.relauncher.Side; /* */ import cpw.mods.fml.relauncher.SideOnly; /* */ import net.minecraft.block.Block; /* */ import net.minecraft.block.Block.SoundType; /* */ import net.minecraft.entity.player.EntityPlayer; /* */ import net.minecraft.item.ItemBlock; /* */ import net.minecraft.item.ItemStack; /* */ import net.minecraft.world.World; /* */ /* */ public class ItemMySlab extends ItemBlock /* */ { /* */ private final boolean isFullBlock; /* */ private final Block theHalfSlab; /* */ private final Block doubleSlab; /* */ /* */ public ItemMySlab(Block block) /* */ { /* 20 */ super(block); /* 21 */ this.theHalfSlab = NewOres.blockObsiSlab; /* 22 */ this.doubleSlab = NewOres.blockObsiSlabDouble; /* 23 */ if (block == NewOres.blockObsiSlabDouble) /* */ { /* 25 */ this.isFullBlock = true; /* */ } /* */ else /* */ { /* 29 */ this.isFullBlock = false; /* */ } /* 31 */ setMaxDamage(0); /* 32 */ setHasSubtypes(true); /* */ } /* */ /* */ @SideOnly(Side.CLIENT) /* */ public net.minecraft.util.IIcon getIconFromDamage(int metadata) /* */ { /* 38 */ return this.field_150939_a.getIcon(2, metadata); /* */ } /* */ /* */ public int getMetadata(int metadata) /* */ { /* 43 */ return metadata; /* */ } /* */ /* */ public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) /* */ { /* 48 */ if (this.isFullBlock) /* */ { /* 50 */ return super.onItemUse(stack, player, world, x, y, z, side, par8, par9, par10); /* */ } /* 52 */ if (stack.stackSize == 0) /* */ { /* 54 */ return false; /* */ } /* 56 */ if (!player.canPlayerEdit(x, y, z, side, stack)) /* */ { /* 58 */ return false; /* */ } /* */ /* */ /* 62 */ Block i1 = world.getBlock(x, y, z); /* 63 */ int j1 = world.getBlockMetadata(x, y, z); /* 64 */ int k1 = j1 & 0x7; /* 65 */ boolean flag = (j1 & 0x8) != 0; /* */ /* 67 */ if (((side == 1) && (!flag)) || ((side == 0) && (flag) && (i1 == this.theHalfSlab) && (k1 == stack.getItemDamage()))) /* */ { /* 69 */ if ((world.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBoxFromPool(world, x, y, z))) && (world.setBlock(x, y, z, this.doubleSlab, k1, 3))) /* */ { /* 71 */ world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, this.doubleSlab.stepSound.getStepResourcePath(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getVolume() * 0.8F); /* 72 */ stack.stackSize -= 1; /* */ } /* 74 */ return true; /* */ } /* */ /* 78 */ return placeDoubleSlabFromTop(stack, player, world, x, y, z, side) ? true : super.onItemUse(stack, player, world, x, y, z, side, par8, par9, par10); /* */ } /* */ /* */ /* */ /* */ @SideOnly(Side.CLIENT) /* */ public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack) /* */ { /* 86 */ int i1 = x; /* 87 */ int j1 = y; /* 88 */ int k1 = z; /* 89 */ Block id = world.getBlock(x, y, z); /* 90 */ int meta = world.getBlockMetadata(x, y, z); /* 91 */ int j2 = meta & 0x7; /* 92 */ boolean flag = (meta & 0x8) != 0; /* */ /* 94 */ if (((side == 1) && (!flag)) || ((side == 0) && (flag) && (id == this.theHalfSlab) && (j2 == stack.getItemDamage()))) /* */ { /* 96 */ return true; /* */ } /* */ /* */ /* 100 */ if (side == 0) /* */ { /* 102 */ y–; /* */ } /* */ /* 105 */ if (side == 1) /* */ { /* 107 */ y++; /* */ } /* */ /* 110 */ if (side == 2) /* */ { /* 112 */ z--; /* */ } /* */ /* 115 */ if (side == 3) /* */ { /* 117 */ z++; /* */ } /* */ /* 120 */ if (side == 4) /* */ { /* 122 */ x--; /* */ } /* */ /* 125 */ if (side == 5) /* */ { /* 127 */ x++; /* */ } /* */ /* 130 */ id = world.getBlock(x, y, z); /* 131 */ meta = world.getBlockMetadata(x, y, z); /* 132 */ j2 = meta & 0x7; /* 133 */ flag = (meta & 0x8) != 0; /* 134 */ return (id == this.theHalfSlab) && (j2 == stack.getItemDamage()) ? true : super.func_150936_a(world, i1, j1, k1, side, player, stack); /* */ } /* */ /* */ /* */ private boolean placeDoubleSlabFromTop(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side) /* */ { /* 140 */ if (side == 0) /* */ { /* 142 */ y--; /* */ } /* */ /* 145 */ if (side == 1) /* */ { /* 147 */ y++; /* */ } /* */ /* 150 */ if (side == 2) /* */ { /* 152 */ z--; /* */ } /* */ /* 155 */ if (side == 3) /* */ { /* 157 */ z++; /* */ } /* */ /* 160 */ if (side == 4) /* */ { /* 162 */ x--; /* */ } /* */ /* 165 */ if (side == 5) /* */ { /* 167 */ x++; /* */ } /* */ /* 170 */ Block i1 = world.getBlock(x, y, z); /* 171 */ int j1 = world.getBlockMetadata(x, y, z); /* 172 */ int k1 = j1 & 0x7; /* */ /* 174 */ if ((i1 == this.theHalfSlab) && (k1 == stack.getItemDamage())) /* */ { /* 176 */ if ((world.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBoxFromPool(world, x, y, z))) && (world.setBlock(x, y, z, this.doubleSlab, k1, 3))) /* */ { /* 178 */ world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, this.doubleSlab.stepSound.getStepResourcePath(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getVolume() * 0.8F); /* 179 */ stack.stackSize -= 1; /* */ } /* */ /* 182 */ return true; /* */ } /* */ /* */ /* 186 */ return false; /* */ } /* */ }
:::
-
Le problème vient surement de la fonction placeDoubleSlabFromTop, mais je ne le vois pas. Faudrait comparer avec la classe ItemSlab de Minecraft.
-
ItemSlab de minecraft:
:::
package net.minecraft.item; import net.minecraft.block.Block; import net.minecraft.block.BlockSlab; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.IIcon; import net.minecraft.world.World; public class ItemSlab extends ItemBlock { private final boolean field_150948_b; private final BlockSlab field_150949_c; private final BlockSlab field_150947_d; private static final String __OBFID = "CL_00000071"; public ItemSlab(Block p_i45355_1_, BlockSlab p_i45355_2_, BlockSlab p_i45355_3_, boolean p_i45355_4_) { super(p_i45355_1_); this.field_150949_c = p_i45355_2_; this.field_150947_d = p_i45355_3_; this.field_150948_b = p_i45355_4_; this.setMaxDamage(0); this.setHasSubtypes(true); } /** * Gets an icon index based on an item's damage value */ public IIcon getIconFromDamage(int p_77617_1_) { return Block.getBlockFromItem(this).getIcon(2, p_77617_1_); } /** * Returns the metadata of the block which this Item (ItemBlock) can place */ public int getMetadata(int p_77647_1_) { return p_77647_1_; } /** * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have * different names based on their damage or NBT. */ public String getUnlocalizedName(ItemStack p_77667_1_) { return this.field_150949_c.func_150002_b(p_77667_1_.getItemDamage()); } /** * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return * True if something happen and false if it don't. This is for ITEMS, not BLOCKS */ public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World p_77648_3_, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) { if (this.field_150948_b) { return super.onItemUse(p_77648_1_, p_77648_2_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_8_, p_77648_9_, p_77648_10_); } else if (p_77648_1_.stackSize == 0) { return false; } else if (!p_77648_2_.canPlayerEdit(p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_1_)) { return false; } else { Block var11 = p_77648_3_.getBlock(p_77648_4_, p_77648_5_, p_77648_6_); int var12 = p_77648_3_.getBlockMetadata(p_77648_4_, p_77648_5_, p_77648_6_); int var13 = var12 & 7; boolean var14 = (var12 & 8) != 0; if ((p_77648_7_ == 1 && !var14 || p_77648_7_ == 0 && var14) && var11 == this.field_150949_c && var13 == p_77648_1_.getItemDamage()) { if (p_77648_3_.checkNoEntityCollision(this.field_150947_d.getCollisionBoundingBoxFromPool(p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_)) && p_77648_3_.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, this.field_150947_d, var13, 3)) { p_77648_3_.playSoundEffect((double)((float)p_77648_4_ + 0.5F), (double)((float)p_77648_5_ + 0.5F), (double)((float)p_77648_6_ + 0.5F), this.field_150947_d.stepSound.func_150496_b(), (this.field_150947_d.stepSound.func_150497_c() + 1.0F) / 2.0F, this.field_150947_d.stepSound.func_150494_d() * 0.8F); –p_77648_1_.stackSize; } return true; } else { return this.func_150946_a(p_77648_1_, p_77648_2_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_) ? true : super.onItemUse(p_77648_1_, p_77648_2_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_8_, p_77648_9_, p_77648_10_); } } } public boolean func_150936_a(World p_150936_1_, int p_150936_2_, int p_150936_3_, int p_150936_4_, int p_150936_5_, EntityPlayer p_150936_6_, ItemStack p_150936_7_) { int var8 = p_150936_2_; int var9 = p_150936_3_; int var10 = p_150936_4_; Block var11 = p_150936_1_.getBlock(p_150936_2_, p_150936_3_, p_150936_4_); int var12 = p_150936_1_.getBlockMetadata(p_150936_2_, p_150936_3_, p_150936_4_); int var13 = var12 & 7; boolean var14 = (var12 & 8) != 0; if ((p_150936_5_ == 1 && !var14 || p_150936_5_ == 0 && var14) && var11 == this.field_150949_c && var13 == p_150936_7_.getItemDamage()) { return true; } else { if (p_150936_5_ == 0) { --p_150936_3_; } if (p_150936_5_ == 1) { ++p_150936_3_; } if (p_150936_5_ == 2) { --p_150936_4_; } if (p_150936_5_ == 3) { ++p_150936_4_; } if (p_150936_5_ == 4) { --p_150936_2_; } if (p_150936_5_ == 5) { ++p_150936_2_; } Block var15 = p_150936_1_.getBlock(p_150936_2_, p_150936_3_, p_150936_4_); int var16 = p_150936_1_.getBlockMetadata(p_150936_2_, p_150936_3_, p_150936_4_); var13 = var16 & 7; return var15 == this.field_150949_c && var13 == p_150936_7_.getItemDamage() ? true : super.func_150936_a(p_150936_1_, var8, var9, var10, p_150936_5_, p_150936_6_, p_150936_7_); } } private boolean func_150946_a(ItemStack p_150946_1_, EntityPlayer p_150946_2_, World p_150946_3_, int p_150946_4_, int p_150946_5_, int p_150946_6_, int p_150946_7_) { if (p_150946_7_ == 0) { --p_150946_5_; } if (p_150946_7_ == 1) { ++p_150946_5_; } if (p_150946_7_ == 2) { --p_150946_6_; } if (p_150946_7_ == 3) { ++p_150946_6_; } if (p_150946_7_ == 4) { --p_150946_4_; } if (p_150946_7_ == 5) { ++p_150946_4_; } Block var8 = p_150946_3_.getBlock(p_150946_4_, p_150946_5_, p_150946_6_); int var9 = p_150946_3_.getBlockMetadata(p_150946_4_, p_150946_5_, p_150946_6_); int var10 = var9 & 7; if (var8 == this.field_150949_c && var10 == p_150946_1_.getItemDamage()) { if (p_150946_3_.checkNoEntityCollision(this.field_150947_d.getCollisionBoundingBoxFromPool(p_150946_3_, p_150946_4_, p_150946_5_, p_150946_6_)) && p_150946_3_.setBlock(p_150946_4_, p_150946_5_, p_150946_6_, this.field_150947_d, var10, 3)) { p_150946_3_.playSoundEffect((double)((float)p_150946_4_ + 0.5F), (double)((float)p_150946_5_ + 0.5F), (double)((float)p_150946_6_ + 0.5F), this.field_150947_d.stepSound.func_150496_b(), (this.field_150947_d.stepSound.func_150497_c() + 1.0F) / 2.0F, this.field_150947_d.stepSound.func_150494_d() * 0.8F); --p_150946_1_.stackSize; } return true; } else { return false; } } }
:::
Bug réglé, fonction onItemUse :
:::public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World p_77648_3_, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) { if (this.isFullBlock) { return super.onItemUse(p_77648_1_, p_77648_2_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_8_, p_77648_9_, p_77648_10_); } else if (p_77648_1_.stackSize == 0) { return false; } else if (!p_77648_2_.canPlayerEdit(p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_1_)) { return false; } else { Block var11 = p_77648_3_.getBlock(p_77648_4_, p_77648_5_, p_77648_6_); int var12 = p_77648_3_.getBlockMetadata(p_77648_4_, p_77648_5_, p_77648_6_); int var13 = var12 & 7; boolean var14 = (var12 & 8) != 0; if ((p_77648_7_ == 1 && !var14 || p_77648_7_ == 0 && var14) && var11 == this.theHalfSlab && var13 == p_77648_1_.getItemDamage()) { if (p_77648_3_.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBoxFromPool(p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_)) && p_77648_3_.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, this.doubleSlab, var13, 3)) { p_77648_3_.playSoundEffect((double)((float)p_77648_4_ + 0.5F), (double)((float)p_77648_5_ + 0.5F), (double)((float)p_77648_6_ + 0.5F), this.doubleSlab.stepSound.func_150496_b(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getVolume() * 0.8F); --p_77648_1_.stackSize; } return true; } else { return this.placeDoubleSlabFromTop(p_77648_1_, p_77648_2_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_) ? true : super.onItemUse(p_77648_1_, p_77648_2_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_8_, p_77648_9_, p_77648_10_); } } }
:::