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 2020-05-06 13:30:20 +02:00
parent 6551ccc247
commit a7e4cdcc49
4 changed files with 138 additions and 15 deletions

View file

@ -41,7 +41,35 @@
ItemStack itemstack1 = this.func_150910_a(itemstack, p_77659_2_, fluid.func_204524_b());
if (!p_77659_1_.field_72995_K) {
CriteriaTriggers.field_204813_j.func_204817_a((ServerPlayerEntity)p_77659_2_, new ItemStack(fluid.func_204524_b()));
@@ -148,7 +165,19 @@
@@ -67,7 +84,7 @@
return ActionResult.func_226251_d_(itemstack);
} else {
BlockState blockstate = p_77659_1_.func_180495_p(blockpos);
- BlockPos blockpos2 = blockstate.func_177230_c() instanceof ILiquidContainer && this.field_77876_a == Fluids.field_204546_a ? blockpos : blockpos1;
+ BlockPos blockpos2 = canBlockContainFluid(p_77659_1_, blockpos, blockstate) ? blockpos : blockpos1;
if (this.func_180616_a(p_77659_2_, p_77659_1_, blockpos2, blockraytraceresult)) {
this.func_203792_a(p_77659_1_, itemstack, blockpos2);
if (p_77659_2_ instanceof ServerPlayerEntity) {
@@ -117,7 +134,8 @@
BlockState blockstate = p_180616_2_.func_180495_p(p_180616_3_);
Material material = blockstate.func_185904_a();
boolean flag = blockstate.func_227032_a_(this.field_77876_a);
- if (blockstate.func_196958_f() || flag || blockstate.func_177230_c() instanceof ILiquidContainer && ((ILiquidContainer)blockstate.func_177230_c()).func_204510_a(p_180616_2_, p_180616_3_, blockstate, this.field_77876_a)) {
+ boolean canContainFluid = canBlockContainFluid(p_180616_2_, p_180616_3_, blockstate);
+ if (blockstate.func_196958_f() || flag || canContainFluid) {
if (p_180616_2_.field_73011_w.func_177500_n() && this.field_77876_a.func_207185_a(FluidTags.field_206959_a)) {
int i = p_180616_3_.func_177958_n();
int j = p_180616_3_.func_177956_o();
@@ -127,7 +145,7 @@
for(int l = 0; l < 8; ++l) {
p_180616_2_.func_195594_a(ParticleTypes.field_197594_E, (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0D, 0.0D, 0.0D);
}
- } else if (blockstate.func_177230_c() instanceof ILiquidContainer && this.field_77876_a == Fluids.field_204546_a) {
+ } else if (canContainFluid) {
if (((ILiquidContainer)blockstate.func_177230_c()).func_204509_a(p_180616_2_, p_180616_3_, blockstate, ((FlowingFluid)this.field_77876_a).func_207204_a(false))) {
this.func_203791_b(p_180616_1_, p_180616_2_, p_180616_3_);
}
@@ -148,7 +166,24 @@
}
protected void func_203791_b(@Nullable PlayerEntity p_203791_1_, IWorld p_203791_2_, BlockPos p_203791_3_) {
@ -61,4 +89,9 @@
+
+ private final java.util.function.Supplier<? extends Fluid> fluidSupplier;
+ public Fluid getFluid() { return fluidSupplier.get(); }
+
+ private boolean canBlockContainFluid(World worldIn, BlockPos posIn, BlockState blockstate)
+ {
+ return blockstate.func_177230_c() instanceof ILiquidContainer && ((ILiquidContainer)blockstate.func_177230_c()).func_204510_a(worldIn, posIn, blockstate, this.field_77876_a);
+ }
}

View file

@ -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();
}
}
}

View file

@ -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;

View file

@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "minecraft:block/stone_brick_wall_post"}
}
}