diff options
author | NotAPenguin <michiel.vandeginste@gmail.com> | 2024-09-02 23:17:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-02 23:17:17 +0200 |
commit | 1b820de08a05070909a267e17f033fcf58ac8710 (patch) | |
tree | 02831a025986a06b20f87e5bcc69d1e0c639a342 /src/main/java/gregtech/common/covers/redstone/CoverAdvancedRedstoneTransmitterBase.java | |
parent | afd3fd92b6a6ab9ab0d0dc3214e6bc8ff7a86c9b (diff) | |
download | GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.tar.gz GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.tar.bz2 GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.zip |
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
Diffstat (limited to 'src/main/java/gregtech/common/covers/redstone/CoverAdvancedRedstoneTransmitterBase.java')
-rw-r--r-- | src/main/java/gregtech/common/covers/redstone/CoverAdvancedRedstoneTransmitterBase.java | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/src/main/java/gregtech/common/covers/redstone/CoverAdvancedRedstoneTransmitterBase.java b/src/main/java/gregtech/common/covers/redstone/CoverAdvancedRedstoneTransmitterBase.java new file mode 100644 index 0000000000..cfa5461305 --- /dev/null +++ b/src/main/java/gregtech/common/covers/redstone/CoverAdvancedRedstoneTransmitterBase.java @@ -0,0 +1,188 @@ +package gregtech.common.covers.redstone; + +import java.util.Objects; +import java.util.UUID; + +import javax.annotation.Nonnull; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import com.google.common.io.ByteArrayDataInput; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; + +import gregtech.api.gui.modularui.CoverUIBuildContext; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.util.GTUtility; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollowerToggleButtonWidget; +import io.netty.buffer.ByteBuf; + +public abstract class CoverAdvancedRedstoneTransmitterBase<T extends CoverAdvancedRedstoneTransmitterBase.TransmitterData> + extends CoverAdvancedWirelessRedstoneBase<T> { + + public CoverAdvancedRedstoneTransmitterBase(Class<T> typeToken, ITexture coverTexture) { + super(typeToken, coverTexture); + } + + private static void unregisterSignal(ForgeDirection side, TransmitterData aCoverVariable, ICoverable aTileEntity) { + final long hash = hashCoverCoords(aTileEntity, side); + removeSignalAt(aCoverVariable.uuid, aCoverVariable.frequency, hash); + } + + @Override + public boolean onCoverRemovalImpl(ForgeDirection side, int aCoverID, TransmitterData aCoverVariable, + ICoverable aTileEntity, boolean aForced) { + unregisterSignal(side, aCoverVariable, aTileEntity); + return true; + } + + @Override + protected void onBaseTEDestroyedImpl(ForgeDirection side, int aCoverID, TransmitterData aCoverVariable, + ICoverable aTileEntity) { + unregisterSignal(side, aCoverVariable, aTileEntity); + } + + @Override + protected T onCoverScrewdriverClickImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity, + EntityPlayer aPlayer, float aX, float aY, float aZ) { + aCoverVariable.invert = !aCoverVariable.invert; + GTUtility.sendChatToPlayer( + aPlayer, + aCoverVariable.invert ? GTUtility.trans("054", "Inverted") : GTUtility.trans("055", "Normal")); + + return aCoverVariable; + } + + @Override + protected void preDataChangedImpl(ForgeDirection side, int aCoverID, int aNewCoverId, T aCoverVariable, + T aNewCoverVariable, ICoverable aTileEntity) { + if (aCoverVariable.frequency != aNewCoverVariable.frequency + || !Objects.equals(aCoverVariable.uuid, aNewCoverVariable.uuid)) { + unregisterSignal(side, aCoverVariable, aTileEntity); + } + } + + public static class TransmitterData extends CoverAdvancedWirelessRedstoneBase.WirelessData { + + protected boolean invert; + + public TransmitterData(int frequency, UUID uuid, boolean invert) { + super(frequency, uuid); + this.invert = invert; + } + + public TransmitterData() { + this(0, null, false); + } + + public boolean isInvert() { + return invert; + } + + @Nonnull + @Override + public ISerializableObject copy() { + return new TransmitterData(frequency, uuid, invert); + } + + @Nonnull + @Override + public NBTBase saveDataToNBT() { + NBTTagCompound tag = (NBTTagCompound) super.saveDataToNBT(); + tag.setBoolean("invert", invert); + + return tag; + } + + @Override + public void writeToByteBuf(ByteBuf aBuf) { + super.writeToByteBuf(aBuf); + aBuf.writeBoolean(invert); + } + + @Override + public void loadDataFromNBT(NBTBase aNBT) { + super.loadDataFromNBT(aNBT); + + NBTTagCompound tag = (NBTTagCompound) aNBT; + invert = tag.getBoolean("invert"); + } + + @Nonnull + @Override + public ISerializableObject readFromPacket(ByteArrayDataInput aBuf, EntityPlayerMP aPlayer) { + super.readFromPacket(aBuf, aPlayer); + invert = aBuf.readBoolean(); + + return this; + } + } + + // GUI stuff + + @Override + public ModularWindow createWindow(CoverUIBuildContext buildContext) { + return new AdvancedRedstoneTransmitterBaseUIFactory(buildContext).createWindow(); + } + + protected class AdvancedRedstoneTransmitterBaseUIFactory extends AdvancedWirelessRedstoneBaseUIFactory { + + public AdvancedRedstoneTransmitterBaseUIFactory(CoverUIBuildContext buildContext) { + super(buildContext); + } + + @Override + protected int getFrequencyRow() { + return 0; + } + + @Override + protected int getButtonRow() { + return 1; + } + + @Override + protected boolean isShiftPrivateLeft() { + return true; + } + + @Override + protected void addUIWidgets(ModularWindow.Builder builder) { + super.addUIWidgets(builder); + builder.widget(TextWidget.dynamicString(() -> { + T coverData = getCoverData(); + if (coverData != null) { + return getCoverData().invert ? GTUtility.trans("INVERTED", "Inverted") + : GTUtility.trans("NORMAL", "Normal"); + } else { + return ""; + } + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 10, 4 + startY + spaceY * getButtonRow())); + } + + @Override + protected void addUIForDataController(CoverDataControllerWidget<T> controller) { + super.addUIForDataController(controller); + controller.addFollower( + CoverDataFollowerToggleButtonWidget.ofRedstone(), + coverData -> coverData.invert, + (coverData, state) -> { + coverData.invert = state; + return coverData; + }, + widget -> widget.addTooltip(0, GTUtility.trans("NORMAL", "Normal")) + .addTooltip(1, GTUtility.trans("INVERTED", "Inverted")) + .setPos(spaceX * 9, spaceY * getButtonRow())); + } + } +} |