Sauf que ma propre entité est extends EntityHorse malheureusement ^^
Du coup je reviens sur ma première proposition. Actuellement donc j’ai simplement les méthodes pour ajouter une touche personnalisée.
@SubscribeEvent
public void onEvent(KeyInputEvent event)
{
if(ModPg2.keyBindPassager.isPressed())
{
keyPassagerTyped();
}
}
private void keyPassagerTyped()
{
if (Minecraft.getMinecraft().thePlayer.ridingEntity != null)
{
// Je fais spawn mon entité qui suivra le joueur
if (Minecraft.getMinecraft().thePlayer.ridingEntity != null)
{
// Je fais spawn mon entité qui suivra le joueur
EntitySittable e = new EntitySittable(Minecraft.getMinecraft().thePlayer.worldObj);
if(!Minecraft.getMinecraft().thePlayer.worldObj.isRemote)
{
e.setPosition(Minecraft.getMinecraft().thePlayer.posX + 0.5F, Minecraft.getMinecraft().thePlayer.posY, Minecraft.getMinecraft().thePlayer.posZ);
Minecraft.getMinecraft().thePlayer.worldObj.spawnEntityInWorld(e);
}
}
}
Minecraft.getMinecraft().thePlayer.addChatComponentMessage(new ChatComponentText("Ok pour la touche"));
}
et la classe de mon entité qui devra suivre le joueur
package fr.powergame.modpg2.common;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class EntitySittable extends Entity
{
public int entityPosX;
public int entityPosY;
public int entityPosZ;
public EntitySittable(World world)
{
super(world);
this.preventEntitySpawning = true;
this.setSize(0.5F, 0.5F);
}
public EntitySittable(World world, EntityPlayer entityplayer, int x, int y, int z, float entityX, float entityY, float entityZ)
{
this(world);
this.entityPosX = x;
this.entityPosY = y;
this.entityPosZ = z;
this.setPosition(entityX, entityY, entityZ);
}
public boolean interact(EntityPlayer entityplayer)
{
if(this.riddenByEntity != null)
{
return true;
}
if(!this.worldObj.isRemote)
{
entityplayer.mountEntity(this);
}
return true;
}
@Override
public void onEntityUpdate()
{
if(this.riddenByEntity == null || this.riddenByEntity.isDead)
{
this.setDead();
}
super.onEntityUpdate();
}
@Override
public void writeEntityToNBT(NBTTagCompound nbt)
{
nbt.setInteger("entityPosX", this.entityPosX);
nbt.setInteger("entityPosY", this.entityPosY);
nbt.setInteger("entityPosZ", this.entityPosZ);
}
@Override
public void readEntityFromNBT(NBTTagCompound nbt)
{
this.entityPosX = nbt.getInteger("entityPosX");
this.entityPosY = nbt.getInteger("entityPosY");
this.entityPosZ = nbt.getInteger("entityPosZ");
}
@Override
protected void entityInit()
{
}
}
A la base cette entité sert pour s’asseoir sur un bloc, j’ai juste renommé les Posx/y/z en attendant.