Hello everyone! I'm trying to make a custom entity, but whenever I try to spawn it in the world, I get this error:
java.lang.NullPointerException: Ticking memory connection
at net.minecraft.entity.DataWatcher.updateObject(DataWatcher.java:157)
at net.minecraft.entity.EntityLivingBase.setHealth(EntityLivingBase.java:860)
at net.minecraft.entity.EntityLivingBase.(EntityLivingBase.java:205)
at net.minecraft.entity.EntityLiving.(EntityLiving.java:98)
at net.minecraft.entity.EntityFlying.(EntityFlying.java:12)
at tlf.apache.entity.EntityApache.(EntityApache.java:61)
at tlf.apache.item.ItemApache.onItemUse(ItemApache.java:30)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:150)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:424)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:596)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:762)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787)
I've traced it back to this function:
public void setHealth(float par1)
{
this.dataWatcher.updateObject(6, Float.valueOf(MathHelper.clamp_float(par1, 0.0F, this.getMaxHealth())));
}
but I can't see any reason why it would crash. Any ideas? Thanks in advance!
Code:
package tlf.apache.entity;
import net.minecraft.entity.EntityFlying;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.world.World;
public class EntityApache extends EntityFlying
{
public final float rotor1RotationIncrement = 0.628F;
/*
public float enginePower = 0.0F;
public float throttle = 0.5F;
public int fuel = 0;
public boolean isOn = false;
public boolean shouldStart = false;
public boolean shouldStop = false;
public boolean isStarting = false;
public boolean isStopping = false;
*/
public float rotor1Rotation = 0.0F;
public int updateCooldown = 0;
private float customRotationYaw = 0.0F;
private IUpdatePlayerListBox soundUpdater;
private class DWIDS {
private static final int FUEL = 12;
private static final int ENGINEPOWER = 13;
private static final int THROTTLE = 14;
private static final int BITMAP = 15;
}
private enum Bools {
ISON(1),
SHOULDSTART(2),
SHOULDSTOP(4),
ISSTARTING(8),
ISSTOPPING(16);
private int bit;
private Bools(int i) {
this.bit = i;
}
public int bit() {
return this.bit;
}
}
public EntityApache(World par1World)
{
super(par1World);
this.setSize(0.4F, 1.8F);
//this.soundUpdater = par1World != null ? new SoundUpdaterApache(Minecraft.getMinecraft().sndManager, this, Minecraft.getMinecraft().thePlayer) : null;
this.setHealth(1.0F);
}
protected void entityInit()
{
this.dataWatcher.addObject(DWIDS.FUEL, 0);
this.dataWatcher.addObject(DWIDS.ENGINEPOWER, 0.0F);
this.dataWatcher.addObject(DWIDS.THROTTLE, 0.5F);
this.dataWatcher.addObject(DWIDS.BITMAP, 0);
}
@Override
public boolean isAIEnabled()
{
return false;
}
@Override
public boolean canBePushed()
{
return false;
}
@Override
public void onLivingUpdate()
{
super.onLivingUpdate();
if (this.dataWatcher.getWatchableObjectInt(DWIDS.FUEL) <= 0)
{
this.setBool(Bools.SHOULDSTOP, true);
}
if (this.getBool(Bools.SHOULDSTART))
{
this.setBool(Bools.SHOULDSTART, false);
this.setBool(Bools.ISSTARTING, true);
this.setBool(Bools.ISSTOPPING, false);
this.setBool(Bools.ISON, true);
}
else if (this.getBool(Bools.SHOULDSTOP))
{
this.setBool(Bools.SHOULDSTOP, false);
this.setBool(Bools.ISSTARTING, false);
this.setBool(Bools.ISSTOPPING, true);
this.setBool(Bools.ISON, false);
}
if (this.updateCooldown > 0) {
this.updateCooldown--;
} else {
this.updateCooldown = 10;
this.updateRotationIncrement();
}
if (this.rotor1Rotation > 6.283F) {
this.rotor1Rotation -= 6.283F;
}
if (this.soundUpdater != null)
{
if (this.isDead) { System.out.println(":D"); }
this.soundUpdater.update();
}
this.dataWatcher.updateObject(DWIDS.THROTTLE, 0.5F);
float enginePower = this.dataWatcher.getWatchableObjectFloat(DWIDS.ENGINEPOWER);
float throttle = this.dataWatcher.getWatchableObjectFloat(DWIDS.THROTTLE);
this.rotor1Rotation += this.rotor1RotationIncrement*enginePower + ((0.5F - throttle)/2);
this.rotationYaw = 0.0F;
}
@Override
public boolean interact(EntityPlayer par1EntityPlayer)
{
if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != par1EntityPlayer)
{
return true;
} else {
if (!this.worldObj.isRemote)
{
if (par1EntityPlayer.isSneaking()) {
if (this.getBool(Bools.ISON)) {
this.setBool(Bools.SHOULDSTOP, true);
} else {
this.setBool(Bools.SHOULDSTART, true);
}
} else {
this.setBool(Bools.SHOULDSTART, true);
par1EntityPlayer.mountEntity(this);
}
}
return true;
}
}
private boolean getBool(Bools key) {
return (this.dataWatcher.getWatchableObjectByte(DWIDS.BITMAP) & key.bit()) != 0;
}
private void setBool(Bools key, boolean value) {
int mask = this.dataWatcher.getWatchableObjectByte(DWIDS.BITMAP);
if (value) {
mask |= key.bit();
} else {
mask &= ~key.bit();
}
this.dataWatcher.updateObject(DWIDS.BITMAP, mask);
}
private void updateRotationIncrement()
{
float enginePower = this.dataWatcher.getWatchableObjectFloat(DWIDS.ENGINEPOWER);
enginePower += this.getBool(Bools.ISSTARTING) ? 0.01F : (this.getBool(Bools.ISSTOPPING) ? -0.005F : 0.0F);
if (enginePower >= 1.0F) {
enginePower = 1.0F;
this.setBool(Bools.ISSTARTING, false);
} else if (enginePower <= 0.0F) {
enginePower = 0.0F;
this.setBool(Bools.ISSTOPPING, false);
}
if (enginePower > 0.5F) {
//this.motionY += (double)(0.5 * (this.rotor1RotationIncrement - 0.5F)/0.5F) ;
}
this.dataWatcher.updateObject(DWIDS.ENGINEPOWER, enginePower);
//this.rotor1EnginePower = 0.0F;
}
@Override
public double getMountedYOffset()
{
return -0.15;
}
@Override
public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeEntityToNBT(par1NBTTagCompound);
par1NBTTagCompound.setInteger("fuel", this.dataWatcher.getWatchableObjectInt(DWIDS.FUEL));
par1NBTTagCompound.setBoolean("isStarting", this.getBool(Bools.ISSTARTING));
par1NBTTagCompound.setBoolean("isOn", this.getBool(Bools.ISON));
par1NBTTagCompound.setBoolean("isStopping", this.getBool(Bools.ISSTOPPING));
par1NBTTagCompound.setFloat("enginePower", this.dataWatcher.getWatchableObjectFloat(DWIDS.ENGINEPOWER));
par1NBTTagCompound.setFloat("rotor1Rotation", this.rotor1Rotation);
}
@Override
public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readEntityFromNBT(par1NBTTagCompound);
this.dataWatcher.updateObject(DWIDS.FUEL, par1NBTTagCompound.getInteger("fuel"));
this.setBool(Bools.ISSTARTING, par1NBTTagCompound.getBoolean("isStarting"));
this.setBool(Bools.ISON, par1NBTTagCompound.getBoolean("isOn"));
this.setBool(Bools.ISSTOPPING, par1NBTTagCompound.getBoolean("isStopping"));
this.dataWatcher.updateObject(DWIDS.ENGINEPOWER, par1NBTTagCompound.getFloat("enginePower"));
this.rotor1Rotation = par1NBTTagCompound.getFloat("rotor1Rotation");
}
}
EDIT: Fixed! Forgot to call 'super.entityInit();' XP
at net.minecraft.entity.DataWatcher.updateObject(DataWatcher.java:157)
at net.minecraft.entity.EntityLivingBase.setHealth(EntityLivingBase.java:860)
at net.minecraft.entity.EntityLivingBase.(EntityLivingBase.java:205)
at net.minecraft.entity.EntityLiving.(EntityLiving.java:98)
at net.minecraft.entity.EntityFlying.(EntityFlying.java:12)
at tlf.apache.entity.EntityApache.(EntityApache.java:61)
at tlf.apache.item.ItemApache.onItemUse(ItemApache.java:30)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:150)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:424)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:596)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:762)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787)
but I can't see any reason why it would crash. Any ideas? Thanks in advance!
Code:
EDIT: Fixed! Forgot to call 'super.entityInit();' XP
-tlf
-tlf