Jump to content

Change spawning entity in a monster spawner | NBTTagCompound at blocks


TupidaMC

Recommended Posts

(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/

Link to comment
Share on other sites

(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()"...

Link to comment
Share on other sites

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

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/

Link to comment
Share on other sites

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();
		}			
	}
}

Link to comment
Share on other sites

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" ?

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.

Announcements



×
×
  • Create New...

Important Information

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