Jump to content

Recommended Posts

Posted

Hi,

For a while i have been trying to get the isEntity inside method of my custom fluid, that extends the FlowingFluid class, to get called. Whatever i do the method just never seems to get called and i do not know what to do. I have watched a lot of tutorials and still haven't really found an answer as to why it just wont work. I did give it the water tag since i do want it to inherrit the behaviour of water.

 

Below is the class that i working with.

public class FluidMilk extends FlowingFluid {

    public Fluid getFlowing() {
        return FluidList.MILK_FLOWING.get();
    }

    public Fluid getSource() {
        return FluidList.MILK_SOURCE.get();
    }

    public Item getBucket() {
        return ItemList.MILK_BUCKET.get();
    }

    @OnlyIn(Dist.CLIENT)
    public void animateTick(World p_204522_1_, BlockPos p_204522_2_, FluidState p_204522_3_, Random p_204522_4_) {
        if (!p_204522_3_.isSource() && !p_204522_3_.getValue(FALLING)) {
            if (p_204522_4_.nextInt(64) == 0) {
                p_204522_1_.playLocalSound((double)p_204522_2_.getX() + 0.5D, (double)p_204522_2_.getY() + 0.5D, (double)p_204522_2_.getZ() + 0.5D, SoundEvents.WATER_AMBIENT, SoundCategory.BLOCKS, p_204522_4_.nextFloat() * 0.25F + 0.75F, p_204522_4_.nextFloat() + 0.5F, false);
            }
        
        } else if (p_204522_4_.nextInt(10) == 0) {
            p_204522_1_.addParticle(ParticleTypes.UNDERWATER, (double)p_204522_2_.getX() + p_204522_4_.nextDouble(), (double)p_204522_2_.getY() + p_204522_4_.nextDouble(), (double)p_204522_2_.getZ() + p_204522_4_.nextDouble(), 0.0D, 0.0D, 0.0D);
        }

    }



    @Nullable
    @OnlyIn(Dist.CLIENT)
    public IParticleData getDripParticle() {
        return ParticleTypes.DRIPPING_WATER;
    }

    protected boolean canConvertToSource() {
        return true;
    }

    protected void beforeDestroyingBlock(IWorld p_205580_1_, BlockPos p_205580_2_, BlockState p_205580_3_) {
        TileEntity tileentity = p_205580_3_.hasTileEntity() ? p_205580_1_.getBlockEntity(p_205580_2_) : null;
        Block.dropResources(p_205580_3_, p_205580_1_, p_205580_2_, tileentity);
    }

    public int getSlopeFindDistance(IWorldReader p_185698_1_) {
        return 4;
    }

    public BlockState createLegacyBlock(FluidState p_204527_1_) {
        //return Blocks.WATER.defaultBlockState().setValue(FlowingFluidBlock.LEVEL, Integer.valueOf(getLegacyLevel(p_204527_1_)));
        return FluidList.MILK.defaultBlockState().setValue(FlowingFluidBlock.LEVEL, Integer.valueOf(getLegacyLevel(p_204527_1_)));
    }

    @Override
    public boolean isSource(FluidState p_207193_1_) {
        return false;
    }

    @Override
    public int getAmount(FluidState p_207192_1_) {
        return 1;
    }

    public boolean isSame(Fluid p_207187_1_) {
        return p_207187_1_ == FluidList.MILK_SOURCE.get()|| p_207187_1_ == FluidList.MILK_FLOWING.get();
    }

    public int getDropOff(IWorldReader p_204528_1_) {
        return 1;
    }

    public int getTickDelay(IWorldReader p_205569_1_) {
        return 5;
    }

    public boolean canBeReplacedWith(FluidState p_215665_1_, IBlockReader p_215665_2_, BlockPos p_215665_3_, Fluid p_215665_4_, Direction p_215665_5_) {
        return p_215665_5_ == Direction.DOWN;
    }



    @Override
    protected FluidAttributes createAttributes() {

        return FluidAttributes.builder(new ResourceLocation("morefluids:blocks/milk_still"), new ResourceLocation("morefluids:blocks/milk_flowing")).translationKey("block/milk").build(this);
    }

    protected float getExplosionResistance() {
        return 100.0F;
    }


