Jump to content

My custom slimeblock doesnt stick to anything


ElTotisPro50

Recommended Posts

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);
    }
}

 

Link to comment
Share on other sites

  • ElTotisPro50 changed the title to My custom slimeblock doesnt stick to anything
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();
    }

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have setup a 1.12.2 forge server  occasionally it throws a '[Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Did the system time change, or is the server overloaded? Running 2316ms behind, skipping 46 tick(s)' and a ram usage spike  I have 32gb of ram installed in my pc and on a vanilla server l would normally just make a run.bat file but it is not working   When I launch the run.bat C:\Users\Max\Desktop\1.12.2 server>java -Xmx4G -Xms4G -jar minecraft_server.1.12.2.jar nogui C:\Users\Max\Desktop\1.12.2 server>PAUSE Press any key to continue . . .   The run.bat file contains java -Xmx4G -Xms4G -jar minecraft_server.1.12.2.jar nogui PAUSE Any advice would be appreciated
    • I'm opening the forge 1.8.9 installer properly I click install with the client option selected, it says it installs properly but when I go into my files and also when I go into the minecraft launcher, it's just not there.  JVM info: Oracle Corporation - 1.8.0_431 - 25.431-b10 java.net.preferIPv4Stack=true Found java version 1.8.0_431 Considering minecraft client jar Considering library net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9: Not Downloading {Wrong Side} Considering library net.minecraft:launchwrapper:1.12: Not Downloading {Wrong Side} Considering library org.ow2.asm:asm-all:5.0.3: Not Downloading {Wrong Side} Considering library jline:jline:2.13: Not Downloading {Wrong Side} Considering library com.typesafe.akka:akka-actor_2.11:2.3.3 Considering library com.typesafe:config:1.2.1 Considering library org.scala-lang:scala-actors-migration_2.11:1.1.0 Considering library org.scala-lang:scala-compiler:2.11.1 Considering library org.scala-lang.plugins:scala-continuations-library_2.11:1.0.2 Considering library org.scala-lang.plugins:scala-continuations-plugin_2.11.1:1.0.2 Considering library org.scala-lang:scala-library:2.11.1 Considering library org.scala-lang:scala-parser-combinators_2.11:1.0.1 Considering library org.scala-lang:scala-reflect:2.11.1 Considering library org.scala-lang:scala-swing_2.11:1.0.1 Considering library org.scala-lang:scala-xml_2.11:1.0.2 Considering library lzma:lzma:0.0.1: Not Downloading {Wrong Side} Considering library net.sf.jopt-simple:jopt-simple:4.6: Not Downloading {Wrong Side} Considering library java3d:vecmath:1.5.2 Considering library net.sf.trove4j:trove4j:3.0.3 Extracting: /forge-1.8.9-11.15.1.2318-1.8.9-universal.jar To: C:\Users\Ian\AppData\Roaming\.minecraft\libraries\net\minecraftforge\forge\1.8.9-11.15.1.2318-1.8.9\forge-1.8.9-11.15.1.2318-1.8.9.jar That's the installer log and I have no idea if anything is wrong.
    • https://mclo.gs/NQ786zI   I don’t understand what I need to do.
    • I am wanting to give the armour in my mod special properties, but I have no idea how to do so.   For the first armour set I want it to be the case that when the full set is worn it has the properties of a carved pumpkin, making it so you won't aggravate endermen when you look at them.    The second, and presumably harder property is that for the second set I would like it to be the case that when the full set is worn, you can walk over the void without falling. (I was considering using the levitation to accomplish this but I wanted to check beforehand).   Would both of these specialities be achievable for each armour set and how exactly would they both be done? Help would be much appreciated. 
    • I finally got my Forge server up and running thanks to the help of the people on this forum and played fine for a day. Now since I started playing today, the server runs for 20-30 minutes then freezes and kicks everyone out but stays up and running but won't let anyone connect. Here is the latest debug log and crashlog from the server. Thank you for reading & helping   https://gist.github.com/Dwolfwoood/d0410e581c86772694f1d8007431c409   https://gist.github.com/Dwolfwoood/b5d521fd071dbfcc816949924757fef9
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.