Jump to content

Mob Spawner help? [SOLVED FINALLY]


SureenInk

Recommended Posts

Okay, so, I want to make a mob spawner. According to the minecraft forge wiki I do the following:

TileEntityMobSpawner spawner1 = (TileEntityMobSpawner)world.getTileEntity(i + 21, j + 6, k + 33);
if (spawner1 == null) {
   System.out.println("TomBoy Spawner 1 is Null.");
} else {
   spawner1.func_145881_a().setEntityName("Zombie");
}

That works perfectly fine. Now the question is... I want to make this zombie spawner spawn Baby Zombies with armor and weapons. How would I go about doing that? I tried this, but it didn't do anything.

	    NBTTagCompound nbt = new NBTTagCompound();
    spawner1.writeToNBT(nbt);
    nbt.setBoolean("IsBaby",true);
    spawner1.readFromNBT(nbt);

Link to comment
Share on other sites

Use

spawner1.func_145881_a().setRandomEntity(new WeightedRandomMinecart(nbt, entityName))

where

nbt

is the NBT you want to give your entities and

entityName

the name of the entity you want to spawn.

 

Using that, you can omit

spawner1.func_145881_a().setEntityName("Zombie");

, since above code does this as well.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

I feel like a noob here... I imagine with the "nbt" in that statement, I input the nbt into that part? Or do I set it up like before with the nbt stuff followed by that line of code? I'm not sure how to code the nbt data into that line if that's what I have to do, and I tried this, but got an error:

		    NBTTagCompound nbt = new NBTTagCompound();
	    spawner1.writeToNBT(nbt);
	    nbt.setBoolean("IsBaby",true);
	    spawner1.readFromNBT(nbt);
		spawner1.func_145881_a().setRandomEntity(new WeightedRandomMinecart(nbt, "Zombie"));

No enclosing instance of type MobSpawnerBaseLogic is accessible. Must qualify the allocation with an enclosing instance of type MobSpawnerBaseLogic (e.g. x.new A() where x is an instance of MobSpawnerBaseLogic).

I know it's probably just a matter of me not understanding the code 100%... but again, that's the problem, I don't understand the code... Like I said, I'm not sure how to input that nbt stuff into the nbt line, and putting the nbt info in and then calling that seems to cause the error, so now I'm confused x.x Sorry.

Link to comment
Share on other sites

I feel like a noob here... I imagine with the "nbt" in that statement, I input the nbt into that part? Or do I set it up like before with the nbt stuff followed by that line of code? I'm not sure how to code the nbt data into that line if that's what I have to do, and I tried this, but got an error:

		    NBTTagCompound nbt = new NBTTagCompound();
	    spawner1.writeToNBT(nbt);
	    nbt.setBoolean("IsBaby",true);
	    spawner1.readFromNBT(nbt);
		spawner1.func_145881_a().setRandomEntity(new WeightedRandomMinecart(nbt, "Zombie"));

No enclosing instance of type MobSpawnerBaseLogic is accessible. Must qualify the allocation with an enclosing instance of type MobSpawnerBaseLogic (e.g. x.new A() where x is an instance of MobSpawnerBaseLogic).

I know it's probably just a matter of me not understanding the code 100%... but again, that's the problem, I don't understand the code... Like I said, I'm not sure how to input that nbt stuff into the nbt line, and putting the nbt info in and then calling that seems to cause the error, so now I'm confused x.x Sorry.

 

1.  you don't need the write/read NBT methods from your spawner.

2. The error has something to do that WeightedRandomMinecart is a non-static inner class from MobSpawnerBaseLogic, means you need to use an instance of MobSpawnerBaseLogic to create a new instance of WeightedRandomMinecart, like this:

spawner1.func_145881_a().new WeightedRandomChestMinecart(nbt, entityName)

 

Also I recommend to save the return value of func_145881_a() in a variable to avoid repeated calls to that method.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

I feel like a noob here... I imagine with the "nbt" in that statement, I input the nbt into that part? Or do I set it up like before with the nbt stuff followed by that line of code? I'm not sure how to code the nbt data into that line if that's what I have to do, and I tried this, but got an error:

		    NBTTagCompound nbt = new NBTTagCompound();
	    spawner1.writeToNBT(nbt);
	    nbt.setBoolean("IsBaby",true);
	    spawner1.readFromNBT(nbt);
		spawner1.func_145881_a().setRandomEntity(new WeightedRandomMinecart(nbt, "Zombie"));

No enclosing instance of type MobSpawnerBaseLogic is accessible. Must qualify the allocation with an enclosing instance of type MobSpawnerBaseLogic (e.g. x.new A() where x is an instance of MobSpawnerBaseLogic).

I know it's probably just a matter of me not understanding the code 100%... but again, that's the problem, I don't understand the code... Like I said, I'm not sure how to input that nbt stuff into the nbt line, and putting the nbt info in and then calling that seems to cause the error, so now I'm confused x.x Sorry.

 

