Un siége
-
Après avoir passé une bonne demi-heure a modéliser mon siège ( non j’abconne 5 min ), j’aimerais bien que l’on puisse s’assoir via un clique droit dessus. Sans plus tarder voila le code :
package assets.city01.Blocks; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import assets.city01.Data.ClientProxy; import assets.city01.Data.HL2; import assets.city01.TileEntity.TileEntitySiege; import assets.city01.TileEntity.TileEntitySiege; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class B_Siege extends BlockContainer { private Icon icontop, iconbottom, iconfront; public B_Siege(int par1) { super(par1, Material.wood); this.setCreativeTab(HL2.Tab); } /* * public void registerIcons(IconRegister iconRegister) { blockIcon = * iconRegister.registerIcon("city01:nope"); iconfront = * iconRegister.registerIcon("city01:a"); icontop = * iconRegister.registerIcon("city01:b"); iconbottom = * iconRegister.registerIcon("city01:c"); } */ public void registerIcons(IconRegister iconregister) { icontop = iconregister.registerIcon("city01:nope"); iconbottom = iconregister.registerIcon("city01:nope"); iconfront = iconregister.registerIcon("city01:nope"); } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { int direction = MathHelper .floor_double((double) (living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3; TileEntity te = world.getBlockTileEntity(x, y, z); if (te != null && stack.getItemDamage() == 2 && te instanceof TileEntitySiege) { ((TileEntitySiege) te).setDirection((byte) direction); world.markBlockForUpdate(x, y, z); } } @SideOnly(Side.CLIENT) public Icon getIcon(int side, int metadata) { /* * return side == 1 ? this.icontop : (side == 0 ? this.iconbottom : * (metadata == 2 && side == 2 ? this.iconfront : (metadata == 3 && side * == 5 ? this.iconfront : (metadata == 0 && side == 3 ? this.iconfront * : (metadata == 1 && side == 4 ? this.iconfront : this.blockIcon))))); */ return blockIcon; } @Override public TileEntity createNewTileEntity(World world) { return new TileEntitySiege(); } public boolean renderAsNormalBlock() { return false; } public boolean isOpaqueCube() { return false; } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { return AxisAlignedBB.getAABBPool().getAABB( (double) x + this.minX , (double) y + this.minY, (double) z + this.minZ , (double) x + this.maxX , (double) y + this.maxY , (double) z + this.maxZ ); } public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { return AxisAlignedBB.getAABBPool().getAABB( (double) x + this.minX , (double) y + this.minY, (double) z + this.minZ , (double) x + this.maxX , (double) y + this.maxY , (double) z + this.maxZ ); } @SideOnly(Side.CLIENT) public int getRenderType() { return ClientProxy.renderInventoryTESRId; } @SideOnly(Side.CLIENT) public Icon getBlockTexture(IBlockAccess blockAccess, int x, int y, int z, int side) { TileEntity te = blockAccess.getBlockTileEntity(x, y, z); if (te != null && te instanceof TileEntitySiege) { TileEntitySiege panneau = (TileEntitySiege) te; int direction = panneau.getDirection(); } return this.getIcon(side, blockAccess.getBlockMetadata(x, y, z)); } }
Merci d’avance.
-
Je pense que le mieux, c’est de faire une entity pour que tu puisses asseoir le joueur. Pour le code, tu peux regardé les class du bateau, du wagon, ou du cheval.
-
onBlockActivated. Et après, je plussoie ce de Superloup10 à dit.
-
J’avais déjà fait une chaise, le mieux est de faire une entité qui meurt au bout de 20 ticks si personne n’est dessus, et qui spawn lors d’un click droit sur la chaise.
-
package assets.city01.Entity; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class EntitySitable extends Entity { public static int Timer; public EntitySitable(World par1World) { super(par1World); } @Override protected void entityInit() { Timer = 0; } @Override protected void readEntityFromNBT(NBTTagCompound nbttagcompound) { } @Override protected void writeEntityToNBT(NBTTagCompound nbttagcompound) { } public boolean interactFirst(EntityPlayer par1EntityPlayer) { if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != par1EntityPlayer) { return true; } else { if (!this.worldObj.isRemote) { par1EntityPlayer.mountEntity(this); Timer = 0; } return true; } } public void onEntityUpdate(EntityPlayer par1EntityPlayer) { if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != par1EntityPlayer) { Timer += 1; } if(Timer == 20) { this.setDead; } } }
J’ai une erreur sur le
this.setDead;
C’est le bon morceau de code ou je dois en mettre un autre ?
-
C’est une méthode setDead ^^
setDead();
Et Timer est une variable, selon la convention Java, pas de majuscule ^^
-
public void onBlockActivated(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { EntitySitable Entity = new EntitySitable(world); Entity.setLocationAndAngles(x, y, z, 0, 0.0F); world.spawnEntityInWorld(Entity); }
Dans ma classe du block, aucun effet lorsque j’appuie dessus.
L’entité :
package assets.city01.Entity; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class EntitySitable extends Entity { public static int timer; public EntitySitable(World par1World) { super(par1World); } @Override protected void entityInit() { timer = 0; } @Override protected void readEntityFromNBT(NBTTagCompound nbttagcompound) { } @Override protected void writeEntityToNBT(NBTTagCompound nbttagcompound) { } public boolean interactFirst(EntityPlayer par1EntityPlayer) { if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != par1EntityPlayer) { return true; } else { if (!this.worldObj.isRemote) { par1EntityPlayer.mountEntity(this); timer = 0; } return true; } } public void onEntityUpdate(EntityPlayer par1EntityPlayer) { if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != par1EntityPlayer) { timer += 1; } if(timer == 20) { setDead(); } } }
-
j’aurai mit player.mountEntity(Entity); à la fin du onBlockActivated.
-
ça ne change rien.