Help- Slime Block behavior replication

Started by CTMx on

Topic category: Advanced modding

Last seen on 10:48, 19. Apr 2019
Joined Feb 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Help- Slime Block behavior replication

Hey fellow modders, a few months ago I'd planned to add colored slimes and slime fluids into my project. I came across 1 problem though. Can't figure out how to make a Slime Block that behaves just like the regular slime block. Would anybody like to lend a hand? What procedues, if any, can replicate this action?

Last seen on 14:12, 3. Jun 2023
Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can recreate the…
Sat, 04/20/2019 - 09:26

You can recreate the behavior of a slime block with some code editing (that is, by copying code snippets from the vanilla slime block).
First of all, add these imports if they're missing:

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;

 

Now you can add this to determine how much fall damage you'll get upon landing:

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

0.0F means no fall damage at all, 1.0F means same fall damage as usual, 0.5F cuts fall damage in half. The entity gets normal fall damage if sneaking. If you don't want to copy the "sneaking doesn't reduce fall damage" behavior, remove everything except for entityIn.fall(fallDistance, 0.0F); line inside the brackets.

 

This piece of code is used to make the entity slower when walking on the block:

@Override
		public void onEntityWalk(World worldIn, BlockPos pos, Entity entityIn)
		{
			entityIn.motionX *= 0.75D;
			entityIn.motionZ *= 0.75D;
			super.onEntityWalk(worldIn, pos, entityIn);
		}

In this case, the entity walks 25% slower. The numbers should be set to a value between 0.0F (the entity doesn't move) and 1.0F (the entity moves normally), and both should be the same value.

 

Finally, this piece of code recreates the "bouncy" effect:

public void onLanded(World worldIn, Entity entityIn)
    {
        if (entityIn.isSneaking())
        {
            super.onLanded(worldIn, entityIn);
        }
        else if (entityIn.motionY < 0.0D)
        {
            entityIn.motionY = -entityIn.motionY * 1.0D;

            if (!(entityIn instanceof EntityLivingBase))
            {
                entityIn.motionY *= 0.8D;
            }
        }
    }

The entity won't bounce if sneaking. If you don't want this behavior, remove everything from if (entityIn.isSneaking()) to else.
if (entityIn.motionY < 0.0D) determines the minimum speed required to bounce: make sure to set it to 0.0D or lower.
entityIn.motionY = -entityIn.motionY * 1.0D; determines how bouncy the block is. Set the number to a value between 0.0D (not bouncy) and 1.0D (as bouncy as a slime block).

Last seen on 02:17, 2. Nov 2022
Joined Jan 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Where do I put this code? I…
Sun, 03/15/2020 - 02:36

Where do I put this code? I put it in Slime.java and it said error. I got rid of the original code, and also tried adding it to the code, but it doesn't work. If you could help I'd really appreciate it :)

Last seen on 05:06, 6. Jul 2023
Joined Sep 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Put it right after this~~…
Sun, 04/05/2020 - 02:10

Put it right after this~~

public static class BlockCustom extends Block {
        public BlockCustom() {
            super(Material.CIRCUITS);
            setUnlocalizedName("slimeblockblk");
            setSoundType(SoundType.SLIME);
            setHardness(0F);
            setResistance(0F);
            setLightLevel(0F);
            setLightOpacity(0);
            setCreativeTab(TabMoneyCraftBlocks.tab);
        }

Last seen on 05:06, 6. Jul 2023
Joined Sep 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
As for~~ import net…
Sun, 04/05/2020 - 02:34

As for~~

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;

Put these after~~

import net.minecraft.block.Block;

Which is located towards the top at the end of a list of similar imports,

Last seen on 16:07, 26. Jan 2021
Joined Dec 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I don't think this code…
Mon, 01/04/2021 - 19:06

I don't think this code makes it stick to other blocks the way slimeblock does. Am I wrong? I don't know

Last seen on 15:51, 16. Jan 2024
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how do I make it work with…
Sun, 10/10/2021 - 23:23

how do I make it work with my block

Last seen on 15:51, 16. Jan 2024
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Nevermind
Sun, 10/10/2021 - 23:26

Nevermind

Last seen on 22:12, 7. Mar 2024
Joined Nov 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How would this work for 1.16…
Sun, 04/10/2022 - 20:41

How would this work for 1.16.5? It seems to throw errors at entityIn.fall(), entityIn.motionY, and EntityLivingBase.