From 1b820de08a05070909a267e17f033fcf58ac8710 Mon Sep 17 00:00:00 2001 From: NotAPenguin Date: Mon, 2 Sep 2024 23:17:17 +0200 Subject: The Great Renaming (#3014) * move kekztech to a single root dir * move detrav to a single root dir * move gtnh-lanthanides to a single root dir * move tectech and delete some gross reflection in gt++ * remove more reflection inside gt5u * delete more reflection in gt++ * fix imports * move bartworks and bwcrossmod * fix proxies * move galactigreg and ggfab * move gtneioreplugin * try to fix gt++ bee loader * apply the rename rules to BW * apply rename rules to bwcrossmod * apply rename rules to detrav scanner mod * apply rename rules to galacticgreg * apply rename rules to ggfab * apply rename rules to goodgenerator * apply rename rules to gtnh-lanthanides * apply rename rules to gt++ * apply rename rules to kekztech * apply rename rules to kubatech * apply rename rules to tectech * apply rename rules to gt apply the rename rules to gt * fix tt import * fix mui hopefully * fix coremod except intergalactic * rename assline recipe class * fix a class name i stumbled on * rename StructureUtility to GTStructureUtility to prevent conflict with structurelib * temporary rename of GTTooltipDataCache to old name * fix gt client/server proxy names --- ...GT_MetaTileEntity_LongDistancePipelineBase.java | 415 --------------------- ...T_MetaTileEntity_LongDistancePipelineFluid.java | 125 ------- ...GT_MetaTileEntity_LongDistancePipelineItem.java | 214 ----------- .../long_distance/MTELongDistancePipelineBase.java | 412 ++++++++++++++++++++ .../MTELongDistancePipelineFluid.java | 124 ++++++ .../long_distance/MTELongDistancePipelineItem.java | 213 +++++++++++ 6 files changed, 749 insertions(+), 754 deletions(-) delete mode 100644 src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineBase.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineFluid.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineItem.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineFluid.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineItem.java (limited to 'src/main/java/gregtech/common/tileentities/machines/long_distance') diff --git a/src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineBase.java b/src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineBase.java deleted file mode 100644 index ff3048f4b2..0000000000 --- a/src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineBase.java +++ /dev/null @@ -1,415 +0,0 @@ -/** - * - * Inspired/ported from GregTech 6 under the LGPL license - * - * Copyright (c) 2020 GregTech-6 Team - * - * This file is part of GregTech. - * - * GregTech 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, either version 3 of the License, or (at your option) any later - * version. - * - * GregTech 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 GregTech. If not, see - * . - */ -package gregtech.common.tileentities.machines.long_distance; - -import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; -import static mcp.mobius.waila.api.SpecialChars.BLUE; -import static mcp.mobius.waila.api.SpecialChars.GOLD; -import static mcp.mobius.waila.api.SpecialChars.GREEN; -import static mcp.mobius.waila.api.SpecialChars.RED; -import static mcp.mobius.waila.api.SpecialChars.RESET; -import static mcp.mobius.waila.api.SpecialChars.YELLOW; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.GregTech_API; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.items.GT_Block_LongDistancePipe; -import gregtech.api.metatileentity.BaseMetaTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicHull_NonElectric; -import gregtech.api.util.GT_Utility; -import mcp.mobius.waila.api.IWailaConfigHandler; -import mcp.mobius.waila.api.IWailaDataAccessor; - -public abstract class GT_MetaTileEntity_LongDistancePipelineBase extends GT_MetaTileEntity_BasicHull_NonElectric { - - protected static final int INPUT_INDEX = 0; - protected static final int OUTPUT_INDEX = 1; - protected static final int SIDE_UP_DOWN_INDEX = 2; - protected static final int SIDE_LEFT_RIGHT_INDEX = 3; - - public static int minimalDistancePoints = 64; - - protected GT_MetaTileEntity_LongDistancePipelineBase mTarget = null; - // these two are updated by machine block update thread, so must be volatile - protected volatile GT_MetaTileEntity_LongDistancePipelineBase mSender = null; - protected volatile ChunkCoordinates mTargetPos = null; - protected GT_MetaTileEntity_LongDistancePipelineBase mTooCloseTarget = null, mTooCloseSender = null; - - public GT_MetaTileEntity_LongDistancePipelineBase(int aID, String aName, String aNameRegional, int aTier, - String aDescription) { - super(aID, aName, aNameRegional, aTier, aDescription); - } - - public GT_MetaTileEntity_LongDistancePipelineBase(String aName, int aTier, String aDescription, - ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public String[] getDescription() { - return new String[] { "Only one Input and Output are allowed per pipeline", - "Only Input and Output have to be chunkloaded", "Transfer rate is solely limited by input rate", - "Minimum distance: " + minimalDistancePoints + " blocks" }; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - if (mTargetPos != null && mTarget != this) { - aNBT.setBoolean("target", true); - aNBT.setInteger("target.x", mTargetPos.posX); - aNBT.setInteger("target.y", mTargetPos.posY); - aNBT.setInteger("target.z", mTargetPos.posZ); - } - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - if (aNBT.hasKey("target")) { - mTargetPos = new ChunkCoordinates( - aNBT.getInteger("target.x"), - aNBT.getInteger("target.y"), - aNBT.getInteger("target.z")); - if (getDistanceToSelf(mTargetPos) < minimalDistancePoints) mTargetPos = null; - } - } - - public boolean isSameClass(GT_MetaTileEntity_LongDistancePipelineBase other) { - return false; - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); - if (tCurrentItem != null) { - if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sSoftHammerList)) { - scanPipes(); - return true; - } - } - return false; - } - - public boolean isDead() { - return getBaseMetaTileEntity() == null || getBaseMetaTileEntity().isDead(); - } - - public boolean checkTarget() { - final IGregTechTileEntity gt_tile = getBaseMetaTileEntity(); - if (gt_tile == null || !gt_tile.isAllowedToWork() || gt_tile.isClientSide()) return false; - World world = gt_tile.getWorld(); - if (world == null) return false; - - if (mTargetPos == null) { - // We don't have a target position, scan the pipes - scanPipes(); - } else if (mTarget == null || mTarget.isDead()) { - // We don't have a target, or it's dead. Try checking the target position - mTarget = null; - if (world.blockExists(mTargetPos.posX, mTargetPos.posY, mTargetPos.posZ)) { - // Only check if the target position is loaded - TileEntity te = world.getTileEntity(mTargetPos.posX, mTargetPos.posY, mTargetPos.posZ); - final IMetaTileEntity tMeta; - if (te instanceof BaseMetaTileEntity - && ((tMeta = ((BaseMetaTileEntity) te) - .getMetaTileEntity()) instanceof GT_MetaTileEntity_LongDistancePipelineBase) - && isSameClass((GT_MetaTileEntity_LongDistancePipelineBase) tMeta)) { - // It's the right type! - mTarget = (GT_MetaTileEntity_LongDistancePipelineBase) tMeta; - } else if (te != null) { - // It isn't the right type, kill the target position - mTargetPos = null; - } - } - } - if (mTooCloseTarget != null && mTooCloseTarget.mSender == null) mTooCloseTarget.mTooCloseSender = this; - if (mTooCloseSender != null && (mTooCloseSender.isDead() || mTooCloseSender.mTarget != null)) - mTooCloseSender = null; - if (mTarget == null || mTarget == this) return false; - if (mTarget.mSender == null || mTarget.mSender.isDead() - || mTarget.mSender.mTarget == null - || mTarget.mSender.mTarget.isDead()) { - mTarget.mSender = this; - mTarget.mTooCloseSender = null; - } - - return mTarget.mSender == this; - } - - @Override - public ArrayList getSpecialDebugInfo(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, - int aLogLevel, ArrayList aList) { - if (mSender != null && !mSender.isDead() && mSender.mTarget == this) { - final ChunkCoordinates coords = mSender.getCoords(); - aList.addAll( - Arrays.asList( - "Is Pipeline Output", - "Pipeline Input is at: X: " + coords.posX + " Y: " + coords.posY + " Z: " + coords.posZ)); - } else { - aList.addAll( - Arrays.asList( - checkTarget() ? "Is connected to Pipeline Output" : "Pipeline Output is not connected/chunkloaded", - "Pipeline Output should be around: X: " + mTargetPos.posX - + " Y: " - + mTargetPos.posY - + " Z: " - + mTargetPos.posZ)); - } - - return aList; - } - - // What meta should the pipes for this pipeline have - public abstract int getPipeMeta(); - - protected void scanPipes() { - if (mSender != null && !mSender.isDead() && mSender.mTarget == this) return; - - // Check if we need to scan anything - final IGregTechTileEntity gtTile = getBaseMetaTileEntity(); - if (gtTile == null) return; - - final World world = gtTile.getWorld(); - if (world == null) return; - - mTargetPos = getCoords(); - mTarget = this; - mSender = null; - - // Start scanning from the output side - Block aBlock = gtTile.getBlockAtSide(gtTile.getBackFacing()); - - if (aBlock instanceof GT_Block_LongDistancePipe) { - byte aMetaData = gtTile.getMetaIDAtSide(gtTile.getBackFacing()); - if (aMetaData != getPipeMeta()) return; - - HashSet tVisited = new HashSet<>(Collections.singletonList(getCoords())), - tWires = new HashSet<>(); - Queue tQueue = new LinkedList<>( - Collections.singletonList(getFacingOffset(gtTile, gtTile.getBackFacing()))); - - while (!tQueue.isEmpty()) { - final ChunkCoordinates aCoords = tQueue.poll(); - - if (world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ) == aBlock - && world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ) == aMetaData) { - // We've got another pipe/wire block - // TODO: Make sure it's the right type of pipe/wire via meta - ChunkCoordinates tCoords; - tWires.add(aCoords); - - // For each direction, if we haven't already visited that coordinate, add it to the end of the - // queue - if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX + 1, aCoords.posY, aCoords.posZ))) - tQueue.add(tCoords); - if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX - 1, aCoords.posY, aCoords.posZ))) - tQueue.add(tCoords); - if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY + 1, aCoords.posZ))) - tQueue.add(tCoords); - if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY - 1, aCoords.posZ))) - tQueue.add(tCoords); - if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ + 1))) - tQueue.add(tCoords); - if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ - 1))) - tQueue.add(tCoords); - } else { - // It's not a block - let's see if it's a tile entity - TileEntity tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ); - if (tTileEntity != gtTile && tTileEntity instanceof BaseMetaTileEntity - && ((BaseMetaTileEntity) tTileEntity) - .getMetaTileEntity() instanceof GT_MetaTileEntity_LongDistancePipelineBase tGtTile) { - if (isSameClass(tGtTile) && tWires.contains( - tGtTile.getFacingOffset( - (BaseMetaTileEntity) tTileEntity, - ((BaseMetaTileEntity) tTileEntity).getFrontFacing()))) { - // If it's the same class, and we've scanned a wire in front of it (the input side), we've - // found our target - // still need to check if it's distant enough - int distance = getDistanceToSelf(aCoords); - if (distance > minimalDistancePoints) { - mTarget = tGtTile; - mTargetPos = tGtTile.getCoords(); - mTooCloseTarget = null; - return; - } else { - if (mTooCloseTarget == null) { - mTooCloseTarget = tGtTile; - } - } - } - - // Remove this block from the visited because we might end up back here from another wire that - // IS connected to the - // input side - tVisited.remove(aCoords); - } - } - } - } - } - - protected int getDistanceToSelf(ChunkCoordinates aCoords) { - return Math.abs(getBaseMetaTileEntity().getXCoord() - aCoords.posX) - + Math.abs(getBaseMetaTileEntity().getYCoord() - aCoords.posY) / 2 - + Math.abs(getBaseMetaTileEntity().getZCoord() - aCoords.posZ); - } - - public ChunkCoordinates getFacingOffset(IGregTechTileEntity gt_tile, ForgeDirection side) { - return new ChunkCoordinates( - gt_tile.getOffsetX(side, 1), - gt_tile.getOffsetY(side, 1), - gt_tile.getOffsetZ(side, 1)); - } - - public ChunkCoordinates getCoords() { - final IGregTechTileEntity gt_tile = getBaseMetaTileEntity(); - return new ChunkCoordinates(gt_tile.getXCoord(), gt_tile.getYCoord(), gt_tile.getZCoord()); - } - - @Override - public void onMachineBlockUpdate() { - mTargetPos = null; - mSender = null; - } - - @Override - public boolean shouldTriggerBlockUpdate() { - return true; - } - - abstract public ITexture[] getTextureOverlays(); - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - ITexture[][][] rTextures = new ITexture[4][17][]; - ITexture[] overlays = getTextureOverlays(); - for (int i = 0; i < rTextures[0].length; i++) { - rTextures[INPUT_INDEX][i] = new ITexture[] { MACHINE_CASINGS[mTier][i], overlays[INPUT_INDEX] }; - rTextures[OUTPUT_INDEX][i] = new ITexture[] { MACHINE_CASINGS[mTier][i], overlays[OUTPUT_INDEX] }; - rTextures[SIDE_UP_DOWN_INDEX][i] = new ITexture[] { MACHINE_CASINGS[mTier][i], - overlays[SIDE_UP_DOWN_INDEX] }; - rTextures[SIDE_LEFT_RIGHT_INDEX][i] = new ITexture[] { MACHINE_CASINGS[mTier][i], - overlays[SIDE_LEFT_RIGHT_INDEX] }; - } - return rTextures; - } - - @Override - public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection sideDirection, - ForgeDirection facingDirection, int colorIndex, boolean active, boolean redstoneLevel) { - colorIndex += 1; - if (sideDirection == facingDirection) return mTextures[INPUT_INDEX][colorIndex]; - else if (sideDirection == facingDirection.getOpposite()) return mTextures[OUTPUT_INDEX][colorIndex]; - else { - switch (facingDirection) { - case UP, DOWN -> { - return mTextures[SIDE_UP_DOWN_INDEX][colorIndex]; - } - case NORTH -> { - switch (sideDirection) { - case DOWN, UP -> { - return mTextures[SIDE_UP_DOWN_INDEX][colorIndex]; - } - case EAST, WEST -> { - return mTextures[SIDE_LEFT_RIGHT_INDEX][colorIndex]; - } - default -> {} - } - } - case SOUTH -> { - switch (sideDirection) { - case DOWN, UP -> { - return mTextures[SIDE_UP_DOWN_INDEX][colorIndex]; - } - case EAST, WEST -> { - return mTextures[SIDE_LEFT_RIGHT_INDEX][colorIndex]; - } - default -> {} - } - } - case EAST, WEST -> { - return mTextures[SIDE_LEFT_RIGHT_INDEX][colorIndex]; - } - default -> {} - } - } - return mTextures[INPUT_INDEX][colorIndex]; // dummy - } - - @Override - public void getWailaBody(ItemStack itemStack, List currentTip, IWailaDataAccessor accessor, - IWailaConfigHandler config) { - final ForgeDirection facing = getBaseMetaTileEntity().getFrontFacing(); - final ForgeDirection side = accessor.getSide(); - - final NBTTagCompound tag = accessor.getNBTData(); - final boolean hasInput = tag.getBoolean("hasInput"); - final boolean hasInputTooClose = tag.getBoolean("hasInputTooClose"); - final boolean hasOutput = tag.getBoolean("hasOutput"); - final boolean hasOutputTooClose = tag.getBoolean("hasOutputTooClose"); - - if (side == facing) currentTip.add(GOLD + "Pipeline Input" + RESET); - else if (side == facing.getOpposite()) currentTip.add(BLUE + "Pipeline Output" + RESET); - else currentTip.add("Pipeline Side"); - - if (!hasInput && !hasInputTooClose && !hasOutput && !hasOutputTooClose) { - currentTip.add(YELLOW + "Not connected" + RESET); - } - - if (hasInput) currentTip.add(GREEN + "Connected to " + GOLD + "Input" + RESET); - else if (hasInputTooClose) currentTip.add(RED + "Connected Input too close" + RESET); - else if (hasOutput) currentTip.add(GREEN + "Connected to " + BLUE + "Output" + RESET); - else if (hasOutputTooClose) currentTip.add(RED + "Connected Output too close" + RESET); - - super.getWailaBody(itemStack, currentTip, accessor, config); - } - - @Override - public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, - int z) { - super.getWailaNBTData(player, tile, tag, world, x, y, z); - - tag.setBoolean("hasInput", mSender != null); - tag.setBoolean("hasInputTooClose", mTooCloseSender != null); - tag.setBoolean("hasOutput", mTarget != null && mTarget != this); - tag.setBoolean("hasOutputTooClose", mTooCloseTarget != null); - } -} diff --git a/src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineFluid.java b/src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineFluid.java deleted file mode 100644 index 70e295f3ad..0000000000 --- a/src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineFluid.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * - * Inspired/ported from GregTech 6 under the LGPL license - * - * Copyright (c) 2020 GregTech-6 Team - * - * This file is part of GregTech. - * - * GregTech 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, either version 3 of the License, or (at your option) any later - * version. - * - * GregTech 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 GregTech. If not, see - * . - */ -package gregtech.common.tileentities.machines.long_distance; - -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_BACK; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_FRONT; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_SIDE_LEFT_RIGHT; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_SIDE_LEFT_RIGHT_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_SIDE_UP_DOWN; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_SIDE_UP_DOWN_GLOW; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidHandler; - -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.render.TextureFactory; - -public class GT_MetaTileEntity_LongDistancePipelineFluid extends GT_MetaTileEntity_LongDistancePipelineBase { - - static final FluidTankInfo[] emptyTank = { new FluidTankInfo(null, Integer.MAX_VALUE) }; - - public GT_MetaTileEntity_LongDistancePipelineFluid(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, "Sends fluids over long distances"); - } - - public GT_MetaTileEntity_LongDistancePipelineFluid(String aName, int aTier, String aDescription, - ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public boolean isSameClass(GT_MetaTileEntity_LongDistancePipelineBase other) { - return other instanceof GT_MetaTileEntity_LongDistancePipelineFluid; - } - - @Override - public int getPipeMeta() { - return 0; - } - - public IFluidHandler getTank() { - final IGregTechTileEntity tTile = mTarget.getBaseMetaTileEntity(); - TileEntity tankTile = tTile.getTileEntityAtSide(tTile.getBackFacing()); - if (tankTile instanceof IFluidHandler) return (IFluidHandler) tankTile; - else return null; - } - - @Override - public FluidTankInfo[] getTankInfo(ForgeDirection side) { - if (checkTarget()) { - final IFluidHandler tankTile = getTank(); - if (tankTile != null) return tankTile.getTankInfo(side); - } - - return emptyTank; - } - - @Override - public int fill(ForgeDirection side, FluidStack aFluid, boolean aDoFill) { - if (checkTarget()) { - final IGregTechTileEntity tTile = mTarget.getBaseMetaTileEntity(); - final IFluidHandler tankTile = getTank(); - if (tankTile != null) return tankTile.fill(tTile.getFrontFacing(), aFluid, aDoFill); - } - return 0; - } - - @Override - public FluidStack drain(ForgeDirection side, FluidStack aFluid, boolean aDoDrain) { - return null; - } - - @Override - public FluidStack drain(ForgeDirection side, int aMaxDrain, boolean aDoDrain) { - return null; - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_LongDistancePipelineFluid(mName, mTier, getDescription()[0], mTextures); - } - - @Override - public ITexture[] getTextureOverlays() { - ITexture[] overlays = new ITexture[4]; - overlays[INPUT_INDEX] = TextureFactory.of(OVERLAY_PIPELINE_FLUID_FRONT); - overlays[OUTPUT_INDEX] = TextureFactory.of(OVERLAY_PIPELINE_FLUID_BACK); - overlays[SIDE_UP_DOWN_INDEX] = TextureFactory.of( - TextureFactory.of(OVERLAY_PIPELINE_FLUID_SIDE_UP_DOWN), - TextureFactory.builder() - .addIcon(OVERLAY_PIPELINE_FLUID_SIDE_UP_DOWN_GLOW) - .glow() - .build()); - overlays[SIDE_LEFT_RIGHT_INDEX] = TextureFactory.of( - TextureFactory.of(OVERLAY_PIPELINE_FLUID_SIDE_LEFT_RIGHT), - TextureFactory.builder() - .addIcon(OVERLAY_PIPELINE_FLUID_SIDE_LEFT_RIGHT_GLOW) - .glow() - .build()); - - return overlays; - } -} diff --git a/src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineItem.java b/src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineItem.java deleted file mode 100644 index e1510f4d3d..0000000000 --- a/src/main/java/gregtech/common/tileentities/machines/long_distance/GT_MetaTileEntity_LongDistancePipelineItem.java +++ /dev/null @@ -1,214 +0,0 @@ -/** - * - * Inspired/ported from GregTech 6 under the LGPL license - * - * Copyright (c) 2020 GregTech-6 Team - * - * This file is part of GregTech. - * - * GregTech 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, either version 3 of the License, or (at your option) any later - * version. - * - * GregTech 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 GregTech. If not, see - * . - */ -package gregtech.common.tileentities.machines.long_distance; - -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_BACK; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_FRONT; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_SIDE_LEFT_RIGHT; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_SIDE_LEFT_RIGHT_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_SIDE_UP_DOWN; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_SIDE_UP_DOWN_GLOW; - -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - -import gregtech.api.enums.GT_Values; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.render.TextureFactory; - -public class GT_MetaTileEntity_LongDistancePipelineItem extends GT_MetaTileEntity_LongDistancePipelineBase { - - public GT_MetaTileEntity_LongDistancePipelineItem(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, "Sends Items over long distances"); - } - - public GT_MetaTileEntity_LongDistancePipelineItem(String aName, int aTier, String aDescription, - ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); - } - - @Override - public boolean isSameClass(GT_MetaTileEntity_LongDistancePipelineBase other) { - return other instanceof GT_MetaTileEntity_LongDistancePipelineItem; - } - - @Override - public int getPipeMeta() { - return 1; - } - - public IInventory getInventory() { - final IGregTechTileEntity tTile = mTarget.getBaseMetaTileEntity(); - TileEntity invTile = tTile.getTileEntityAtSide(tTile.getBackFacing()); - if (invTile instanceof IInventory) return (IInventory) invTile; - else return null; - } - - @Override - public ItemStack decrStackSize(int aSlot, int aDecrement) { - if (checkTarget()) { - IInventory iInventory = getInventory(); - if (iInventory != null) return iInventory.decrStackSize(aSlot, aDecrement); - } - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int aSlot) { - if (checkTarget()) { - IInventory iInventory = getInventory(); - if (iInventory != null) return iInventory.getStackInSlotOnClosing(aSlot); - } - return null; - } - - @Override - public ItemStack getStackInSlot(int aSlot) { - if (checkTarget()) { - IInventory iInventory = getInventory(); - if (iInventory != null) return iInventory.getStackInSlot(aSlot); - } - return null; - } - - @Override - public String getInventoryName() { - if (checkTarget()) { - IInventory iInventory = getInventory(); - if (iInventory != null) return iInventory.getInventoryName(); - } - return super.getInventoryName(); - } - - @Override - public int getSizeInventory() { - if (checkTarget()) { - IInventory iInventory = getInventory(); - if (iInventory != null) return iInventory.getSizeInventory(); - } - return 0; - } - - @Override - public int getInventoryStackLimit() { - if (checkTarget()) { - IInventory iInventory = getInventory(); - if (iInventory != null) return iInventory.getInventoryStackLimit(); - } - return 0; - } - - @Override - public void setInventorySlotContents(int aSlot, ItemStack aStack) { - if (checkTarget()) { - IInventory iInventory = getInventory(); - if (iInventory != null) iInventory.setInventorySlotContents(aSlot, aStack); - } - } - - @Override - public boolean hasCustomInventoryName() { - if (checkTarget()) { - IInventory iInventory = getInventory(); - if (iInventory != null) return iInventory.hasCustomInventoryName(); - } - return false; - } - - @Override - public boolean isItemValidForSlot(int aSlot, ItemStack aStack) { - if (checkTarget()) { - IInventory iInventory = getInventory(); - if (iInventory != null) return iInventory.isItemValidForSlot(aSlot, aStack); - } - return false; - } - - // // Relay Sided Inventories - // - - @Override - public int[] getAccessibleSlotsFromSide(int ordinalSide) { - if (checkTarget()) { - final IGregTechTileEntity tTile = mTarget.getBaseMetaTileEntity(); - final IInventory iInventory = getInventory(); - if (iInventory instanceof ISidedInventory inv) return inv.getAccessibleSlotsFromSide( - tTile.getFrontFacing() - .ordinal()); - if (iInventory != null) { - final int[] tReturn = new int[iInventory.getSizeInventory()]; - for (int i = 0; i < tReturn.length; i++) tReturn[i] = i; - return tReturn; - } - } - - return GT_Values.emptyIntArray; - } - - @Override - public boolean canInsertItem(int aSlot, ItemStack aStack, int ordinalSide) { - if (checkTarget()) { - final IGregTechTileEntity tTile = mTarget.getBaseMetaTileEntity(); - IInventory iInventory = getInventory(); - if (iInventory instanceof ISidedInventory iSidedInventory) return iSidedInventory.canInsertItem( - aSlot, - aStack, - tTile.getFrontFacing() - .ordinal()); - return iInventory != null; - } - return false; - } - - @Override - public boolean canExtractItem(int aSlot, ItemStack aStack, int ordinalSide) { - return false; - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_LongDistancePipelineItem(mName, mTier, getDescription()[0], mTextures); - } - - @Override - public ITexture[] getTextureOverlays() { - ITexture[] overlays = new ITexture[4]; - overlays[INPUT_INDEX] = TextureFactory.of(OVERLAY_PIPELINE_ITEM_FRONT); - overlays[OUTPUT_INDEX] = TextureFactory.of(OVERLAY_PIPELINE_ITEM_BACK); - overlays[SIDE_UP_DOWN_INDEX] = TextureFactory.of( - TextureFactory.of(OVERLAY_PIPELINE_ITEM_SIDE_UP_DOWN), - TextureFactory.builder() - .addIcon(OVERLAY_PIPELINE_ITEM_SIDE_UP_DOWN_GLOW) - .glow() - .build()); - overlays[SIDE_LEFT_RIGHT_INDEX] = TextureFactory.of( - TextureFactory.of(OVERLAY_PIPELINE_ITEM_SIDE_LEFT_RIGHT), - TextureFactory.builder() - .addIcon(OVERLAY_PIPELINE_ITEM_SIDE_LEFT_RIGHT_GLOW) - .glow() - .build()); - - return overlays; - } -} diff --git a/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java new file mode 100644 index 0000000000..6f6f01f3ba --- /dev/null +++ b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java @@ -0,0 +1,412 @@ +/** + * + * Inspired/ported from GregTech 6 under the LGPL license + * + * Copyright (c) 2020 GregTech-6 Team + * + * This file is part of GregTech. + * + * GregTech 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, either version 3 of the License, or (at your option) any later + * version. + * + * GregTech 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 GregTech. If not, see + * . + */ +package gregtech.common.tileentities.machines.long_distance; + +import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; +import static mcp.mobius.waila.api.SpecialChars.BLUE; +import static mcp.mobius.waila.api.SpecialChars.GOLD; +import static mcp.mobius.waila.api.SpecialChars.GREEN; +import static mcp.mobius.waila.api.SpecialChars.RED; +import static mcp.mobius.waila.api.SpecialChars.RESET; +import static mcp.mobius.waila.api.SpecialChars.YELLOW; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.GregTechAPI; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.BlockLongDistancePipe; +import gregtech.api.metatileentity.BaseMetaTileEntity; +import gregtech.api.metatileentity.implementations.MTEBasicHullNonElectric; +import gregtech.api.util.GTUtility; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +public abstract class MTELongDistancePipelineBase extends MTEBasicHullNonElectric { + + protected static final int INPUT_INDEX = 0; + protected static final int OUTPUT_INDEX = 1; + protected static final int SIDE_UP_DOWN_INDEX = 2; + protected static final int SIDE_LEFT_RIGHT_INDEX = 3; + + public static int minimalDistancePoints = 64; + + protected MTELongDistancePipelineBase mTarget = null; + // these two are updated by machine block update thread, so must be volatile + protected volatile MTELongDistancePipelineBase mSender = null; + protected volatile ChunkCoordinates mTargetPos = null; + protected MTELongDistancePipelineBase mTooCloseTarget = null, mTooCloseSender = null; + + public MTELongDistancePipelineBase(int aID, String aName, String aNameRegional, int aTier, String aDescription) { + super(aID, aName, aNameRegional, aTier, aDescription); + } + + public MTELongDistancePipelineBase(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { "Only one Input and Output are allowed per pipeline", + "Only Input and Output have to be chunkloaded", "Transfer rate is solely limited by input rate", + "Minimum distance: " + minimalDistancePoints + " blocks" }; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + if (mTargetPos != null && mTarget != this) { + aNBT.setBoolean("target", true); + aNBT.setInteger("target.x", mTargetPos.posX); + aNBT.setInteger("target.y", mTargetPos.posY); + aNBT.setInteger("target.z", mTargetPos.posZ); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("target")) { + mTargetPos = new ChunkCoordinates( + aNBT.getInteger("target.x"), + aNBT.getInteger("target.y"), + aNBT.getInteger("target.z")); + if (getDistanceToSelf(mTargetPos) < minimalDistancePoints) mTargetPos = null; + } + } + + public boolean isSameClass(MTELongDistancePipelineBase other) { + return false; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); + if (tCurrentItem != null) { + if (GTUtility.isStackInList(tCurrentItem, GregTechAPI.sSoftHammerList)) { + scanPipes(); + return true; + } + } + return false; + } + + public boolean isDead() { + return getBaseMetaTileEntity() == null || getBaseMetaTileEntity().isDead(); + } + + public boolean checkTarget() { + final IGregTechTileEntity gt_tile = getBaseMetaTileEntity(); + if (gt_tile == null || !gt_tile.isAllowedToWork() || gt_tile.isClientSide()) return false; + World world = gt_tile.getWorld(); + if (world == null) return false; + + if (mTargetPos == null) { + // We don't have a target position, scan the pipes + scanPipes(); + } else if (mTarget == null || mTarget.isDead()) { + // We don't have a target, or it's dead. Try checking the target position + mTarget = null; + if (world.blockExists(mTargetPos.posX, mTargetPos.posY, mTargetPos.posZ)) { + // Only check if the target position is loaded + TileEntity te = world.getTileEntity(mTargetPos.posX, mTargetPos.posY, mTargetPos.posZ); + final IMetaTileEntity tMeta; + if (te instanceof BaseMetaTileEntity + && ((tMeta = ((BaseMetaTileEntity) te).getMetaTileEntity()) instanceof MTELongDistancePipelineBase) + && isSameClass((MTELongDistancePipelineBase) tMeta)) { + // It's the right type! + mTarget = (MTELongDistancePipelineBase) tMeta; + } else if (te != null) { + // It isn't the right type, kill the target position + mTargetPos = null; + } + } + } + if (mTooCloseTarget != null && mTooCloseTarget.mSender == null) mTooCloseTarget.mTooCloseSender = this; + if (mTooCloseSender != null && (mTooCloseSender.isDead() || mTooCloseSender.mTarget != null)) + mTooCloseSender = null; + if (mTarget == null || mTarget == this) return false; + if (mTarget.mSender == null || mTarget.mSender.isDead() + || mTarget.mSender.mTarget == null + || mTarget.mSender.mTarget.isDead()) { + mTarget.mSender = this; + mTarget.mTooCloseSender = null; + } + + return mTarget.mSender == this; + } + + @Override + public ArrayList getSpecialDebugInfo(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, + int aLogLevel, ArrayList aList) { + if (mSender != null && !mSender.isDead() && mSender.mTarget == this) { + final ChunkCoordinates coords = mSender.getCoords(); + aList.addAll( + Arrays.asList( + "Is Pipeline Output", + "Pipeline Input is at: X: " + coords.posX + " Y: " + coords.posY + " Z: " + coords.posZ)); + } else { + aList.addAll( + Arrays.asList( + checkTarget() ? "Is connected to Pipeline Output" : "Pipeline Output is not connected/chunkloaded", + "Pipeline Output should be around: X: " + mTargetPos.posX + + " Y: " + + mTargetPos.posY + + " Z: " + + mTargetPos.posZ)); + } + + return aList; + } + + // What meta should the pipes for this pipeline have + public abstract int getPipeMeta(); + + protected void scanPipes() { + if (mSender != null && !mSender.isDead() && mSender.mTarget == this) return; + + // Check if we need to scan anything + final IGregTechTileEntity gtTile = getBaseMetaTileEntity(); + if (gtTile == null) return; + + final World world = gtTile.getWorld(); + if (world == null) return; + + mTargetPos = getCoords(); + mTarget = this; + mSender = null; + + // Start scanning from the output side + Block aBlock = gtTile.getBlockAtSide(gtTile.getBackFacing()); + + if (aBlock instanceof BlockLongDistancePipe) { + byte aMetaData = gtTile.getMetaIDAtSide(gtTile.getBackFacing()); + if (aMetaData != getPipeMeta()) return; + + HashSet tVisited = new HashSet<>(Collections.singletonList(getCoords())), + tWires = new HashSet<>(); + Queue tQueue = new LinkedList<>( + Collections.singletonList(getFacingOffset(gtTile, gtTile.getBackFacing()))); + + while (!tQueue.isEmpty()) { + final ChunkCoordinates aCoords = tQueue.poll(); + + if (world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ) == aBlock + && world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ) == aMetaData) { + // We've got another pipe/wire block + // TODO: Make sure it's the right type of pipe/wire via meta + ChunkCoordinates tCoords; + tWires.add(aCoords); + + // For each direction, if we haven't already visited that coordinate, add it to the end of the + // queue + if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX + 1, aCoords.posY, aCoords.posZ))) + tQueue.add(tCoords); + if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX - 1, aCoords.posY, aCoords.posZ))) + tQueue.add(tCoords); + if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY + 1, aCoords.posZ))) + tQueue.add(tCoords); + if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY - 1, aCoords.posZ))) + tQueue.add(tCoords); + if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ + 1))) + tQueue.add(tCoords); + if (tVisited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ - 1))) + tQueue.add(tCoords); + } else { + // It's not a block - let's see if it's a tile entity + TileEntity tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ); + if (tTileEntity != gtTile && tTileEntity instanceof BaseMetaTileEntity + && ((BaseMetaTileEntity) tTileEntity) + .getMetaTileEntity() instanceof MTELongDistancePipelineBase tGtTile) { + if (isSameClass(tGtTile) && tWires.contains( + tGtTile.getFacingOffset( + (BaseMetaTileEntity) tTileEntity, + ((BaseMetaTileEntity) tTileEntity).getFrontFacing()))) { + // If it's the same class, and we've scanned a wire in front of it (the input side), we've + // found our target + // still need to check if it's distant enough + int distance = getDistanceToSelf(aCoords); + if (distance > minimalDistancePoints) { + mTarget = tGtTile; + mTargetPos = tGtTile.getCoords(); + mTooCloseTarget = null; + return; + } else { + if (mTooCloseTarget == null) { + mTooCloseTarget = tGtTile; + } + } + } + + // Remove this block from the visited because we might end up back here from another wire that + // IS connected to the + // input side + tVisited.remove(aCoords); + } + } + } + } + } + + protected int getDistanceToSelf(ChunkCoordinates aCoords) { + return Math.abs(getBaseMetaTileEntity().getXCoord() - aCoords.posX) + + Math.abs(getBaseMetaTileEntity().getYCoord() - aCoords.posY) / 2 + + Math.abs(getBaseMetaTileEntity().getZCoord() - aCoords.posZ); + } + + public ChunkCoordinates getFacingOffset(IGregTechTileEntity gt_tile, ForgeDirection side) { + return new ChunkCoordinates( + gt_tile.getOffsetX(side, 1), + gt_tile.getOffsetY(side, 1), + gt_tile.getOffsetZ(side, 1)); + } + + public ChunkCoordinates getCoords() { + final IGregTechTileEntity gt_tile = getBaseMetaTileEntity(); + return new ChunkCoordinates(gt_tile.getXCoord(), gt_tile.getYCoord(), gt_tile.getZCoord()); + } + + @Override + public void onMachineBlockUpdate() { + mTargetPos = null; + mSender = null; + } + + @Override + public boolean shouldTriggerBlockUpdate() { + return true; + } + + abstract public ITexture[] getTextureOverlays(); + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[4][17][]; + ITexture[] overlays = getTextureOverlays(); + for (int i = 0; i < rTextures[0].length; i++) { + rTextures[INPUT_INDEX][i] = new ITexture[] { MACHINE_CASINGS[mTier][i], overlays[INPUT_INDEX] }; + rTextures[OUTPUT_INDEX][i] = new ITexture[] { MACHINE_CASINGS[mTier][i], overlays[OUTPUT_INDEX] }; + rTextures[SIDE_UP_DOWN_INDEX][i] = new ITexture[] { MACHINE_CASINGS[mTier][i], + overlays[SIDE_UP_DOWN_INDEX] }; + rTextures[SIDE_LEFT_RIGHT_INDEX][i] = new ITexture[] { MACHINE_CASINGS[mTier][i], + overlays[SIDE_LEFT_RIGHT_INDEX] }; + } + return rTextures; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection sideDirection, + ForgeDirection facingDirection, int colorIndex, boolean active, boolean redstoneLevel) { + colorIndex += 1; + if (sideDirection == facingDirection) return mTextures[INPUT_INDEX][colorIndex]; + else if (sideDirection == facingDirection.getOpposite()) return mTextures[OUTPUT_INDEX][colorIndex]; + else { + switch (facingDirection) { + case UP, DOWN -> { + return mTextures[SIDE_UP_DOWN_INDEX][colorIndex]; + } + case NORTH -> { + switch (sideDirection) { + case DOWN, UP -> { + return mTextures[SIDE_UP_DOWN_INDEX][colorIndex]; + } + case EAST, WEST -> { + return mTextures[SIDE_LEFT_RIGHT_INDEX][colorIndex]; + } + default -> {} + } + } + case SOUTH -> { + switch (sideDirection) { + case DOWN, UP -> { + return mTextures[SIDE_UP_DOWN_INDEX][colorIndex]; + } + case EAST, WEST -> { + return mTextures[SIDE_LEFT_RIGHT_INDEX][colorIndex]; + } + default -> {} + } + } + case EAST, WEST -> { + return mTextures[SIDE_LEFT_RIGHT_INDEX][colorIndex]; + } + default -> {} + } + } + return mTextures[INPUT_INDEX][colorIndex]; // dummy + } + + @Override + public void getWailaBody(ItemStack itemStack, List currentTip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + final ForgeDirection facing = getBaseMetaTileEntity().getFrontFacing(); + final ForgeDirection side = accessor.getSide(); + + final NBTTagCompound tag = accessor.getNBTData(); + final boolean hasInput = tag.getBoolean("hasInput"); + final boolean hasInputTooClose = tag.getBoolean("hasInputTooClose"); + final boolean hasOutput = tag.getBoolean("hasOutput"); + final boolean hasOutputTooClose = tag.getBoolean("hasOutputTooClose"); + + if (side == facing) currentTip.add(GOLD + "Pipeline Input" + RESET); + else if (side == facing.getOpposite()) currentTip.add(BLUE + "Pipeline Output" + RESET); + else currentTip.add("Pipeline Side"); + + if (!hasInput && !hasInputTooClose && !hasOutput && !hasOutputTooClose) { + currentTip.add(YELLOW + "Not connected" + RESET); + } + + if (hasInput) currentTip.add(GREEN + "Connected to " + GOLD + "Input" + RESET); + else if (hasInputTooClose) currentTip.add(RED + "Connected Input too close" + RESET); + else if (hasOutput) currentTip.add(GREEN + "Connected to " + BLUE + "Output" + RESET); + else if (hasOutputTooClose) currentTip.add(RED + "Connected Output too close" + RESET); + + super.getWailaBody(itemStack, currentTip, accessor, config); + } + + @Override + public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, + int z) { + super.getWailaNBTData(player, tile, tag, world, x, y, z); + + tag.setBoolean("hasInput", mSender != null); + tag.setBoolean("hasInputTooClose", mTooCloseSender != null); + tag.setBoolean("hasOutput", mTarget != null && mTarget != this); + tag.setBoolean("hasOutputTooClose", mTooCloseTarget != null); + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineFluid.java b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineFluid.java new file mode 100644 index 0000000000..e3886360c6 --- /dev/null +++ b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineFluid.java @@ -0,0 +1,124 @@ +/** + * + * Inspired/ported from GregTech 6 under the LGPL license + * + * Copyright (c) 2020 GregTech-6 Team + * + * This file is part of GregTech. + * + * GregTech 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, either version 3 of the License, or (at your option) any later + * version. + * + * GregTech 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 GregTech. If not, see + * . + */ +package gregtech.common.tileentities.machines.long_distance; + +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_BACK; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_FRONT; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_SIDE_LEFT_RIGHT; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_SIDE_LEFT_RIGHT_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_SIDE_UP_DOWN; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_FLUID_SIDE_UP_DOWN_GLOW; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.render.TextureFactory; + +public class MTELongDistancePipelineFluid extends MTELongDistancePipelineBase { + + static final FluidTankInfo[] emptyTank = { new FluidTankInfo(null, Integer.MAX_VALUE) }; + + public MTELongDistancePipelineFluid(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, "Sends fluids over long distances"); + } + + public MTELongDistancePipelineFluid(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public boolean isSameClass(MTELongDistancePipelineBase other) { + return other instanceof MTELongDistancePipelineFluid; + } + + @Override + public int getPipeMeta() { + return 0; + } + + public IFluidHandler getTank() { + final IGregTechTileEntity tTile = mTarget.getBaseMetaTileEntity(); + TileEntity tankTile = tTile.getTileEntityAtSide(tTile.getBackFacing()); + if (tankTile instanceof IFluidHandler) return (IFluidHandler) tankTile; + else return null; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection side) { + if (checkTarget()) { + final IFluidHandler tankTile = getTank(); + if (tankTile != null) return tankTile.getTankInfo(side); + } + + return emptyTank; + } + + @Override + public int fill(ForgeDirection side, FluidStack aFluid, boolean aDoFill) { + if (checkTarget()) { + final IGregTechTileEntity tTile = mTarget.getBaseMetaTileEntity(); + final IFluidHandler tankTile = getTank(); + if (tankTile != null) return tankTile.fill(tTile.getFrontFacing(), aFluid, aDoFill); + } + return 0; + } + + @Override + public FluidStack drain(ForgeDirection side, FluidStack aFluid, boolean aDoDrain) { + return null; + } + + @Override + public FluidStack drain(ForgeDirection side, int aMaxDrain, boolean aDoDrain) { + return null; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTELongDistancePipelineFluid(mName, mTier, getDescription()[0], mTextures); + } + + @Override + public ITexture[] getTextureOverlays() { + ITexture[] overlays = new ITexture[4]; + overlays[INPUT_INDEX] = TextureFactory.of(OVERLAY_PIPELINE_FLUID_FRONT); + overlays[OUTPUT_INDEX] = TextureFactory.of(OVERLAY_PIPELINE_FLUID_BACK); + overlays[SIDE_UP_DOWN_INDEX] = TextureFactory.of( + TextureFactory.of(OVERLAY_PIPELINE_FLUID_SIDE_UP_DOWN), + TextureFactory.builder() + .addIcon(OVERLAY_PIPELINE_FLUID_SIDE_UP_DOWN_GLOW) + .glow() + .build()); + overlays[SIDE_LEFT_RIGHT_INDEX] = TextureFactory.of( + TextureFactory.of(OVERLAY_PIPELINE_FLUID_SIDE_LEFT_RIGHT), + TextureFactory.builder() + .addIcon(OVERLAY_PIPELINE_FLUID_SIDE_LEFT_RIGHT_GLOW) + .glow() + .build()); + + return overlays; + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineItem.java b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineItem.java new file mode 100644 index 0000000000..f619d40329 --- /dev/null +++ b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineItem.java @@ -0,0 +1,213 @@ +/** + * + * Inspired/ported from GregTech 6 under the LGPL license + * + * Copyright (c) 2020 GregTech-6 Team + * + * This file is part of GregTech. + * + * GregTech 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, either version 3 of the License, or (at your option) any later + * version. + * + * GregTech 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 GregTech. If not, see + * . + */ +package gregtech.common.tileentities.machines.long_distance; + +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_BACK; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_FRONT; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_SIDE_LEFT_RIGHT; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_SIDE_LEFT_RIGHT_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_SIDE_UP_DOWN; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPELINE_ITEM_SIDE_UP_DOWN_GLOW; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import gregtech.api.enums.GTValues; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.render.TextureFactory; + +public class MTELongDistancePipelineItem extends MTELongDistancePipelineBase { + + public MTELongDistancePipelineItem(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, "Sends Items over long distances"); + } + + public MTELongDistancePipelineItem(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public boolean isSameClass(MTELongDistancePipelineBase other) { + return other instanceof MTELongDistancePipelineItem; + } + + @Override + public int getPipeMeta() { + return 1; + } + + public IInventory getInventory() { + final IGregTechTileEntity tTile = mTarget.getBaseMetaTileEntity(); + TileEntity invTile = tTile.getTileEntityAtSide(tTile.getBackFacing()); + if (invTile instanceof IInventory) return (IInventory) invTile; + else return null; + } + + @Override + public ItemStack decrStackSize(int aSlot, int aDecrement) { + if (checkTarget()) { + IInventory iInventory = getInventory(); + if (iInventory != null) return iInventory.decrStackSize(aSlot, aDecrement); + } + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(int aSlot) { + if (checkTarget()) { + IInventory iInventory = getInventory(); + if (iInventory != null) return iInventory.getStackInSlotOnClosing(aSlot); + } + return null; + } + + @Override + public ItemStack getStackInSlot(int aSlot) { + if (checkTarget()) { + IInventory iInventory = getInventory(); + if (iInventory != null) return iInventory.getStackInSlot(aSlot