Posted January 18, 201411 yr Hey all, Im trying to grab info about a tile entity using forges event handler: @ForgeSubscribe public void onBlockHarvest(BlockEvent.HarvestDropsEvent event) { if (event.block.equals(Block.mobSpawner)) { TileEntity te = event.world.getBlockTileEntity(event.x, event.y, event.z); String eName = null; if(te != null) { System.out.println("wooooooooo"); eName = ((TileEntityMobSpawner) te).getSpawnerLogic().getEntityNameToSpawn(); } System.out.println(eName); ItemStack spawnerDrop = new ItemStack(mymod.myitem, 1, 1); event.drops.add(spawnerDrop); event.dropChance = 1.0F; } } If i remove the IF statement and just add a drop it works, but I want a different drop per mob spawner type. im a little confused as to why the tile entity is null, I never get inside the IF. Any clues or a better way of achieving the same result.
January 18, 201411 yr Author Darn, ok gonna have to rethink this, can anyone think of another way of detecting the type of a mob spawner and changing drops accordingly?
January 18, 201411 yr Author I went about it another way, i was piggybacking the normal mob spawner block so didnt have metadata available, as thats available in the event i added my custom block extending BlockMobSpawner so I could assign meta based on mob type, then I can just use: @ForgeSubscribe public void onBlockHarvest(BlockEvent.HarvestDropsEvent event) { if (event.block.equals(mymod.mycustomspawnblock)) { ItemStack spawnerDrop = new ItemStack(mymod.myitem, 1, event.blockMetadata); event.drops.add(spawnerDrop); event.dropChance = 1.0F; } }
January 18, 201411 yr An idea - perhaps you can use both events - i.e. in BreakEvent, record the block that the player is attempting to break. Then, in HarvestDropsEvent, the block that was broken is (presumably) the last one recorded in BreakEvent. (see ItemInWorldManager.tryHarvestBlock for the order that the various events and method occur) Worth a try I think. Just need to remember that blocks can be harvested by non-players (eg explosions) -TGG
January 18, 201411 yr If you are generating your own custom Block then you could just override Block.dropBlockAsItemWithChance, and not bother with the event at all? -TGG
January 18, 201411 yr The HarvestDropsEvent only fires if the block can be harvested...i am not sure there is even a case where a player can harvest a mob spawner.
February 6, 201411 yr Hey all, Im trying to grab info about a tile entity using forges event handler: @ForgeSubscribe public void onBlockHarvest(BlockEvent.HarvestDropsEvent event) { if (event.block.equals(Block.mobSpawner)) { TileEntity te = event.world.getBlockTileEntity(event.x, event.y, event.z); String eName = null; if(te != null) { System.out.println("wooooooooo"); eName = ((TileEntityMobSpawner) te).getSpawnerLogic().getEntityNameToSpawn(); } System.out.println(eName); ItemStack spawnerDrop = new ItemStack(mymod.myitem, 1, 1); event.drops.add(spawnerDrop); event.dropChance = 1.0F; } } If i remove the IF statement and just add a drop it works, but I want a different drop per mob spawner type. im a little confused as to why the tile entity is null, I never get inside the IF. Any clues or a better way of achieving the same result. Thanks for the code. It's the most helpful. I have an idea. ex: Create a ItemTool. Fill these code in to it. You can drop a item: if (!par2World.isRemote) { EntityItem entityitem = new EntityItem(par2World, (float)par4, (float) par5, (float) par6, new ItemStack(Block.mobSpawner.blockID,1, 0)); //par2World, par4, par5, par6 is the parameter of onBlockDestroyed. par3 is the blockId which block has been destroyed. //Your code can get metadata of the mobSpawner. entityitem.delayBeforeCanPickup = 10; par2World.spawnEntityInWorld(entityitem); } Yeah... Sorry for my English. My English is so worse.
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.