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.



×
×
  • Create New...

Important Information

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