Jump to content

Recommended Posts

Posted

So, I am trying to create an entity that floats in the middle of my transparent block. Pretty simple, except that it won't spawn! It throws a NullPointerException at my super(world) in my Entity class. Here is everything, I hope I can get some help.

 

EntityClass:

package com.happykiller.weightlimit.entites;

import net.minecraft.entity.EntityLiving;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityUpgradeCore extends EntityLiving {

public int innerRotation;

public EntityUpgradeCore(World world) {
	super(world); //THIS IS WHERE I GET THE NULL ERROR
        this.preventEntitySpawning = true;
        this.setSize(2.0F, 2.0F);
        this.innerRotation = this.rand.nextInt(100000);
}

@SideOnly(Side.CLIENT)
public EntityUpgradeCore(World worldIn, double posX, double posY, double posZ) {
	this(worldIn);
	this.setPosition(posX, posY, posZ);
}

protected boolean canTriggerWalking() {
	return false;
}

public boolean canBeCollidedWith() {
	return false;
}

public void onUpdate() {
	innerRotation++;
}

protected void entityInit() {}
}

 

Render:

package com.happykiller.weightlimit.client.renderer;

import com.happykiller.weightlimit.entites.EntityUpgradeCore;
import com.happykiller.weightlimit.main.ModReference;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderEntityUCore extends RenderLiving<EntityUpgradeCore> {

private ResourceLocation rl = new ResourceLocation(ModReference.MOD_RL + "/textures/entity/entity_upgrade_core.png");

public RenderEntityUCore(RenderManager renderManager, ModelBase model, float scale) {
	super(renderManager, model, scale);
	this.shadowSize = 0.0F;
}

protected ResourceLocation getEntityTexture(EntityUpgradeCore entity) {
	return rl;
}
}

 

Registering (called in my init):

public void registerEntityRenders() {
RenderManager rm = Minecraft.getMinecraft().getRenderManager();

RenderingRegistry.registerEntityRenderingHandler(EntityUpgradeCore.class, new RenderEntityUCore(rm, new ModelUpgradeCore(), 0.0F));
}

 

How I am trying to spawn it:

public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
	Entity entity = new EntityUpgradeCore(worldIn);
	entity.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), worldIn.rand.nextFloat() * 360.0F, 0.0F);

	if(!worldIn.isRemote)
		worldIn.spawnEntityInWorld(entity);

	super.onBlockAdded(worldIn, pos, state);
}

 

Any help is welcome!

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Here it is:

Caused by: java.lang.NullPointerException
at net.minecraft.entity.DataWatcher.updateObject(DataWatcher.java:150) ~[DataWatcher.class:?]
at net.minecraft.entity.EntityLivingBase.setHealth(EntityLivingBase.java:824) ~[EntityLivingBase.class:?]
at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:164) ~[EntityLivingBase.class:?]
at net.minecraft.entity.EntityLiving.<init>(EntityLiving.java:74) ~[EntityLiving.class:?]
at com.happykiller.weightlimit.entites.EntityUpgradeCore.<init>(EntityUpgradeCore.java:13) ~[EntityUpgradeCore.class:?]
at com.happykiller.weightlimit.blocks.BlockUpgradeStation.onBlockAdded(BlockUpgradeStation.java:47) ~[blockUpgradeStation.class:?]
at net.minecraft.world.chunk.Chunk.setBlockState(Chunk.java:729) ~[Chunk.class:?]
at net.minecraft.world.World.setBlockState(World.java:375) ~[World.class:?]
at net.minecraft.item.ItemBlock.placeBlockAt(ItemBlock.java:192) ~[itemBlock.class:?]
at net.minecraft.item.ItemBlock.onItemUse(ItemBlock.java:66) ~[itemBlock.class:?]
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:720) ~[ForgeHooks.class:?]
at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:143) ~[itemStack.class:?]
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:481) ~[itemInWorldManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:617) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:70) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:10) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_66]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_66]
at net.minecraft.util.Util.func_181617_a(Util.java:22) ~[util.class:?]
... 5 more

 

It doesn't crash the game, and line 13 is my main constructor's (the one with just a world param) super.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

The exception is being thrown because it's trying to update an object (the entity's health, index 6) that doesn't exist in the

