Fluid moves, you just loose 1/2 of it

This commit is contained in:
modmuss50 2016-05-10 21:45:54 +01:00
parent 25280e9e7e
commit 37dc52d6df

View file

@ -29,6 +29,7 @@ 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.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import reborncore.common.misc.Functions; import reborncore.common.misc.Functions;
@ -43,448 +44,394 @@ import java.util.*;
/** /**
* Created by modmuss50 on 09/05/2016. * Created by modmuss50 on 09/05/2016.
*/ */
public class MultipartFluidPipe extends Multipart implements INormallyOccludingPart, ISlottedPart, ITickable public class MultipartFluidPipe extends Multipart implements INormallyOccludingPart, ISlottedPart, ITickable {
{
public static final IUnlistedProperty<Boolean> UP = Properties.toUnlisted(PropertyBool.create("up")); public static final IUnlistedProperty<Boolean> UP = Properties.toUnlisted(PropertyBool.create("up"));
public static final IUnlistedProperty<Boolean> DOWN = Properties.toUnlisted(PropertyBool.create("down")); public static final IUnlistedProperty<Boolean> DOWN = Properties.toUnlisted(PropertyBool.create("down"));
public static final IUnlistedProperty<Boolean> NORTH = Properties.toUnlisted(PropertyBool.create("north")); public static final IUnlistedProperty<Boolean> NORTH = Properties.toUnlisted(PropertyBool.create("north"));
public static final IUnlistedProperty<Boolean> EAST = Properties.toUnlisted(PropertyBool.create("east")); public static final IUnlistedProperty<Boolean> EAST = Properties.toUnlisted(PropertyBool.create("east"));
public static final IUnlistedProperty<Boolean> SOUTH = Properties.toUnlisted(PropertyBool.create("south")); public static final IUnlistedProperty<Boolean> SOUTH = Properties.toUnlisted(PropertyBool.create("south"));
public static final IUnlistedProperty<Boolean> WEST = Properties.toUnlisted(PropertyBool.create("west")); public static final IUnlistedProperty<Boolean> WEST = Properties.toUnlisted(PropertyBool.create("west"));
public static final IProperty<EnumFluidPipeTypes> TYPE = PropertyEnum.create("type", EnumFluidPipeTypes.class); public static final IProperty<EnumFluidPipeTypes> TYPE = PropertyEnum.create("type", EnumFluidPipeTypes.class);
public static final double thickness = 11; public static final double thickness = 11;
public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14]; public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
public float center = 0.6F; public float center = 0.6F;
public float offset = 0.10F; public float offset = 0.10F;
public Map<EnumFacing, BlockPos> connectedSides; public Map<EnumFacing, BlockPos> connectedSides;
EnumFluidPipeTypes currentType = EnumFluidPipeTypes.EMPTY; EnumFluidPipeTypes currentType = EnumFluidPipeTypes.EMPTY;
Tank tank = new Tank("MultipartFluidPipe", 1000, null); Tank tank = new Tank("MultipartFluidPipe", 1000, null);
public MultipartFluidPipe() public MultipartFluidPipe() {
{ connectedSides = new HashMap<>();
connectedSides = new HashMap<>(); refreshBounding();
refreshBounding(); }
}
public static MultipartFluidPipe getPartFromWorld(World world, BlockPos pos, EnumFacing side) public static MultipartFluidPipe getPartFromWorld(World world, BlockPos pos, EnumFacing side) {
{ if (world == null || pos == null) {
if (world == null || pos == null) return null;
{ }
return null; IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
} if (side != null && container != null) {
IMultipartContainer container = MultipartHelper.getPartContainer(world, pos); ISlottedPart slottedPart = container.getPartInSlot(PartSlot.getFaceSlot(side));
if (side != null && container != null) if (slottedPart instanceof IMicroblock.IFaceMicroblock && !((IMicroblock.IFaceMicroblock) slottedPart)
{ .isFaceHollow()) {
ISlottedPart slottedPart = container.getPartInSlot(PartSlot.getFaceSlot(side)); return null;
if (slottedPart instanceof IMicroblock.IFaceMicroblock && !((IMicroblock.IFaceMicroblock) slottedPart) }
.isFaceHollow()) }
{
return null;
}
}
if (container == null) if (container == null) {
{ return null;
return null; }
} ISlottedPart part = container.getPartInSlot(PartSlot.CENTER);
ISlottedPart part = container.getPartInSlot(PartSlot.CENTER); if (part instanceof MultipartFluidPipe) {
if (part instanceof MultipartFluidPipe) return (MultipartFluidPipe) part;
{ }
return (MultipartFluidPipe) part; return null;
} }
return null;
}
public void refreshBounding() public void refreshBounding() {
{ float centerFirst = center - offset;
float centerFirst = center - offset; double w = (thickness / 16) - 0.5;
double w = (thickness / 16) - 0.5; boundingBoxes[6] = new Vecs3dCube(centerFirst - w, centerFirst - w, centerFirst - w, centerFirst + w,
boundingBoxes[6] = new Vecs3dCube(centerFirst - w, centerFirst - w, centerFirst - w, centerFirst + w, centerFirst + w, centerFirst + w);
centerFirst + w, centerFirst + w);
int i = 0; int i = 0;
for (EnumFacing dir : EnumFacing.VALUES) for (EnumFacing dir : EnumFacing.VALUES) {
{ double xMin1 = (dir.getFrontOffsetX() < 0 ?
double xMin1 = (dir.getFrontOffsetX() < 0 ? 0.0 :
0.0 : (dir.getFrontOffsetX() == 0 ? centerFirst - w : centerFirst + w));
(dir.getFrontOffsetX() == 0 ? centerFirst - w : centerFirst + w)); double xMax1 = (dir.getFrontOffsetX() > 0 ?
double xMax1 = (dir.getFrontOffsetX() > 0 ? 1.0 :
1.0 : (dir.getFrontOffsetX() == 0 ? centerFirst + w : centerFirst - w));
(dir.getFrontOffsetX() == 0 ? centerFirst + w : centerFirst - w));
double yMin1 = (dir.getFrontOffsetY() < 0 ? double yMin1 = (dir.getFrontOffsetY() < 0 ?
0.0 : 0.0 :
(dir.getFrontOffsetY() == 0 ? centerFirst - w : centerFirst + w)); (dir.getFrontOffsetY() == 0 ? centerFirst - w : centerFirst + w));
double yMax1 = (dir.getFrontOffsetY() > 0 ? double yMax1 = (dir.getFrontOffsetY() > 0 ?
1.0 : 1.0 :
(dir.getFrontOffsetY() == 0 ? centerFirst + w : centerFirst - w)); (dir.getFrontOffsetY() == 0 ? centerFirst + w : centerFirst - w));
double zMin1 = (dir.getFrontOffsetZ() < 0 ? double zMin1 = (dir.getFrontOffsetZ() < 0 ?
0.0 : 0.0 :
(dir.getFrontOffsetZ() == 0 ? centerFirst - w : centerFirst + w)); (dir.getFrontOffsetZ() == 0 ? centerFirst - w : centerFirst + w));
double zMax1 = (dir.getFrontOffsetZ() > 0 ? double zMax1 = (dir.getFrontOffsetZ() > 0 ?
1.0 : 1.0 :
(dir.getFrontOffsetZ() == 0 ? centerFirst + w : centerFirst - w)); (dir.getFrontOffsetZ() == 0 ? centerFirst + w : centerFirst - w));
boundingBoxes[i] = new Vecs3dCube(xMin1, yMin1, zMin1, xMax1, yMax1, zMax1); boundingBoxes[i] = new Vecs3dCube(xMin1, yMin1, zMin1, xMax1, yMax1, zMax1);
i++; i++;
} }
} }
@Override public void addCollisionBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) @Override
{ public void addCollisionBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) {
for (EnumFacing dir : EnumFacing.VALUES) for (EnumFacing dir : EnumFacing.VALUES) {
{ if (connectedSides.containsKey(dir) && mask
if (connectedSides.containsKey(dir) && mask .intersectsWith(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB()))
.intersectsWith(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB())) list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB()); }
} if (mask.intersectsWith(boundingBoxes[6].toAABB())) {
if (mask.intersectsWith(boundingBoxes[6].toAABB())) list.add(boundingBoxes[6].toAABB());
{ }
list.add(boundingBoxes[6].toAABB()); super.addCollisionBoxes(mask, list, collidingEntity);
} }
super.addCollisionBoxes(mask, list, collidingEntity);
}
@Override public void addSelectionBoxes(List<AxisAlignedBB> list) @Override
{ public void addSelectionBoxes(List<AxisAlignedBB> list) {
for (EnumFacing dir : EnumFacing.VALUES) for (EnumFacing dir : EnumFacing.VALUES) {
{ if (connectedSides.containsKey(dir))
if (connectedSides.containsKey(dir)) list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB()); }
} list.add(boundingBoxes[6].toAABB());
list.add(boundingBoxes[6].toAABB()); super.addSelectionBoxes(list);
super.addSelectionBoxes(list); }
}
@Override public void onRemoved() @Override
{ public void onRemoved() {
super.onRemoved(); super.onRemoved();
for (EnumFacing dir : EnumFacing.VALUES) for (EnumFacing dir : EnumFacing.VALUES) {
{ MultipartFluidPipe multipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
MultipartFluidPipe multipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir); if (multipart != null) {
if (multipart != null) multipart.nearByChange();
{ }
multipart.nearByChange(); }
} }
}
}
@Override public void addOcclusionBoxes(List<AxisAlignedBB> list) @Override
{ public void addOcclusionBoxes(List<AxisAlignedBB> list) {
for (EnumFacing dir : EnumFacing.VALUES) for (EnumFacing dir : EnumFacing.VALUES) {
{ if (connectedSides.containsKey(dir))
if (connectedSides.containsKey(dir)) list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB()); }
} list.add(boundingBoxes[6].toAABB());
list.add(boundingBoxes[6].toAABB()); }
}
@Override public void onNeighborBlockChange(Block block) @Override
{ public void onNeighborBlockChange(Block block) {
super.onNeighborBlockChange(block); super.onNeighborBlockChange(block);
nearByChange(); nearByChange();
} }
public void nearByChange() public void nearByChange() {
{ checkConnectedSides();
checkConnectedSides(); for (EnumFacing direction : EnumFacing.VALUES) {
for (EnumFacing direction : EnumFacing.VALUES) BlockPos blockPos = getPos().offset(direction);
{ WorldUtils.updateBlock(getWorld(), blockPos);
BlockPos blockPos = getPos().offset(direction); MultipartFluidPipe part = getPartFromWorld(getWorld(), blockPos, direction);
WorldUtils.updateBlock(getWorld(), blockPos); if (part != null) {
MultipartFluidPipe part = getPartFromWorld(getWorld(), blockPos, direction); part.checkConnectedSides();
if (part != null) }
{ }
part.checkConnectedSides(); }
}
}
}
@Override public void onAdded() @Override
{ public void onAdded() {
nearByChange(); nearByChange();
} }
public boolean shouldConnectTo(EnumFacing dir) public boolean shouldConnectTo(EnumFacing dir) {
{ if (dir != null) {
if (dir != null) if (internalShouldConnectTo(dir)) {
{ MultipartFluidPipe multipartFluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
if (internalShouldConnectTo(dir)) if (multipartFluidPipe != null && multipartFluidPipe.internalShouldConnectTo(dir.getOpposite())) {
{ return true;
MultipartFluidPipe multipartFluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir); }
if (multipartFluidPipe != null && multipartFluidPipe.internalShouldConnectTo(dir.getOpposite())) } else {
{ TileEntity tile = getNeighbourTile(dir);
return true;
}
} else
{
TileEntity tile = getNeighbourTile(dir);
if (tile instanceof IFluidHandler && (currentType == EnumFluidPipeTypes.EXTRACT if (tile instanceof IFluidHandler && (currentType == EnumFluidPipeTypes.EXTRACT
|| currentType == EnumFluidPipeTypes.INSERT)) || currentType == EnumFluidPipeTypes.INSERT)) {
{ return true;
return true; }
} }
} }
} return false;
return false; }
}
public boolean internalShouldConnectTo(EnumFacing dir) public boolean internalShouldConnectTo(EnumFacing dir) {
{ ISlottedPart part = getContainer().getPartInSlot(PartSlot.getFaceSlot(dir));
ISlottedPart part = getContainer().getPartInSlot(PartSlot.getFaceSlot(dir)); if (part instanceof IMicroblock.IFaceMicroblock) {
if (part instanceof IMicroblock.IFaceMicroblock) if (!((IMicroblock.IFaceMicroblock) part).isFaceHollow()) {
{ return false;
if (!((IMicroblock.IFaceMicroblock) part).isFaceHollow()) }
{ }
return false;
}
}
if (!OcclusionHelper.occlusionTest(getContainer().getParts(), p -> p == this, if (!OcclusionHelper.occlusionTest(getContainer().getParts(), p -> p == this,
boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB())) boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB())) {
{ return false;
return false; }
}
MultipartFluidPipe multipartFluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir.getOpposite()); MultipartFluidPipe multipartFluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir.getOpposite());
return multipartFluidPipe != null; return multipartFluidPipe != null;
} }
public TileEntity getNeighbourTile(EnumFacing side) public TileEntity getNeighbourTile(EnumFacing side) {
{ return side != null ? getWorld().getTileEntity(getPos().offset(side)) : null;
return side != null ? getWorld().getTileEntity(getPos().offset(side)) : null; }
}
public void checkConnectedSides() public void checkConnectedSides() {
{ refreshBounding();
refreshBounding(); connectedSides = new HashMap<>();
connectedSides = new HashMap<>(); for (EnumFacing dir : EnumFacing.values()) {
for (EnumFacing dir : EnumFacing.values()) int d = Functions.getIntDirFromDirection(dir);
{ if (getWorld() == null) {
int d = Functions.getIntDirFromDirection(dir); return;
if (getWorld() == null) }
{ TileEntity te = getNeighbourTile(dir);
return; if (shouldConnectTo(dir)) {
} connectedSides.put(dir, te.getPos());
TileEntity te = getNeighbourTile(dir); }
if (shouldConnectTo(dir)) }
{ }
connectedSides.put(dir, te.getPos());
}
}
}
@Override public EnumSet<PartSlot> getSlotMask() @Override
{ public EnumSet<PartSlot> getSlotMask() {
return EnumSet.of(PartSlot.CENTER); return EnumSet.of(PartSlot.CENTER);
} }
@Override public IBlockState getExtendedState(IBlockState state) @Override
{ public IBlockState getExtendedState(IBlockState state) {
IExtendedBlockState extendedBlockState = (IExtendedBlockState) state; IExtendedBlockState extendedBlockState = (IExtendedBlockState) state;
return extendedBlockState.withProperty(DOWN, shouldConnectTo(EnumFacing.DOWN)) return extendedBlockState.withProperty(DOWN, shouldConnectTo(EnumFacing.DOWN))
.withProperty(UP, shouldConnectTo(EnumFacing.UP)).withProperty(NORTH, shouldConnectTo(EnumFacing.NORTH)) .withProperty(UP, shouldConnectTo(EnumFacing.UP)).withProperty(NORTH, shouldConnectTo(EnumFacing.NORTH))
.withProperty(SOUTH, shouldConnectTo(EnumFacing.SOUTH)) .withProperty(SOUTH, shouldConnectTo(EnumFacing.SOUTH))
.withProperty(WEST, shouldConnectTo(EnumFacing.WEST)) .withProperty(WEST, shouldConnectTo(EnumFacing.WEST))
.withProperty(EAST, shouldConnectTo(EnumFacing.EAST)).withProperty(TYPE, currentType); .withProperty(EAST, shouldConnectTo(EnumFacing.EAST)).withProperty(TYPE, currentType);
} }
@Override public BlockStateContainer createBlockState() @Override
{ public BlockStateContainer createBlockState() {
return new ExtendedBlockState(MCMultiPartMod.multipart, new IProperty[] { TYPE }, return new ExtendedBlockState(MCMultiPartMod.multipart, new IProperty[]{TYPE},
new IUnlistedProperty[] { DOWN, UP, NORTH, SOUTH, WEST, EAST }); new IUnlistedProperty[]{DOWN, UP, NORTH, SOUTH, WEST, EAST});
} }
@Override public float getHardness(PartMOP hit) @Override
{ public float getHardness(PartMOP hit) {
return 0.5F; return 0.5F;
} }
public Material getMaterial() public Material getMaterial() {
{ return Material.CLOTH;
return Material.CLOTH; }
}
@Override public List<ItemStack> getDrops() @Override
{ public List<ItemStack> getDrops() {
List<ItemStack> list = new ArrayList<>(); List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(TechRebornParts.fluidPipe, 1, 0)); list.add(new ItemStack(TechRebornParts.fluidPipe, 1, 0));
return list; return list;
} }
@Override public ResourceLocation getModelPath() @Override
{ public ResourceLocation getModelPath() {
return new ResourceLocation("techreborn:fluidpipe"); return new ResourceLocation("techreborn:fluidpipe");
} }
@Override public boolean canRenderInLayer(BlockRenderLayer layer) @Override
{ public boolean canRenderInLayer(BlockRenderLayer layer) {
return layer == BlockRenderLayer.CUTOUT; return layer == BlockRenderLayer.CUTOUT;
} }
@Override public void update() @Override
{ public void update() {
if (!getWorld().isRemote) if (!getWorld().isRemote) {
{ for (EnumFacing dir : EnumFacing.VALUES) {
for (EnumFacing dir : EnumFacing.VALUES) //if (connectedSides.containsKey(dir)) {
{ MultipartFluidPipe fluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
if (connectedSides.containsKey(dir)) if (fluidPipe != null) {
{ System.out.println(tank.getFluidAmount());
if (currentType != EnumFluidPipeTypes.EMPTY) if (!tank.isEmpty()){
{ if(fluidPipe.tank.isEmpty() || fluidPipe.tank.getFluid().getFluid() == tank.getFluid().getFluid()){
MultipartFluidPipe fluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir); int sharedAmount = (fluidPipe.tank.getFluidAmount() + tank.getFluidAmount()) / 2;
if (fluidPipe != null) fluidPipe.tank.setFluid(tank.getFluid());
{ fluidPipe.tank.setFluidAmount(sharedAmount + sharedAmount % 2 == 0 ? 0 : 1);
if (!fluidPipe.tank.isFull() && (fluidPipe.tank.getFluid() == null tank.setFluidAmount(sharedAmount);
|| 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) {
TileEntity tileEntity = getNeighbourTile(dir); if (!tank.isFull()) {
if (tileEntity != null) FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite());
{ if (fluidTankInfos.length != 0) {
if (tileEntity instanceof IFluidHandler) FluidTankInfo info = fluidTankInfos[0];
{ if (info != null & info.fluid != null) {
IFluidHandler handler = (IFluidHandler) tileEntity; if(tank.isEmpty() || info.fluid.getFluid() == tank.getFluid().getFluid()){
if (currentType == EnumFluidPipeTypes.EXTRACT) if(handler.canDrain(dir.getOpposite(), info.fluid.getFluid())){
{ int amountToMove = Math.min(100, tank.getCapacity() - tank.getFluidAmount());
if (!tank.isFull()) int fluidAmount = tank.getFluidAmount();
{ FluidStack fluidStack = handler.drain(dir.getOpposite(), amountToMove, true);
FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite()); tank.fill(fluidStack, true);
if (fluidTankInfos.length > 1) tank.setFluid(fluidStack);
{ tank.setFluidAmount(fluidAmount + fluidStack.amount);
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()); } else if (currentType == EnumFluidPipeTypes.INSERT) {
tank.fill(handler.drain(dir.getOpposite(), amountToMove, false), false); if (!tank.isEmpty()) {
} FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite());
} if (fluidTankInfos.length != 0) {
} FluidTankInfo info = fluidTankInfos[0];
} else if (currentType == EnumFluidPipeTypes.INSERT) if (info.fluid == null || info.fluid.getFluid() == null
{ || info.fluid.getFluid() == tank.getFluid().getFluid() && handler
if (!tank.isEmpty()) .canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
{ int infoSpace = info.capacity;
FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite()); if(info.fluid != null){
if (fluidTankInfos.length > 1) infoSpace = info.capacity - info.fluid.amount;
{ }
FluidTankInfo info = fluidTankInfos[1]; int amountToMove = Math.min(100, infoSpace);
if (info.fluid.getFluid() == null FluidStack fluidStack = tank.drain(amountToMove, true);
|| info.fluid.getFluid() == tank.getFluid().getFluid() && handler handler.fill(dir.getOpposite(), fluidStack, true);
.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 public boolean onActivated(EntityPlayer player, EnumHand hand, ItemStack heldItem, PartMOP hit) @Override
{ public boolean onActivated(EntityPlayer player, EnumHand hand, ItemStack heldItem, PartMOP hit) {
//TODO make only wrench able to change mode, shift-click with wrench picks up pipe, and click with empty hand displays current mode in chat (doesn't change it) //TODO make only wrench able to change mode, shift-click with wrench picks up pipe, and click with empty hand displays current mode in chat (doesn't change it)
//TODO move to client side only class //TODO move to client side only class
if (getWorld().isRemote) if (getWorld().isRemote) {
{ try {
try GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI();
{ Field field = chat.getClass().getDeclaredField("chatLines");
GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI(); field.setAccessible(true);
Field field = chat.getClass().getDeclaredField("chatLines"); List<ChatLine> lines = (List<ChatLine>) field.get(chat);
field.setAccessible(true); List<Integer> linesToRemove = new ArrayList<>();
List<ChatLine> lines = (List<ChatLine>) field.get(chat); for (ChatLine line : lines) {
List<Integer> linesToRemove = new ArrayList<>(); if (line.getChatComponent() instanceof TextComponetValue) {
for (ChatLine line : lines) linesToRemove.add(line.getChatLineID());
{ }
if (line.getChatComponent() instanceof TextComponetValue) }
{ for (Integer integer : linesToRemove) {
linesToRemove.add(line.getChatLineID()); chat.deleteChatLine(integer);
} }
} } catch (NoSuchFieldException e) {
for (Integer integer : linesToRemove) e.printStackTrace();
{ } catch (IllegalAccessException e) {
chat.deleteChatLine(integer); e.printStackTrace();
} }
} catch (NoSuchFieldException e) }
{
e.printStackTrace();
} catch (IllegalAccessException e)
{
e.printStackTrace();
}
}
//TODO sync this with the server/client //TODO sync this to the client, and also when part is loaded
if (currentType == EnumFluidPipeTypes.EMPTY) //if (!getWorld().isRemote) {
{ if (currentType == EnumFluidPipeTypes.EMPTY) {
currentType = EnumFluidPipeTypes.EXTRACT; currentType = EnumFluidPipeTypes.EXTRACT;
if (getWorld().isRemote) } else if (currentType == EnumFluidPipeTypes.EXTRACT) {
player.addChatMessage(new TextComponetValue("Mode set to: " + ChatFormatting.GOLD + "Extract")); currentType = EnumFluidPipeTypes.INSERT;
} else if (currentType == EnumFluidPipeTypes.EXTRACT) } else if (currentType == EnumFluidPipeTypes.INSERT) {
{ currentType = EnumFluidPipeTypes.EMPTY;
currentType = EnumFluidPipeTypes.INSERT; }
if (getWorld().isRemote) // }
player.addChatMessage(new TextComponetValue("Mode set to: " + ChatFormatting.BLUE + "Insert"));
} else if (currentType == EnumFluidPipeTypes.INSERT)
{
currentType = EnumFluidPipeTypes.EMPTY;
if (getWorld().isRemote)
player.addChatMessage(new TextComponetValue("Mode set to: " + ChatFormatting.DARK_GRAY + "Normal"));
}
markRenderUpdate(); if (getWorld().isRemote) {
return true; player.addChatMessage(new TextComponetValue("Mode set to: " + ChatFormatting.GOLD + currentType.getName()));
} }
@Override public void writeToNBT(NBTTagCompound tag) markRenderUpdate();
{ return true;
super.writeToNBT(tag); }
tank.writeToNBT(tag);
tag.setString("mode", currentType.getName());
}
@Override public void readFromNBT(NBTTagCompound tag) @Override
{ public void writeToNBT(NBTTagCompound tag) {
super.readFromNBT(tag); super.writeToNBT(tag);
tank.readFromNBT(tag); tank.writeToNBT(tag);
String mode = tag.getString("mode"); tag.setString("mode", currentType.getName());
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;
}
}
public class TextComponetValue extends TextComponentString @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;
}
}
public TextComponetValue(String msg) public class TextComponetValue extends TextComponentString {
{
super(msg); public TextComponetValue(String msg) {
} super(msg);
} }
}
} }