1.  you don't need the write/read NBT methods from your spawner.

2. The error has something to do that WeightedRandomMinecart is a non-static inner class from MobSpawnerBaseLogic, means you need to use an instance of MobSpawnerBaseLogic to create a new instance of WeightedRandomMinecart, like this:

spawner1.func_145881_a().new WeightedRandomChestMinecart(nbt, entityName)

 

Also I recommend to save the return value of func_145881_a() in a variable to avoid repeated calls to that method.

I'm confused...didn't I have that code in there, though? Or am I missing something? I got rid of the read/write nbt lines, so now I have:

	    NBTTagCompound nbt = new NBTTagCompound();
	    nbt.setBoolean("IsBaby",true);
		spawner1.func_145881_a().setRandomEntity(new WeightedRandomMinecart(nbt, "Zombie"));

That last line there is the line you gave me... Unless I'm not supposed to be inputting the actual entityName into it and am supposed to be doing that separate somewhere else? I'm sorry I'm being a bit of a pain about this... This is probably something super simple that I should have been able to set up with just your initial statement... but I just don't understand how this works...

Link to comment
Share on other sites

If you didn't see the difference in the code SanAndreasP posted and yours it's here:

 

spawner1.func_145881_a().new WeightedRandomChestMinecart(nbt, entityName)

 

This creates a new WeightedRandomChestMinecart object with the specified parameters

--Remember to "Thank you" posts that actually helped you, and if a person seems nice, why not give them an applaud while you're at it--

Link to comment
Share on other sites

Oh wow... I feel stupid now. Yeah, that is different code. It looked very similar, so my mind read it as being the same code (I have a number of reading disorders). That said... I got an error on the WeightedRandomChestMinecart. Java told me to change it to "WeightedRandomMinecart".

MobSpawnerBaseLogic.WeightedRandomChestMinecart cannot be resolved to a type

I changed it to the WeightedRandomMinecart instead like it said...but it doesn't seem to change anything with the mob spawner. I'm still getting regular Zombies and I'm trying to make it spawn Baby Zombies.

 

EDIT: Correction... I forgot to destroy the spawners and then regenerate them. They've all turned into pig spawners now...

TileEntityMobSpawner spawner1 = (TileEntityMobSpawner)world.getTileEntity(i + 21, j + 6, k + 33);
	if (spawner1 == null) {
		System.out.println("TomBoy Spawner 1 is Null.");
	} else {
	    NBTTagCompound nbt = new NBTTagCompound();
	    nbt.setBoolean("IsBaby",true);
	    spawner1.func_145881_a().new WeightedRandomMinecart(nbt, "Zombie");
	}

Did I do this wrong again?

Link to comment
Share on other sites

Dont be silly anything is possible with modded minecraft!

 

I couldn't get what SanAndreasP was talking about to work for some reason but this works

 

TileEntity spawner = world.getTileEntity(x, y, z);
if (spawner instanceof TileEntityMobSpawner){
MobSpawnerBaseLogic logic = ((TileEntityMobSpawner)spawner).func_145881_a();
logic.setEntityName("Zombie");

EntityZombie zombie = new EntityZombie(world);
zombie.setChild(true);

NBTTagCompound compound = new NBTTagCompound();
zombie.writeEntityToNBT(compound);

NBTTagCompound compound2 = new NBTTagCompound();
logic.writeToNBT(compound2);
compound2.setTag("SpawnData", compound);

logic.readFromNBT(compound2);
}

 

This works by modifying the spanners nbt its not as good as what SanAndreasP suggested but it works. 

 

Edit: only down side i have found is that it only spawns one mob at a time like that.

I am the author of Draconic Evolution

Link to comment
Share on other sites

Dont be silly anything is possible with modded minecraft!

 

I couldn't get what SanAndreasP was talking about to work for some reason but this works

 

TileEntity spawner = world.getTileEntity(x, y, z);
if (spawner instanceof TileEntityMobSpawner){
MobSpawnerBaseLogic logic = ((TileEntityMobSpawner)spawner).func_145881_a();
logic.setEntityName("Zombie");

EntityZombie zombie = new EntityZombie(world);
zombie.setChild(true);

NBTTagCompound compound = new NBTTagCompound();
zombie.writeEntityToNBT(compound);

NBTTagCompound compound2 = new NBTTagCompound();
logic.writeToNBT(compound2);
compound2.setTag("SpawnData", compound);

logic.readFromNBT(compound2);
}

 

This works by modifying the spanners nbt its not as good as what SanAndreasP suggested but it works. 

 

Edit: only down side i have found is that it only spawns one mob at a time like that.

If I could hit Thank You 100 times, I would. Thank you so much, this works finally! I've been trying to get this thing figured out for months now (before I made this topic). Thank you so much!

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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