DataWatcher

. This is added in

EntityLivingBase#entityInit

, but you've overridden this to do nothing.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

How would I go about fixing this? Don't have too much experience with entities. :/

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

If you override the method, make sure you call the super method. Or just don't override it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I seem to get no errors now, but my entity isn't rendering. :/ I called the super on #onUpdate, and #entityInit. I also removed the server check before spawning the entity, to see if that would fix it. Sadly, it had no affect.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Alright, I was simply registering my Entity wrong. :P My only problems now consist of it still being able to fall, and entities able to collide with it. I need it to float in the middle of my block, and this is not possible when it still can fall. :/

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Have you considered extending

Entity

instead of

EntityLiving

? It doesn't seem like your entity is a living entity with AI, equipment, etc.

 

I'm not entirely sure, but I think

EntityLivingBase

/

EntityLiving

may apply downward motion to any entity not on the ground.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

It seems that was the case. I extended Entity, and followed some render options used in the RenderEnderCrystal to get it working. My only problem now seems to be that the hit box is WAY below the actual entity:

 

 

If I can figure out how to fix this, I think I'll be good. Here are the new classes:

 

Rendering (I think the problem lies here, but I'm unsure):

package com.happykiller.weightlimit.client.renderer;

import com.happykiller.weightlimit.entites.EntityUpgradeCore;
import com.happykiller.weightlimit.main.ModReference;
import com.happykiller.weightlimit.render.models.ModelUpgradeCore;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelEnderCrystal;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderEntity;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.item.EntityEnderCrystal;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderEntityUCore extends Render<EntityUpgradeCore> {

private static final ResourceLocation rl = new ResourceLocation(ModReference.MOD_RL + "textures/entity/entity_upgrade_core.png");
    private ModelBase model = new ModelUpgradeCore();

    public RenderEntityUCore(RenderManager renderManagerIn) {
        super(renderManagerIn);
        this.shadowSize = 0.5F;
    }
    
    public void doRender(EntityUpgradeCore entity, double x, double y, double z, float entityYaw, float partialTicks) {
        float f = (float)entity.innerRotation + partialTicks;
        GlStateManager.pushMatrix();
        GlStateManager.translate((float)x, (float)y, (float)z);
        this.bindTexture(rl);
        float f1 = MathHelper.sin(f * 0.2F) / 2.0F + 0.5F;
        f1 = f1 * f1 + f1;
        this.model.render(entity, 0.0F, f * 3.0F, f1 * 0.2F, 0.0F, 0.0F, 0.0625F);
        GlStateManager.popMatrix();
        super.doRender(entity, x, y, z, entityYaw, partialTicks);
    }

protected ResourceLocation getEntityTexture(EntityUpgradeCore entity) {
	return rl;
}
}

 

Entity:

package com.happykiller.weightlimit.entites;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityUpgradeCore extends Entity {

public int innerRotation;

public EntityUpgradeCore(World world) {
	super(world);
        this.preventEntitySpawning = true;
        this.setSize(0.1F, 0.1F);
        this.innerRotation = this.rand.nextInt(100000);
}

@SideOnly(Side.CLIENT) //Most likely will be removed, only here because of the EntityEnderCrystal
public EntityUpgradeCore(World worldIn, double posX, double posY, double posZ) {
	this(worldIn);
	this.setPosition(posX, posY, posZ);
}

protected boolean canTriggerWalking() {
	return false;
}

public boolean canBeCollidedWith() {
	return true;
}

public void onUpdate() {
	super.onUpdate();
	innerRotation++;
}

protected void entityInit() {}

protected void readEntityFromNBT(NBTTagCompound tagCompund) {

}

protected void writeEntityToNBT(NBTTagCompound tagCompound) {

}
}

 

Spawning:

public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
	super.onBlockAdded(worldIn, pos, state);

	Entity entity = new EntityUpgradeCore(worldIn);
	entity.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), 0.0F, 0.0F);

	if(!worldIn.isRemote)
		worldIn.spawnEntityInWorld(entity);
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

After having some trial and error, I discovered the Enchantment Table uses a TileEntitySpecialRenderer to render it's model on the block. I've switched to this, and it works nearly flawlessly. :P Thanks for the help!

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.