diff options
Diffstat (limited to 'src/main/java/gregtech/api/interfaces/tileentity')
31 files changed, 1632 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IAllSidedTexturedTileEntity.java b/src/main/java/gregtech/api/interfaces/tileentity/IAllSidedTexturedTileEntity.java new file mode 100644 index 0000000000..1d00aa5d76 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IAllSidedTexturedTileEntity.java @@ -0,0 +1,24 @@ +package gregtech.api.interfaces.tileentity; + +import net.minecraft.block.Block; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.ITexture; + +/** + * Block which has same texture on all sides + */ +public interface IAllSidedTexturedTileEntity extends ITexturedTileEntity { + + /** + * @return the Textures rendered by the GT Rendering + */ + default ITexture[] getTexture(Block aBlock, ForgeDirection side) { + return getTexture(aBlock); + } + + /** + * @return the Textures rendered by the GT Rendering + */ + ITexture[] getTexture(Block aBlock); +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IBasicEnergyContainer.java b/src/main/java/gregtech/api/interfaces/tileentity/IBasicEnergyContainer.java new file mode 100644 index 0000000000..37d62894bb --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IBasicEnergyContainer.java @@ -0,0 +1,110 @@ +package gregtech.api.interfaces.tileentity; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Interface for internal Code, which is mainly used for independent Energy conversion. + */ +public interface IBasicEnergyContainer extends IEnergyConnected, IHasWorldObjectAndCoords { + + /** + * Gets if that Amount of Energy is stored inside the Machine. It is used for checking the contained Energy before + * consuming it. If this returns false, it will also give a Message inside the Scanner, that this Machine doesn't + * have enough Energy. + */ + boolean isUniversalEnergyStored(long aEnergyAmount); + + /** + * Gets the stored electric, kinetic or steam Energy (with EU as reference Value) Always returns the largest one. + */ + long getUniversalEnergyStored(); + + /** + * Gets the largest electric, kinetic or steam Energy Capacity (with EU as reference Value) + */ + long getUniversalEnergyCapacity(); + + /** + * Gets the amount of Energy Packets per tick. + */ + long getOutputAmperage(); + + /** + * Gets the Output in EU/p. + */ + long getOutputVoltage(); + + /** + * Gets the amount of Energy Packets per tick. + */ + long getInputAmperage(); + + /** + * Gets the maximum Input in EU/p. + */ + long getInputVoltage(); + + /** + * Decreases the Amount of stored universal Energy. If ignoring too less Energy, then it just sets the Energy to 0 + * and returns false. + */ + boolean decreaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooLessEnergy); + + /** + * Increases the Amount of stored electric Energy. If ignoring too much Energy, then the Energy Limit is just being + * ignored. + */ + boolean increaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooMuchEnergy); + + /** + * Drain Energy Call for Electricity. + */ + boolean drainEnergyUnits(ForgeDirection side, long aVoltage, long aAmperage); + + /** + * returns the amount of Electricity, accepted by this Block the last 5 ticks as Average. + */ + long getAverageElectricInput(); + + /** + * returns the amount of Electricity, outputted by this Block the last 5 ticks as Average. + */ + long getAverageElectricOutput(); + + /** + * returns the amount of electricity contained in this Block, in EU units! + */ + long getStoredEU(); + + /** + * returns the amount of electricity containable in this Block, in EU units! + */ + long getEUCapacity(); + + /** + * returns the amount of Steam contained in this Block, in EU units! + */ + default long getStoredSteam() { + return 0; + } + + /** + * returns the amount of Steam containable in this Block, in EU units! + */ + default long getSteamCapacity() { + return 0; + } + + /** + * Increases stored Energy. Energy Base Value is in EU, even though it's Steam! + * + * @param aEnergy The Energy to add to the Machine. + * @param aIgnoreTooMuchEnergy if it shall ignore if it has too much Energy. + * @return if it was successful + * <p/> + * And yes, you can't directly decrease the Steam of a Machine. That is done by decreaseStoredEnergyUnits + */ + default boolean increaseStoredSteam(long aEnergy, boolean aIgnoreTooMuchEnergy) { + return false; + } +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IColoredTileEntity.java b/src/main/java/gregtech/api/interfaces/tileentity/IColoredTileEntity.java new file mode 100644 index 0000000000..ec760dd346 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IColoredTileEntity.java @@ -0,0 +1,27 @@ +package gregtech.api.interfaces.tileentity; + +import gregtech.api.enums.Dyes; +import gregtech.api.util.GT_Util; + +public interface IColoredTileEntity { + + /** + * @return 0 - 15 are Colors, while -1 means uncolored + */ + byte getColorization(); + + /** + * Sets the Color Modulation of the Block + * + * @param aColor the Color you want to set it to. -1 for reset. + */ + byte setColorization(byte aColor); + + /** + * @return Actual color shown on GUI + */ + default int getGUIColorization() { + return GT_Util + .getRGBInt((getColorization() != -1 ? Dyes.get(getColorization()) : Dyes.MACHINE_METAL).getRGBA()); + } +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java b/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java new file mode 100644 index 0000000000..8834678984 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java @@ -0,0 +1,91 @@ +package gregtech.api.interfaces.tileentity; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_CoverBehaviorBase; +import gregtech.api.util.ISerializableObject; +import gregtech.common.covers.CoverInfo; + +public interface ICoverable extends IRedstoneTileEntity, IHasInventory, IBasicEnergyContainer { + + boolean canPlaceCoverIDAtSide(ForgeDirection side, int aID); + + boolean canPlaceCoverItemAtSide(ForgeDirection side, ItemStack aCover); + + boolean dropCover(ForgeDirection side, ForgeDirection droppedSide, boolean aForced); + + @Deprecated + void setCoverDataAtSide(ForgeDirection side, int aData); + + default void setCoverDataAtSide(ForgeDirection side, ISerializableObject aData) { + if (aData instanceof ISerializableObject.LegacyCoverData) + setCoverDataAtSide(side, ((ISerializableObject.LegacyCoverData) aData).get()); + } + + void setCoverIdAndDataAtSide(ForgeDirection side, int aId, ISerializableObject aData); + + void setCoverIDAtSide(ForgeDirection side, int aID); + + boolean setCoverIDAtSideNoUpdate(ForgeDirection side, int aID); + + void setCoverItemAtSide(ForgeDirection side, ItemStack aCover); + + @Deprecated + int getCoverDataAtSide(ForgeDirection side); + + default CoverInfo getCoverInfoAtSide(ForgeDirection side) { + return null; + } + + default ISerializableObject getComplexCoverDataAtSide(ForgeDirection side) { + return new ISerializableObject.LegacyCoverData(getCoverDataAtSide(side)); + } + + int getCoverIDAtSide(ForgeDirection side); + + ItemStack getCoverItemAtSide(ForgeDirection side); + + @Deprecated + GT_CoverBehavior getCoverBehaviorAtSide(ForgeDirection side); + + default GT_CoverBehaviorBase<?> getCoverBehaviorAtSideNew(ForgeDirection side) { + return getCoverBehaviorAtSide(side); + } + + /** + * For use by the regular MetaTileEntities. Returns the Cover Manipulated input Redstone. Don't use this if you are + * a Cover Behavior. Only for MetaTileEntities. + */ + byte getInternalInputRedstoneSignal(ForgeDirection side); + + /** + * For use by the regular MetaTileEntities. This makes it not conflict with Cover based Redstone Signals. Don't use + * this if you are a Cover Behavior. Only for MetaTileEntities. + */ + void setInternalOutputRedstoneSignal(ForgeDirection side, byte aStrength); + + /** + * Causes a general Cover Texture update. Sends 6 Integers to Client + causes @issueTextureUpdate() + */ + void issueCoverUpdate(ForgeDirection side); + + /** + * Receiving a packet with cover data. + */ + void receiveCoverData(ForgeDirection coverSide, int coverID, int coverData); + + /** + * Receiving a packet with cover data. + * + * @param coverSide cover side + * @param aPlayer the player who made the change + */ + default void receiveCoverData(ForgeDirection coverSide, int aCoverID, ISerializableObject aCoverData, + EntityPlayerMP aPlayer) { + if (aCoverData instanceof ISerializableObject.LegacyCoverData) + receiveCoverData(coverSide, aCoverID, ((ISerializableObject.LegacyCoverData) aCoverData).get()); + } +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IDebugableTileEntity.java b/src/main/java/gregtech/api/interfaces/tileentity/IDebugableTileEntity.java new file mode 100644 index 0000000000..5208944d66 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IDebugableTileEntity.java @@ -0,0 +1,18 @@ +package gregtech.api.interfaces.tileentity; + +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; + +public interface IDebugableTileEntity { + + /** + * Returns a Debug Message, for a generic DebugItem + * + * @param aPlayer the Player, who rightclicked with his Debug Item + * @param aLogLevel the Log Level of the Debug Item. 0 = Obvious 1 = Visible for the regular Scanner 2 = Only + * visible to more advanced Scanners 3 = Debug ONLY + * @return a String-Array containing the DebugInfo, every Index is a separate line (0 = first Line) + */ + ArrayList<String> getDebugInfo(EntityPlayer aPlayer, int aLogLevel); +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IDigitalChest.java b/src/main/java/gregtech/api/interfaces/tileentity/IDigitalChest.java new file mode 100644 index 0000000000..9a08e65b78 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IDigitalChest.java @@ -0,0 +1,33 @@ +package gregtech.api.interfaces.tileentity; + +import net.minecraft.item.ItemStack; + +/** + * You are allowed to include this File in your Download, as i will not change it. + */ +public interface IDigitalChest extends IHasWorldObjectAndCoords { + + /** + * Is this even a TileEntity of a Digital Chest? I need things like this Function for MetaTileEntities, you MUST + * check this!!! Do not assume that it's a Digital Chest or similar Device, when it just implements this Interface. + */ + boolean isDigitalChest(); + + /** + * Gives an Array of Stacks with Size (of all the Data-stored Items) of the correspondent Item kinds (regular + * QChests have only one) Does NOT include the 64 "ready" Items inside the Slots, and neither the 128 Items in the + * overflow Buffer. + */ + ItemStack[] getStoredItemData(); + + /** + * A generic Interface for just setting the amount of contained Items + */ + void setItemCount(int aCount); + + /** + * Gets the maximum Item count for this QChest alike Storage. This applies to the Data-Storage, not for the up to + * 192 buffered Items! + */ + int getMaxItemCount(); +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConductor.java b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConductor.java new file mode 100644 index 0000000000..e285c6f0e3 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConductor.java @@ -0,0 +1,41 @@ +package gregtech.api.interfaces.tileentity; + +import gregtech.api.enums.Materials; + +/** + * Informative Class for Cables. Not used for now. + * <p/> + * Not all Data might be reliable. This is just for Information sake. + */ +public interface IEnergyConductor extends IEnergyConnected, IHasWorldObjectAndCoords { + + /** + * @return if this is actually a Cable. (you must check this) + */ + boolean isConductor(); + + /** + * @return the maximum Voltage of the Cable. + */ + long getMaxVoltage(); + + /** + * @return the maximum Amperage of the Cable, per Wire. + */ + long getMaxAmperage(); + + /** + * @return the Loss of the Cable, per Meter. + */ + long getLossPerMeter(); + + /** + * @return the Material the Cable consists of. (may return Materials._NULL) + */ + Materials getCableMaterial(); + + /** + * @return the Material the Cable Insulation consists of. (may return Materials._NULL) + */ + Materials getInsulationMaterial(); +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java new file mode 100644 index 0000000000..91a9759e47 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java @@ -0,0 +1,178 @@ +package gregtech.api.interfaces.tileentity; + +import java.util.Objects; + +import javax.annotation.Nonnull; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +import cofh.api.energy.IEnergyReceiver; +import gregtech.api.GregTech_API; +import gregtech.api.logic.PowerLogic; +import gregtech.api.logic.interfaces.PowerLogicHost; +import gregtech.api.util.GT_Utility; +import ic2.api.energy.tile.IEnergySink; + +/** + * Interface for getting Connected to the GregTech Energy Network. + * <p/> + * This is all you need to connect to the GT Network. IColoredTileEntity is needed for not connecting differently + * coloured Blocks to each other. IHasWorldObjectAndCoords is needed for the InWorld related Stuff. @BaseTileEntity does + * implement most of that Interface. + */ +public interface IEnergyConnected extends IColoredTileEntity { + + /** + * Inject Energy Call for Electricity. Gets called by EnergyEmitters to inject Energy into your Block + * <p/> + * Note: you have to check for @inputEnergyFrom because the Network won't check for that by itself. + * + * @param side 0 - 5 = Vanilla Directions of YOUR Block the Energy gets inserted to. 6 = No specific Side (don't do + * Side checks for this Side) + * @return amount of used Amperes. 0 if not accepted anything. + */ + long injectEnergyUnits(ForgeDirection side, long aVoltage, long aAmperage); + + /** + * Sided Energy Input + */ + boolean inputEnergyFrom(ForgeDirection side); + + default boolean inputEnergyFrom(ForgeDirection side, boolean waitForActive) { + return inputEnergyFrom(side); + } + + /** + * Sided Energy Output + */ + boolean outputsEnergyTo(ForgeDirection side); + + default boolean outputsEnergyTo(ForgeDirection side, boolean waitForActive) { + return outputsEnergyTo(side); + } + + /** + * Utility for the Network + */ + final class Util { + + // TODO: Deduplicate code by rewokring the Enet system using the GTCEu one as inspiration - BlueWeabo + /** + * Emits Energy to the E-net. Also compatible with adjacent IC2 TileEntities. + * + * @return the used Amperage. + */ + public static long emitEnergyToNetwork(long voltage, long amperage, IEnergyConnected emitter) { + long usedAmperes = 0; + if (!(emitter instanceof IHasWorldObjectAndCoords emitterTile)) { + return 0; + } + + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + if (usedAmperes > amperage) break; + if (!emitter.outputsEnergyTo(side)) { + continue; + } + + final ForgeDirection oppositeSide = Objects.requireNonNull(side.getOpposite()); + final TileEntity tTileEntity = emitterTile.getTileEntityAtSide(side); + if (tTileEntity instanceof PowerLogicHost host) { + + final PowerLogic logic = host.getPowerLogic(oppositeSide); + if (logic == null || logic.isEnergyReceiver()) { + continue; + } + + usedAmperes += logic.injectEnergy(voltage, amperage - usedAmperes); + } else if (tTileEntity instanceof IEnergyConnected energyConnected) { + if (emitter.getColorization() >= 0) { + final byte tColor = energyConnected.getColorization(); + if (tColor >= 0 && tColor != emitter.getColorization()) continue; + } + usedAmperes += energyConnected.injectEnergyUnits(oppositeSide, voltage, amperage - usedAmperes); + + } else if (tTileEntity instanceof IEnergySink sink) { + if (sink.acceptsEnergyFrom((TileEntity) emitter, oppositeSide)) { + while (amperage > usedAmperes && sink.getDemandedEnergy() > 0 + && sink.injectEnergy(oppositeSide, voltage, voltage) < voltage) usedAmperes++; + } + } else if (GregTech_API.mOutputRF && tTileEntity instanceof IEnergyReceiver receiver) { + final int rfOut = GT_Utility.safeInt(voltage * GregTech_API.mEUtoRF / 100); + if (receiver.receiveEnergy(oppositeSide, rfOut, true) == rfOut) { + receiver.receiveEnergy(oppositeSide, rfOut, false); + usedAmperes++; + } + } + } + return usedAmperes; + } + + /** + * Same as {@link #emitEnergyToNetwork(long, long, IEnergyConnected)}, but instead we remove the energy directly from the logic itself. + * @param emitter The host, which is trying to emit energy in the network + * @param outputSide side from where energy is being outputted to. If its {@link ForgeDirection#UNKNOWN} then it doesn't emit energy to the network + */ + public static void emitEnergyToNetwork(@Nonnull final PowerLogicHost emitter, @Nonnull final ForgeDirection outputSide) { + if (outputSide == ForgeDirection.UNKNOWN) return; + final PowerLogic emitterLogic = emitter.getPowerLogic(); + long usedAmperes = 0; + long voltage = emitterLogic.getVoltage(); + long amperage = emitterLogic.getMaxAmperage(); + if (!(emitter instanceof final IHasWorldObjectAndCoords emitterTile)) { + return; + } + // We need to make sure we can actually output energy on this side. This is more of a safety check. + if (emitter.getPowerLogic(outputSide) == null) { + return; + } + + final ForgeDirection oppositeSide = Objects.requireNonNull(outputSide.getOpposite()); + final TileEntity tileEntity = emitterTile.getTileEntityAtSide(outputSide); + if (tileEntity instanceof PowerLogicHost host) { + + final PowerLogic logic = host.getPowerLogic(oppositeSide); + if (logic == null || logic.isEnergyReceiver()) { + return; + } + + usedAmperes += logic.injectEnergy(voltage, amperage); + emitterLogic.removeEnergyUnsafe(usedAmperes * voltage); + return; + } + + if (tileEntity instanceof IEnergyConnected energyConnected) { + if (emitter instanceof IColoredTileEntity coloredEmitter && coloredEmitter.getColorization() >= 0) { + final byte tColor = energyConnected.getColorization(); + if (tColor >= 0 && tColor != coloredEmitter.getColorization()) { + return; + } + } + usedAmperes += energyConnected.injectEnergyUnits(oppositeSide, voltage, amperage - usedAmperes); + emitterLogic.removeEnergyUnsafe(usedAmperes * voltage); + return; + } + + if (tileEntity instanceof IEnergySink sink) { + if (sink.acceptsEnergyFrom((TileEntity) emitter, oppositeSide)) { + while (amperage > usedAmperes && sink.getDemandedEnergy() > 0 + && sink.injectEnergy(oppositeSide, voltage, voltage) < voltage) { + usedAmperes++; + } + emitterLogic.removeEnergyUnsafe(usedAmperes * voltage); + return; + } + } + + if (GregTech_API.mOutputRF && tileEntity instanceof IEnergyReceiver receiver) { + final int rfOut = GT_Utility.safeInt(voltage * GregTech_API.mEUtoRF / 100); + if (receiver.receiveEnergy(oppositeSide, rfOut, true) == rfOut) { + receiver.receiveEnergy(oppositeSide, rfOut, false); + usedAmperes++; + emitterLogic.removeEnergyUnsafe(usedAmperes * voltage); + return; + } + } + } + } +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IFibreConnected.java b/src/main/java/gregtech/api/interfaces/tileentity/IFibreConnected.java new file mode 100644 index 0000000000..2f7f26e723 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IFibreConnected.java @@ -0,0 +1,34 @@ +package gregtech.api.interfaces.tileentity; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * This File has just internal Information about the Fibre Redstone State of a TileEntity + */ +public interface IFibreConnected extends IColoredTileEntity, IHasWorldObjectAndCoords { + + /** + * If this Blocks accepts Fibre from this Side + */ + void inputFibreFrom(ForgeDirection side); + + /** + * If this Blocks emits Fibre to this Side + */ + void outputsFibreTo(ForgeDirection side); + + /** + * Sets the Signal this Blocks outputs to this Fibre Color + */ + void setFibreOutput(ForgeDirection side, byte aColor, byte aRedstoneStrength); + + /** + * Gets the Signal this Blocks outputs to this Fibre Color + */ + byte getFibreOutput(ForgeDirection side, byte aColor); + + /** + * Gets the Signal this Blocks receives from this Fibre Color + */ + byte getFibreInput(ForgeDirection side, byte aColor); +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IGTEnet.java b/src/main/java/gregtech/api/interfaces/tileentity/IGTEnet.java new file mode 100644 index 0000000000..77b894fea7 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IGTEnet.java @@ -0,0 +1,19 @@ +package gregtech.api.interfaces.tileentity; + +public interface IGTEnet { + + /** + * @return true if this Device consumes Energy at all + */ + default boolean isEnetInput() { + return false; + } + + /** + * + * @return true if this Device emits Energy at all + */ + default boolean isEnetOutput() { + return false; + } +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IGearEnergyTileEntity.java b/src/main/java/gregtech/api/interfaces/tileentity/IGearEnergyTileEntity.java new file mode 100644 index 0000000000..7eeee90c8c --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IGearEnergyTileEntity.java @@ -0,0 +1,21 @@ +package gregtech.api.interfaces.tileentity; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IGearEnergyTileEntity { + + /** + * If Rotation Energy can be accepted on this Side. This means that the Gear/Axle will connect to this Side, and can + * cause the Gear/Axle to stop if the Energy isn't accepted. + */ + boolean acceptsRotationalEnergy(ForgeDirection side); + + /** + * Inject Energy Call for Rotational Energy. Rotation Energy can't be stored, this is just for things like internal + * Dynamos, which convert it into Energy, or into Progress. + * + * @param side inject to this side + * @param aSpeed Positive = Clockwise, Negative = Counterclockwise + */ + boolean injectRotationalEnergy(ForgeDirection side, long aSpeed, long aEnergy); +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IGregTechDeviceInformation.java b/src/main/java/gregtech/api/interfaces/tileentity/IGregTechDeviceInformation.java new file mode 100644 index 0000000000..001ed44825 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/tileentity/IGregTechDeviceInformation.java @@ -0,0 +1,22 @@ +package gregtech.api.interfaces.tileentity; + +/** + * You are allowed to include this File in your Download, as i will not change |
