Fix custom item entities not showing on the client

Fix crystal growth not syncing
This commit is contained in:
Sebastian Hartte
2020-06-13 20:25:00 +02:00
parent b9381fc2e1
commit 0db7e70722
19 changed files with 111 additions and 51 deletions
@@ -25,25 +25,38 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.IPacket;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;
public abstract class AEBaseEntityItem extends ItemEntity
{
public AEBaseEntityItem( EntityType<? extends AEBaseEntityItem> entityType, final World world )
protected AEBaseEntityItem( EntityType<? extends AEBaseEntityItem> entityType, final World world )
{
super( entityType, world );
}
public AEBaseEntityItem( final World world, final double x, final double y, final double z, final ItemStack stack )
protected AEBaseEntityItem( EntityType<? extends AEBaseEntityItem> entityType, final World world, final double x, final double y, final double z, final ItemStack stack )
{
super( world, x, y, z, stack );
this(entityType, world);
this.setPosition(x, y, z);
this.rotationYaw = this.rand.nextFloat() * 360.0F;
this.setMotion(this.rand.nextDouble() * 0.2D - 0.1D, 0.2D, this.rand.nextDouble() * 0.2D - 0.1D);
this.setItem(stack);
this.lifespan = stack.getEntityLifespan(world);
}
protected List<Entity> getCheckedEntitiesWithinAABBExcludingEntity( final AxisAlignedBB region )
{
return this.world.getEntitiesWithinAABBExcludingEntity( this, region );
}
@Override
public IPacket<?> createSpawnPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
}
@@ -45,6 +45,8 @@ import appeng.util.Platform;
public final class EntityChargedQuartz extends AEBaseEntityItem
{
public static EntityType<EntityChargedQuartz> TYPE;
private int delay = 0;
private int transformTime = 0;
@@ -54,7 +56,7 @@ public final class EntityChargedQuartz extends AEBaseEntityItem
public EntityChargedQuartz(final World w, final double x, final double y, final double z, final ItemStack is )
{
super( w, x, y, z, is );
super( TYPE, w, x, y, z, is );
}
@Override
@@ -19,28 +19,33 @@
package appeng.entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public final class EntityFloatingItem extends ItemEntity
// This is not supposed to ever spawn on the server-side
public final class EntityFloatingItem extends AEBaseEntityItem
{
private final ICanDie parent;
public static EntityType<EntityFloatingItem> TYPE;
private ICanDie parent;
private int superDeath = 0;
private float progress = 0;
public EntityFloatingItem( final ICanDie parent, final World world, final double x, final double y, final double z, final ItemStack stack )
public EntityFloatingItem(EntityType<? extends AEBaseEntityItem> entityType, World world) {
super(entityType, world);
}
public EntityFloatingItem(final ICanDie parent, final World world, final double x, final double y, final double z, final ItemStack stack )
{
super( world, x, y, z, stack );
super( TYPE, world, x, y, z, stack );
this.setMotion( 0, 0, 0 );
this.rotationYaw = 0;
this.parent = parent;
}
// public boolean isEntityAlive()
@Override
public void tick()
{
@@ -39,9 +39,11 @@ import appeng.api.features.AEFeature;
import appeng.util.Platform;
public final class EntityGrowingCrystal extends ItemEntity
public final class EntityGrowingCrystal extends AEBaseEntityItem
{
public static EntityType<EntityGrowingCrystal> TYPE;
private int progress_1000 = 0;
public EntityGrowingCrystal(EntityType<? extends EntityGrowingCrystal> type, World world) {
@@ -50,7 +52,7 @@ public final class EntityGrowingCrystal extends ItemEntity
public EntityGrowingCrystal(final World w, final double x, final double y, final double z, final ItemStack is )
{
super( w, x, y, z, is );
super( TYPE, w, x, y, z, is );
this.setNoDespawn();
}
@@ -143,7 +145,10 @@ public final class EntityGrowingCrystal extends ItemEntity
if( this.progress_1000 > 1000 )
{
this.progress_1000 -= 1000;
this.setItem( cry.triggerGrowth( is ) );
// We need to copy the stack or the change detection will not work and not sync
// this new stack to the client
ItemStack newItem = cry.triggerGrowth(is.copy());
this.setItem(newItem);
}
}
}
@@ -195,4 +200,11 @@ public final class EntityGrowingCrystal extends ItemEntity
return te instanceof ICrystalGrowthAccelerator && ( (ICrystalGrowthAccelerator) te ).isPowered();
}
// Don't let seeds "float" on water surface
@Override
protected void applyFloatMotion() {
}
}
@@ -42,6 +42,8 @@ import appeng.util.Platform;
public final class EntitySingularity extends AEBaseEntityItem
{
public static EntityType<EntitySingularity> TYPE;
private static int randTickSeed = 0;
public EntitySingularity(EntityType<? extends EntitySingularity> entityType, final World w )
@@ -51,7 +53,7 @@ public final class EntitySingularity extends AEBaseEntityItem
public EntitySingularity( final World w, final double x, final double y, final double z, final ItemStack is )
{
super( w, x, y, z, is );
super( TYPE, w, x, y, z, is );
}
@Override
@@ -54,6 +54,8 @@ import appeng.util.Platform;
public final class EntityTinyTNTPrimed extends TNTEntity implements IEntityAdditionalSpawnData
{
public static EntityType<EntityTinyTNTPrimed> TYPE;
public EntityTinyTNTPrimed( EntityType<? extends EntityTinyTNTPrimed> type, World worldIn )
{
super( type, worldIn );