Bon bah je crois que c’est “bon”, en tous cas merci quand même à Robin et pour l’info l’item permet de placer la deuxième demie-dalle pour former une double demie-dalle. Avant en faite j’avais beaucoup de mal avec les jsons et je débutais le coding donc forcement j’arrivais pas vraiment à bidouiller mais maintenant c’est bon 😄 Bon ça à pas le même rendue étant donné que j’utilise la fonction :
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ){}
Pour placer la deuxième demie-dalle parce que je sais pas vraiment comment faire sinon pour faire en sorte que quand on clique droit sur le dessus du bloc seulement ça marche (en ajoutant le son du placement de bois qui n’est du coup pas présent) mais c’est déjà très bien comme ça et ça doit être encore améliorable alors.
Bref sinon voilà le code pour les personnes pas très téméraire qui voudrais faire ça facilement (méthode ultra condensée) :
public class BaseSlab extends BaseBlock
{
public static final PropertyEnum HALF = PropertyEnum.create("half", BaseSlab.EnumBlockHalf.class);
private boolean isDouble;
public BaseSlab(boolean par1, Material materialIn)
{
super(materialIn);
isDouble = par1;
IBlockState iblockstate = this.blockState.getBaseState();
if(!isDouble)
{
this.fullBlock = true;
this.setCreativeTab(EmotionTab.EmotionCreativeTab5);
iblockstate = iblockstate.withProperty(HALF, BaseSlab.EnumBlockHalf.BOTTOM);
}
else
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
}
this.setHardness(2.0F);
this.setResistance(5.0F);
this.setStepSound(soundTypeWood);
this.setLightOpacity(255);
}
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
if(this == EmotionBlocks.cherryDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.cherrySlab);
if(this == EmotionBlocks.pearDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.pearSlab);
if(this == EmotionBlocks.orangeDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.orangeSlab);
if(this == EmotionBlocks.atlasDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.atlasSlab);
if(this == EmotionBlocks.pineDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.pineSlab);
if(this == EmotionBlocks.cocoDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.cocoSlab);
return Item.getItemFromBlock(this);
}
@SideOnly(Side.CLIENT)
public Item getItem(World worldIn, BlockPos pos)
{
if(this == EmotionBlocks.cherryDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.cherrySlab);
if(this == EmotionBlocks.pearDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.pearSlab);
if(this == EmotionBlocks.orangeDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.orangeSlab);
if(this == EmotionBlocks.atlasDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.atlasSlab);
if(this == EmotionBlocks.pineDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.pineSlab);
if(this == EmotionBlocks.cocoDoubleSlab)
return Item.getItemFromBlock(EmotionBlocks.cocoSlab);
return Item.getItemFromBlock(this);
}
public IBlockState getStateFromMeta(int meta)
{
IBlockState iblockstate = this.getDefaultState();
if(!isDouble)
{
iblockstate = iblockstate.withProperty(HALF, (meta & 8) == 0 ? BaseSlab.EnumBlockHalf.BOTTOM : BaseSlab.EnumBlockHalf.TOP);
}
return iblockstate;
}
public int getMetaFromState(IBlockState state)
{
byte b0 = 0;
int i = b0;
if(!isDouble && state.getValue(HALF) == BaseSlab.EnumBlockHalf.TOP)
{
i |= 8;
}
return i;
}
protected BlockState createBlockState()
{
return isDouble ? new BlockState(this) : new BlockState(this, new IProperty[] {HALF});
}
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
{
if(player.getCurrentEquippedItem() != null)
{
if(player.getCurrentEquippedItem().getItem() == Item.getItemFromBlock(EmotionBlocks.cherrySlab))
world.setBlockState(pos, EmotionBlocks.cherryDoubleSlab.getDefaultState());
if(player.getCurrentEquippedItem().getItem() == Item.getItemFromBlock(EmotionBlocks.pearSlab))
world.setBlockState(pos, EmotionBlocks.pearDoubleSlab.getDefaultState());
if(player.getCurrentEquippedItem().getItem() == Item.getItemFromBlock(EmotionBlocks.orangeSlab))
world.setBlockState(pos, EmotionBlocks.orangeDoubleSlab.getDefaultState());
if(player.getCurrentEquippedItem().getItem() == Item.getItemFromBlock(EmotionBlocks.atlasSlab))
world.setBlockState(pos, EmotionBlocks.atlasDoubleSlab.getDefaultState());
if(player.getCurrentEquippedItem().getItem() == Item.getItemFromBlock(EmotionBlocks.pineSlab))
world.setBlockState(pos, EmotionBlocks.pineDoubleSlab.getDefaultState());
if(player.getCurrentEquippedItem().getItem() == Item.getItemFromBlock(EmotionBlocks.cocoSlab))
world.setBlockState(pos, EmotionBlocks.cocoDoubleSlab.getDefaultState());
if(!player.capabilities.isCreativeMode && –player.inventory.getCurrentItem().stackSize <= 0)
{
player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
}
return true;
}
return false;
}
protected boolean canSilkHarvest()
{
return false;
}
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
{
if(isDouble)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
else
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if(iblockstate.getBlock() == this)
{
if(iblockstate.getValue(HALF) == BaseSlab.EnumBlockHalf.TOP)
{
this.setBlockBounds(0.0F, 0.5F, 0.0F, 1.0F, 1.0F, 1.0F);
}
else
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
}
}
}
}
public void setBlockBoundsForItemRender()
{
if(isDouble)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
else
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
}
}
public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity collidingEntity)
{
this.setBlockBoundsBasedOnState(worldIn, pos);
super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
}
public boolean isOpaqueCube()
{
return isDouble;
}
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
IBlockState iblockstate = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(HALF, BaseSlab.EnumBlockHalf.BOTTOM);
return isDouble ? iblockstate : (facing != EnumFacing.DOWN && (facing == EnumFacing.UP || (double)hitY <= 0.5D) ? iblockstate : iblockstate.withProperty(HALF, BaseSlab.EnumBlockHalf.TOP));
}
public int quantityDropped(Random random)
{
return isDouble ? 2 : 1;
}
public boolean isFullCube()
{
return isDouble;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
{
if(isDouble)
{
return super.shouldSideBeRendered(worldIn, pos, side);
}
else if(side != EnumFacing.UP && side != EnumFacing.DOWN && !super.shouldSideBeRendered(worldIn, pos, side))
{
return false;
}
else
{
BlockPos blockpos1 = pos.offset(side.getOpposite());
IBlockState iblockstate = worldIn.getBlockState(pos);
IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
boolean flag = isSlab(iblockstate.getBlock()) && iblockstate.getValue(HALF) == BaseSlab.EnumBlockHalf.TOP;
boolean flag1 = isSlab(iblockstate1.getBlock()) && iblockstate1.getValue(HALF) == BaseSlab.EnumBlockHalf.TOP;
return flag1 ? (side == EnumFacing.DOWN ? true : (side == EnumFacing.UP && super.shouldSideBeRendered(worldIn, pos, side) ? true : !isSlab(iblockstate.getBlock()) || !flag)) : (side == EnumFacing.UP ? true : (side == EnumFacing.DOWN && super.shouldSideBeRendered(worldIn, pos, side) ? true : !isSlab(iblockstate.getBlock()) || flag));
}
}
@SideOnly(Side.CLIENT)
protected static boolean isSlab(Block blockIn)
{
return blockIn == EmotionBlocks.cherrySlab || blockIn == EmotionBlocks.pearSlab || blockIn == EmotionBlocks.orangeSlab || blockIn == EmotionBlocks.atlasSlab || blockIn == EmotionBlocks.pineSlab || blockIn == EmotionBlocks.cocoSlab;
}
public int getDamageValue(World worldIn, BlockPos pos)
{
return super.getDamageValue(worldIn, pos) & 7;
}
public static enum EnumBlockHalf implements IStringSerializable
{
TOP("top"), BOTTOM("bottom");
private final String name;
private EnumBlockHalf(String name)
{
this.name = name;
}
public String toString()
{
return this.name;
}
public String getName()
{
return this.name;
}
}
}