Posted July 20, 20178 yr 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!
July 21, 20178 yr 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 July 21, 20178 yr by WuestMan
July 22, 20178 yr 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 July 22, 20178 yr 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.