    public static class Flowing extends FluidMilk {
        protected void createFluidStateDefinition(StateContainer.Builder<Fluid, FluidState> p_207184_1_) {
            super.createFluidStateDefinition(p_207184_1_);
            p_207184_1_.add(LEVEL);
        }

        @Override
        public boolean isEntityInside(FluidState state, IWorldReader world, BlockPos pos, Entity entity, double yToTest, Tag<Fluid> tag, boolean testingHead) {
            return super.isEntityInside(state, world, pos, entity, yToTest, tag, testingHead);
        }

        @Nullable
        @Override
        public Boolean isAABBInsideMaterial(FluidState state, IWorldReader world, BlockPos pos, AxisAlignedBB boundingBox, Material materialIn) {
            return super.isAABBInsideMaterial(state, world, pos, boundingBox, materialIn);
        }

        @Nullable
        @Override
        public Boolean isAABBInsideLiquid(FluidState state, IWorldReader world, BlockPos pos, AxisAlignedBB boundingBox) {
            return super.isAABBInsideLiquid(state, world, pos, boundingBox);
        }

        //        @Override
//        protected FluidAttributes createAttributes() {
//
//            return FluidAttributes.builder(new ResourceLocation("blocks/milk_still"), new ResourceLocation("blocks/milk_flowing")).translationKey("block/milk").build(this);
//        }

        public int getAmount(FluidState p_207192_1_) {
            return p_207192_1_.getValue(LEVEL);
        }

        public boolean isSource(FluidState p_207193_1_) {
            return false;
        }

    }

    public static class Source extends FluidMilk {

        protected void createFluidStateDefinition(StateContainer.Builder<Fluid, FluidState> p_207184_1_) {
            super.createFluidStateDefinition(p_207184_1_);
            p_207184_1_.add(LEVEL);
        }
        @Override
        public boolean isEntityInside(FluidState state, IWorldReader world, BlockPos pos, Entity entity, double yToTest, Tag<Fluid> tag, boolean testingHead) {
            return super.isEntityInside(state, world, pos, entity, yToTest, tag, testingHead);
        }

        @Nullable
        @Override
        public Boolean isAABBInsideMaterial(FluidState state, IWorldReader world, BlockPos pos, AxisAlignedBB boundingBox, Material materialIn) {
            return super.isAABBInsideMaterial(state, world, pos, boundingBox, materialIn);
        }

        @Nullable
        @Override
        public Boolean isAABBInsideLiquid(FluidState state, IWorldReader world, BlockPos pos, AxisAlignedBB boundingBox) {
            return super.isAABBInsideLiquid(state, world, pos, boundingBox);
        }
//        @Override
//        protected FluidAttributes createAttributes() {
//
//            return FluidAttributes.builder(new ResourceLocation("blocks/milk_still"), new ResourceLocation("blocks/milk_flowing")).translationKey("block/milk").build(this);
//        }
        public int getAmount(FluidState p_207192_1_) {
            return 8;
        }

        public boolean isSource(FluidState p_207193_1_) {
            return true;
        }

    }

    @Nullable
    @Override
    public Boolean isAABBInsideLiquid(FluidState state, IWorldReader world, BlockPos pos, AxisAlignedBB boundingBox) {
        return null;
    }

    @Nullable
    @Override
    public Boolean isAABBInsideMaterial(FluidState state, IWorldReader world, BlockPos pos, AxisAlignedBB boundingBox, Material materialIn) {
        return null;
    }

    @Override
    public boolean isEntityInside(FluidState state, IWorldReader world, BlockPos pos, Entity entity, double yToTest, Tag<Fluid> tag, boolean testingHead) {
        boolean inside = state.getType().isEntityInside(state, world, pos, entity, yToTest, tag, testingHead);

            if (entity instanceof LivingEntity) {
                LivingEntity livingEntity = (LivingEntity) entity;
                Collection<EffectInstance> list = livingEntity.getActiveEffects();

                for (EffectInstance effectInstance : list) {
                    Effect effect = effectInstance.getEffect();
                    livingEntity.removeEffect(effect);
                }


            }

        System.out.println(inside);
        return inside;
    }
}

Also this is the fluidlist.

public class FluidList {

