Jump to content

Recommended Posts

Posted

I made a red slime block with all its properties, but mine isnt sticking to normal blocks or honey/slime blocks; i added 2 overrides(isStickyBlock and canStickTo) but is not changing anything and slime block and honey block doesnt have those 2 properties of stick bu them work

public class RedSlimeBlock extends BreakableBlock {
    public RedSlimeBlock(Properties properties) {
        super(properties);
    }

    public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance) {
        if (entityIn.isSuppressingBounce()) {
            super.onFallenUpon(worldIn, pos, entityIn, fallDistance);
        } else {
            entityIn.onLivingFall(fallDistance, 0.0F);
        }
    }

    /**
     * Called when an Entity lands on this Block. This method *must* update motionY because the entity will not do that
     * on its own
     */
    public void onLanded(IBlockReader worldIn, Entity entityIn) {
        if (entityIn.isSuppressingBounce()) {
            super.onLanded(worldIn, entityIn);
        } else {
            this.bounceEntity(entityIn);
        }
    }

    @Override
    public boolean isStickyBlock(BlockState state) {
        return state.getBlock() == Blocks.SLIME_BLOCK || state.getBlock() == Blocks.HONEY_BLOCK;
    }

    @Override
    public boolean canStickTo(BlockState state, BlockState other) {
        if(state.getBlock() == Blocks.SLIME_BLOCK || state.getBlock() == Blocks.HONEY_BLOCK) return false;
        return state.isStickyBlock() || other.isStickyBlock();
    }

    private void bounceEntity(Entity entity) {
        Vector3d vector3d = entity.getMotion();
        if (vector3d.y < 0.0D) {
            double d0 = entity instanceof LivingEntity ? 1.0D : 0.8D;
            entity.setMotion(vector3d.x, -vector3d.y * d0, vector3d.z);
        }
    }

    /**
     * Called when the given entity walks on this Block
     */
    public void onEntityWalk(World worldIn, BlockPos pos, Entity entityIn) {
        double d0 = Math.abs(entityIn.getMotion().y);
        if (d0 < 0.1D && !entityIn.isSteppingCarefully()) {
            double d1 = 0.4D + d0 * 0.2D;
            entityIn.setMotion(entityIn.getMotion().mul(d1, 1.0D, d1));
        }
        super.onEntityWalk(worldIn, pos, entityIn);
    }
}

 

  • ElTotisPro50 changed the title to My custom slimeblock doesnt stick to anything
Posted
1 hour ago, diesieben07 said:

Use @Override when overriding methods.

How do you think this will ever return true?

ok i put "!=" operator in isStickyWork and now it sticks... but to every block and it supose to mean that it doesnt stick to slime or honey

 @Override
    public boolean isStickyBlock(BlockState state) {
        return state.getBlock() != Blocks.SLIME_BLOCK || state.getBlock() != Blocks.HONEY_BLOCK;
    }

    @Override
    public boolean canStickTo(BlockState state, BlockState other) {
        if(state.getBlock() == Blocks.SLIME_BLOCK || state.getBlock() == Blocks.HONEY_BLOCK) return false;
        return state.isStickyBlock() || other.isStickyBlock();
    }

 

Posted
4 hours ago, diesieben07 said:

This now always returns true. Why do you have these checks here?

Since isStickyBlock always returns true for your block, this always returns true. The first if condition is never true, because your block is neither Slime nor Honey.

ok i tried some shit and didnt work, isStickyBlock should be always true right?, so i returned true in there without any condition, but how do i get it work

@Override
    public boolean isStickyBlock(BlockState state) {
        return true;
    }

    @Override
    public boolean canStickTo(BlockState state, BlockState other) {
        if(state.getBlock() == Blocks.SLIME_BLOCK || state.getBlock() == Blocks.HONEY_BLOCK) return false;
        return state.isStickyBlock() || other.isStickyBlock();
    }

it sticks to all blocks again, what should i do please just code quickly the answer

Posted
1 hour ago, diesieben07 said:

You need to write your logic in canStickTo. Your canStickTo always returns true currently, which means that your block sticks to everything.

in canStickTo o made some combinations for the logic but none of them worked:

if(state.getBlock() != Blocks.SLIME_BLOCK || state.getBlock() != Blocks.HONEY_BLOCK) return true; return state.isStickyBlock() || other.isStickyBlock();

if(state.getBlock() = Blocks.SLIME_BLOCK || state.getBlock() = Blocks.HONEY_BLOCK) return true; return state.isStickyBlock() || other.isStickyBlock();

if(state.getBlock() != Blocks.SLIME_BLOCK || state.getBlock() != Blocks.HONEY_BLOCK) return false; return state.isStickyBlock() || other.isStickyBlock();

if(state.getBlock() = Blocks.SLIME_BLOCK || state.getBlock() = Blocks.HONEY_BLOCK) return false; return state.isStickyBlock() || other.isStickyBlock();

 

i dont think the logic is different than this...

Posted
1 hour ago, diesieben07 said:

state is the state of YOUR block. How would it ever be honey or slime? So that if statement never matches.

