TupidaMC Posted September 20, 2014 Share Posted September 20, 2014 Can I use NBTTagCompound at blocks? I wan't to change the spawning entity in a monster spawner. How can I do that? Quote Link to comment Share on other sites More sharing options...
TupidaMC Posted September 20, 2014 Author Share Posted September 20, 2014 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? Quote Link to comment Share on other sites More sharing options...
larsgerrits Posted September 20, 2014 Share Posted September 20, 2014 (TileEntityMobSpawner) spawner = (TileEntityMobSpawner)world.getTileEntity(x,y,z) Quote 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 More sharing options...
TupidaMC Posted September 20, 2014 Author Share Posted September 20, 2014 (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()"... Quote Link to comment Share on other sites More sharing options...
larsgerrits Posted September 20, 2014 Share Posted September 20, 2014 Can you post the method in which you call that code? Quote 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 More sharing options...
TupidaMC Posted September 20, 2014 Author Share Posted September 20, 2014 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(); } } } Quote Link to comment Share on other sites More sharing options...
TupidaMC Posted September 20, 2014 Author Share Posted September 20, 2014 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 What do you mean with "Also make sure to only do this on the server" ? Quote Link to comment Share on other sites More sharing options...
TupidaMC Posted September 20, 2014 Author Share Posted September 20, 2014 #push Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.