    public static final RegistryObject<FlowingFluid> MILK_SOURCE = Registration.FLUIDS.register("milk_still", FluidMilk.Source::new);
    public static final RegistryObject<FlowingFluid> MILK_FLOWING = Registration.FLUIDS.register("milk_flowing", FluidMilk.Flowing::new);
    public static final FlowingFluidBlock MILK = new FlowingFluidBlock(FluidList.MILK_SOURCE, AbstractBlock.Properties.of(new Material.Builder(MaterialColor.WATER).noCollider().nonSolid().replaceable().liquid().build()));

    public static void register () {
        Registration.BLOCKS.register("milk", () -> MILK);
    }
}

I do realise that i might not be the cleanest code but my main objective is to get this working.

Anyone got any ideas?

Posted (edited)

Found the sollution.

 

If your FlowingFluid block has a method called entityInside which is marked deprecated. After tons of digging around in the source code and documentation it appears that with minecraft deprecated can mean that you have to override the method. Kind of a weird way tbh.

 

Here is eveything i used to make it work. The Registry.Fluids is a DeferredRegister of the type fluid.

public class FluidMilkBlock extends FlowingFluidBlock {
    public FluidMilkBlock(Supplier<? extends FlowingFluid> supplier, Properties p_i48368_1_) {
        super(supplier, p_i48368_1_);
    }

    @Override
    public void entityInside(BlockState p_196262_1_, World p_196262_2_, BlockPos p_196262_3_, Entity p_196262_4_) {
        FluidState state = p_196262_1_.getFluidState();
        if(state != null) {
            state.isEntityInside(p_196262_2_, p_196262_3_, p_196262_4_, p_196262_3_.getY() , null, false);
        }

        super.entityInside(p_196262_1_, p_196262_2_, p_196262_3_, p_196262_4_);
    }
}
public class FluidMilk extends ForgeFlowingFluid {

    protected FluidMilk(Properties properties) {
        super(properties);
    }

    public Fluid getFlowing() {
        return FluidList.MILK_FLOWING.get();

    }

    public Fluid getSource() {
        return FluidList.MILK_SOURCE.get();
    }

    public Item getBucket() {
        return ItemList.MILK_BUCKET.get();
    }

    @OnlyIn(Dist.CLIENT)
    public void animateTick(World p_204522_1_, BlockPos p_204522_2_, FluidState p_204522_3_, Random p_204522_4_) {
        if (!p_204522_3_.isSource() && !p_204522_3_.getValue(FALLING)) {
            if (p_204522_4_.nextInt(64) == 0) {
                p_204522_1_.playLocalSound((double)p_204522_2_.getX() + 0.5D, (double)p_204522_2_.getY() + 0.5D, (double)p_204522_2_.getZ() + 0.5D, SoundEvents.WATER_AMBIENT, SoundCategory.BLOCKS, p_204522_4_.nextFloat() * 0.25F + 0.75F, p_204522_4_.nextFloat() + 0.5F, false);
            }
        
        } else if (p_204522_4_.nextInt(10) == 0) {
            p_204522_1_.addParticle(ParticleTypes.UNDERWATER, (double)p_204522_2_.getX() + p_204522_4_.nextDouble(), (double)p_204522_2_.getY() + p_204522_4_.nextDouble(), (double)p_204522_2_.getZ() + p_204522_4_.nextDouble(), 0.0D, 0.0D, 0.0D);
        }

    }

    @Nullable
    @OnlyIn(Dist.CLIENT)
    public IParticleData getDripParticle() {
        return ParticleTypes.DRIPPING_WATER;
    }

    protected boolean canConvertToSource() {
        return true;
    }

    protected void beforeDestroyingBlock(IWorld p_205580_1_, BlockPos p_205580_2_, BlockState p_205580_3_) {
        TileEntity tileentity = p_205580_3_.hasTileEntity() ? p_205580_1_.getBlockEntity(p_205580_2_) : null;
        Block.dropResources(p_205580_3_, p_205580_1_, p_205580_2_, tileentity);
    }

    public int getSlopeFindDistance(IWorldReader p_185698_1_) {
        return 4;
    }

    public BlockState createLegacyBlock(FluidState p_204527_1_) {
        return FluidList.MILK_BLOCK.get().defaultBlockState().setValue(FlowingFluidBlock.LEVEL, Integer.valueOf(getLegacyLevel(p_204527_1_)));
    }

    @Override
    public boolean isSource(FluidState p_207193_1_) {
        return false;
    }

    @Override
    public int getAmount(FluidState p_207192_1_) {
        return 1;
    }

