Je suis arrivé à çà :
package fr.scarex.st18.ST18Blocks;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import fr.scarex.st18.ST18;
import fr.scarex.st18.ST18Entity.EntitySit;
public class BlockSittable extends Block
{
private static final String name = "block_sittable";
protected BlockSittable() {
super(Material.rock);
GameRegistry.registerBlock(this, name);
setUnlocalizedName(ST18.MODID + "_" + name);
setCreativeTab(CreativeTabs.tabBlock);
}
public static final String getName() {
return name;
}
@Override
public boolean onBlockActivated(World worldIn, final BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {
List list = worldIn.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos.getX() + minX - 1.0D, pos.getY() + minY - 1.0D, pos.getZ() + minZ - 1.0D, pos.getX() + maxX + 1.0D, pos.getY() + maxY + 1.0D, pos.getZ() + maxZ + 1.0D), new Predicate(){
@Override
public boolean apply(Object input) {
return input instanceof EntitySit && ((Entity)input).getPosition().equals(pos);
}
});
if (list.size() > 0) {
playerIn.mountEntity((Entity) list.get(0));
} else {
worldIn.spawnEntityInWorld(new EntitySit(worldIn, pos));
}
}
return true;
}
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
if (!worldIn.isRemote) worldIn.spawnEntityInWorld(new EntitySit(worldIn, pos));
}
}
package fr.scarex.st18.ST18Entity;
import fr.scarex.st18.ST18Blocks.BlockSittable;
import fr.scarex.st18.ST18Blocks.ST18Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityHanging;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
public class EntitySit extends EntityHanging
{
public EntitySit(World worldIn, BlockPos pos) {
super(worldIn, pos);
this.field_174860_b = EnumFacing.NORTH;
this.setLocationAndAngles(pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, 0.0F, 0.0F);
setEntityBoundingBox(new AxisAlignedBB(this.hangingPosition.getX(), this.hangingPosition.getY(), this.hangingPosition.getZ(), this.hangingPosition.getX() + 1.0D, this.hangingPosition.getY() + 1.0D, this.hangingPosition.getZ() + 1.0D));
}
public EntitySit(World world) {
super(world);
this.field_174860_b = EnumFacing.NORTH;
}
@Override
public int getWidthPixels() {
return 8;
}
@Override
public int getHeightPixels() {
return 8;
}
@Override
public void onBroken(Entity entity) {}
@Override
public float getCollisionBorderSize() {
return 0.0F;
}
@Override
public double getMountedYOffset() {
return 0.0D;
}
@Override
public void onUpdate() {
super.onUpdate();
if (this.worldObj.getBlockState(this.hangingPosition).getBlock() != ST18Blocks.blockSittable) this.setDead();
}
@Override
public boolean onValidSurface() {
return true;
}
}