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 --- .../redstone/GT_MetaTileEntity_RedstoneBase.java | 111 ---- .../GT_MetaTileEntity_RedstoneButtonPanel.java | 205 ------- .../GT_MetaTileEntity_RedstoneCircuitBlock.java | 654 --------------------- .../redstone/GT_MetaTileEntity_RedstoneLamp.java | 73 --- .../GT_MetaTileEntity_RedstoneStrengthDisplay.java | 139 ----- .../GT_MetaTileEntity_RedstoneStrengthScale.java | 54 -- .../tileentities/redstone/MTERedstoneBase.java | 111 ++++ .../redstone/MTERedstoneButtonPanel.java | 204 +++++++ .../redstone/MTERedstoneCircuitBlock.java | 652 ++++++++++++++++++++ .../tileentities/redstone/MTERedstoneLamp.java | 73 +++ .../redstone/MTERedstoneStrengthDisplay.java | 138 +++++ .../redstone/MTERedstoneStrengthScale.java | 53 ++ 12 files changed, 1231 insertions(+), 1236 deletions(-) delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneBase.java delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneButtonPanel.java delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneCircuitBlock.java delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneLamp.java delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthDisplay.java delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthScale.java create mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneBase.java create mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneButtonPanel.java create mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java create mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneLamp.java create mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneStrengthDisplay.java create mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneStrengthScale.java (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone') diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneBase.java deleted file mode 100644 index ee6ccff4b1..0000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneBase.java +++ /dev/null @@ -1,111 +0,0 @@ -package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import org.apache.commons.lang3.ArrayUtils; - -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; -import gregtech.api.objects.GT_ItemStack; -import gtPlusPlus.core.lib.CORE; - -public abstract class GT_MetaTileEntity_RedstoneBase extends GT_MetaTileEntity_TieredMachineBlock { - - protected int mOpenerCount; - - public GT_MetaTileEntity_RedstoneBase(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, - String aDescription, ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); - } - - public GT_MetaTileEntity_RedstoneBase(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, - String[] aDescription, ITexture... aTextures) { - super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); - } - - public GT_MetaTileEntity_RedstoneBase(String aName, int aTier, int aInvSlotCount, String[] aDescription, - ITexture[][][] aTextures) { - super(aName, aTier, aInvSlotCount, aDescription, aTextures); - } - - @Override - public final boolean isSimpleMachine() { - return false; - } - - @Override - public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aStack) { - return side != getBaseMetaTileEntity().getFrontFacing(); - } - - @Override - public final boolean isValidSlot(int aIndex) { - return false; - } - - @Override - public final boolean isFacingValid(ForgeDirection facing) { - return true; - } - - @Override - public final boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - @Override - public abstract void saveNBTData(NBTTagCompound aNBT); - - @Override - public abstract void loadNBTData(NBTTagCompound aNBT); - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - return false; - } - - @Override - public final void onOpenGUI() { - super.onOpenGUI(); - mOpenerCount++; - } - - @Override - public final void onCloseGUI() { - super.onCloseGUI(); - mOpenerCount--; - } - - public boolean hasRedstoneSignal() { - if (getBaseMetaTileEntity().getStrongestRedstone() > 0) { - return true; - } - for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - if (getBaseMetaTileEntity().getOutputRedstoneSignal(side) > 0) { - return true; - } - } - return false; - } - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, - ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, - ItemStack aStack) { - return false; - } - - @Override - public String[] getDescription() { - return ArrayUtils.add(this.mDescriptionArray, CORE.GT_Tooltip.get()); - } -} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneButtonPanel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneButtonPanel.java deleted file mode 100644 index 174a13d3c8..0000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneButtonPanel.java +++ /dev/null @@ -1,205 +0,0 @@ -package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.objects.GT_RenderedTexture; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; - -public class GT_MetaTileEntity_RedstoneButtonPanel extends GT_MetaTileEntity_RedstoneBase { - - public byte mRedstoneStrength = 0, mType = 0, mUpdate = 0; - - public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[64]; - - static { - for (int i = 0; i < 64; i++) { - sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/ButtonPanel/" + i); - } - } - - public GT_MetaTileEntity_RedstoneButtonPanel(int aID) { - super( - aID, - "redstone.button.panel", - "Button Panel", - 5, - 0, - "Right-click with Screwdriver to change Button Design"); - } - - public GT_MetaTileEntity_RedstoneButtonPanel(final String aName, String[] aDescription, - final ITexture[][][] aTextures) { - super(aName, 5, 0, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneButtonPanel(this.mName, mDescriptionArray, this.mTextures); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setByte("mRedstoneStrength", mRedstoneStrength); - aNBT.setByte("mType", mType); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mRedstoneStrength = aNBT.getByte("mRedstoneStrength"); - mType = aNBT.getByte("mType"); - } - - @Override - public void onValueUpdate(byte aValue) { - mRedstoneStrength = (byte) (aValue & 15); - mType = (byte) (aValue >>> 4); - } - - @Override - public byte getUpdateData() { - return (byte) ((mRedstoneStrength & 15) | (mType << 4)); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, - float aX, float aY, float aZ) { - if (side == getBaseMetaTileEntity().getFrontFacing()) { - if (getBaseMetaTileEntity().isServerSide()) { - mUpdate = 2; - switch (mType) { - case 0: - default: - switch (side) { - case DOWN, UP -> mRedstoneStrength = (byte) ((byte) (aX * 4) + 4 * (byte) (aZ * 4)); - case NORTH -> mRedstoneStrength = (byte) ((byte) (4 - aX * 4) + 4 * (byte) (4 - aY * 4)); - case SOUTH -> mRedstoneStrength = (byte) ((byte) (aX * 4) + 4 * (byte) (4 - aY * 4)); - case WEST -> mRedstoneStrength = (byte) ((byte) (aZ * 4) + 4 * (byte) (4 - aY * 4)); - case EAST -> mRedstoneStrength = (byte) ((byte) (4 - aZ * 4) + 4 * (byte) (4 - aY * 4)); - } - break; - case 1: - switch (side) { - case DOWN, UP -> mRedstoneStrength = (byte) (mRedstoneStrength - ^ (1 << (((byte) (aX * 2) + 2 * (byte) (aZ * 2))))); - case NORTH -> mRedstoneStrength = (byte) (mRedstoneStrength - ^ (1 << (((byte) (2 - aX * 2) + 2 * (byte) (2 - aY * 2))))); - case SOUTH -> mRedstoneStrength = (byte) (mRedstoneStrength - ^ (1 << (((byte) (aX * 2) + 2 * (byte) (2 - aY * 2))))); - case WEST -> mRedstoneStrength = (byte) (mRedstoneStrength - ^ (1 << (((byte) (aZ * 2) + 2 * (byte) (2 - aY * 2))))); - case EAST -> mRedstoneStrength = (byte) (mRedstoneStrength - ^ (1 << (((byte) (2 - aZ * 2) + 2 * (byte) (2 - aY * 2))))); - } - break; - case 2: - switch (side) { - case DOWN, UP -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (aZ * 4)))); - case NORTH -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); - case SOUTH -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); - case WEST -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); - case EAST -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); - } - break; - } - } - return true; - } - return false; - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (getBaseMetaTileEntity().isServerSide()) { - getBaseMetaTileEntity().setGenericRedstoneOutput(true); - if (mUpdate > 0) { - mUpdate--; - } else if (getBaseMetaTileEntity().isAllowedToWork()) { - mRedstoneStrength = 0; - } - for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - getBaseMetaTileEntity().setStrongOutputRedstoneSignal( - side, - side == getBaseMetaTileEntity().getFrontFacing() ? (byte) 0 : mRedstoneStrength); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal( - side, - side == getBaseMetaTileEntity().getFrontFacing() ? (byte) 0 : mRedstoneStrength); - } - } - } - - @Override - public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (side == getBaseMetaTileEntity().getFrontFacing()) mType = (byte) ((mType + 1) % 3); - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getSides(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFront(i); - rTextures[6][i + 1] = this.getSidesActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, - final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { - if (side == facing) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], - new GT_RenderedTexture(sIconList[mType * 16 + mRedstoneStrength]) }; - } - return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (side == facing ? 0 - : side == facing.getOpposite() ? 1 - : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1] }; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Main_Off) }; - } - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Main_On) }; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Main_Off) }; - } - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Main_On) }; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Main_Off) }; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Main_On) }; - } -} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneCircuitBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneCircuitBlock.java deleted file mode 100644 index 3b9b9af9a0..0000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneCircuitBlock.java +++ /dev/null @@ -1,654 +0,0 @@ -package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.oredict.OreDictionary; - -import com.gtnewhorizons.modularui.api.screen.ModularWindow; -import com.gtnewhorizons.modularui.api.screen.UIBuildContext; -import com.gtnewhorizons.modularui.common.widget.ButtonWidget; -import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; -import com.gtnewhorizons.modularui.common.widget.DrawableWidget; -import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; -import com.gtnewhorizons.modularui.common.widget.SlotWidget; -import com.gtnewhorizons.modularui.common.widget.TextWidget; - -import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.modularui.GT_UIInfos; -import gregtech.api.gui.modularui.GT_UITextures; -import gregtech.api.interfaces.IRedstoneCircuitBlock; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.modularui.IAddUIWidgets; -import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.objects.GT_ItemStack; -import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_CircuitryBehavior; -import gregtech.api.util.GT_CoverBehavior; -import gregtech.api.util.GT_Log; -import gregtech.api.util.GT_Utility; -import gregtech.api.util.ISerializableObject; -import gtPlusPlus.xmod.gregtech.api.gui.GTPP_UITextures; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; - -public class GT_MetaTileEntity_RedstoneCircuitBlock extends GT_MetaTileEntity_RedstoneBase - implements IRedstoneCircuitBlock, IAddUIWidgets { - - public int mGate = 0, mGateData[] = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; - public boolean bOutput = true; - - public GT_MetaTileEntity_RedstoneCircuitBlock(int aID) { - super(aID, "redstone.circuit", "Redstone Circuit Block", 1, 5, "Computes Redstone"); - } - - public GT_MetaTileEntity_RedstoneCircuitBlock(final String aName, String[] aDescription, - final ITexture[][][] aTextures) { - super(aName, 1, 5, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneCircuitBlock(this.mName, mDescriptionArray, this.mTextures); - } - - @Override - public boolean hasSidedRedstoneOutputBehavior() { - return true; - } - - @Override - public boolean isEnetInput() { - return true; - } - - @Override - public boolean isEnetOutput() { - return true; - } - - @Override - public boolean isInputFacing(ForgeDirection side) { - return !this.isOutputFacing(side); - } - - @Override - public boolean isElectric() { - return true; - } - - @Override - public boolean isPneumatic() { - return false; - } - - @Override - public boolean isSteampowered() { - return false; - } - - @Override - public boolean isOutputFacing(ForgeDirection side) { - return side == this.getOutputFacing(); - } - - @Override - public long getMinimumStoredEU() { - return 512; - } - - @Override - public long maxEUInput() { - return GT_Values.V[1]; - } - - @Override - public long maxEUOutput() { - return bOutput ? GT_Values.V[1] : 0; - } - - @Override - public long maxAmperesIn() { - return 2; - } - - @Override - public long maxAmperesOut() { - return 1; - } - - @Override - public int getSizeInventory() { - return 5; - } - - @Override - public long maxEUStore() { - return GT_Values.V[3] * 1024; - } - - @Override - public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { - GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); - return true; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mGate", mGate); - aNBT.setIntArray("mGateData", mGateData); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mGate = aNBT.getInteger("mGate"); - mGateData = aNBT.getIntArray("mGateData"); - if (mGateData.length != 8) mGateData = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; - } - - public void switchGateForward(boolean aShift) { - try { - Set tKeys = GregTech_API.sCircuitryBehaviors.keySet(); - ArrayList tList = new ArrayList<>(); - tList.addAll(tKeys); - if (tList.size() <= 0) return; - Collections.sort(tList); - if (!GregTech_API.sCircuitryBehaviors.containsKey(mGate)) mGate = tList.get(0); - int tIndex = Collections.binarySearch(tList, mGate); - tIndex += aShift ? 16 : 1; - while (tIndex >= tList.size()) tIndex -= tList.size(); - mGate = tList.get(tIndex); - switchGate(); - } catch (Throwable e) { - GT_Log.err.print(e); - } - } - - public void switchGateBackward(boolean aShift) { - try { - Set tKeys = GregTech_API.sCircuitryBehaviors.keySet(); - ArrayList tList = new ArrayList<>(); - tList.addAll(tKeys); - if (tList.size() <= 0) return; - Collections.sort(tList); - if (!GregTech_API.sCircuitryBehaviors.containsKey(mGate)) mGate = tList.get(0); - int tIndex = Collections.binarySearch(tList, mGate); - tIndex -= aShift ? 16 : 1; - while (tIndex < 0) tIndex += tList.size(); - mGate = tList.get(tIndex); - switchGate(); - } catch (Throwable e) { - GT_Log.err.print(e); - } - } - - @Override - public void onFacingChange() { - resetRedstone(); - } - - private void resetRedstone() { - getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.DOWN, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.UP, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.NORTH, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.SOUTH, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.WEST, (byte) 0); - getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.EAST, (byte) 0); - } - - public void changeGateData(int aIndex, int aValue) { - mGateData[aIndex] += aValue; - validateGateData(); - } - - public void stackGateData(int aIndex, ItemStack aStack) { - mGateData[aIndex] = GT_Utility.stackToInt(aStack); - validateGateData(); - } - - private void switchGate() { - resetRedstone(); - Arrays.fill(mGateData, 0); - GT_CircuitryBehavior tBehaviour = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tBehaviour != null) try { - tBehaviour.initParameters(mGateData, this); - } catch (Throwable e) { - GT_Log.err.print(e); - } - validateGateData(); - } - - private void validateGateData() { - GT_CircuitryBehavior tBehaviour = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tBehaviour != null) try { - tBehaviour.validateParameters(mGateData, this); - } catch (Throwable e) { - GT_Log.err.print(e); - } - } - - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - super.onFirstTick(aBaseMetaTileEntity); - getBaseMetaTileEntity().setGenericRedstoneOutput(true); - validateGateData(); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - getBaseMetaTileEntity().setGenericRedstoneOutput(true); - if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { - mInventory[0] = mInventory[1] = mInventory[2] = mInventory[3] = mInventory[4] = null; - if (getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU()) { - if (getBaseMetaTileEntity().isActive()) { - GT_CircuitryBehavior tBehaviour = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tBehaviour != null) { - try { - tBehaviour.onTick(mGateData, this); - if (tBehaviour.displayItemStack(mGateData, this, 0)) - mInventory[1] = getCoverByID(mGateData[0]); - if (tBehaviour.displayItemStack(mGateData, this, 1)) - mInventory[2] = getCoverByID(mGateData[1]); - if (tBehaviour.displayItemStack(mGateData, this, 2)) - mInventory[3] = getCoverByID(mGateData[2]); - if (tBehaviour.displayItemStack(mGateData, this, 3)) - mInventory[4] = getCoverByID(mGateData[3]); - } catch (Throwable e) { - GT_Log.err.print(e); - } - } - } - getBaseMetaTileEntity().setErrorDisplayID(0); - } else { - getBaseMetaTileEntity().setErrorDisplayID(1); - } - } - } - - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - // Only Calc server-side - if (!this.getBaseMetaTileEntity() - .isServerSide()) { - return; - } - // Emit Redstone - for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - byte aRedstone = getBaseMetaTileEntity().getOutputRedstoneSignal(side); - this.getBaseMetaTileEntity() - .setInternalOutputRedstoneSignal(side, aRedstone); - } - } - - @Override - public final boolean hasRedstoneSignal() { - for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - if (getBaseMetaTileEntity().getOutputRedstoneSignal(side) > 0) { - return true; - } - } - return false; - } - - @Override - public boolean allowGeneralRedstoneOutput() { - return true; - } - - /** The Item List for Covers */ - public static final Map sCoversItems = new HashMap<>(); - - private static void initCovers() { - for (GT_ItemStack aKey : GregTech_API.sCovers.keySet()) { - ItemStack aStack = aKey.toStack() - .copy(); - if (aStack != null) { - sCoversItems.put(GT_Utility.stackToInt(aStack), aStack); - } - } - } - - public static ItemStack getCoverByID(int aStack) { - if (sCoversItems.isEmpty()) { - initCovers(); - } - return sCoversItems.get(Integer.valueOf(aStack)); - } - - @Override - public ForgeDirection getOutputFacing() { - return getBaseMetaTileEntity().getBackFacing(); - } - - @Override - public boolean setRedstone(byte aStrength, ForgeDirection side) { - if (getOutputRedstone(side) != aStrength) { - if (getBaseMetaTileEntity().decreaseStoredEnergyUnits(1, false)) { - getBaseMetaTileEntity().setInternalOutputRedstoneSignal(side, aStrength); - getBaseMetaTileEntity().setErrorDisplayID(0); - return true; - } else { - getBaseMetaTileEntity().setErrorDisplayID(1); - return false; - } - } - return false; - } - - /* - * @Override public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { if (aSide == - * getOutputFacing()) { if (side == ForgeDirection.DOWN) return aRedstone ? 56 : 54; if (side == ForgeDirection.UP) - * return aRedstone ? 53 : 52; return aRedstone ? 94 : 93; } if (side == ForgeDirection.DOWN) return aRedstone ? 60 - * : 59; if (side == ForgeDirection.UP) return aRedstone ? 58 : 57; return aRedstone ? 62 : 61; } - */ - - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, - ItemStack aStack) { - return false; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, - ItemStack aStack) { - return false; - } - - public byte getOutputRedstone(ForgeDirection side) { - return getBaseMetaTileEntity().getOutputRedstoneSignal(side); - } - - @Override - public byte getInputRedstone(ForgeDirection side) { - return getBaseMetaTileEntity().getInternalInputRedstoneSignal(side); - } - - @Override - public Block getBlockAtSide(ForgeDirection side) { - return getBaseMetaTileEntity().getBlockAtSide(side); - } - - @Override - public byte getMetaIDAtSide(ForgeDirection side) { - return getBaseMetaTileEntity().getMetaIDAtSide(side); - } - - @Override - public TileEntity getTileEntityAtSide(ForgeDirection side) { - return getBaseMetaTileEntity().getTileEntityAtSide(side); - } - - @Override - public int getRandom(int aRange) { - return getBaseMetaTileEntity().getRandomNumber(aRange); - } - - @Override - public GT_CoverBehavior getCover(ForgeDirection side) { - return (GT_CoverBehavior) getBaseMetaTileEntity().getCoverBehaviorAtSideNew(side); - } - - @Override - public int getCoverID(ForgeDirection side) { - return getBaseMetaTileEntity().getCoverIDAtSide(side); - } - - @Override - public int getCoverVariable(ForgeDirection side) { - return ((ISerializableObject.LegacyCoverData) getBaseMetaTileEntity().getComplexCoverDataAtSide(side)).get(); - } - - @Override - public ICoverable getOwnTileEntity() { - return getBaseMetaTileEntity(); - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getSides(i); - rTextures[1][i + 1] = this.getBack(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getSidesActive(i); - rTextures[6][i + 1] = this.getBackActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, - final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (side == facing ? 0 - : side == facing.getOpposite() ? 1 - : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; - } - - private GT_RenderedTexture getBase() { - return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] { getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Off) }; - } - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[] { getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_On) }; - } - - public ITexture[] getBack(final byte aColor) { - return new ITexture[] { getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off), - new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red) }; - } - - public ITexture[] getBackActive(final byte aColor) { - return new ITexture[] { getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On), - new GT_RenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red_Redstone) }; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] { getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Off) }; - } - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[] { getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_On) }; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off) }; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] { getBase(), new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On) }; - } - - @Override - public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { - builder.widget( - new DrawableWidget().setDrawable(GTPP_UITextures.PICTURE_REDSTONE_CIRCUIT_SCREEN) - .setPos(43, 5) - .setSize(108, 72)); - for (int i = 0; i < 4; i++) { - final int index = i; - builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> { - ItemStack tStack = widget.getContext() - .getPlayer().inventory.getItemStack(); - if (tStack == null) { - changeGateData( - index, - clickData.mouseButton == 0 ? clickData.shift ? +128 : +1 : clickData.shift ? -128 : -1); - } else { - tStack = GT_Utility.copy(tStack); - if (clickData.mouseButton != 0) tStack.setItemDamage(OreDictionary.WILDCARD_VALUE); - stackGateData(index, tStack); - } - }) - .setBackground(GT_UITextures.BUTTON_STANDARD, GTPP_UITextures.OVERLAY_BUTTON_PLUS_MINUS) - .setPos(7, 5 + i * 18) - .setSize(18, 18)) - .widget( - SlotWidget.phantom(inventoryHandler, i + 1) - .disableInteraction() - .setPos(25, 5 + i * 18)); - } - builder.widget( - new CycleButtonWidget().setToggle(() -> bOutput, val -> bOutput = val) - .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) - .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_EMIT_ENERGY) - .addTooltip("Toggle EU Output") - .setPos(151, 5) - .setSize(18, 18)) - .widget( - new CycleButtonWidget() - .setToggle(() -> getBaseMetaTileEntity().isActive(), val -> getBaseMetaTileEntity().setActive(val)) - .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) - .setStaticTexture(GTPP_UITextures.OVERLAY_BUTTON_ACTIVE_STATE) - .addTooltip("Toggle Active State") - .setPos(151, 23) - .setSize(18, 18)) - .widget(new ButtonWidget().setOnClick((clickData, widget) -> { - if (clickData.mouseButton == 0) switchGateForward(clickData.shift); - else switchGateBackward(clickData.shift); - }) - .setBackground(GT_UITextures.BUTTON_STANDARD, GTPP_UITextures.OVERLAY_BUTTON_CHANGE_MODE) - .addTooltip("Change Redstone Circuit") - .setPos(151, 41) - .setSize(18, 18)); - - builder.widget(new FakeSyncWidget.IntegerSyncer(() -> mGate, val -> mGate = val)); - for (int i = 0; i < mGateData.length; i++) { - final int index = i; - builder.widget(new FakeSyncWidget.IntegerSyncer(() -> mGateData[index], val -> mGateData[index] = val)); - } - - builder.widget(new DrawableWidget().setDrawable(() -> { - if (getBaseMetaTileEntity().getErrorDisplayID() > 0) { - if ((getBaseMetaTileEntity().getTimer() / 5) % 2 == 0) { - return GTPP_UITextures.PICTURE_ELECTRICITY_ERROR; - } else { - return null; - } - } else { - return GTPP_UITextures.PICTURE_ELECTRICITY_FINE; - } - }) - .setPos(140, 9) - .setSize(7, 7)) - .widget( - new FakeSyncWidget.IntegerSyncer( - () -> getBaseMetaTileEntity().getErrorDisplayID(), - val -> getBaseMetaTileEntity().setErrorDisplayID(val))); - - builder.widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) return tCircuit.getName(); - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(46, 8)) - .widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) return tCircuit.getDescription(); - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(46, 19)) - .widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) return tCircuit.getDataDescription(mGateData, 0); - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(46, 33)) - .widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) return tCircuit.getDataDescription(mGateData, 1); - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(46, 44)) - .widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) return tCircuit.getDataDescription(mGateData, 2); - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(46, 55)) - .widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) return tCircuit.getDataDescription(mGateData, 3); - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(46, 66)) - .widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) { - String tString = tCircuit.getDataDisplay(mGateData, 0); - return tString == null ? GT_Utility.parseNumberToString(mGateData[0]) : tString; - } - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(99, 33)) - .widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) { - String tString = tCircuit.getDataDisplay(mGateData, 1); - return tString == null ? GT_Utility.parseNumberToString(mGateData[1]) : tString; - } - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(99, 44)) - .widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) { - String tString = tCircuit.getDataDisplay(mGateData, 2); - return tString == null ? GT_Utility.parseNumberToString(mGateData[2]) : tString; - } - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(99, 55)) - .widget(TextWidget.dynamicString(() -> { - GT_CircuitryBehavior tCircuit = GregTech_API.sCircuitryBehaviors.get(mGate); - if (tCircuit != null) { - String tString = tCircuit.getDataDisplay(mGateData, 3); - return tString == null ? GT_Utility.parseNumberToString(mGateData[3]) : tString; - } - return ""; - }) - .setSynced(false) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setPos(99, 66)); - } -} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneLamp.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneLamp.java deleted file mode 100644 index 06dd76c3f4..0000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneLamp.java +++ /dev/null @@ -1,73 +0,0 @@ -package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.objects.GT_RenderedTexture; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; - -public class GT_MetaTileEntity_RedstoneLamp extends GT_MetaTileEntity_RedstoneBase { - - public byte mRedstoneStrength = 0, mType = 0; - public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[2]; - - static { - sIconList[0] = new CustomIcon("TileEntities/gt4/redstone/Lamp/off"); - sIconList[1] = new CustomIcon("TileEntities/gt4/redstone/Lamp/on"); - } - - public GT_MetaTileEntity_RedstoneLamp(int aID) { - super(aID, "redstone.lamp", "Redstone Controlled Lamp", 0, 0, "Redstone Controlled Lamp"); - } - - public GT_MetaTileEntity_RedstoneLamp(final String aName, String[] aDescription, final ITexture[][][] aTextures) { - super(aName, 0, 0, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneLamp(this.mName, mDescriptionArray, this.mTextures); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) {} - - @Override - public void loadNBTData(NBTTagCompound aNBT) {} - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { - getBaseMetaTileEntity().setLightValue(getBaseMetaTileEntity().getStrongestRedstone()); - getBaseMetaTileEntity().setActive(getBaseMetaTileEntity().getStrongestRedstone() > 0); - } - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getSides(i); - rTextures[1][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, - final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { - return this.mTextures[(aActive ? 1 : 0)][aColorIndex + 1]; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(sIconList[0]) }; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] { new GT_RenderedTexture(sIconList[1]) }; - } -} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthDisplay.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthDisplay.java deleted file mode 100644 index b3b9d0fdcb..0000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthDisplay.java +++ /dev/null @@ -1,139 +0,0 @@ -package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.objects.GT_RenderedTexture; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; - -public class GT_MetaTileEntity_RedstoneStrengthDisplay extends GT_MetaTileEntity_RedstoneBase { - - public byte mRedstoneStrength = 0, mType = 0; - public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[144]; - - static { - for (int i = 0; i < 144; i++) { - sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/Display/" + i); - } - } - - public GT_MetaTileEntity_RedstoneStrengthDisplay(int aID, String aUnlocal, String aLocal, String aDescription) { - super(aID, aUnlocal, aLocal, 5, 0, aDescription); - } - - public GT_MetaTileEntity_RedstoneStrengthDisplay(final String aName, String[] aDescription, - final ITexture[][][] aTextures) { - super(aName, 5, 0, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneStrengthDisplay(this.mName, mDescriptionArray, this.mTextures); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setByte("mRedstoneStrength", mRedstoneStrength); - aNBT.setByte("mType", mType); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - mRedstoneStrength = aNBT.getByte("mRedstoneStrength"); - mType = aNBT.getByte("mType"); - } - - @Override - public void onValueUpdate(byte aValue) { - mRedstoneStrength = (byte) (aValue & 15); - mType = (byte) (aValue >>> 4); - } - - @Override - public byte getUpdateData() { - return (byte) ((mRedstoneStrength & 15) | (mType << 4)); - } - - @Override - public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPreTick(aBaseMetaTileEntity, aTick); - if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { - mRedstoneStrength = getBaseMetaTileEntity().getStrongestRedstone(); - } - } - - @Override - public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (side == getBaseMetaTileEntity().getFrontFacing()) mType = (byte) ((mType + 1) % 6); - } - - @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - final ITexture[][][] rTextures = new ITexture[10][17][]; - for (byte i = -1; i < 16; i++) { - rTextures[0][i + 1] = this.getFront(i); - rTextures[1][i + 1] = this.getSides(i); - rTextures[2][i + 1] = this.getBottom(i); - rTextures[3][i + 1] = this.getTop(i); - rTextures[4][i + 1] = this.getSides(i); - rTextures[5][i + 1] = this.getFront(i); - rTextures[6][i + 1] = this.getSidesActive(i); - rTextures[7][i + 1] = this.getBottomActive(i); - rTextures[8][i + 1] = this.getTopActive(i); - rTextures[9][i + 1] = this.getSidesActive(i); - } - return rTextures; - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, - final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { - if (side == facing) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], - new GT_RenderedTexture(sIconList[mType * 16 + mRedstoneStrength]) }; - } - return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (side == facing ? 0 - : side == facing.getOpposite() ? 1 - : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; - } - - public ITexture[] getFront(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1] }; - } - - public ITexture[] getTop(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Off) }; - } - - public ITexture[] getTopActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Top_On) }; - } - - public ITexture[] getBottom(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Off) }; - } - - public ITexture[] getBottomActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_On) }; - } - - public ITexture[] getSides(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off) }; - } - - public ITexture[] getSidesActive(final byte aColor) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], - new GT_RenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On) }; - } -} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthScale.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthScale.java deleted file mode 100644 index 5821dbab1a..0000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/GT_MetaTileEntity_RedstoneStrengthScale.java +++ /dev/null @@ -1,54 +0,0 @@ -package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.objects.GT_RenderedTexture; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; - -public class GT_MetaTileEntity_RedstoneStrengthScale extends GT_MetaTileEntity_RedstoneStrengthDisplay { - - public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[32]; - - static { - for (int i = 0; i < 32; i++) { - sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/Scale/" + i); - } - } - - public GT_MetaTileEntity_RedstoneStrengthScale(int aID) { - super(aID, "redstone.display.scale", "Redstone Scale", "Redstone Strength on a Scale"); - } - - public GT_MetaTileEntity_RedstoneStrengthScale(final String aName, String[] aDescription, - final ITexture[][][] aTextures) { - super(aName, aDescription, aTextures); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_RedstoneStrengthScale(this.mName, mDescriptionArray, this.mTextures); - } - - @Override - public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (side == getBaseMetaTileEntity().getFrontFacing()) mType = (byte) ((mType + 1) % 2); - } - - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, - final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { - if (side == facing) { - return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], - new GT_RenderedTexture(sIconList[mType * 16 + mRedstoneStrength]) }; - } - return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (side == facing ? 0 - : side == facing.getOpposite() ? 1 - : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; - } -} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneBase.java new file mode 100644 index 0000000000..6da66be563 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneBase.java @@ -0,0 +1,111 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.MTETieredMachineBlock; +import gregtech.api.objects.GTItemStack; +import gtPlusPlus.core.lib.GTPPCore; + +public abstract class MTERedstoneBase extends MTETieredMachineBlock { + + protected int mOpenerCount; + + public MTERedstoneBase(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, + String aDescription, ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); + } + + public MTERedstoneBase(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, + String[] aDescription, ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); + } + + public MTERedstoneBase(String aName, int aTier, int aInvSlotCount, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @Override + public final boolean isSimpleMachine() { + return false; + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GTItemStack aStack) { + return side != getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public final boolean isValidSlot(int aIndex) { + return false; + } + + @Override + public final boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public final boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public abstract void saveNBTData(NBTTagCompound aNBT); + + @Override + public abstract void loadNBTData(NBTTagCompound aNBT); + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + return false; + } + + @Override + public final void onOpenGUI() { + super.onOpenGUI(); + mOpenerCount++; + } + + @Override + public final void onCloseGUI() { + super.onCloseGUI(); + mOpenerCount--; + } + + public boolean hasRedstoneSignal() { + if (getBaseMetaTileEntity().getStrongestRedstone() > 0) { + return true; + } + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + if (getBaseMetaTileEntity().getOutputRedstoneSignal(side) > 0) { + return true; + } + } + return false; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public String[] getDescription() { + return ArrayUtils.add(this.mDescriptionArray, GTPPCore.GT_Tooltip.get()); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneButtonPanel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneButtonPanel.java new file mode 100644 index 0000000000..a83d05f928 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneButtonPanel.java @@ -0,0 +1,204 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GTRenderedTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; + +public class MTERedstoneButtonPanel extends MTERedstoneBase { + + public byte mRedstoneStrength = 0, mType = 0, mUpdate = 0; + + public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[64]; + + static { + for (int i = 0; i < 64; i++) { + sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/ButtonPanel/" + i); + } + } + + public MTERedstoneButtonPanel(int aID) { + super( + aID, + "redstone.button.panel", + "Button Panel", + 5, + 0, + "Right-click with Screwdriver to change Button Design"); + } + + public MTERedstoneButtonPanel(final String aName, String[] aDescription, final ITexture[][][] aTextures) { + super(aName, 5, 0, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTERedstoneButtonPanel(this.mName, mDescriptionArray, this.mTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("mRedstoneStrength", mRedstoneStrength); + aNBT.setByte("mType", mType); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mRedstoneStrength = aNBT.getByte("mRedstoneStrength"); + mType = aNBT.getByte("mType"); + } + + @Override + public void onValueUpdate(byte aValue) { + mRedstoneStrength = (byte) (aValue & 15); + mType = (byte) (aValue >>> 4); + } + + @Override + public byte getUpdateData() { + return (byte) ((mRedstoneStrength & 15) | (mType << 4)); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, + float aX, float aY, float aZ) { + if (side == getBaseMetaTileEntity().getFrontFacing()) { + if (getBaseMetaTileEntity().isServerSide()) { + mUpdate = 2; + switch (mType) { + case 0: + default: + switch (side) { + case DOWN, UP -> mRedstoneStrength = (byte) ((byte) (aX * 4) + 4 * (byte) (aZ * 4)); + case NORTH -> mRedstoneStrength = (byte) ((byte) (4 - aX * 4) + 4 * (byte) (4 - aY * 4)); + case SOUTH -> mRedstoneStrength = (byte) ((byte) (aX * 4) + 4 * (byte) (4 - aY * 4)); + case WEST -> mRedstoneStrength = (byte) ((byte) (aZ * 4) + 4 * (byte) (4 - aY * 4)); + case EAST -> mRedstoneStrength = (byte) ((byte) (4 - aZ * 4) + 4 * (byte) (4 - aY * 4)); + } + break; + case 1: + switch (side) { + case DOWN, UP -> mRedstoneStrength = (byte) (mRedstoneStrength + ^ (1 << (((byte) (aX * 2) + 2 * (byte) (aZ * 2))))); + case NORTH -> mRedstoneStrength = (byte) (mRedstoneStrength + ^ (1 << (((byte) (2 - aX * 2) + 2 * (byte) (2 - aY * 2))))); + case SOUTH -> mRedstoneStrength = (byte) (mRedstoneStrength + ^ (1 << (((byte) (aX * 2) + 2 * (byte) (2 - aY * 2))))); + case WEST -> mRedstoneStrength = (byte) (mRedstoneStrength + ^ (1 << (((byte) (aZ * 2) + 2 * (byte) (2 - aY * 2))))); + case EAST -> mRedstoneStrength = (byte) (mRedstoneStrength + ^ (1 << (((byte) (2 - aZ * 2) + 2 * (byte) (2 - aY * 2))))); + } + break; + case 2: + switch (side) { + case DOWN, UP -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (aZ * 4)))); + case NORTH -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); + case SOUTH -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); + case WEST -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); + case EAST -> mRedstoneStrength = (byte) (mRedstoneStrength ^ (1 << ((byte) (4 - aY * 4)))); + } + break; + } + } + return true; + } + return false; + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (getBaseMetaTileEntity().isServerSide()) { + getBaseMetaTileEntity().setGenericRedstoneOutput(true); + if (mUpdate > 0) { + mUpdate--; + } else if (getBaseMetaTileEntity().isAllowedToWork()) { + mRedstoneStrength = 0; + } + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + getBaseMetaTileEntity().setStrongOutputRedstoneSignal( + side, + side == getBaseMetaTileEntity().getFrontFacing() ? (byte) 0 : mRedstoneStrength); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal( + side, + side == getBaseMetaTileEntity().getFrontFacing() ? (byte) 0 : mRedstoneStrength); + } + } + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (side == getBaseMetaTileEntity().getFrontFacing()) mType = (byte) ((mType + 1) % 3); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getSides(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getSidesActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == facing) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], + new GTRenderedTexture(sIconList[mType * 16 + mRedstoneStrength]) }; + } + return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1] }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Main_Off) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Main_On) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Main_Off) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Main_On) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Main_Off) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Main_On) }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java new file mode 100644 index 0000000000..20cd569e24 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java @@ -0,0 +1,652 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; + +import gregtech.api.GregTechAPI; +import gregtech.api.enums.GTValues; +import gregtech.api.gui.modularui.GTUIInfos; +import gregtech.api.gui.modularui.GTUITextures; +import gregtech.api.interfaces.IRedstoneCircuitBlock; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GTItemStack; +import gregtech.api.objects.GTRenderedTexture; +import gregtech.api.util.CircuitryBehavior; +import gregtech.api.util.CoverBehavior; +import gregtech.api.util.GTLog; +import gregtech.api.util.GTUtility; +import gregtech.api.util.ISerializableObject; +import gtPlusPlus.xmod.gregtech.api.gui.GTPPUITextures; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class MTERedstoneCircuitBlock extends MTERedstoneBase implements IRedstoneCircuitBlock, IAddUIWidgets { + + public int mGate = 0, mGateData[] = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; + public boolean bOutput = true; + + public MTERedstoneCircuitBlock(int aID) { + super(aID, "redstone.circuit", "Redstone Circuit Block", 1, 5, "Computes Redstone"); + } + + public MTERedstoneCircuitBlock(final String aName, String[] aDescription, final ITexture[][][] aTextures) { + super(aName, 1, 5, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTERedstoneCircuitBlock(this.mName, mDescriptionArray, this.mTextures); + } + + @Override + public boolean hasSidedRedstoneOutputBehavior() { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isInputFacing(ForgeDirection side) { + return !this.isOutputFacing(side); + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isPneumatic() { + return false; + } + + @Override + public boolean isSteampowered() { + return false; + } + + @Override + public boolean isOutputFacing(ForgeDirection side) { + return side == this.getOutputFacing(); + } + + @Override + public long getMinimumStoredEU() { + return 512; + } + + @Override + public long maxEUInput() { + return GTValues.V[1]; + } + + @Override + public long maxEUOutput() { + return bOutput ? GTValues.V[1] : 0; + } + + @Override + public long maxAmperesIn() { + return 2; + } + + @Override + public long maxAmperesOut() { + return 1; + } + + @Override + public int getSizeInventory() { + return 5; + } + + @Override + public long maxEUStore() { + return GTValues.V[3] * 1024; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + GTUIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mGate", mGate); + aNBT.setIntArray("mGateData", mGateData); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mGate = aNBT.getInteger("mGate"); + mGateData = aNBT.getIntArray("mGateData"); + if (mGateData.length != 8) mGateData = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; + } + + public void switchGateForward(boolean aShift) { + try { + Set tKeys = GregTechAPI.sCircuitryBehaviors.keySet(); + ArrayList tList = new ArrayList<>(); + tList.addAll(tKeys); + if (tList.size() <= 0) return; + Collections.sort(tList); + if (!GregTechAPI.sCircuitryBehaviors.containsKey(mGate)) mGate = tList.get(0); + int tIndex = Collections.binarySearch(tList, mGate); + tIndex += aShift ? 16 : 1; + while (tIndex >= tList.size()) tIndex -= tList.size(); + mGate = tList.get(tIndex); + switchGate(); + } catch (Throwable e) { + GTLog.err.print(e); + } + } + + public void switchGateBackward(boolean aShift) { + try { + Set tKeys = GregTechAPI.sCircuitryBehaviors.keySet(); + ArrayList tList = new ArrayList<>(); + tList.addAll(tKeys); + if (tList.size() <= 0) return; + Collections.sort(tList); + if (!GregTechAPI.sCircuitryBehaviors.containsKey(mGate)) mGate = tList.get(0); + int tIndex = Collections.binarySearch(tList, mGate); + tIndex -= aShift ? 16 : 1; + while (tIndex < 0) tIndex += tList.size(); + mGate = tList.get(tIndex); + switchGate(); + } catch (Throwable e) { + GTLog.err.print(e); + } + } + + @Override + public void onFacingChange() { + resetRedstone(); + } + + private void resetRedstone() { + getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.DOWN, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.UP, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.NORTH, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.SOUTH, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.WEST, (byte) 0); + getBaseMetaTileEntity().setInternalOutputRedstoneSignal(ForgeDirection.EAST, (byte) 0); + } + + public void changeGateData(int aIndex, int aValue) { + mGateData[aIndex] += aValue; + validateGateData(); + } + + public void stackGateData(int aIndex, ItemStack aStack) { + mGateData[aIndex] = GTUtility.stackToInt(aStack); + validateGateData(); + } + + private void switchGate() { + resetRedstone(); + Arrays.fill(mGateData, 0); + CircuitryBehavior tBehaviour = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tBehaviour != null) try { + tBehaviour.initParameters(mGateData, this); + } catch (Throwable e) { + GTLog.err.print(e); + } + validateGateData(); + } + + private void validateGateData() { + CircuitryBehavior tBehaviour = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tBehaviour != null) try { + tBehaviour.validateParameters(mGateData, this); + } catch (Throwable e) { + GTLog.err.print(e); + } + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + getBaseMetaTileEntity().setGenericRedstoneOutput(true); + validateGateData(); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + getBaseMetaTileEntity().setGenericRedstoneOutput(true); + if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { + mInventory[0] = mInventory[1] = mInventory[2] = mInventory[3] = mInventory[4] = null; + if (getBaseMetaTileEntity().getUniversalEnergyStored() >= getMinimumStoredEU()) { + if (getBaseMetaTileEntity().isActive()) { + CircuitryBehavior tBehaviour = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tBehaviour != null) { + try { + tBehaviour.onTick(mGateData, this); + if (tBehaviour.displayItemStack(mGateData, this, 0)) + mInventory[1] = getCoverByID(mGateData[0]); + if (tBehaviour.displayItemStack(mGateData, this, 1)) + mInventory[2] = getCoverByID(mGateData[1]); + if (tBehaviour.displayItemStack(mGateData, this, 2)) + mInventory[3] = getCoverByID(mGateData[2]); + if (tBehaviour.displayItemStack(mGateData, this, 3)) + mInventory[4] = getCoverByID(mGateData[3]); + } catch (Throwable e) { + GTLog.err.print(e); + } + } + } + getBaseMetaTileEntity().setErrorDisplayID(0); + } else { + getBaseMetaTileEntity().setErrorDisplayID(1); + } + } + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + // Only Calc server-side + if (!this.getBaseMetaTileEntity() + .isServerSide()) { + return; + } + // Emit Redstone + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + byte aRedstone = getBaseMetaTileEntity().getOutputRedstoneSignal(side); + this.getBaseMetaTileEntity() + .setInternalOutputRedstoneSignal(side, aRedstone); + } + } + + @Override + public final boolean hasRedstoneSignal() { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + if (getBaseMetaTileEntity().getOutputRedstoneSignal(side) > 0) { + return true; + } + } + return false; + } + + @Override + public boolean allowGeneralRedstoneOutput() { + return true; + } + + /** The Item List for Covers */ + public static final Map sCoversItems = new HashMap<>(); + + private static void initCovers() { + for (GTItemStack aKey : GregTechAPI.sCovers.keySet()) { + ItemStack aStack = aKey.toStack() + .copy(); + if (aStack != null) { + sCoversItems.put(GTUtility.stackToInt(aStack), aStack); + } + } + } + + public static ItemStack getCoverByID(int aStack) { + if (sCoversItems.isEmpty()) { + initCovers(); + } + return sCoversItems.get(Integer.valueOf(aStack)); + } + + @Override + public ForgeDirection getOutputFacing() { + return getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean setRedstone(byte aStrength, ForgeDirection side) { + if (getOutputRedstone(side) != aStrength) { + if (getBaseMetaTileEntity().decreaseStoredEnergyUnits(1, false)) { + getBaseMetaTileEntity().setInternalOutputRedstoneSignal(side, aStrength); + getBaseMetaTileEntity().setErrorDisplayID(0); + return true; + } else { + getBaseMetaTileEntity().setErrorDisplayID(1); + return false; + } + } + return false; + } + + /* + * @Override public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { if (aSide == + * getOutputFacing()) { if (side == ForgeDirection.DOWN) return aRedstone ? 56 : 54; if (side == ForgeDirection.UP) + * return aRedstone ? 53 : 52; return aRedstone ? 94 : 93; } if (side == ForgeDirection.DOWN) return aRedstone ? 60 + * : 59; if (side == ForgeDirection.UP) return aRedstone ? 58 : 57; return aRedstone ? 62 : 61; } + */ + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + public byte getOutputRedstone(ForgeDirection side) { + return getBaseMetaTileEntity().getOutputRedstoneSignal(side); + } + + @Override + public byte getInputRedstone(ForgeDirection side) { + return getBaseMetaTileEntity().getInternalInputRedstoneSignal(side); + } + + @Override + public Block getBlockAtSide(ForgeDirection side) { + return getBaseMetaTileEntity().getBlockAtSide(side); + } + + @Override + public byte getMetaIDAtSide(ForgeDirection side) { + return getBaseMetaTileEntity().getMetaIDAtSide(side); + } + + @Override + public TileEntity getTileEntityAtSide(ForgeDirection side) { + return getBaseMetaTileEntity().getTileEntityAtSide(side); + } + + @Override + public int getRandom(int aRange) { + return getBaseMetaTileEntity().getRandomNumber(aRange); + } + + @Override + public CoverBehavior getCover(ForgeDirection side) { + return (CoverBehavior) getBaseMetaTileEntity().getCoverBehaviorAtSideNew(side); + } + + @Override + public int getCoverID(ForgeDirection side) { + return getBaseMetaTileEntity().getCoverIDAtSide(side); + } + + @Override + public int getCoverVariable(ForgeDirection side) { + return ((ISerializableObject.LegacyCoverData) getBaseMetaTileEntity().getComplexCoverDataAtSide(side)).get(); + } + + @Override + public ICoverable getOwnTileEntity() { + return getBaseMetaTileEntity(); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getSides(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getSidesActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + private GTRenderedTexture getBase() { + return new GTRenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { getBase(), new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Off) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { getBase(), new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Top_On) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { getBase(), new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off), + new GTRenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red) }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { getBase(), new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On), + new GTRenderedTexture(TexturesGtBlock.Casing_InventoryManagaer_Red_Redstone) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { getBase(), new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Off) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { getBase(), new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_On) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { getBase(), new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { getBase(), new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On) }; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + new DrawableWidget().setDrawable(GTPPUITextures.PICTURE_REDSTONE_CIRCUIT_SCREEN) + .setPos(43, 5) + .setSize(108, 72)); + for (int i = 0; i < 4; i++) { + final int index = i; + builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> { + ItemStack tStack = widget.getContext() + .getPlayer().inventory.getItemStack(); + if (tStack == null) { + changeGateData( + index, + clickData.mouseButton == 0 ? clickData.shift ? +128 : +1 : clickData.shift ? -128 : -1); + } else { + tStack = GTUtility.copy(tStack); + if (clickData.mouseButton != 0) tStack.setItemDamage(OreDictionary.WILDCARD_VALUE); + stackGateData(index, tStack); + } + }) + .setBackground(GTUITextures.BUTTON_STANDARD, GTPPUITextures.OVERLAY_BUTTON_PLUS_MINUS) + .setPos(7, 5 + i * 18) + .setSize(18, 18)) + .widget( + SlotWidget.phantom(inventoryHandler, i + 1) + .disableInteraction() + .setPos(25, 5 + i * 18)); + } + builder.widget( + new CycleButtonWidget().setToggle(() -> bOutput, val -> bOutput = val) + .setVariableBackground(GTUITextures.BUTTON_STANDARD_TOGGLE) + .setStaticTexture(GTUITextures.OVERLAY_BUTTON_EMIT_ENERGY) + .addTooltip("Toggle EU Output") + .setPos(151, 5) + .setSize(18, 18)) + .widget( + new CycleButtonWidget() + .setToggle(() -> getBaseMetaTileEntity().isActive(), val -> getBaseMetaTileEntity().setActive(val)) + .setVariableBackground(GTUITextures.BUTTON_STANDARD_TOGGLE) + .setStaticTexture(GTPPUITextures.OVERLAY_BUTTON_ACTIVE_STATE) + .addTooltip("Toggle Active State") + .setPos(151, 23) + .setSize(18, 18)) + .widget(new ButtonWidget().setOnClick((clickData, widget) -> { + if (clickData.mouseButton == 0) switchGateForward(clickData.shift); + else switchGateBackward(clickData.shift); + }) + .setBackground(GTUITextures.BUTTON_STANDARD, GTPPUITextures.OVERLAY_BUTTON_CHANGE_MODE) + .addTooltip("Change Redstone Circuit") + .setPos(151, 41) + .setSize(18, 18)); + + builder.widget(new FakeSyncWidget.IntegerSyncer(() -> mGate, val -> mGate = val)); + for (int i = 0; i < mGateData.length; i++) { + final int index = i; + builder.widget(new FakeSyncWidget.IntegerSyncer(() -> mGateData[index], val -> mGateData[index] = val)); + } + + builder.widget(new DrawableWidget().setDrawable(() -> { + if (getBaseMetaTileEntity().getErrorDisplayID() > 0) { + if ((getBaseMetaTileEntity().getTimer() / 5) % 2 == 0) { + return GTPPUITextures.PICTURE_ELECTRICITY_ERROR; + } else { + return null; + } + } else { + return GTPPUITextures.PICTURE_ELECTRICITY_FINE; + } + }) + .setPos(140, 9) + .setSize(7, 7)) + .widget( + new FakeSyncWidget.IntegerSyncer( + () -> getBaseMetaTileEntity().getErrorDisplayID(), + val -> getBaseMetaTileEntity().setErrorDisplayID(val))); + + builder.widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) return tCircuit.getName(); + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 8)) + .widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) return tCircuit.getDescription(); + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 19)) + .widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) return tCircuit.getDataDescription(mGateData, 0); + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 33)) + .widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) return tCircuit.getDataDescription(mGateData, 1); + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 44)) + .widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) return tCircuit.getDataDescription(mGateData, 2); + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 55)) + .widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) return tCircuit.getDataDescription(mGateData, 3); + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 66)) + .widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) { + String tString = tCircuit.getDataDisplay(mGateData, 0); + return tString == null ? GTUtility.parseNumberToString(mGateData[0]) : tString; + } + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(99, 33)) + .widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) { + String tString = tCircuit.getDataDisplay(mGateData, 1); + return tString == null ? GTUtility.parseNumberToString(mGateData[1]) : tString; + } + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(99, 44)) + .widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) { + String tString = tCircuit.getDataDisplay(mGateData, 2); + return tString == null ? GTUtility.parseNumberToString(mGateData[2]) : tString; + } + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(99, 55)) + .widget(TextWidget.dynamicString(() -> { + CircuitryBehavior tCircuit = GregTechAPI.sCircuitryBehaviors.get(mGate); + if (tCircuit != null) { + String tString = tCircuit.getDataDisplay(mGateData, 3); + return tString == null ? GTUtility.parseNumberToString(mGateData[3]) : tString; + } + return ""; + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(99, 66)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneLamp.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneLamp.java new file mode 100644 index 0000000000..7b963d3c7d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneLamp.java @@ -0,0 +1,73 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GTRenderedTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; + +public class MTERedstoneLamp extends MTERedstoneBase { + + public byte mRedstoneStrength = 0, mType = 0; + public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[2]; + + static { + sIconList[0] = new CustomIcon("TileEntities/gt4/redstone/Lamp/off"); + sIconList[1] = new CustomIcon("TileEntities/gt4/redstone/Lamp/on"); + } + + public MTERedstoneLamp(int aID) { + super(aID, "redstone.lamp", "Redstone Controlled Lamp", 0, 0, "Redstone Controlled Lamp"); + } + + public MTERedstoneLamp(final String aName, String[] aDescription, final ITexture[][][] aTextures) { + super(aName, 0, 0, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTERedstoneLamp(this.mName, mDescriptionArray, this.mTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) {} + + @Override + public void loadNBTData(NBTTagCompound aNBT) {} + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { + getBaseMetaTileEntity().setLightValue(getBaseMetaTileEntity().getStrongestRedstone()); + getBaseMetaTileEntity().setActive(getBaseMetaTileEntity().getStrongestRedstone() > 0); + } + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getSides(i); + rTextures[1][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 1 : 0)][aColorIndex + 1]; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { new GTRenderedTexture(sIconList[0]) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { new GTRenderedTexture(sIconList[1]) }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneStrengthDisplay.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneStrengthDisplay.java new file mode 100644 index 0000000000..c2591c6a41 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneStrengthDisplay.java @@ -0,0 +1,138 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GTRenderedTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; + +public class MTERedstoneStrengthDisplay extends MTERedstoneBase { + + public byte mRedstoneStrength = 0, mType = 0; + public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[144]; + + static { + for (int i = 0; i < 144; i++) { + sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/Display/" + i); + } + } + + public MTERedstoneStrengthDisplay(int aID, String aUnlocal, String aLocal, String aDescription) { + super(aID, aUnlocal, aLocal, 5, 0, aDescription); + } + + public MTERedstoneStrengthDisplay(final String aName, String[] aDescription, final ITexture[][][] aTextures) { + super(aName, 5, 0, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTERedstoneStrengthDisplay(this.mName, mDescriptionArray, this.mTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("mRedstoneStrength", mRedstoneStrength); + aNBT.setByte("mType", mType); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mRedstoneStrength = aNBT.getByte("mRedstoneStrength"); + mType = aNBT.getByte("mType"); + } + + @Override + public void onValueUpdate(byte aValue) { + mRedstoneStrength = (byte) (aValue & 15); + mType = (byte) (aValue >>> 4); + } + + @Override + public byte getUpdateData() { + return (byte) ((mRedstoneStrength & 15) | (mType << 4)); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide()) { + mRedstoneStrength = getBaseMetaTileEntity().getStrongestRedstone(); + } + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (side == getBaseMetaTileEntity().getFrontFacing()) mType = (byte) ((mType + 1) % 6); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getSides(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getSidesActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == facing) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], + new GTRenderedTexture(sIconList[mType * 16 + mRedstoneStrength]) }; + } + return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1] }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Top_Off) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Top_On) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_Off) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Bottom_On) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Side_Off) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GTRenderedTexture(TexturesGtBlock.Casing_Redstone_Side_On) }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneStrengthScale.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneStrengthScale.java new file mode 100644 index 0000000000..e59500dcc0 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneStrengthScale.java @@ -0,0 +1,53 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.redstone; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GTRenderedTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; + +public class MTERedstoneStrengthScale extends MTERedstoneStrengthDisplay { + + public static TexturesGtBlock.CustomIcon[] sIconList = new TexturesGtBlock.CustomIcon[32]; + + static { + for (int i = 0; i < 32; i++) { + sIconList[i] = new CustomIcon("TileEntities/gt4/redstone/Scale/" + i); + } + } + + public MTERedstoneStrengthScale(int aID) { + super(aID, "redstone.display.scale", "Redstone Scale", "Redstone Strength on a Scale"); + } + + public MTERedstoneStrengthScale(final String aName, String[] aDescription, final ITexture[][][] aTextures) { + super(aName, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTERedstoneStrengthScale(this.mName, mDescriptionArray, this.mTextures); + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (side == getBaseMetaTileEntity().getFrontFacing()) mType = (byte) ((mType + 1) % 2); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == facing) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], + new GTRenderedTexture(sIconList[mType * 16 + mRedstoneStrength]) }; + } + return this.mTextures[(aActive || hasRedstoneSignal() ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } +} -- cgit