diff options
Diffstat (limited to 'src/main/java/gregtech/api/logic/interfaces')
5 files changed, 419 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/logic/interfaces/FluidInventoryLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/FluidInventoryLogicHost.java new file mode 100644 index 0000000000..c12333a4c6 --- /dev/null +++ b/src/main/java/gregtech/api/logic/interfaces/FluidInventoryLogicHost.java @@ -0,0 +1,95 @@ +package gregtech.api.logic.interfaces; + +import static com.google.common.primitives.Ints.saturatedCast; + +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +import gregtech.api.enums.InventoryType; +import gregtech.api.logic.FluidInventoryLogic; + +public interface FluidInventoryLogicHost extends IFluidHandler { + + /** + * To be used for single blocks or when directly interacting with the controller + * + * @param side The side from where fluids are being inputted or extracted from + * @param type The type of inventory being accessed. For inputting its Input, For outputting its Output. + * @return The Fluid Logic responsible for said type. Can return null if the side is invalid + */ + @Nullable + FluidInventoryLogic getFluidLogic(@Nonnull ForgeDirection side, @Nonnull InventoryType type); + + /** + * Only to be used by MultiBlockPart for accessing the Controller Inventory + * + * @param type Type of inventory, is it Input or Output + * @param id ID of the locked inventory. A null id is all inventories of said controller of said type + * @return The Fluid Logic responsible for everything that should be done with said inventory + */ + @Nonnull + default FluidInventoryLogic getFluidLogic(@Nonnull InventoryType type, @Nullable UUID id) { + return Objects.requireNonNull(getFluidLogic(ForgeDirection.UNKNOWN, type)); + } + + /** + * Returns an empty set if the type is {@link InventoryType#Both} or when the machine isn't a controller. + */ + @Nonnull + default Set<Entry<UUID, FluidInventoryLogic>> getAllFluidInventoryLogics(@Nonnull InventoryType type) { + return new HashSet<>(); + } + + @Override + default boolean canDrain(@Nonnull ForgeDirection from, Fluid fluid) { + FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Output); + return logic != null; + } + + @Override + default boolean canFill(@Nonnull ForgeDirection from, Fluid fluid) { + FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Input); + return logic != null; + } + + @Override + @Nullable + default FluidStack drain(@Nonnull ForgeDirection from, @Nonnull FluidStack resource, boolean doDrain) { + FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Output); + if (logic == null) return null; + return logic.drain(resource.getFluid(), resource.amount, !doDrain); + } + + @Override + @Nullable + default FluidStack drain(@Nonnull ForgeDirection from, int maxDrain, boolean doDrain) { + FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Output); + if (logic == null) return null; + return logic.drain(maxDrain, !doDrain); + } + + @Override + default int fill(@Nonnull ForgeDirection from, @Nonnull FluidStack resource, boolean doFill) { + FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Input); + if (logic == null) return 0; + return saturatedCast(logic.fill(resource.getFluid(), resource.amount, !doFill)); + } + + @Override + @Nullable + default FluidTankInfo[] getTankInfo(@Nonnull ForgeDirection from) { + return null; + } +} diff --git a/src/main/java/gregtech/api/logic/interfaces/ItemInventoryLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/ItemInventoryLogicHost.java new file mode 100644 index 0000000000..a65f3c50f1 --- /dev/null +++ b/src/main/java/gregtech/api/logic/interfaces/ItemInventoryLogicHost.java @@ -0,0 +1,172 @@ +package gregtech.api.logic.interfaces; + +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.InventoryType; +import gregtech.api.logic.ItemInventoryLogic; + +public interface ItemInventoryLogicHost extends ISidedInventory { + + /** + * To be used for single blocks or when directly interacting with the controller + * + * @param side The side from where items are being inputted or extracted from + * @param type The type of inventory being accessed. For inputting its Input, For outputting its Output. + * @return The Item Logic responsible for said type. Will return null if the side is not valid + */ + @Nullable + ItemInventoryLogic getItemLogic(@Nonnull ForgeDirection side, @Nonnull InventoryType type); + + /** + * Only to be used by MultiBlockPart for accessing the Controller Inventory + * + * @param type Type of inventory, is it Input or Output + * @param id ID of the locked inventory. A null id is all inventories of said controller of said type + * @return The Item Logic responsible for everything that should be done with said inventory + */ + @Nonnull + default ItemInventoryLogic getItemLogic(@Nonnull InventoryType type, @Nullable UUID id) { + return Objects.requireNonNull(getItemLogic(ForgeDirection.UNKNOWN, type)); + } + + /** + * Only to be used for MultiBlockPart + * + * @return + */ + @Nullable + default InventoryType getItemInventoryType() { + return null; + } + + /** + * Returns an empty set if the type is {@link InventoryType#Both} or this is used when the machine isn't a + * controller + */ + @Nonnull + default Set<Entry<UUID, ItemInventoryLogic>> getAllItemInventoryLogics(@Nonnull InventoryType type) { + return new HashSet<>(); + } + + @Override + @Nullable + default ItemStack decrStackSize(int slot, int count) { + InventoryType type = getItemInventoryType(); + if (type == InventoryType.Both) return null; + ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); + if (logic == null) return null; + return logic.extractItem(slot, count); + } + + @Override + default int getSizeInventory() { + InventoryType type = getItemInventoryType(); + if (type == InventoryType.Both) return 0; + ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); + if (logic == null) return 0; + return logic.getSlots(); + } + + @Override + @Nullable + default ItemStack getStackInSlot(int slot) { + InventoryType type = getItemInventoryType(); + if (type == InventoryType.Both) return null; + ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); + if (logic == null) return null; + return logic.getInventory() + .getStackInSlot(slot); + } + + @Override + default boolean isItemValidForSlot(int slot, @Nullable ItemStack stack) { + InventoryType type = getItemInventoryType(); + if (type == InventoryType.Both) return false; + ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); + if (logic == null) return false; + return logic.getInventory() + .isItemValid(slot, stack); + } + + @Override + default void setInventorySlotContents(int slot, @Nullable ItemStack stack) { + InventoryType type = getItemInventoryType(); + if (type == InventoryType.Both) return; + ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); + if (logic == null) return; + logic.getInventory() + .setStackInSlot(slot, stack); + } + + @Override + default boolean canExtractItem(int ignoredSlot, ItemStack ignoredItem, int side) { + InventoryType type = getItemInventoryType(); + if (type == null) return false; + return getItemLogic(ForgeDirection.getOrientation(side), type) != null; + } + + @Override + default boolean canInsertItem(int ignoredSlot, ItemStack ignoredItem, int side) { + InventoryType type = getItemInventoryType(); + if (type == null) return false; + return getItemInventoryType() != InventoryType.Output + && getItemLogic(ForgeDirection.getOrientation(side), type) != null; + } + + @Override + default int[] getAccessibleSlotsFromSide(int side) { + InventoryType type = getItemInventoryType(); + if (type == null) return new int[0]; + ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); + if (logic == null) return new int[0]; + int[] indexes = new int[logic.getSlots()]; + for (int i = 0; i < logic.getSlots(); i++) { + indexes[i] = i; + } + return indexes; + } + + @Override + default void closeInventory() {} + + @Override + default String getInventoryName() { + return ""; + } + + @Override + default int getInventoryStackLimit() { + return 64; + } + + @Override + default ItemStack getStackInSlotOnClosing(int index) { + return null; + } + + @Override + default boolean hasCustomInventoryName() { + return false; + } + + @Override + default boolean isUseableByPlayer(@Nonnull EntityPlayer player) { + return false; + } + + @Override + default void openInventory() {} + +} diff --git a/src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java new file mode 100644 index 0000000000..9a0afaa539 --- /dev/null +++ b/src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java @@ -0,0 +1,10 @@ +package gregtech.api.logic.interfaces; + +import gregtech.api.logic.ModelRenderLogic; + +public interface ModelRenderLogicHost { + + ModelRenderLogic getRenderLogic(); + + boolean shouldRenderModel(); +} diff --git a/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java new file mode 100644 index 0000000000..4903d7fa23 --- /dev/null +++ b/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java @@ -0,0 +1,60 @@ +package gregtech.api.logic.interfaces; + +import java.util.Objects; + +import javax.annotation.Nonnull; + +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.tileentity.IEnergyConnected; +import gregtech.api.logic.PowerLogic; + +/** + * Power logic class for one to use to enable a machine to use energy + */ +public interface PowerLogicHost { + + /** + * + * @param side Side being access to try and get the power logic from + * @return Can return NullPowerLogic if the side doesn't allow the return of the logic. That power logic is unusable + */ + @Nonnull + PowerLogic getPowerLogic(@Nonnull ForgeDirection side); + + /** + * Gives the power logic ignoring the side. + */ + @Nonnull + default PowerLogic getPowerLogic() { + return Objects.requireNonNull(getPowerLogic(ForgeDirection.UNKNOWN)); + } + + /** + * Shortcut to the method of {@link PowerLogic#isEnergyReceiver()} + */ + default boolean isEnergyReceiver() { + return getPowerLogic().isEnergyReceiver(); + } + + /** + * Shortcut to the method of {@link PowerLogic#isEnergyEmitter()} + */ + default boolean isEnergyEmitter() { + return getPowerLogic().isEnergyEmitter(); + } + + /** + * Method for emitting energy to other blocks and machines. Override when it needs to be changed. + */ + default void emitEnergyFromLogic() { + IEnergyConnected.Util.emitEnergyToNetwork(this, getPowerOutputSide()); + } + + /** + * From where does the machine output energy from? + * When the output side is {@link ForgeDirection#UNKNOWN} then it won't output energy + */ + @Nonnull + ForgeDirection getPowerOutputSide(); +} diff --git a/src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java new file mode 100644 index 0000000000..b8291c9843 --- /dev/null +++ b/src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java @@ -0,0 +1,82 @@ +package gregtech.api.logic.interfaces; + +import javax.annotation.Nonnull; + +import gregtech.api.enums.VoidingMode; +import gregtech.api.interfaces.tileentity.IMachineProgress; +import gregtech.api.interfaces.tileentity.IVoidable; +import gregtech.api.logic.MuTEProcessingLogic; + +public interface ProcessingLogicHost<P extends MuTEProcessingLogic<P>> + extends IVoidable, ItemInventoryLogicHost, FluidInventoryLogicHost, IMachineProgress { + + /** + * Get the processing logic for the current machine + */ + @Nonnull + P getProcessingLogic(); + + boolean isInputSeparated(); + + void setInputSeparation(Boolean inputSeparation); + + default boolean supportsInputSeparation() { + return true; + } + + default boolean getDefaultInputSeparationMode() { + return false; + } + + boolean isRecipeLockingEnabled(); + + void setRecipeLocking(Boolean recipeLocked); + + default boolean supportsSingleRecipeLocking() { + return true; + } + + default boolean getDefaultRecipeLockingMode() { + return false; + } + + default boolean supportsBatchMode() { + return true; + } + + void setBatchMode(Boolean batchMode); + + boolean isBatchModeEnabled(); + + default boolean getDefaultBatchMode() { + return false; + } + + /** + * Get what the machine can void or not + */ + @Nonnull + VoidingMode getVoidMode(); + + /** + * Called when the processing logic should be updated by {@link #needsUpdate()} + */ + default void updateProcessingLogic(@Nonnull P processingLogic) {} + + /** + * Called before the recipe check, but after any other updates + */ + default void setProcessingLogicPower(@Nonnull P processingLogic) {} + + /** + * DO NOT CALL YOURSELF!!! + * + * If you want to make the processing logic be updated call {@link #setProcessingUpdate(boolean)} + */ + boolean needsUpdate(); + + /** + * To be called when one needs to updated the processing logic. That can be when parallel changes, ect. + */ + void setProcessingUpdate(boolean update); +} |