Jump to content

Recommended Posts

Posted (edited)

Hi,

I would like to add a new slime block to the game, which works in a simular way to the original slime block, that is: it can move other blocks around and other slime blocks of the same type, but not other sticky blocks (honey blocks).

I found two functions in IForgeBlock file:

 

default boolean isStickyBlock(BlockState state)
{
   return state.getBlock() == Blocks.SLIME_BLOCK || state.getBlock() == Blocks.field_226907_mc_;
}

 

default boolean canStickTo(BlockState state, BlockState other)
{
        if (state.getBlock() == Blocks.field_226907_mc_ && other.getBlock() == Blocks.SLIME_BLOCK) return false;
        if (state.getBlock() == Blocks.SLIME_BLOCK && other.getBlock() == Blocks.field_226907_mc_) return false;
        return state.isStickyBlock() || other.isStickyBlock();
}

Is there a way to replace them and add the new block to the functions so they also check for it?

Or is there another way to do that?

 

Cheers,

Corgam

Edited by Corgam
  • 2 weeks later...
Posted (edited)
On 3/17/2020 at 11:54 PM, larsgerrits said:

Override the methods in your Block class and make them return true.

It works but only in one way. When slime and honey blocks are pushed they don't move the new slime block, but when you try to push the new slime block with the piston is moves normal slime block and honey with it. 

Any idea how to fix that?

I think I would need to override canStickTo() methode in normal SlimeBlock and honey block, but how can I do it, If I cannot modify the vanilla code?

Edited by Corgam
Posted (edited)
On 3/26/2020 at 6:03 PM, Alpvax said:

I think you need to leave the default implementation of canStickTo, just override isStickyBlock

Unfortunately no, isStickyBlock makes that it can move other blocks (all of movable blocks), but doesn't prevent it from sticking to another slime block or honeyblock.

canStickTo makes it that other sticky blocks cannot move it, but as for now I didn't find a way to stop the new block from moving other sticky blocks while being moved. (so it works only one way)

 

Edit: This is what I mean: https://imgur.com/J6TRxXx

Edited by Corgam
Posted

Oh, re-reading the code, I think you need to override canStickTo to only return true if the other block is itself or non sticky. To be honest, I'm surprised that slime doesn't push your block.

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.