Started by
CTMx
on
Topic category: Advanced modding
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?
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:
Now you can add this to determine how much fall damage you'll get upon landing:
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:
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:
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).
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 :)
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);
}
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,
I don't think this code makes it stick to other blocks the way slimeblock does. Am I wrong? I don't know
how do I make it work with my block
Nevermind
How would this work for 1.16.5? It seems to throw errors at entityIn.fall(), entityIn.motionY, and EntityLivingBase.