mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
1st pass at the fluid placer and collector.
This commit is contained in:
parent
ce972eb1f3
commit
660e976a1f
5 changed files with 78 additions and 34 deletions
|
@ -84,10 +84,10 @@ public final class ActuallyBlocks {
|
||||||
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityPlacer::new);
|
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityPlacer::new);
|
||||||
public static final AABlockReg<BlockDropper, AABlockItem, TileEntityDropper> DROPPER = new AABlockReg<>("dropper", BlockDropper::new,
|
public static final AABlockReg<BlockDropper, AABlockItem, TileEntityDropper> DROPPER = new AABlockReg<>("dropper", BlockDropper::new,
|
||||||
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityDropper::new);
|
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityDropper::new);
|
||||||
public static final AABlockReg<BlockFluidCollector, AABlockItem, TileEntityFluidCollector> FLUID_PLACER = new AABlockReg<>("fluid_placer", () -> new BlockFluidCollector(true),
|
public static final AABlockReg<BlockFluidCollector, AABlockItem, TileEntityFluidPlacer> FLUID_PLACER = new AABlockReg<>("fluid_placer", () -> new BlockFluidCollector(true),
|
||||||
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityFluidCollector::new);
|
|
||||||
public static final AABlockReg<BlockFluidCollector, AABlockItem, TileEntityFluidPlacer> FLUID_COLLECTOR = new AABlockReg<>("fluid_collector", () -> new BlockFluidCollector(false),
|
|
||||||
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityFluidPlacer::new);
|
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityFluidPlacer::new);
|
||||||
|
public static final AABlockReg<BlockFluidCollector, AABlockItem, TileEntityFluidCollector> FLUID_COLLECTOR = new AABlockReg<>("fluid_collector", () -> new BlockFluidCollector(false),
|
||||||
|
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityFluidCollector::new);
|
||||||
|
|
||||||
public static final AABlockReg<BlockFarmer, AABlockItem, TileEntityFarmer> FARMER = new AABlockReg<>("farmer", BlockFarmer::new,
|
public static final AABlockReg<BlockFarmer, AABlockItem, TileEntityFarmer> FARMER = new AABlockReg<>("farmer", BlockFarmer::new,
|
||||||
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityFarmer::new);
|
(b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityFarmer::new);
|
||||||
|
|
|
@ -11,20 +11,33 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.blocks;
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.base.FullyDirectionalBlock;
|
import de.ellpeck.actuallyadditions.mod.blocks.base.FullyDirectionalBlock;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDropper;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFermentingBarrel;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFluidCollector;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFluidCollector;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFluidPlacer;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFluidPlacer;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.util.ActionResultType;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.SoundCategory;
|
||||||
|
import net.minecraft.util.SoundEvents;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.BlockRayTraceResult;
|
import net.minecraft.util.math.BlockRayTraceResult;
|
||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fluids.FluidUtil;
|
||||||
|
import net.minecraftforge.fml.network.NetworkHooks;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class BlockFluidCollector extends FullyDirectionalBlock.Container {
|
public class BlockFluidCollector extends FullyDirectionalBlock.Container {
|
||||||
private final boolean isPlacer;
|
private final boolean isPlacer;
|
||||||
|
|
||||||
|
@ -33,24 +46,38 @@ public class BlockFluidCollector extends FullyDirectionalBlock.Container {
|
||||||
this.isPlacer = isPlacer;
|
this.isPlacer = isPlacer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Override
|
@Override
|
||||||
public TileEntity newBlockEntity(IBlockReader worldIn) {
|
public boolean hasTileEntity(BlockState state) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||||
return this.isPlacer
|
return this.isPlacer
|
||||||
? new TileEntityFluidPlacer()
|
? new TileEntityFluidPlacer()
|
||||||
: new TileEntityFluidCollector();
|
: new TileEntityFluidCollector();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
public ActionResultType use(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand handIn, @Nonnull BlockRayTraceResult hit) {
|
||||||
|
if (world.isClientSide)
|
||||||
|
return ActionResultType.SUCCESS;
|
||||||
|
|
||||||
if (this.tryToggleRedstone(world, pos, player)) {
|
if (this.tryToggleRedstone(world, pos, player)) {
|
||||||
return ActionResultType.PASS;
|
return ActionResultType.CONSUME;
|
||||||
|
}
|
||||||
|
if (FluidUtil.interactWithFluidHandler(player, handIn, world, pos, hit.getDirection())) {
|
||||||
|
return ActionResultType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.openGui(world, player, pos, TileEntityFluidCollector.class);
|
return this.openGui(world, player, pos, TileEntityFluidCollector.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
public VoxelShape getShape(BlockState state, @Nonnull IBlockReader worldIn, @Nonnull BlockPos pos, @Nonnull ISelectionContext context) {
|
||||||
switch (state.getValue(FACING)) {
|
switch (state.getValue(FACING)) {
|
||||||
case UP:
|
case UP:
|
||||||
return Shapes.FluidCollectorShapes.SHAPE_U;
|
return Shapes.FluidCollectorShapes.SHAPE_U;
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package de.ellpeck.actuallyadditions.mod.fluids;
|
||||||
|
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class AATank extends FluidTank {
|
||||||
|
public AATank(int capacity) {
|
||||||
|
super(capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AATank(int capacity, Predicate<FluidStack> validator) {
|
||||||
|
super(capacity, validator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int fillInternal(FluidStack res, FluidAction action) {
|
||||||
|
return super.fill(res, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public FluidStack drainInternal(int maxDrain, FluidAction action) {
|
||||||
|
return super.drain(maxDrain, action);
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,12 +48,9 @@ public class GuiFluidCollector extends AAScreen<ContainerFluidCollector> {
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
super.init();
|
super.init();
|
||||||
//this.fluid = new FluidDisplay(this.leftPos + 67, this.topPos + 5, this.collector.tank);
|
this.fluid = new FluidDisplay(this.leftPos + 67, this.topPos + 5, this.collector.tank);
|
||||||
}
|
titleLabelX = (int) (imageWidth / 2.0f - font.width(title) / 2.0f);
|
||||||
|
titleLabelY = -10;
|
||||||
@Override
|
|
||||||
public void renderLabels(@Nonnull MatrixStack matrices, int x, int y) {
|
|
||||||
AssetUtil.displayNameString(matrices, this.font, this.imageWidth, -10, this.collector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,12 +11,14 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.fluids.AATank;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFluidCollector;
|
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFluidCollector;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.block.FlowingFluidBlock;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
|
@ -32,8 +34,10 @@ import net.minecraft.util.SoundEvents;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
import net.minecraft.util.text.StringTextComponent;
|
||||||
|
import net.minecraft.util.text.TranslationTextComponent;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
|
import net.minecraftforge.fluids.FluidAttributes;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidBlock;
|
import net.minecraftforge.fluids.IFluidBlock;
|
||||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||||
|
@ -45,7 +49,7 @@ import javax.annotation.Nullable;
|
||||||
public class TileEntityFluidCollector extends TileEntityBase implements ISharingFluidHandler, INamedContainerProvider {
|
public class TileEntityFluidCollector extends TileEntityBase implements ISharingFluidHandler, INamedContainerProvider {
|
||||||
|
|
||||||
public boolean isPlacer;
|
public boolean isPlacer;
|
||||||
public final FluidTank tank = new FluidTank(8 * Util.BUCKET) {
|
public final AATank tank = new AATank(8 * FluidAttributes.BUCKET_VOLUME) {
|
||||||
@Override
|
@Override
|
||||||
public int fill(FluidStack resource, FluidAction action) {
|
public int fill(FluidStack resource, FluidAction action) {
|
||||||
if (!TileEntityFluidCollector.this.isPlacer) {
|
if (!TileEntityFluidCollector.this.isPlacer) {
|
||||||
|
@ -57,7 +61,7 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public FluidStack drain(int maxDrain, FluidAction action) {
|
public FluidStack drain(int maxDrain, FluidAction action) {
|
||||||
if (!TileEntityFluidCollector.this.isPlacer) {
|
if (TileEntityFluidCollector.this.isPlacer) {
|
||||||
return FluidStack.EMPTY;
|
return FluidStack.EMPTY;
|
||||||
}
|
}
|
||||||
return super.drain(maxDrain, action);
|
return super.drain(maxDrain, action);
|
||||||
|
@ -66,7 +70,7 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public FluidStack drain(FluidStack resource, FluidAction action) {
|
public FluidStack drain(FluidStack resource, FluidAction action) {
|
||||||
if (!TileEntityFluidCollector.this.isPlacer) {
|
if (TileEntityFluidCollector.this.isPlacer) {
|
||||||
return FluidStack.EMPTY;
|
return FluidStack.EMPTY;
|
||||||
}
|
}
|
||||||
return super.drain(resource, action);
|
return super.drain(resource, action);
|
||||||
|
@ -104,32 +108,22 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing
|
||||||
|
|
||||||
BlockState stateToBreak = this.level.getBlockState(coordsBlock);
|
BlockState stateToBreak = this.level.getBlockState(coordsBlock);
|
||||||
Block blockToBreak = stateToBreak.getBlock();
|
Block blockToBreak = stateToBreak.getBlock();
|
||||||
if (!this.isPlacer && Util.BUCKET <= this.tank.getCapacity() - this.tank.getFluidAmount()) {
|
if (!this.isPlacer && FluidAttributes.BUCKET_VOLUME <= this.tank.getCapacity() - this.tank.getFluidAmount()) {
|
||||||
if (blockToBreak instanceof IFluidBlock && ((IFluidBlock) blockToBreak).getFluid() != null) {
|
if (blockToBreak instanceof FlowingFluidBlock && stateToBreak.getFluidState().isSource() && ((FlowingFluidBlock) blockToBreak).getFluid() != null) {
|
||||||
if (this.tank.fill(new FluidStack(((IFluidBlock) blockToBreak).getFluid(), Util.BUCKET), IFluidHandler.FluidAction.SIMULATE) >= Util.BUCKET) {
|
if (this.tank.fillInternal(new FluidStack(((FlowingFluidBlock) blockToBreak).getFluid(), FluidAttributes.BUCKET_VOLUME), IFluidHandler.FluidAction.SIMULATE) >= FluidAttributes.BUCKET_VOLUME) {
|
||||||
this.tank.fill(new FluidStack(((IFluidBlock) blockToBreak).getFluid(), Util.BUCKET), IFluidHandler.FluidAction.EXECUTE);
|
this.tank.fillInternal(new FluidStack(((FlowingFluidBlock) blockToBreak).getFluid(), FluidAttributes.BUCKET_VOLUME), IFluidHandler.FluidAction.EXECUTE);
|
||||||
this.level.setBlockAndUpdate(coordsBlock, Blocks.AIR.defaultBlockState());
|
|
||||||
}
|
|
||||||
} else if (blockToBreak == Blocks.LAVA) {
|
|
||||||
if (this.tank.fill(new FluidStack(Fluids.LAVA, Util.BUCKET), IFluidHandler.FluidAction.SIMULATE) >= Util.BUCKET) {
|
|
||||||
this.tank.fill(new FluidStack(Fluids.LAVA, Util.BUCKET), IFluidHandler.FluidAction.EXECUTE);
|
|
||||||
this.level.setBlockAndUpdate(coordsBlock, Blocks.AIR.defaultBlockState());
|
|
||||||
}
|
|
||||||
} else if (blockToBreak == Blocks.WATER) {
|
|
||||||
if (this.tank.fill(new FluidStack(Fluids.WATER, Util.BUCKET), IFluidHandler.FluidAction.SIMULATE) >= Util.BUCKET) {
|
|
||||||
this.tank.fill(new FluidStack(Fluids.WATER, Util.BUCKET), IFluidHandler.FluidAction.EXECUTE);
|
|
||||||
this.level.setBlockAndUpdate(coordsBlock, Blocks.AIR.defaultBlockState());
|
this.level.setBlockAndUpdate(coordsBlock, Blocks.AIR.defaultBlockState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (this.isPlacer && blockToBreak.defaultBlockState().getMaterial().isReplaceable()) {
|
} else if (this.isPlacer && blockToBreak.defaultBlockState().getMaterial().isReplaceable()) {
|
||||||
if (this.tank.getFluidAmount() >= Util.BUCKET) {
|
if (this.tank.getFluidAmount() >= FluidAttributes.BUCKET_VOLUME) {
|
||||||
FluidStack stack = this.tank.getFluid();
|
FluidStack stack = this.tank.getFluid();
|
||||||
Block fluid = stack.getFluid().defaultFluidState().createLegacyBlock().getBlock();
|
Block fluid = stack.getFluid().defaultFluidState().createLegacyBlock().getBlock();
|
||||||
if (fluid != null) {
|
if (fluid != null) {
|
||||||
BlockPos offsetPos = this.worldPosition.relative(sideToManipulate);
|
BlockPos offsetPos = this.worldPosition.relative(sideToManipulate);
|
||||||
boolean placeable = !(blockToBreak instanceof IFluidBlock) && blockToBreak.defaultBlockState().getMaterial().isReplaceable();
|
boolean placeable = !(blockToBreak instanceof IFluidBlock) && blockToBreak.defaultBlockState().getMaterial().isReplaceable();
|
||||||
if (placeable) {
|
if (placeable) {
|
||||||
this.tank.drain(Util.BUCKET, IFluidHandler.FluidAction.EXECUTE);
|
this.tank.drainInternal(FluidAttributes.BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE);
|
||||||
// TODO: [port] validate this check is still valid.
|
// TODO: [port] validate this check is still valid.
|
||||||
if (this.level.dimensionType().ultraWarm() && fluid.defaultBlockState().getMaterial() == Material.WATER) {
|
if (this.level.dimensionType().ultraWarm() && fluid.defaultBlockState().getMaterial() == Material.WATER) {
|
||||||
this.level.playSound(null, offsetPos, SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.8F);
|
this.level.playSound(null, offsetPos, SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.8F);
|
||||||
|
@ -221,7 +215,7 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ITextComponent getDisplayName() {
|
public ITextComponent getDisplayName() {
|
||||||
return StringTextComponent.EMPTY;
|
return new TranslationTextComponent(isPlacer ? "container.actuallyadditions.fluidPlacer" : "container.actuallyadditions.fluidCollector");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
Loading…
Reference in a new issue