Patch the bucket logic to not hardcode some checks to WATER. Fixes not being able to place custom fluids into modded fluid-loggable blocks that accept fluids other than water.

This commit is contained in:
David Quintana committed 2020-05-06 13:30:20 +02:00
1 parent 6551ccc247
commit a7e4cdcc49
4 files changed
+138 -15

No files matched your search

@@ -19,20 +19,22 @@
package net.minecraftforge.debug.fluid;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.*;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraftforge.common.util.Lazy;
import org.apache.commons.lang3.Validate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.fluid.FlowingFluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fluids.FluidAttributes;
@@ -58,11 +60,18 @@ public class NewFluidTest
public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID);
public static final DeferredRegister<Fluid> FLUIDS = new DeferredRegister<>(ForgeRegistries.FLUIDS, MODID);
private static ForgeFlowingFluid.Properties makeProperties()
{
return new ForgeFlowingFluid.Properties(test_fluid, test_fluid_flowing,
FluidAttributes.builder(FLUID_STILL, FLUID_FLOWING).overlay(FLUID_OVERLAY).color(0x3F1080FF))
.bucket(test_fluid_bucket).block(test_fluid_block);
}
public static RegistryObject<FlowingFluid> test_fluid = FLUIDS.register("test_fluid", () ->
new ForgeFlowingFluid.Source(NewFluidTest.test_fluid_properties)
new ForgeFlowingFluid.Source(makeProperties())
);
public static RegistryObject<FlowingFluid> test_fluid_flowing = FLUIDS.register("test_fluid_flowing", () ->
new ForgeFlowingFluid.Flowing(NewFluidTest.test_fluid_properties)
new ForgeFlowingFluid.Flowing(makeProperties())
);
public static RegistryObject<FlowingFluidBlock> test_fluid_block = BLOCKS.register("test_fluid_block", () ->
@@ -72,9 +81,13 @@ public class NewFluidTest
new BucketItem(test_fluid, new Item.Properties().containerItem(Items.BUCKET).maxStackSize(1).group(ItemGroup.MISC))
);
public static final ForgeFlowingFluid.Properties test_fluid_properties =
new ForgeFlowingFluid.Properties(test_fluid, test_fluid_flowing, FluidAttributes.builder(FLUID_STILL, FLUID_FLOWING).overlay(FLUID_OVERLAY).color(0x3F1080FF))
.bucket(test_fluid_bucket).block(test_fluid_block);
// WARNING: this doesn't allow "any fluid", only the fluid from this test mod!
public static RegistryObject<Block> fluidloggable_block = BLOCKS.register("fluidloggable_block", () ->
new FluidloggableBlock(Block.Properties.create(Material.WOOD).doesNotBlockMovement().hardnessAndResistance(100.0F).noDrops())
);
public static RegistryObject<Item> fluidloggable_blockitem = ITEMS.register("fluidloggable_block", () ->
new BlockItem(fluidloggable_block.get(), new Item.Properties().group(ItemGroup.MISC))
);
public NewFluidTest()
{
@@ -96,4 +109,57 @@ public class NewFluidTest
ItemStack stack = Fluids.WATER.getAttributes().getBucket(new FluidStack(Fluids.WATER, 1));
Validate.isTrue(stack.getItem() == Fluids.WATER.getFilledBucket());
}
// WARNING: this doesn't allow "any fluid", only the fluid from this test mod!
private static class FluidloggableBlock extends Block implements IWaterLoggable
{
public static final BooleanProperty FLUIDLOGGED = BooleanProperty.create("fluidlogged");
public FluidloggableBlock(Properties properties)
{
super(properties);
setDefaultState(getStateContainer().getBaseState().with(FLUIDLOGGED, false));
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder)
{
builder.add(FLUIDLOGGED);
}
@Override
public boolean canContainFluid(IBlockReader worldIn, BlockPos pos, BlockState state, Fluid fluidIn) {
return !state.get(FLUIDLOGGED) && fluidIn == test_fluid.get();
}
@Override
public boolean receiveFluid(IWorld worldIn, BlockPos pos, BlockState state, IFluidState fluidStateIn) {
if (canContainFluid(worldIn, pos, state, fluidStateIn.getFluid())) {
if (!worldIn.isRemote()) {
worldIn.setBlockState(pos, state.with(FLUIDLOGGED, true), 3);
worldIn.getPendingFluidTicks().scheduleTick(pos, fluidStateIn.getFluid(), fluidStateIn.getFluid().getTickRate(worldIn));
}
return true;
} else {
return false;
}
}
@Override
public Fluid pickupFluid(IWorld worldIn, BlockPos pos, BlockState state) {
if (state.get(FLUIDLOGGED)) {
worldIn.setBlockState(pos, state.with(FLUIDLOGGED, false), 3);
return test_fluid.get();
} else {
return Fluids.EMPTY;
}
}
@Override
public IFluidState getFluidState(BlockState state)
{
return state.get(FLUIDLOGGED) ? test_fluid.get().getDefaultState() : Fluids.EMPTY.getDefaultState();
}
}
}
@@ -1,3 +1,22 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.world;
import net.minecraftforge.event.world.ChunkDataEvent;