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/gtPlusPlus/xmod/gregtech/common/covers/CoverToggleVisual.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/gtPlusPlus/xmod/gregtech/common/covers/CoverToggleVisual.java')
-rw-r--r-- | src/main/java/gtPlusPlus/xmod/gregtech/common/covers/CoverToggleVisual.java | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/CoverToggleVisual.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/CoverToggleVisual.java new file mode 100644 index 0000000000..2ba532d11f --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/CoverToggleVisual.java @@ -0,0 +1,184 @@ +package gtPlusPlus.xmod.gregtech.common.covers; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; + +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.XSTR; +import gregtech.api.util.CoverBehavior; +import gregtech.api.util.GTUtility; +import gregtech.api.util.ISerializableObject; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.minecraft.PlayerUtils; + +public class CoverToggleVisual extends CoverBehavior { + + private static final Map<String, Integer> sConnectionStateForEntityMap = new ConcurrentHashMap<>(); + private static final Map<String, String> sPrefixMap = new ConcurrentHashMap<>(); + private static final int VALUE_OFF = 0; + private static final int VALUE_ON = 1; + + public static String generateUniqueKey(ForgeDirection side, ICoverable aEntity) { + try { + BlockPos aPos = new BlockPos( + aEntity.getIGregTechTileEntity(aEntity.getXCoord(), aEntity.getYCoord(), aEntity.getZCoord())); + + String s = aEntity.getInventoryName() + "." + aPos.getUniqueIdentifier() + side.name(); + return s; + } catch (Throwable t) {} + XSTR x = new XSTR(); + return "ERROR." + x.getSeed() + x.hashCode() + x.nextDouble() + ".ID"; + } + + public boolean onCoverRightclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + EntityPlayer aPlayer, float aX, float aY, float aZ) { + PlayerUtils + .messagePlayer(aPlayer, GTUtility.trans("756", "Connectable: ") + getConnectionState(aCoverVariable)); + return super.onCoverRightclick(side, aCoverID, aCoverVariable, aTileEntity, aPlayer, aX, aY, aZ); + } + + public int onCoverScrewdriverclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + EntityPlayer aPlayer, float aX, float aY, float aZ) { + return super.onCoverScrewdriverclick(side, aCoverID, aCoverVariable, aTileEntity, aPlayer, aX, aY, aZ); + } + + public boolean letsEnergyIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsEnergyOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsFluidIn(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid, + ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsFluidOut(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid, + ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsItemsIn(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot, + ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsItemsOut(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot, + ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return 1; + } + + @Override + public int doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, + ICoverable aTileEntity, long aTimer) { + try { + String aKey = generateUniqueKey(side, aTileEntity); + Integer b = sConnectionStateForEntityMap.get(aKey); + // Logger.INFO("Val: "+aCoverVariable); + if (b != null && aCoverVariable != b) { + aCoverVariable = b; + } + if (b == null) { + b = aCoverVariable; + sConnectionStateForEntityMap.put(aKey, b); + trySetState(side, b == VALUE_ON ? VALUE_ON : VALUE_OFF, aTileEntity); + } + } catch (Throwable t) { + + } + return aCoverVariable; + } + + @Override + public boolean letsRedstoneGoIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + @Override + public boolean letsRedstoneGoOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + @Override + public boolean alwaysLookConnected(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return super.alwaysLookConnected(side, aCoverID, aCoverVariable, aTileEntity); + } + + @Override + public byte getRedstoneInput(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, + ICoverable aTileEntity) { + if (!getConnectionState(aCoverVariable)) { + return 0; + } + return super.getRedstoneInput(side, aInputRedstone, aCoverID, aCoverVariable, aTileEntity); + } + + @Override + public void placeCover(ForgeDirection side, ItemStack aCover, ICoverable aTileEntity) { + String aKey = generateUniqueKey(side, aTileEntity); + boolean state = getCoverConnections(aCover); + sPrefixMap.put(aKey, aCover.getUnlocalizedName()); + Logger.INFO("Mapping key " + aKey + " to " + state); + sConnectionStateForEntityMap.put(aKey, state ? VALUE_ON : VALUE_OFF); + Logger.INFO("Key Value: " + (state ? VALUE_ON : VALUE_OFF)); + // Try set cover state directly + // trySetState(aSide, state ? VALUE_ON : VALUE_OFF, aTileEntity); + super.placeCover(side, aCover, aTileEntity); + } + + @Override + public boolean onCoverRemoval(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + boolean aForced) { + String aKey = generateUniqueKey(side, aTileEntity); + sConnectionStateForEntityMap.remove(aKey); + // Logger.INFO("Unmapping key "+aKey+"."); + return true; + } + + public static boolean getConnectionState(int aCoverVar) { + return aCoverVar == VALUE_ON; + } + + private static void trySetState(ForgeDirection side, int aState, ICoverable aTile) { + // Try set cover state directly + if (aTile instanceof IGregTechTileEntity gTileEntity) { + gTileEntity.setCoverDataAtSide(side, new ISerializableObject.LegacyCoverData(aState)); + } + } + + public static boolean getConnectionState(ForgeDirection side, ICoverable aTile) { + String aKey = generateUniqueKey(side, aTile); + return getConnectionState(aKey); + } + + public static boolean getConnectionState(String aKey) { + Integer b = sConnectionStateForEntityMap.get(aKey); + // Logger.INFO("Get State: "+b+" | "+aKey); + return b != null ? b == VALUE_ON : false; + } + + public static final boolean getCoverConnections(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("CustomCoverMeta"); + if (aNBT != null) { + return aNBT.getBoolean("AllowConnections"); + } + } + return false; + } +} |