mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 04:32:15 +00:00
Backport a7e4cdcc49 (Bucket unable to place custom fluid on block with custom fluid-loggable implementation)
This commit is contained in:
1 parent
dc3dec48b1
commit
e758126529
3 files changed
+134
-10
No files matched your search
@@ -19,16 +19,20 @@
|
||||
|
||||
package net.minecraftforge.debug.fluid;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.FlowingFluidBlock;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.fluid.FlowingFluid;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -41,6 +45,8 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Mod(NewFluidTest.MODID)
|
||||
public class NewFluidTest
|
||||
{
|
||||
@@ -53,11 +59,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).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", () ->
|
||||
@@ -67,9 +80,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).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()
|
||||
{
|
||||
@@ -91,4 +108,73 @@ 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);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context)
|
||||
{
|
||||
IFluidState state = context.getWorld().getFluidState(context.getPos());
|
||||
return getDefaultState().with(FLUIDLOGGED, state.getFluid() == test_fluid.get());
|
||||
}
|
||||
|
||||
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
|
||||
if (stateIn.get(FLUIDLOGGED)) {
|
||||
worldIn.getPendingFluidTicks().scheduleTick(currentPos, test_fluid.get(), test_fluid.get().getTickRate(worldIn));
|
||||
}
|
||||
|
||||
return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"variants": {
|
||||
"": { "model": "minecraft:block/stone_brick_wall_post"}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user