    public boolean isSame(Fluid p_207187_1_) {
        return p_207187_1_ == FluidList.MILK_SOURCE.get()|| p_207187_1_ == FluidList.MILK_FLOWING.get();
    }

    public int getDropOff(IWorldReader p_204528_1_) {
        return 1;
    }

    public int getTickDelay(IWorldReader p_205569_1_) {
        return 5;
    }

    public boolean canBeReplacedWith(FluidState p_215665_1_, IBlockReader p_215665_2_, BlockPos p_215665_3_, Fluid p_215665_4_, Direction p_215665_5_) {
        return p_215665_5_ == Direction.DOWN;
    }

    @Override
    protected FluidAttributes createAttributes() {
        return FluidAttributes.builder(new ResourceLocation("morefluids:blocks/milk_still"), new ResourceLocation("morefluids:blocks/milk_flowing")).translationKey("block/milk").build(this);
    }

    protected float getExplosionResistance() {
        return 100.0F;
    }


    public static class Flowing extends FluidMilk {
        public Flowing(Properties properties) {
            super(properties);
        }

        protected void createFluidStateDefinition(StateContainer.Builder<Fluid, FluidState> p_207184_1_) {
            super.createFluidStateDefinition(p_207184_1_);
            p_207184_1_.add(LEVEL);
        }

        @Override
        public boolean isEntityInside(FluidState state, IWorldReader world, BlockPos pos, Entity entity, double yToTest, Tag<Fluid> tag, boolean testingHead) {
            return super.isEntityInside(state, world, pos, entity, yToTest, tag, testingHead);
        }

        public int getAmount(FluidState p_207192_1_) {
            return p_207192_1_.getValue(LEVEL);
        }

        public boolean isSource(FluidState p_207193_1_) {
            return false;
        }

    }

    public static class Source extends FluidMilk {

        public Source(Properties properties) {
            super(properties);
        }

        protected void createFluidStateDefinition(StateContainer.Builder<Fluid, FluidState> p_207184_1_) {
            super.createFluidStateDefinition(p_207184_1_);
            p_207184_1_.add(LEVEL);
        }
        @Override
        public boolean isEntityInside(FluidState state, IWorldReader world, BlockPos pos, Entity entity, double yToTest, Tag<Fluid> tag, boolean testingHead) {
            return super.isEntityInside(state, world, pos, entity, yToTest, tag, testingHead);
        }

        public int getAmount(FluidState p_207192_1_) {
            return 8;
        }

        public boolean isSource(FluidState p_207193_1_) {
            return true;
        }

    }

    @Override
    public boolean isEntityInside(FluidState state, IWorldReader world, BlockPos pos, Entity entity, double yToTest, Tag<Fluid> tag, boolean testingHead) {

            if (entity instanceof LivingEntity) {
                LivingEntity livingEntity = (LivingEntity) entity;
                Collection<EffectInstance> list = livingEntity.getActiveEffects();

                for (EffectInstance effectInstance : list) {
                    Effect effect = effectInstance.getEffect();
                    livingEntity.removeEffect(effect);
                }


            }
        return true;
    }
}
public class FluidList {
	public static final ResourceLocation WATER_STILL_RL = new ResourceLocation("block/water_still");
    public static final ResourceLocation WATER_FLOWING_RL = new ResourceLocation("block/water_flow");
    public static final ResourceLocation WATER_OVERLAY_RL = new ResourceLocation("block/water_overlay");

    public static RegistryObject<FluidMilk.Source> MILK_SOURCE;
    public static RegistryObject<FluidMilk.Flowing> MILK_FLOWING;
    public static RegistryObject<FluidMilkBlock> MILK_BLOCK;
      
