Jump to content

Recommended Posts

Posted

I've created an item that overrides Item's onItemUse method:

 

@Override
public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer player, World world, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_)
{
    if (world.isRemote) return false;

    MinecraftServer server = MinecraftServer.getServer();

    FakePlayer fakePlayer = new FakePlayer(
            server,
            server.worldServerForDimension(player.dimension),
            new GameProfile(null, "Fake Player"),
            new ItemInWorldManager(world)
    );

    world.spawnEntityInWorld(fakePlayer);

    return true;
}

 

I've wrapped the whole thing in a try/catch block but a NullPointerException keeps getting thrown somewhere:

 

java.lang.NullPointerException: Exception in server tick loop
at net.minecraft.entity.EntityTrackerEntry.func_151261_b(EntityTrackerEntry.java:323)
at net.minecraft.entity.EntityTrackerEntry.func_111190_b(EntityTrackerEntry.java:289)
at net.minecraft.entity.EntityTrackerEntry.func_73122_a(EntityTrackerEntry.java:226)
at net.minecraft.entity.EntityTracker.func_72788_a(EntityTracker.java:270)
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:648)
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:547)
at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:111)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685)

 

EntityTrackerEntry.func_151261_b deals with packet stuff. Do I need to use the Simple Network Wrapper stuff?

I like trains.

Posted

No, it has to do with the entity's spawn packet, which you would get by registering the entity to the game registry using registerModEntity, but why the heck are you trying to spawn a FakePlayer? I don't think that this is what it was designed for...

 

Oh I have a class called FakePlayer, I'm not using the one in Forge (didn't know there was one when I made this topic). Okay I'll look for the registerModEntity method.

I like trains.

Posted

I'm getting this exception when I spawn my fake player:

 

java.lang.NoSuchMethodException: untouchedwagons.minecraft.fakeplayer.entities.FakePlayer.<init>(net.minecraft.world.World)

 

My FakePlayer class:

 

package untouchedwagons.minecraft.fakeplayer.entities;

import com.mojang.authlib.GameProfile;
import cpw.mods.fml.common.Mod;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.ItemInWorldManager;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;

public class FakePlayer extends EntityPlayerMP
{
    public FakePlayer(MinecraftServer p_i45285_1_, WorldServer p_i45285_2_, GameProfile p_i45285_3_, ItemInWorldManager p_i45285_4_)
    {
        super(p_i45285_1_, p_i45285_2_, p_i45285_3_, p_i45285_4_);


    }

    @Mod.EventHandler
    public void init(World world)
    {

    }
}

I like trains.

Posted

Some object, somewhere, has tried used reflection to find a constructor for your FakePlayer class taking a single parameter of type World. Since your constructor takes 4 parameters, it could not be found and the object threw the exception.

 

You need to look at the exception's stack trace to find where the problem is.

Posted

Yeah I've figured out that I need my class to extend EntityLiving, not EntityPlayerMP:

 

package untouchedwagons.minecraft.fakeplayer.entities;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.world.World;

public class FakePlayer extends EntityLiving
{
    public FakePlayer(World world) {
        super(world);

        this.setAlwaysRenderNameTag(true);
        this.setCanPickUpLoot(false);
        this.setCustomNameTag("Fake Player");
        this.setHealth(20);

        // This method makes the mob not despawn
        this.func_110163_bv();

        this.tasks.addTask(0, new EntityAILookIdle(this));
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0);
    }

    @Override
    public boolean isAIEnabled()
    {
        return false;
    }
}

 

However this entity doesn't activate spawners which is ultimately what I want to do, but I don't know how to do it. I've looked at the TileEntityMobSpawner class, followed it to MobSpawnerBaseLogic then to World's getClosestPlayer and noticed that a spawner is activated when a EntityPlayer class is within 16 blocks (or whatever) of the spawner. If I add my entity to the world instance's playerEntities list then the game crashes because my entity can't be cast to an instance of EntityPlayerMP. I don't know what to do from that point.

I like trains.

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.