Jump to content

Recommended Posts

Posted (edited)

I'm trying to create an ore block that is infinitely harvestable. When the player goes to harvest the block they will get a smeltable item, but the ore block will remain. I figure it has something to do with "removedByPlayer", but I don't know how to proceed. I tried overriding removedByPlayer in my blocks class, but that seems impossible and/or incorrect.

 

[SOLUTION]

override the "removedByPlayer" method. also override the "harvestBlock" method so you can set the spawnDrops location to the players position.

    @Override
    public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, @Nullable TileEntity te, ItemStack stack) {
        player.addStat(Stats.BLOCK_MINED.get(this));
        player.addExhaustion(0.005F);
        BlockPos pPos = player.getPosition();
        spawnDrops(state, worldIn, pPos, te, player, stack);
    }

    @Override
    public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, IFluidState fluid)
    {
        return true;
    }

 

Edited by andGarrett
Posted (edited)

I think I got it. I just added this to my blocks class:

 

@Override 
public void onPlayerDestroy(IWorld worldIn, BlockPos pos, BlockState state) 
{
	worldIn.setBlockState(pos, state, 0); 
}

 

let me know if there is a simpler way or if this would cause problems.

Edited by andGarrett
Posted

As an example:

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/block/ore/HardOreBlock.java#L115-L136

 

Do note two things:

1) the block will disappear and pop back into place on the client because the client assumes that all blocks when broken stay broken (and the chunk update packet arrives a fraction of a second latter correcting that notion).

2) if your block generates any drops you'll want to spawn them in an adjacent block or weird stuff will happen (if there are blocks above yours, those drops will vibrate their way upwards to the "surface" even if its 30 or 40 blocks). You can see how I did that here. There's no attempt to make sure that the space is as close to the player as possible, just looks for a non-solid spot to put them (and there is guaranteed to be one because the block was harvested somehow).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Thanks! I don't know why I was unable to override "removedByPlayer" before, but pasting in Draco18s code allowed me to do what was needed.

 I have the "harvestBlock" method spawn the drops at the players location.

    @Override
    public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, @Nullable TileEntity te, ItemStack stack) {
        player.addStat(Stats.BLOCK_MINED.get(this));
        player.addExhaustion(0.005F);
        BlockPos pPos = player.getPosition();
        spawnDrops(state, worldIn, pPos, te, player, stack);
    }

    @Override
    public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, IFluidState fluid)
    {
        return true;
    }

 

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.