Jump to content

FlowingFluid collision


lazackna

Recommended Posts

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Losing a significant amount of money to scammers can be a bizarre experience that leaves you feeling helpless and betrayed. This was the situation I found myself in after investing over a hundred thousand dollars in a crypto platform that turned out to be a scam. I was introduced to this platform by a friend of my cousin, and everything seemed legitimate until it was too late for me to realize that I had been duped. The days following the realization of my loss were some of the darkest I have ever experienced. I was consumed by feelings of depression and desperation as I tried everything in my power to retrieve my hard-earned money. I reached out to various authorities and sought advice from friends and family, but it seemed like there was no way to recover what I had lost. It was during this time that a friend mentioned a platform called Wizard Web Recovery that specialized in recovering funds lost to scams. At first, I was skeptical and hesitant to trust another company with my money, but I was running out of options and decided to give them a chance. Looking back, this decision turned out to be the best one I could have made. From the moment I contacted Wizard Web Recovery, I was impressed by their dedication to helping me recover my funds. Their team of experts guided me through the process step by step, explaining each stage clearly and answering all of my questions along the way. They kept me informed of their progress and worked tirelessly to ensure that my case was given the attention it deserved. I was amazed at how quickly Wizard Web Recovery was able to track down the scammers and retrieve my money. Within a relatively short period, I received the news that my funds had been successfully recovered, and I couldn't believe it. It felt like a weight had been lifted off my shoulders, and I was filled with gratitude for the team at Wizard Web Recovery who had made it possible.    
    • my game crashed and I have no idea why here is a link to the pastebin of the crash https://pastebin.com/vv89r9vC
    • ok apparently the issue is even stupider than that. the folder the server was in was called "𝓯𝓻𝓮𝓪𝓴𝔂 server" and apparently the special characters in the folder name break the whole damn thing. this is the stupidest thing in the history of ever
    • Thanks, but now I have the 3d model in hand (and in inventory bcz I won't need that anymore) but now when I try to throw it, it doesnt rotate and its just the end of the trident not the head part. Edit: I removed the 3d custom model. I use the original minecraft files. Json and etc. In minecraft the rendering is made in code. I sent the code in the first message. I have mostly the code. But I don't know how to register the renderers like minecraft do. For example, in minecraft there are 2 jsons: trident_in_hand and trident_throwing , I have both of them. They don't render while I have the item in hand. That's the main problem. I checked the code but I still can't figure out how to register and render the entity basically, in hand
  • Topics

×
×
  • Create New...

Important Information

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