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

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.

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

  • 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;

}

}

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

If you are generating your own custom Block then you could just override Block.dropBlockAsItemWithChance, and not bother with the event at all?

 

-TGG

 

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.

  • 3 weeks later...

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.

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.