I'm working on a mod which involves an entity that, when right clicked, shows the crafting table GUI. Here's my entity code:
public class EntityFakeWorkbench extends EntityTameable implements IEntityOwnable
{
public EntityFakeWorkbench(World world)
{
super(world);
this.setSize(0.5F, 0.5F);
this.setTamed(true);
this.tasks.addTask(1, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
this.tasks.addTask(1, new EntityAIWander(this, 1.0D));
this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityMob.class, 8.0F));
this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(1, new EntityAILookIdle(this));
this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
}
@Override
public boolean isAIEnabled()
{
return true;
}
@Override
public boolean canDespawn()
{
return false;
}
@Override
public void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.3D);
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(12.0D);
this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(60.0D);
}
@Override
public boolean interact(EntityPlayer player)
{
ItemStack itemstack = player.inventory.getCurrentItem();
if(itemstack == null)
{
this.func_152115_b(player.getUniqueID().toString());
int x = (int)player.posX;
int y = (int)player.posY;
int z = (int)player.posZ;
player.displayGUIWorkbench(x, y, z);
return true;
}
else
{
return true;
}
}
@Override
public EntityAgeable createChild(EntityAgeable entity)
{
return null;
}
}
I want the crafting table GUI to open whenever the entity is right-clicked. With the code above, it displays the GUI for only a split second. What am I doing wrong?
It may be because your using the vanilla crafting GUI... its canInteract method looks for a crafting block at the provided coords and checks the players distance relative to that point, so your split second of display time might just be the lag between you trying to open the GUI and this condition invariably testing false
I'm working on a mod which involves an entity that, when right clicked, shows the crafting table GUI. Here's my entity code:
public class EntityFakeWorkbench extends EntityTameable implements IEntityOwnable
{
public EntityFakeWorkbench(World world)
{
super(world);
this.setSize(0.5F, 0.5F);
this.setTamed(true);
this.tasks.addTask(1, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
this.tasks.addTask(1, new EntityAIWander(this, 1.0D));
this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityMob.class, 8.0F));
this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(1, new EntityAILookIdle(this));
this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
}
@Override
public boolean isAIEnabled()
{
return true;
}
@Override
public boolean canDespawn()
{
return false;
}
@Override
public void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.3D);
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(12.0D);
this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(60.0D);
}
@Override
protected String getLivingSound()
{
return "minecraft:dig.wood";
}
@Override
protected String getHurtSound()
{
return "minecraft:dig.wood";
}
@Override
protected String getDeathSound()
{
return "minecraft:random.chestclosed";
}
@Override
public boolean interact(EntityPlayer player)
{
ItemStack itemstack = player.inventory.getCurrentItem();
if(itemstack == null)
{
this.func_152115_b(player.getUniqueID().toString());
int x = (int)player.posX;
int y = (int)player.posY;
int z = (int)player.posZ;
player.displayGUIWorkbench(x, y, z);
return true;
}
else
{
return true;
}
}
@Override
public EntityAgeable createChild(EntityAgeable entity)
{
return null;
}
}
I want the crafting table GUI to open whenever the entity is right-clicked. With the code above, it displays the GUI for only a split second. What am I doing wrong?
Thanks for all help!
It may be because your using the vanilla crafting GUI... its canInteract method looks for a crafting block at the provided coords and checks the players distance relative to that point, so your split second of display time might just be the lag between you trying to open the GUI and this condition invariably testing false