Jump to content

[1.12] Having a Mob Spawner in a generated structure.


Recommended Posts

Hello all again!


I'm trying to determine how to set a mob spawner to a certain mob and I feel like I'm doing something wrong.

From what I read, the mob spawner needs to be set after its placed.

worldIn.setBlockState(new BlockPos(x+2,y,z+2), Blocks.MOB_SPAWNER.getStateFromMeta(1));
		TileEntityMobSpawner spawn = (TileEntityMobSpawner)worldIn.getTileEntity(new BlockPos(x+2,y,z+2));
		NBTTagCompound compound = new NBTTagCompound();
		NBTTagCompound compound2 = new NBTTagCompound();
		compound.setTag("SpawnData", compound2);

This is how I was attempting to do it first with some confusing results like this: 



Unsure of how the mob spawner changed to the default entity after one spawn event.


I read in another post to try modifying the mobspawnerbaselogic, but this appears to have not done anything.

MobSpawnerBaseLogic john = spawn.getSpawnerBaseLogic();
		john.setEntityId(new ResourceLocation("Zombie"));


Any help is appreciated!

Link to comment
Share on other sites

This is the way I was doing it in my mod to set the mob spawner to spawn zombies.


// Get the tile entity at this position.
TileEntity tileEntity = world.getTileEntity(pos);

// Always check to see if the tileEntity is of the type you expect before casting.
// I am not doing it here on purpose.
TileEntityMobSpawner spawner = (TileEntityMobSpawner)tileEntity;



Edited by WuestMan
Link to comment
Share on other sites

Currently doing the calls in the onItemUse method of an item to generate the structure to make sure it looks okay before putting it in my structureGen class. 


I'm still trying to do the entire structure generation via just setBlockStates, I'm aware of the newer structure based method, but haven't given it a shot.

Going to remove the NBT nonsense to see maybe if its conflicting with the spawner logic.


UPDATE: This fixed it. Seems to work fine now. Thanks guys!

Edited by Heen
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.

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.