Jump to content

[SOLVED]-[1.16.1] How to handle Custom Slime Death


Recommended Posts

I've made an Custom Slime Entity that his color works like Sheep's color. So i have one white slime template and for each slime created i "randomize" it's color.
The problem is that when the slime dies, it's childs spawn with the template color and not with the "parent" color.
I've already googled around and searched betwen the classes but ended up with nothing, so how can i pass the color to the new little slimes when a big one dies?

the Entity code:

package net.ddns.samjviana.morethings.entity;

import java.util.Arrays;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

import com.google.common.collect.Maps;

import net.minecraft.entity.EntitySize;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ILivingEntityData;
import net.minecraft.entity.Pose;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.monster.SlimeEntity;
import net.minecraft.item.DyeColor;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;

public class ColoredSlimeEntity extends SlimeEntity {
    private static final DataParameter<Byte> DYE_COLOR = EntityDataManager.createKey(SlimeEntity.class,
    private static final Map<DyeColor, float[]> DYE_TO_RGB = Maps.newEnumMap(Arrays.stream(DyeColor.values()).collect(Collectors.toMap(
        (DyeColor dyeColor) -> {
            return dyeColor;
        }, ColoredSlimeEntity::createSlimeColor)));

    public ColoredSlimeEntity(final EntityType<? extends ColoredSlimeEntity> entityType, final World world) {
        super(entityType, world);

    protected void setSlimeSize(int size, boolean resetHealth) {
        super.setSlimeSize(size, resetHealth);

    protected boolean spawnCustomParticles() {
        int i = this.getSlimeSize();

        for(int j = 0; j < i * 8; ++j) {
            float f = this.rand.nextFloat() * ((float)Math.PI * 2F);
            float f1 = this.rand.nextFloat() * 0.5F + 0.5F;
            float f2 = MathHelper.sin(f) * (float)i * 0.5F * f1;
            float f3 = MathHelper.cos(f) * (float)i * 0.5F * f1;
            this.world.addParticle(this.getSquishParticle(), this.getPosX() + (double)f2, this.getPosY(), this.getPosZ() + (double)f3, 0.0D, 0.0D, 0.0D);
        return super.spawnCustomParticles();

    public void onDeath(DamageSource cause) {
        // TODO Auto-generated method stub

    public static float[] getDyeRgb(DyeColor dyeColor) {
        return DYE_TO_RGB.get(dyeColor);

    private static float[] createSlimeColor(DyeColor dyeColorIn) {
        if (dyeColorIn == DyeColor.WHITE) {
           return new float[]{0.9019608F, 0.9019608F, 0.9019608F};
        } else {
           float[] afloat = dyeColorIn.getColorComponentValues();
           return new float[]{afloat[0] * 0.75F, afloat[1] * 0.75F, afloat[2] * 0.75F};

    public static AttributeModifierMap getAttributes() {
        AttributeModifierMap.MutableAttribute attributes = SlimeEntity.func_233666_p_();


        return attributes.func_233813_a_();

    public ILivingEntityData onInitialSpawn(IWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, ILivingEntityData spawnDataIn, CompoundNBT dataTag) {
        return super.onInitialSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag);

    public void setSlimeColor(DyeColor color) {
        byte b0 = this.dataManager.get(DYE_COLOR);
        this.dataManager.set(DYE_COLOR, (byte)(b0 & 240 | color.getId() & 15));

    public static DyeColor getRandomSlimeColor(Random random) {
        int i = random.nextInt(15);
        return DyeColor.byId(i);
    protected void registerData() {
        this.dataManager.register(DYE_COLOR, (byte)0);
    public void writeAdditional(CompoundNBT compound) {
        compound.putByte("Color", (byte)this.getSlimeColor().getId());

    public DyeColor getSlimeColor() {
        return DyeColor.byId(this.dataManager.get(DYE_COLOR) & 15);

    public EntitySize getSize(Pose poseIn) {
        return super.getSize(poseIn);

    public int getSlimeSize() {
        return super.getSlimeSize();


Edited by samjviana
Link to comment
Share on other sites

  • samjviana changed the title to [SOLVED]-[1.16.1] How to handle Custom Slime Death

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.

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

    • Hi everyone  I'm trying to make a custom door and give it a custom sound. In order to do so I've registered the sounds like this   private static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, MineWorld.MOD_ID); ... public static final RegistryObject<SoundEvent> SCULK_DOOR_CLOSE = SOUNDS.register("sculk_door_close", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(MineWorld.MOD_ID, "sculk_door_close"))); public static final RegistryObject<SoundEvent> SCULK_DOOR_OPEN = SOUNDS.register("sculk_door_open", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(MineWorld.MOD_ID, "sculk_door_open"))); call the register method of the Sounds registry as the first thing in my mod initialize method IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); SOUNDS.register(eventBus); Then I create a BlockSetType like this   public static final BlockSetType SCULK = BlockSetType.register(new BlockSetType(new ResourceLocation(MineWorld.MOD_ID, "sculk").toString(), true, SoundType.WOOD, SCULK_DOOR_CLOSE.get(), SCULK_DOOR_OPEN.get(), SoundEvents.WOODEN_TRAPDOOR_CLOSE, SoundEvents.WOODEN_TRAPDOOR_OPEN, SoundEvents.WOODEN_PRESSURE_PLATE_CLICK_OFF, SoundEvents.WOODEN_PRESSURE_PLATE_CLICK_ON, SoundEvents.WOODEN_BUTTON_CLICK_OFF, SoundEvents.WOODEN_BUTTON_CLICK_ON); And finally the door block like this private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MineWorld.MOD_ID); ... BLOCKS.register("sculk_door", () -> new DoorBlock(BlockBehaviour.Properties.copy(Blocks.OAK_DOOR), blockSetType)); But when I launch the game I get this error   Registry Object not present: mineworld:sculk_door_close Am I doing something wrong? Maybe the BlockSetType registration needs to be done in a different way? I have other BlockSetTypes registered like this that only uses vanilla sounds and they work just fine. You can see an example in my GitHub repo here: https://github.com/JimiIT92/MineWorld/blob/master/src/main/java/org/mineworld/core/MWBlockSetTypes.java
    • it was eldritch end, thank you
    • Okay. Thank you. I think it works now. I added the jdk-17 path to the batch instead of the jvm arguments txt file. The windows command prompt is just blank, but when I close the native windows command prompt, the java command prompt opens & loads the server. If that won't cause issues then I'm all good. 
    • I have no idea - the last mentioned mods are eldritch_end, supplementaries and mahoutsukai Start with removing mahoutsukai
  • Topics

  • Create New...

Important Information

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