The 2nd part of the return always returns true, because once again state is YOUR block, so isStickyBlock is always true. true || whatever is always true -> all of the statements you posted always return true.

oh god i made this and it works but is the opposite, is sticking to slime/honey but not to normal blocks

@Override
    public boolean canStickTo(BlockState state, BlockState other) {
        if(other.getBlock() == Blocks.SLIME_BLOCK || other.getBlock() == Blocks.HONEY_BLOCK) return true;
        return other.isStickyBlock();
    }

i tried to return false: if(other.getBlock() == Blocks.SLIME_BLOCK || other.getBlock() == Blocks.HONEY_BLOCK) return true; or put != but nope, how do i invert this?? i cant put if(!other.getBlock)

Posted

...return false?

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

To invert this statement:

if(other.getBlock() == Blocks.SLIME_BLOCK || other.getBlock() == Blocks.HONEY_BLOCK) return true;

Do this:

if(other.getBlock() == Blocks.SLIME_BLOCK || other.getBlock() == Blocks.HONEY_BLOCK) return false;

You then need to realize that this statement doesn't do what you want:

return other.isStickyBlock(); //only stick to other blocks if the other block is also sticky

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
1 hour ago, Draco18s said:

To invert this statement:

if(other.getBlock() == Blocks.SLIME_BLOCK || other.getBlock() == Blocks.HONEY_BLOCK) return true;

Do this:

if(other.getBlock() == Blocks.SLIME_BLOCK || other.getBlock() == Blocks.HONEY_BLOCK) return false;

You then need to realize that this statement doesn't do what you want:

return other.isStickyBlock(); //only stick to other blocks if the other block is also sticky

if i do:  return !other.isStickyBlock(); could it work?

Posted

Well, think about it. You want your sticky blocks to pull each other, yes?

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
1 hour ago, Draco18s said:

Well, think about it. You want your sticky blocks to pull each other, yes?

kind of, i will make more slime blocks of all colors so they cant stick between them or between normal slime block or honey block

Posted

Ok, now think about the logic you have in your canStickTo function.

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
1 hour ago, Draco18s said:

Ok, now think about the logic you have in your canStickTo function.

ok this works exactly how it suposed to work but only at the top and the bottom of the block:

@Override
    public boolean isStickyBlock(BlockState state) {
        return true;
    }

    @Override
    public boolean canStickTo(BlockState state, BlockState other) {
        if(other.getBlock() == Blocks.SLIME_BLOCK || other.getBlock() == Blocks.HONEY_BLOCK)
            return false;
        if(other.getBlock() == ModBlocks.SLIMEBLOCK_RED.get())
            return true;
        return super.canStickTo(state, other);
    }

if i put slime/honey at t he top or bottom of my block it doesnt stick and with a normal block it sticks, but at the 4 sides of the block it sticks to sticky blocks and normal blocks(in resume my block work but only at the top and the bottom) A EXAMPLE OF WHAT IM SAYING: https://imgur.com/a/rGlm9Dq

Posted

Try checking whether the other block is`this` (which is an easier way to check if it it red slime). If it is, return true.

If it is not this block, but is sticky (or it is slime or honey, because you say they do not return true for isSticky), return false.

Otherwise (for all other blocks) return true.

Posted
8 hours ago, Alpvax said:

Try checking whether the other block is`this` (which is an easier way to check if it it red slime). If it is, return true.

If it is not this block, but is sticky (or it is slime or honey, because you say they do not return true for isSticky), return false.

Otherwise (for all other blocks) return true.

thats exactly what i did i told you that it works but only for the top and the bottom of the block(slime/honey doesnt stick to my block and for example stone sticks BUT ONLY FOR THE TOP AND THE BOTTOM), for the 4 sides of the block(north,south,west and east any block sticks) https://imgur.com/a/rGlm9Dq, i need a fix for it to work on all 6 sides(only works in 2 sides)

Posted
1 hour ago, diesieben07 said:

You are returning false explicitly for slime and honey. You need to return true if you want it to stick to slime.

no i dont want it to stick to slime/honey but it does at the 4 sides of the block, at the BOTTOM AND TOP it works correctly, nothing should stick to my block except the same block(as i wrote in the code) but apparently is ignoring the 4 sides of the block

Posted
1 hour ago, diesieben07 said:

Slimes will stick to any other sticky block though. So it is slimes sticking to your block, not your block sticking to slimes. It seems the patches here do not really allow for what you want to do.

no is there a way that my block doesnt stick to slime and slime doesnt stick to my block?? i saw some mods that do that(but the source code isnt available)

Posted
1 hour ago, diesieben07 said:

You cannot change what slimes stick to. The block closest to the piston in terms of push direction determines whether it can stick to the next one. Because slimes stick to everything that is sticky but not honey, they will stick to your block - and you cannot change this. If your block comes first and it says it cannot stick to slimes then it won't stick.

come on is minecraft you can even change the physics(if you know everything about modding and programming) how could you change players camera, add animations, etc but you cant change the slime block :c

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.