diff options
Diffstat (limited to 'src')
50 files changed, 2073 insertions, 136 deletions
diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java index 7a52021eea..9b039409dc 100644 --- a/src/main/java/gregtech/api/GregTech_API.java +++ b/src/main/java/gregtech/api/GregTech_API.java @@ -173,6 +173,12 @@ public class GregTech_API { */ public static final Map<Integer, Byte> sWirelessRedstone = new ConcurrentHashMap<>(); /** + * The Advanced Redstone Frequencies + */ + public static final Map<String, Map<Integer, Map<Long, Byte>>> sAdvancedWirelessRedstone = + new ConcurrentHashMap<>(); + + /** * The IDSU Frequencies */ public static final Map<Integer, Integer> sIDSUList = new ConcurrentHashMap<>(); diff --git a/src/main/java/gregtech/api/enums/ItemList.java b/src/main/java/gregtech/api/enums/ItemList.java index 279233d101..a6d93af7a3 100644 --- a/src/main/java/gregtech/api/enums/ItemList.java +++ b/src/main/java/gregtech/api/enums/ItemList.java @@ -1529,6 +1529,15 @@ public enum ItemList implements IItemContainer { Hatch_Output_Bus_ME, NULL, + Cover_AdvancedRedstoneTransmitterExternal, + Cover_AdvancedRedstoneTransmitterInternal, + Cover_AdvancedRedstoneReceiverExternal, + Cover_AdvancedRedstoneReceiverInternal, + + Cover_WirelessFluidDetector, + Cover_WirelessItemDetector, + Cover_WirelessNeedsMaintainance, + Cover_RedstoneTransmitterExternal, Cover_RedstoneTransmitterInternal, Cover_RedstoneReceiverExternal, diff --git a/src/main/java/gregtech/api/enums/Textures.java b/src/main/java/gregtech/api/enums/Textures.java index ee335c749e..77e28482ce 100644 --- a/src/main/java/gregtech/api/enums/Textures.java +++ b/src/main/java/gregtech/api/enums/Textures.java @@ -491,6 +491,16 @@ public class Textures { OVERLAY_FLUIDDETECTOR, OVERLAY_ITEMDETECTOR, + OVERLAY_REDSTONE_TRANSMITTER, + OVERLAY_REDSTONE_RECEIVER, + OVERLAY_MAINTENANCE_DETECTOR, + + OVERLAY_ADVANCED_REDSTONE_TRANSMITTER, + OVERLAY_ADVANCED_REDSTONE_RECEIVER, + OVERLAY_WIRELESS_ITEM_DETECTOR, + OVERLAY_WIRELESS_FLUID_DETECTOR, + OVERLAY_WIRELESS_MAINTENANCE_DETECTOR, + OVERLAY_FLUID_STORAGE_MONITOR0, OVERLAY_FLUID_STORAGE_MONITOR1, OVERLAY_FLUID_STORAGE_MONITOR2, diff --git a/src/main/java/gregtech/api/gui/GT_GUIScreen.java b/src/main/java/gregtech/api/gui/GT_GUIScreen.java index 281be1e55d..d39a6b738e 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIScreen.java +++ b/src/main/java/gregtech/api/gui/GT_GUIScreen.java @@ -28,8 +28,8 @@ public abstract class GT_GUIScreen extends GuiScreen implements GT_IToolTipRende protected int gui_height = 107; protected int guiTop, guiLeft; protected boolean drawButtons = true; + protected ResourceLocation mGUIbackgroundLocation; - private ResourceLocation mGUIbackgroundLocation; private GuiButton selectedButton; private GT_GUIColorOverride colorOverride; private final int textColor; diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java index 37e1a6d960..43fbe0711c 100644 --- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java +++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java @@ -30,6 +30,12 @@ public enum GT_GuiIcon implements IGuiIcon { GREEN_ARROW_DOWN(0, 32 * 5, 32 * 2), CYCLIC(0, 32 * 6, 32 * 2), + AND_GATE(0, 0, 32 * 3), + NAND_GATE(0, 32, 32 * 3), + OR_GATE(0, 32 * 2, 32 * 3), + NOR_GATE(0, 32 * 3, 32 * 3), + ANALOG_MODE(0, 32 * 4, 32 * 3), + SLOT_DARKGRAY(1, 176, 0, 18, 18), SLOT_GRAY(1, 176, 18, 18, 18), diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index 0fdaa90c1a..7c75bb97d4 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -776,6 +776,8 @@ public class BaseMetaPipeEntity extends CommonMetaTileEntity if (hasCover) tNBT.setIntArray("mCoverSides", mCoverSides); if (hasValidMetaTileEntity()) mMetaTileEntity.setItemNBT(tNBT); if (!tNBT.hasNoTags()) rStack.setTagCompound(tNBT); + + onBaseTEDestroyed(); return new ArrayList<>(Collections.singletonList(rStack)); } diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index cdc81220e6..08ead9a946 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -1423,6 +1423,8 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity if (hasValidMetaTileEntity()) mMetaTileEntity.setItemNBT(tNBT); if (!tNBT.hasNoTags()) rStack.setTagCompound(tNBT); + + onBaseTEDestroyed(); return new ArrayList<>(Collections.singletonList(rStack)); } diff --git a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java index caf3c1b15f..9df38b2725 100644 --- a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java @@ -320,6 +320,14 @@ public abstract class CoverableTileEntity extends BaseTileEntity implements ICov return false; } + protected void onBaseTEDestroyed() { + for (byte side = 0; side < 6; ++side) { + GT_CoverBehaviorBase<?> behavior = getCoverBehaviorAtSideNew(side); + if (behavior != GregTech_API.sNoBehavior) + behavior.onBaseTEDestroyed(side, getCoverIDAtSide(side), mCoverData[side], this); + } + } + @Override public void setOutputRedstoneSignal(byte aSide, byte aStrength) { aStrength = (byte) Math.min(Math.max(0, aStrength), 15); @@ -414,10 +422,19 @@ public abstract class CoverableTileEntity extends BaseTileEntity implements ICov public void receiveCoverData( byte aCoverSide, int aCoverID, ISerializableObject aCoverData, EntityPlayerMP aPlayer) { if ((aCoverSide >= 0 && aCoverSide < 6)) { + GT_CoverBehaviorBase<?> behaviorBase = getCoverBehaviorAtSideNew(aCoverSide); + behaviorBase.preDataChanged( + aCoverSide, + getCoverIDAtSide(aCoverSide), + aCoverID, + getComplexCoverDataAtSide(aCoverSide), + aCoverData, + this); + setCoverIDAtSideNoUpdate(aCoverSide, aCoverID); setCoverDataAtSide(aCoverSide, aCoverData); if (isClientSide()) { - getCoverBehaviorAtSideNew(aCoverSide).onDataChanged(aCoverSide, aCoverID, aCoverData, this); + behaviorBase.onDataChanged(aCoverSide, aCoverID, aCoverData, this); } } } diff --git a/src/main/java/gregtech/api/multitileentity/base/BaseMultiTileEntity.java b/src/main/java/gregtech/api/multitileentity/base/BaseMultiTileEntity.java index 18dc310bb7..385ae310f1 100644 --- a/src/main/java/gregtech/api/multitileentity/base/BaseMultiTileEntity.java +++ b/src/main/java/gregtech/api/multitileentity/base/BaseMultiTileEntity.java @@ -906,6 +906,8 @@ public abstract class BaseMultiTileEntity extends CoverableTileEntity final ArrayList<ItemStack> rList = new ArrayList<>(); final MultiTileEntityRegistry tRegistry = MultiTileEntityRegistry.getRegistry(getMultiTileEntityRegistryID()); if (tRegistry != null) rList.add(tRegistry.getItem(getMultiTileEntityID(), writeItemNBT(new NBTTagCompound()))); + + onBaseTEDestroyed(); return rList; } diff --git a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java index efbff79957..1092a24307 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java @@ -131,6 +131,20 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { } /** + * Called before receiving data from network. Use {@link ICoverable#isClientSide()} to determine the side. + */ + public final void preDataChanged( + byte aSide, + int aCoverID, + int aNewCoverId, + ISerializableObject aCoverVariable, + ISerializableObject aNewCoverVariable, + ICoverable aTileEntity) { + preDataChangedImpl( + aSide, aCoverID, aNewCoverId, forceCast(aCoverVariable), forceCast(aNewCoverVariable), aTileEntity); + } + + /** * Called upon cover being removed. Called on both server and client. */ public final void onDropped(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { @@ -222,6 +236,15 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { } /** + * Called upon Base TE being destroyed (once getDrops is called), + * thus getting called only when destroyed in survival. + */ + public final void onBaseTEDestroyed( + byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { + onBaseTEDestroyedImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + + /** * Gives a small Text for the status of the Cover. */ public final String getDescription( @@ -410,8 +433,13 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { protected void onDataChangedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {} + protected void preDataChangedImpl( + byte aSide, int aCoverID, int aNewCoverId, T aCoverVariable, T aNewCoverVariable, ICoverable aTileEntity) {} + protected void onDroppedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {} + protected void onBaseTEDestroyedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {} + protected boolean isRedstoneSensitiveImpl( byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, long aTimer) { return true; diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 270619363f..c9aa55d291 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -4276,6 +4276,30 @@ public class GT_Utility { for (int i = 0; i < 25; i++) if (itemStack.isItemEqual(GT_Utility.getIntegratedCircuit(i))) return true; return false; } +public static byte convertRatioToRedstone(long used, long max, int threshold, boolean inverted) { + byte signal; + if (used <= 0) { // Empty + signal = 0; + } else if (used >= max) { // Full + signal = 15; + } else { // Range 1-14 + signal = (byte) (1 + (14 * used) / max); + } + + if (inverted) { + signal = (byte) (15 - signal); + } + + if (threshold > 0) { + if (inverted && used >= threshold) { + return 0; + } else if (!inverted && used < threshold) { + return 0; + } + } + + return signal; + } @AutoValue public abstract static class ItemId { diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java b/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java index 82dffaf7a8..c894857b32 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java @@ -74,66 +74,47 @@ public class GT_Cover_ItemMeter extends GT_CoverBehaviorBase<GT_Cover_ItemMeter. return false; } - @Override - protected ItemMeterData doCoverThingsImpl( - byte aSide, - byte aInputRedstone, - int aCoverID, - ItemMeterData aCoverVariable, - ICoverable aTileEntity, - long aTimer) { - long tMax = 0; - long tUsed = 0; - IMetaTileEntity mte = ((IGregTechTileEntity) aTileEntity).getMetaTileEntity(); + public static byte computeSignalBasedOnItems( + ICoverable tileEntity, boolean inverted, int threshold, int slot, int side) { + long max = 0; + long used = 0; + IMetaTileEntity mte = ((IGregTechTileEntity) tileEntity).getMetaTileEntity(); if (mte instanceof GT_MetaTileEntity_DigitalChestBase) { GT_MetaTileEntity_DigitalChestBase dc = (GT_MetaTileEntity_DigitalChestBase) mte; - tMax = dc.getMaxItemCount(); // currently it is limited by int, but there is not much reason for that - ItemStack[] inv = dc.getStoredItemData(); - if (inv != null && inv.length > 1 && inv[1] != null) tUsed = inv[1].stackSize; + max = dc.getMaxItemCount(); + used = dc.getProgresstime(); } else if (GregTech_API.mAE2 && mte instanceof GT_MetaTileEntity_Hatch_OutputBus_ME) { if (((GT_MetaTileEntity_Hatch_OutputBus_ME) mte).isLastOutputFailed()) { - tMax = 64; - tUsed = 64; + max = 64; + used = 64; } } else { - int[] tSlots = aCoverVariable.slot >= 0 - ? new int[] {aCoverVariable.slot} - : aTileEntity.getAccessibleSlotsFromSide(aSide); - - for (int i : tSlots) { - if (i >= 0 && i < aTileEntity.getSizeInventory()) { - tMax += 64; - ItemStack tStack = aTileEntity.getStackInSlot(i); - if (tStack != null) tUsed += (tStack.stackSize << 6) / tStack.getMaxStackSize(); + int[] slots = slot >= 0 ? new int[] {slot} : tileEntity.getAccessibleSlotsFromSide(side); + + for (int i : slots) { + if (i >= 0 && i < tileEntity.getSizeInventory()) { + max += 64; + ItemStack stack = tileEntity.getStackInSlot(i); + if (stack != null) used += ((long) stack.stackSize << 6) / stack.getMaxStackSize(); } } } - long redstoneSignal; - if (tUsed == 0L) { - // nothing - redstoneSignal = 0; - } else if (tUsed >= tMax) { - // full - redstoneSignal = 15; - } else { - // 1-14 range - redstoneSignal = 1 + (14 * tUsed) / tMax; - } - - if (aCoverVariable.inverted) { - redstoneSignal = 15 - redstoneSignal; - } + return GT_Utility.convertRatioToRedstone(used, max, threshold, inverted); + } - if (aCoverVariable.threshold > 0) { - if (aCoverVariable.inverted && tUsed >= aCoverVariable.threshold) { - redstoneSignal = 0; - } else if (!aCoverVariable.inverted && tUsed < aCoverVariable.threshold) { - redstoneSignal = 0; - } - } + @Override + protected ItemMeterData doCoverThingsImpl( + byte aSide, + byte aInputRedstone, + int aCoverID, + ItemMeterData aCoverVariable, + ICoverable aTileEntity, + long aTimer) { + byte signal = computeSignalBasedOnItems( + aTileEntity, aCoverVariable.inverted, aCoverVariable.threshold, aCoverVariable.slot, aSide); + aTileEntity.setOutputRedstoneSignal(aSide, signal); - aTileEntity.setOutputRedstoneSignal(aSide, (byte) redstoneSignal); return aCoverVariable; } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_LiquidMeter.java b/src/main/java/gregtech/common/covers/GT_Cover_LiquidMeter.java index ce795bdd09..48304d3fed 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_LiquidMeter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_LiquidMeter.java @@ -53,6 +53,29 @@ public class GT_Cover_LiquidMeter extends GT_CoverBehaviorBase<GT_Cover_LiquidMe return false; } + public static byte computeSignalBasedOnFluid(ICoverable tileEntity, boolean inverted, int threshold) { + if (tileEntity instanceof IFluidHandler) { + FluidTankInfo[] tanks = ((IFluidHandler) tileEntity).getTankInfo(ForgeDirection.UNKNOWN); + long max = 0; + long used = 0; + if (tanks != null) { + for (FluidTankInfo tank : tanks) { + if (tank != null) { + max += tank.capacity; + FluidStack tLiquid = tank.fluid; + if (tLiquid != null) { + used += tLiquid.amount; + } + } + } + } + + return GT_Utility.convertRatioToRedstone(used, max, threshold, inverted); + } else { + return 0; + } + } + @Override protected LiquidMeterData doCoverThingsImpl( byte aSide, @@ -61,50 +84,9 @@ public class GT_Cover_LiquidMeter extends GT_CoverBehaviorBase<GT_Cover_LiquidMe LiquidMeterData aCoverVariable, ICoverable aTileEntity, long aTimer) { - if ((aTileEntity instanceof IFluidHandler)) { - FluidTankInfo[] tTanks = ((IFluidHandler) aTileEntity).getTankInfo(ForgeDirection.UNKNOWN); - long tMax = 0; - long tUsed = 0; - if (tTanks != null) { - for (FluidTankInfo tTank : tTanks) { - if (tTank != null) { - tMax += tTank.capacity; - FluidStack tLiquid = tTank.fluid; - if (tLiquid != null) { - tUsed += tLiquid.amount; - } - } - } - } - - long redstoneSignal; - if (tUsed == 0L) { - // nothing - redstoneSignal = 0; - } else if (tUsed >= tMax) { - // full - redstoneSignal = 15; - } else { - // 1-14 range - redstoneSignal = 1 + (14 * tUsed) / tMax; - } - - if (aCoverVariable.inverted) { - redstoneSignal = 15 - redstoneSignal; - } - - if (aCoverVariable.threshold > 0) { - if (aCoverVariable.inverted && tUsed >= aCoverVariable.threshold) { - redstoneSignal = 0; - } else if (!aCoverVariable.inverted && tUsed < aCoverVariable.threshold) { - redstoneSignal = 0; - } - } + byte signal = computeSignalBasedOnFluid(aTileEntity, aCoverVariable.inverted, aCoverVariable.threshold); + aTileEntity.setOutputRedstoneSignal(aSide, signal); - aTileEntity.setOutputRedstoneSignal(aSide, (byte) redstoneSignal); - } else { - aTileEntity.setOutputRedstoneSignal(aSide, (byte) 0); - } return aCoverVariable; } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_NeedMaintainance.java b/src/main/java/gregtech/common/covers/GT_Cover_NeedMaintainance.java index 369778ef12..2ea5a2c951 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_NeedMaintainance.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_NeedMaintainance.java @@ -32,11 +32,11 @@ public class GT_Cover_NeedMaintainance extends GT_CoverBehavior { super(coverTexture); } - private boolean isRotor(ItemStack aRotor) { - return !(aRotor == null - || !(aRotor.getItem() instanceof GT_MetaGenerated_Tool) - || aRotor.getItemDamage() < 170 - || aRotor.getItemDamage() > 176); + public static boolean isRotor(ItemStack rotor) { + return (rotor != null + && rotor.getItem() instanceof GT_MetaGenerated_Tool + && rotor.getItemDamage() >= 170 + && rotor.getItemDamage() <= 176); } @Override diff --git a/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java b/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java index a942d39b57..a024400094 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java @@ -15,6 +15,7 @@ import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.Fluid; public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { @@ -198,10 +199,13 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { private static final int spaceX = 18; private static final int spaceY = 18; + private static final String guiTexturePath = "gregtech:textures/gui/GuiCoverLong.png"; + private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); + super(aTileEntity, 250, 107, GT_Utility.intToStack(aCoverID)); + this.mGUIbackgroundLocation = new ResourceLocation(guiTexturePath); this.side = aSide; this.coverID = aCoverID; this.coverVariable = aCoverVariable; diff --git a/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneReceiverBase.java b/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneReceiverBase.java new file mode 100644 index 0000000000..233be511a3 --- /dev/null +++ b/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneReceiverBase.java @@ -0,0 +1,193 @@ +package gregtech.common.covers.redstone; + +import com.google.common.io.ByteArrayDataInput; +import gregtech.api.gui.widgets.GT_GuiIcon; +import gregtech.api.gui.widgets.GT_GuiIconButton; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; +import io.netty.buffer.ByteBuf; +import java.util.UUID; +import javax.annotation.Nonnull; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +public abstract class GT_Cover_AdvancedRedstoneReceiverBa |
