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

Can I use NBTTagCompound at blocks? I wan't to change the spawning entity in a monster spawner. How can I do that?

  • Author

func_145881_a

on a

TileEntityMobSpawner

will give you the

MobSpawnerBaseLogic

. That has methods for setting the Entity to spawn.

How do I get the TileEntityMobSpawner?

(TileEntityMobSpawner) spawner = (TileEntityMobSpawner)world.getTileEntity(x,y,z)

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

(TileEntityMobSpawner) spawner = (TileEntityMobSpawner)world.getTileEntity(x,y,z)

 

w.setBlock(x, y, z, Blocks.mob_spawner);
TileEntityMobSpawner spawner = (TileEntityMobSpawner) w.getTileEntity(x, y, z);
MobSpawnerBaseLogic logic = spawner.func_145881_a();
logic.setEntityName("Witch");
logic.updateSpawner();

 

This (used in the PlayerInteractEvent) works, but when I right click on the spawner, it dissapers. Looks like, Minecraft doesn't accept the "setBlock()"...

  • Author

Can you post the method in which you call that code?

 

@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent e){
	if(e.action == Action.RIGHT_CLICK_BLOCK){	
		EntityPlayer p = e.entityPlayer;			
		ItemStack items = p.inventory.getCurrentItem();
		if(items == null) return;
		Item item = items.getItem();
		String name = item.getUnlocalizedName();
		if(name.equals(Blocks.mob_spawner.getUnlocalizedName())){
			World w = e.world;
			int x = e.x;
			int y = e.y;
			int z = e.z;
			Block b = e.world.getBlock(x, y, z);
			if(!b.getUnlocalizedName().equalsIgnoreCase(Blocks.tallgrass.getUnlocalizedName())){
				switch(e.face){
				case 0: y--; break;
				case 1: y++; break;
				case 2: z--; break;
				case 3: z++; break;
				case 4: x--; break;
				case 5: x++; break;
				}
			}					
			w.setBlock(x, y, z, Blocks.mob_spawner);
			TileEntityMobSpawner spawner = (TileEntityMobSpawner) w.getTileEntity(x, y, z);
			MobSpawnerBaseLogic logic = spawner.func_145881_a();
			logic.setEntityName("Witch");
			logic.updateSpawner();
		}			
	}
}

  • Author

First of all: Don't compare via unlocalized names. To get a Block from an Item use

Block.getBlockFromItem

. Then: don't call updateSpawner, why do you call that? Don't just randomly call methods...

Also make sure to only do this on the server (world.isRemote is false).

 

I don't now what you mean :/

 

I removed the updateSpawner and changed the comparation stuff. But how can I fix the world.setBlock() ? This has not to do with the MobSpawner. I tested the world.setBlock() with an other block and it dissapears at all when I click on it O.o

 

What do you mean with "Also make sure to only do this on the server" ?

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.