    public static ForgeFlowingFluid.Properties MILK_PROPERTIES;
 	public static void register () {
        MILK_PROPERTIES = new ForgeFlowingFluid.Properties(
                  () -> MILK_SOURCE.get(), () -> MILK_FLOWING.get(), FluidAttributes.builder(WATER_STILL_RL, WATER_FLOWING_RL)
                  .density(15).luminosity(2).viscosity(5).sound(SoundEvents.HONEY_DRINK).overlay(WATER_OVERLAY_RL)
                  .color(0xbffed0d0)).slopeFindDistance(2).levelDecreasePerBlock(2)
                  .block(() -> FluidList.MILK_BLOCK.get()).bucket(() -> ItemList.MILK_BUCKET.get());

          MILK_SOURCE = Registration.FLUIDS.register("milk_still", () -> new FluidMilk.Source(MILK_PROPERTIES));
          MILK_FLOWING = Registration.FLUIDS.register("milk_flowing", () -> new FluidMilk.Flowing(MILK_PROPERTIES));
          MILK_BLOCK = Registration.BLOCKS.register("milk",
                  () -> new FluidMilkBlock(() ->FluidList.MILK_SOURCE.get(), AbstractBlock.Properties.of(Material.WATER).noCollission().noDrops()
                  ));
      }

 

Edited by lazackna
typo

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • But what could be the issue with that? Maybe the confiq file?  
    • There is an issue with legendarysurvivaloverhaul
    • I am playing on a nitrado server with friends and everytime i try to join i am getting the same crash.log Does somebody understand what the problem here could be?  Crash Log
    • I see. I'm sure I tried again with a lower case word, a few times. I ended up doing the same thing as pixxy in the end. Is this beyond the scope of the admins to fix? Are they already aware of it, or should I use 'contact us' to post a ticket?
    • I’m working on a Manta Ray entity in MCreator using GeckoLib animations, and my goal is to have a looping (flip) animation that ends at −360°, then transitions seamlessly into a swim animation starting at 0°. However, every method I’ve tried—like quickly interpolating the angle, inserting a brief keyframe at 0°, or using a micro “bridge” animation—still causes a visible “flash” https://imgur.com/a/5ucjUb9 or "jump" when the rotation resets. I want a perfectly smooth motion from the flip’s final rotation to the swim’s initial rotation. If anyone has solved this in MCreator/GeckoLib, or found a better trick for handling the −360° →0° gap without a snap, I’d appreciate some advice ! P.S.- I cannot set swim to start at -360 because I would have the same issue but in reverse. Here's the custom LoopingAnimationGoal :   class LoopingAnimationGoal extends Goal { private final MantaRayEntity entity; private final int cooldownTime; private int animationTimer; private int cooldownTimer; // New boolean to prevent double calls private boolean isLoopingActive = false; public LoopingAnimationGoal(MantaRayEntity entity, int cooldownTime) { this.entity = entity; this.cooldownTime = cooldownTime; this.animationTimer = 0; this.cooldownTimer = 0; this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK)); } @Override public boolean canUse() { System.out.println("[DEBUG] LoopingGoal canUse => cooldownTimer=" + cooldownTimer); if (cooldownTimer > 0) { cooldownTimer--; return false; } BlockPos entityPos = entity.blockPosition(); boolean canUse = entity.isWaterAbove(entityPos, 4); System.out.println("[DEBUG] LoopingGoal canUse => WATER " + (canUse ? "DETECTED" : "NOT DETECTED") + " at " + entityPos + ", returning " + canUse); return canUse; } @Override public void start() { entity.setAnimation("looping"); animationTimer = 63; isLoopingActive = true; System.out.println("[DEBUG] Looping animation STARTED. Timer=" + animationTimer + ", gameTime=" + entity.level().getGameTime()); } @Override public boolean canContinueToUse() { System.out.println("[DEBUG] LoopingGoal canContinueToUse => animationTimer=" + animationTimer); return animationTimer > 0; } @Override public void tick() { animationTimer--; System.out.println("[DEBUG] LoopingGoal TICK => animationTimer=" + animationTimer); // We stop ONLY if we are still looping if (animationTimer <= 0 && isLoopingActive) { System.out.println("[DEBUG] condition => animationTimer <= 0 && isLoopingActive"); stop(); } } @Override public void stop() { // Check if already stopped if (!isLoopingActive) { System.out.println("[DEBUG] stop() called again, but isLoopingActive = false. Doing nothing."); return; } System.out.println("[DEBUG] Looping STOP at tick=" + entity.level().getGameTime() + ", last known rotation=" + entity.getXRot() + "/" + entity.getYRot() + ", animationTimer=" + animationTimer); // Immediately switch to "swim" entity.setAnimation("swim"); // Reset cooldown cooldownTimer = cooldownTime; // Disable looping to prevent a second stop isLoopingActive = false; System.out.println("[DEBUG] Looping STOP => setAnimation('swim'), cooldownTimer=" + cooldownTimer); } }  
  • Topics

×
×
  • Create New...

Important Information

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