Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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();
		spawn.writeToNBT(compound);
		compound2.setString("id","minecraft:zombie");
		compound.setTag("SpawnData", compound2);
		spawn.readFromNBT(compound);

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

https://i.gyazo.com/feb4ff50914044fd7d15e8e6ce9d902e.mp4

 

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"));
		//spawn.update();

 

Any help is appreciated!

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;

spawner.getSpawnerBaseLogic().setEntityId(EntityList.getKey(EntityZombie.class));

 

Edited by WuestMan

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.