Help- Slime Block behavior replication

Started by CTMx on

Topic category: Advanced modding

Active 6 years ago
Joined Feb 2019
Points:
678

User statistics:

  • Modifications: 0
  • Forum topics: 3
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 8
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?

Active 4 months ago
Joined Nov 2017
Points:
901

User statistics:

  • Modifications: 1
  • Forum topics: 15
  • Wiki pages: 2
  • MCreator plugins: 0
  • Comments: 180
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).

Active 7 months ago
Joined Jan 2020
Points:
670

User statistics:

  • Modifications: 1
  • Forum topics: 3
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 41
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 :)

Active 1 year ago
Joined Sep 2018
Points:
845

User statistics:

  • Modifications: 1
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 79
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);
        }

Active 1 year ago
Joined Sep 2018
Points:
845

User statistics:

  • Modifications: 1
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 79
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,

Active 4 years ago
Joined Dec 2020
Points:
567

User statistics:

  • Modifications: 0
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 3
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

Active 1 year ago
Joined Feb 2020
Points:
777

User statistics:

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

how do I make it work with my block

Active 1 year ago
Joined Feb 2020
Points:
777

User statistics:

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

Nevermind

Active 1 year ago
Joined Nov 2021
Points:
564

User statistics:

  • Modifications: 7
  • Forum topics: 6
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 21
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.