mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 15:03:04 +00:00
[1.11.x] Refine fluid placement utilities (#3509)
This commit is contained in:
1 parent
160427b12c
commit
8eea766288
12 files changed
+615
-69
No files matched your search
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016.
|
||||
*
|
||||
* 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.fluids.capability.templates;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static net.minecraftforge.fluids.capability.templates.EmptyFluidHandler.EMPTY_TANK_INFO;
|
||||
import static net.minecraftforge.fluids.capability.templates.EmptyFluidHandler.EMPTY_TANK_PROPERTIES_ARRAY;
|
||||
|
||||
/**
|
||||
* VoidFluidHandler is a template fluid handler that can be filled indefinitely without ever getting full.
|
||||
* It does not store fluid that gets filled into it, but "destroys" it upon receiving it.
|
||||
*/
|
||||
public class VoidFluidHandler implements IFluidHandler, IFluidTank
|
||||
{
|
||||
public static final EmptyFluidHandler INSTANCE = new EmptyFluidHandler();
|
||||
|
||||
public VoidFluidHandler() {}
|
||||
|
||||
@Override
|
||||
public IFluidTankProperties[] getTankProperties()
|
||||
{
|
||||
return EMPTY_TANK_PROPERTIES_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FluidStack getFluid()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidAmount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo getInfo()
|
||||
{
|
||||
return EMPTY_TANK_INFO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
return resource.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+16
-3
@@ -26,7 +26,7 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemBucket;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -39,7 +39,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
/**
|
||||
* Wrapper to handle vanilla Water or Lava as an IFluidHandler.
|
||||
* Methods are modeled after {@link net.minecraft.item.ItemBucket#onItemRightClick(ItemStack, World, EntityPlayer, EnumHand)}
|
||||
* Methods are modeled after {@link ItemBucket#onItemRightClick(World, EntityPlayer, EnumHand)}
|
||||
*/
|
||||
public class BlockLiquidWrapper implements IFluidHandler
|
||||
{
|
||||
@@ -69,7 +69,20 @@ public class BlockLiquidWrapper implements IFluidHandler
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
return 0;
|
||||
// NOTE: "Filling" means placement in this context!
|
||||
if (resource.amount < Fluid.BUCKET_VOLUME)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (doFill)
|
||||
{
|
||||
Material material = blockLiquid.getDefaultState().getMaterial();
|
||||
BlockLiquid block = BlockLiquid.getStaticBlock(material);
|
||||
world.setBlockState(blockPos, block.getDefaultState().withProperty(BlockLiquid.LEVEL, 0), 11);
|
||||
}
|
||||
|
||||
return Fluid.BUCKET_VOLUME;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016.
|
||||
*
|
||||
* 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.fluids.capability.wrappers;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.templates.VoidFluidHandler;
|
||||
|
||||
/**
|
||||
* Wrapper around any block, only accounts for fluid placement, otherwise the block acts a void.
|
||||
* If the block in question inherits from the default Vanilla or Forge implementations,
|
||||
* consider using {@link BlockLiquidWrapper} or {@link FluidBlockWrapper} respectively.
|
||||
*/
|
||||
public class BlockWrapper extends VoidFluidHandler
|
||||
{
|
||||
protected final Block block;
|
||||
protected final World world;
|
||||
protected final BlockPos blockPos;
|
||||
|
||||
public BlockWrapper(Block block, World world, BlockPos blockPos)
|
||||
{
|
||||
this.block = block;
|
||||
this.world = world;
|
||||
this.blockPos = blockPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
// NOTE: "Filling" means placement in this context!
|
||||
if (resource.amount < Fluid.BUCKET_VOLUME)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (doFill)
|
||||
{
|
||||
world.setBlockState(blockPos, block.getDefaultState(), 11);
|
||||
}
|
||||
return Fluid.BUCKET_VOLUME;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,12 @@ public class FluidBlockWrapper implements IFluidHandler
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
return 0;
|
||||
// NOTE: "Filling" means placement in this context!
|
||||
if (resource == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return fluidBlock.place(world, blockPos, resource, doFill);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in new issue
Block a user