Drain block for liquid gathering

https://wiki.techreborn.ovh/doku.php?id=mods:techreborn:drain
This commit is contained in:
Justin Vitale 2020-06-18 21:39:40 +10:00 committed by GitHub
parent f915c4619d
commit 025740d8ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 12 deletions

View file

@ -24,17 +24,24 @@
package techreborn.blockentity.machine.misc;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.FluidDrainable;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import reborncore.api.IListInfoProvider;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.util.math.BlockPos;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.fluid.FluidValue;
import reborncore.common.fluid.container.FluidInstance;
import reborncore.common.util.Tank;
import techreborn.init.TRBlockEntities;
public class DrainBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IListInfoProvider, IContainerProvider {
import javax.annotation.Nullable;
public class DrainBlockEntity extends MachineBaseBlockEntity {
protected Tank internalTank = new Tank("tank", FluidValue.BUCKET, this);
public DrainBlockEntity(){
this(TRBlockEntities.DRAIN);
@ -45,12 +52,41 @@ public class DrainBlockEntity extends MachineBaseBlockEntity implements Inventor
}
@Override
public Inventory getInventory() {
return null;
public void tick() {
super.tick();
if(world.isClient){
return;
}
if (world.getTime() % 10 == 0) {
if(internalTank.isEmpty()) {
tryDrain();
}
}
}
@Nullable
@Override
public BuiltContainer createContainer(int syncID, PlayerEntity player) {
return null;
public Tank getTank() {
return internalTank;
}
private void tryDrain(){
// Position above drain
BlockPos above = this.getPos().up();
// Block and state above drain
BlockState aboveBlockState = world.getBlockState(above);
Block aboveBlock = aboveBlockState.getBlock();
if (aboveBlock instanceof FluidDrainable) {
Fluid drainFluid = ((FluidDrainable) aboveBlock).tryDrainFluid(world, above, aboveBlockState);
if (drainFluid != Fluids.EMPTY) {
internalTank.setFluidInstance(new FluidInstance(drainFluid, FluidValue.BUCKET));
}
}
}
}

View file

@ -65,7 +65,7 @@ public class StackToolTipHandler implements ItemTooltipCallback {
ItemTooltipCallback.EVENT.register(new StackToolTipHandler());
// WIP injection
wipBlocks.add(TRContent.Machine.DRAIN.block);
// wipBlocks.add(TRContent.Machine.NAME.block);
}

View file

@ -690,6 +690,8 @@
"techreborn.message.info.block.techreborn.quantum_tank": "Stores near-infinite of a single liquid",
"techreborn.message.info.block.techreborn.charge_o_mat": "Charges up to 6 items simultaneously",
"techreborn.message.info.block.techreborn.chunk_loader": "Keeps chunks loaded, allows machines to run when you're not nearby",
"techreborn.message.info.block.techreborn.drain": "Pulls any fluid directly above it, pairs nicely with a tank unit underneath",
"keys.techreborn.category": "TechReborn Category",
"keys.techreborn.config": "Config",

View file

@ -0,0 +1,25 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"PHP",
"FBF",
"PFP"
],
"key": {
"P": {
"item": "techreborn:refined_iron_plate"
},
"B": {
"item": "minecraft:bucket"
},
"H": {
"item": "minecraft:hopper"
},
"F": {
"item": "techreborn:basic_machine_frame"
}
},
"result": {
"item": "techreborn:drain"
}
}