Jump to content

Recommended Posts

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.

Posted

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;

}

}

Posted

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

  • 3 weeks later...
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.

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...

×   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.