- 5,149
- 49
- 899
господа, всем добрый вечер. С огромными мучениями прорываясь сквозь дебри своего собственного говнокода и незнания форджа я родил таки класс энтити, который полностью удовлетворяет моему желанию... за малым исключением. При перезаходе сущности исчезают! Что за дела? Все перепробовал уже.
Java:
public class ItemWallpaper extends Item
{
private final Class <? extends EntityHanging > hangingEntityClass;
public ItemWallpaper(String name, Class <? extends EntityHanging > entityClass)
{
this.hangingEntityClass = entityClass;
this.setCreativeTab(SovietCore.tabMain);
this.setRegistryName(name);
this.setUnlocalizedName(name);
}
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack itemstack = player.getHeldItem(hand);
BlockPos blockpos = pos.offset(facing);
if (facing != EnumFacing.DOWN && facing != EnumFacing.UP)
{
EntityHanging entityhanging = new EntityWallpaper(worldIn, blockpos, facing);
if(worldIn.isRemote) {
worldIn.spawnEntity(entityhanging);
entityhanging.playPlaceSound();
}
itemstack.shrink(1);
return EnumActionResult.SUCCESS;
}
else
{
return EnumActionResult.FAIL;
}
}
}
нбт присутствуют...
Код:
public class EntityWallpaper extends EntityHanging {
public EntityWallpaper(World worldIn)
{
super(worldIn);
}
public EntityWallpaper(World worldIn, BlockPos pos, EnumFacing facing)
{
super(worldIn, pos);
this.updateFacingWithBoundingBox(facing);
}
@Override
public void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
}
@Override
public void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
}
public int getWidthPixels()
{
return 16;
}
public int getHeightPixels()
{
return 16;
}
@Override
public boolean attackEntityFrom(DamageSource source, float amount)
{
if(this.getEntityWorld().isRemote) this.setDead();
return true;
}
@Override
public void onBroken(@Nullable Entity brokenEntity)
{
return;
}
public void playPlaceSound()
{
this.playSound(SoundEvents.ENTITY_PAINTING_PLACE, 1.0F, 1.0F);
}
/**
* Sets the location and Yaw/Pitch of an entity in the world
*/
public void setLocationAndAngles(double x, double y, double z, float yaw, float pitch)
{
this.setPosition(x, y, z);
}
@SideOnly(Side.CLIENT)
public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
{
BlockPos blockpos = this.hangingPosition.add(x - this.posX, y - this.posY, z - this.posZ);
this.setPosition((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
}
}