Started work on fluid movement mechanic
This commit is contained in:
parent
a78b2b6745
commit
6488a9227e
2 changed files with 88 additions and 28 deletions
|
@ -9,18 +9,7 @@ public enum EnumFluidPipeTypes implements IStringSerializable {
|
||||||
|
|
||||||
EMPTY("empty","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
EMPTY("empty","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
||||||
INSERT("insert","techreborn:blocks/fluidPipes/fluidpipe_insert", false, true),
|
INSERT("insert","techreborn:blocks/fluidPipes/fluidpipe_insert", false, true),
|
||||||
EXTRACT("extract","techreborn:blocks/fluidPipes/fluidpipe_extract", true, false),
|
EXTRACT("extract","techreborn:blocks/fluidPipes/fluidpipe_extract", true, false);
|
||||||
FLV1("flv1","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
|
||||||
FLV2("flv2","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
|
||||||
FLV3("flv3","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
|
||||||
FLV4("flv4","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
|
||||||
FLV5("flv5","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
|
||||||
FLV6("flv6","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
|
||||||
FLV7("flv7","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
|
||||||
FLV8("flv8","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
|
||||||
FLV9("flv9","techreborn:blocks/fluidPipes/fluidpipe", false, false),
|
|
||||||
FLV10("flv10","techreborn:blocks/fluidPipes/fluidpipe", false, false);
|
|
||||||
|
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
public String textureName = "minecraft:blocks/iron_block";
|
public String textureName = "minecraft:blocks/iron_block";
|
||||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.client.gui.GuiNewChat;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.*;
|
import net.minecraft.util.*;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
|
@ -28,10 +29,11 @@ import net.minecraftforge.common.property.ExtendedBlockState;
|
||||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||||
import net.minecraftforge.common.property.Properties;
|
import net.minecraftforge.common.property.Properties;
|
||||||
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
import reborncore.api.power.IEnergyInterfaceTile;
|
|
||||||
import reborncore.common.misc.Functions;
|
import reborncore.common.misc.Functions;
|
||||||
import reborncore.common.misc.vecmath.Vecs3dCube;
|
import reborncore.common.misc.vecmath.Vecs3dCube;
|
||||||
|
import reborncore.common.util.Tank;
|
||||||
import reborncore.common.util.WorldUtils;
|
import reborncore.common.util.WorldUtils;
|
||||||
import techreborn.parts.TechRebornParts;
|
import techreborn.parts.TechRebornParts;
|
||||||
|
|
||||||
|
@ -58,6 +60,8 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
|
||||||
public Map<EnumFacing, BlockPos> connectedSides;
|
public Map<EnumFacing, BlockPos> connectedSides;
|
||||||
public static final int thickness = 11;
|
public static final int thickness = 11;
|
||||||
|
|
||||||
|
Tank tank = new Tank("MultipartFluidPipe", 1000, null);
|
||||||
|
|
||||||
public MultipartFluidPipe() {
|
public MultipartFluidPipe() {
|
||||||
connectedSides = new HashMap<>();
|
connectedSides = new HashMap<>();
|
||||||
refreshBounding();
|
refreshBounding();
|
||||||
|
@ -286,7 +290,51 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
|
if (!getWorld().isRemote) {
|
||||||
|
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||||
|
if (connectedSides.containsKey(dir)) {
|
||||||
|
if (currentType != EnumFluidPipeTypes.EMPTY) {
|
||||||
|
MultipartFluidPipe fluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||||
|
if (fluidPipe != null) {
|
||||||
|
if (!fluidPipe.tank.isFull() && (fluidPipe.tank.getFluid() == null || fluidPipe.tank.getFluid().getFluid() == tank.getFluid().getFluid())) {
|
||||||
|
int sharedAmount = (fluidPipe.tank.getFluidAmount() + tank.getFluidAmount()) / 2;
|
||||||
|
fluidPipe.tank.setFluidAmount(sharedAmount);
|
||||||
|
tank.setFluidAmount(sharedAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TileEntity tileEntity = getNeighbourTile(dir);
|
||||||
|
if (tileEntity != null) {
|
||||||
|
if (tileEntity instanceof IFluidHandler) {
|
||||||
|
IFluidHandler handler = (IFluidHandler) tileEntity;
|
||||||
|
if (currentType == EnumFluidPipeTypes.EXTRACT) {
|
||||||
|
if (!tank.isFull()) {
|
||||||
|
FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite());
|
||||||
|
if (fluidTankInfos.length > 1) {
|
||||||
|
FluidTankInfo info = fluidTankInfos[1];
|
||||||
|
if (tank.getFluid() == null || info.fluid.getFluid() == tank.getFluid().getFluid() && handler.canDrain(dir.getOpposite(), tank.getFluid().getFluid())) {
|
||||||
|
int amountToMove = Math.min(100, tank.getCapacity() - tank.getFluidAmount());
|
||||||
|
tank.fill(handler.drain(dir.getOpposite(), amountToMove, false), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (currentType == EnumFluidPipeTypes.INSERT) {
|
||||||
|
if (!tank.isEmpty()) {
|
||||||
|
FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite());
|
||||||
|
if (fluidTankInfos.length > 1) {
|
||||||
|
FluidTankInfo info = fluidTankInfos[1];
|
||||||
|
if (info.fluid.getFluid() == null || info.fluid.getFluid() == tank.getFluid().getFluid() && handler.canFill(dir.getOpposite(), info.fluid.getFluid())) {
|
||||||
|
int amountToMove = Math.min(100, info.capacity - info.fluid.amount);
|
||||||
|
tank.fill(handler.drain(dir.getOpposite(), amountToMove, false), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -314,6 +362,7 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO sync this with the server/client
|
||||||
if (currentType == EnumFluidPipeTypes.EMPTY) {
|
if (currentType == EnumFluidPipeTypes.EMPTY) {
|
||||||
currentType = EnumFluidPipeTypes.EXTRACT;
|
currentType = EnumFluidPipeTypes.EXTRACT;
|
||||||
if (getWorld().isRemote)
|
if (getWorld().isRemote)
|
||||||
|
@ -327,6 +376,7 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
|
||||||
if (getWorld().isRemote)
|
if (getWorld().isRemote)
|
||||||
player.addChatMessage(new TextComponetValue("Mode set to: " + ChatFormatting.WHITE + "Normal"));
|
player.addChatMessage(new TextComponetValue("Mode set to: " + ChatFormatting.WHITE + "Normal"));
|
||||||
}
|
}
|
||||||
|
|
||||||
markRenderUpdate();
|
markRenderUpdate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -337,4 +387,25 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
|
||||||
super(msg);
|
super(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound tag) {
|
||||||
|
super.writeToNBT(tag);
|
||||||
|
tank.writeToNBT(tag);
|
||||||
|
tag.setString("mode", currentType.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound tag) {
|
||||||
|
super.readFromNBT(tag);
|
||||||
|
tank.readFromNBT(tag);
|
||||||
|
String mode = tag.getString("mode");
|
||||||
|
if (mode.equals(EnumFluidPipeTypes.EMPTY)) {
|
||||||
|
currentType = EnumFluidPipeTypes.EMPTY;
|
||||||
|
} else if (mode.equals(EnumFluidPipeTypes.INSERT)) {
|
||||||
|
currentType = EnumFluidPipeTypes.INSERT;
|
||||||
|
} else if (mode.equals(EnumFluidPipeTypes.EXTRACT)) {
|
||||||
|
currentType = EnumFluidPipeTypes.EXTRACT;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue