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 --- .../GT_MetaTileEntity_AdvSeismicProspector.java | 309 ---- .../basic/GT_MetaTileEntity_BetterJukebox.java | 702 --------- .../basic/GT_MetaTileEntity_Boxinator.java | 229 --- .../machines/basic/GT_MetaTileEntity_Charger.java | 110 -- .../basic/GT_MetaTileEntity_IndustrialApiary.java | 1555 -------------------- .../basic/GT_MetaTileEntity_Massfabricator.java | 241 --- ..._MetaTileEntity_MicrowaveEnergyTransmitter.java | 495 ------- .../machines/basic/GT_MetaTileEntity_Miner.java | 407 ----- .../basic/GT_MetaTileEntity_MonsterRepellent.java | 182 --- .../basic/GT_MetaTileEntity_PotionBrewer.java | 225 --- .../machines/basic/GT_MetaTileEntity_Pump.java | 846 ----------- .../basic/GT_MetaTileEntity_Replicator.java | 130 -- .../basic/GT_MetaTileEntity_RockBreaker.java | 169 --- .../machines/basic/GT_MetaTileEntity_Scanner.java | 425 ------ .../basic/GT_MetaTileEntity_Teleporter.java | 601 -------- .../basic/GT_MetaTileEntity_TurboCharger.java | 146 -- .../basic/GT_MetaTileEntity_WorldAccelerator.java | 470 ------ .../machines/basic/MTEAdvSeismicProspector.java | 307 ++++ .../machines/basic/MTEBetterJukebox.java | 701 +++++++++ .../tileentities/machines/basic/MTEBoxinator.java | 231 +++ .../tileentities/machines/basic/MTECharger.java | 107 ++ .../machines/basic/MTEIndustrialApiary.java | 1554 +++++++++++++++++++ .../machines/basic/MTEMassfabricator.java | 241 +++ .../basic/MTEMicrowaveEnergyTransmitter.java | 474 ++++++ .../tileentities/machines/basic/MTEMiner.java | 406 +++++ .../machines/basic/MTEMonsterRepellent.java | 182 +++ .../machines/basic/MTEPotionBrewer.java | 224 +++ .../tileentities/machines/basic/MTEPump.java | 846 +++++++++++ .../tileentities/machines/basic/MTEReplicator.java | 130 ++ .../machines/basic/MTERockBreaker.java | 169 +++ .../tileentities/machines/basic/MTEScanner.java | 425 ++++++ .../tileentities/machines/basic/MTETeleporter.java | 586 ++++++++ .../machines/basic/MTETurboCharger.java | 145 ++ .../machines/basic/MTEWorldAccelerator.java | 470 ++++++ 34 files changed, 7198 insertions(+), 7242 deletions(-) delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_BetterJukebox.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Boxinator.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Charger.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_IndustrialApiary.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MonsterRepellent.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_PotionBrewer.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Replicator.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_RockBreaker.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Scanner.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Teleporter.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_TurboCharger.java delete mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_WorldAccelerator.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEAdvSeismicProspector.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEBetterJukebox.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEBoxinator.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTECharger.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEIndustrialApiary.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEMassfabricator.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEMicrowaveEnergyTransmitter.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEMiner.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEMonsterRepellent.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEPotionBrewer.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEPump.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEReplicator.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTERockBreaker.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEScanner.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTETeleporter.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTETurboCharger.java create mode 100644 src/main/java/gregtech/common/tileentities/machines/basic/MTEWorldAccelerator.java (limited to 'src/main/java/gregtech/common/tileentities/machines/basic') diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java deleted file mode 100644 index 78ed9982fc..0000000000 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java +++ /dev/null @@ -1,309 +0,0 @@ -package gregtech.common.tileentities.machines.basic; - -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER_ACTIVE; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER_ACTIVE_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SIDE_ROCK_BREAKER; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SIDE_ROCK_BREAKER_ACTIVE; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SIDE_ROCK_BREAKER_ACTIVE_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SIDE_ROCK_BREAKER_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER_ACTIVE; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER_ACTIVE_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER_GLOW; -import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.ChunkCoordIntPair; -import net.minecraft.world.chunk.Chunk; -import net.minecraftforge.fluids.FluidStack; - -import gregtech.api.GregTech_API; -import gregtech.api.enums.ItemList; -import gregtech.api.enums.Materials; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; -import gregtech.api.objects.ItemData; -import gregtech.api.render.TextureFactory; -import gregtech.api.util.GT_OreDictUnificator; -import gregtech.api.util.GT_Utility; -import gregtech.common.blocks.GT_Block_Ores_Abstract; -import gregtech.common.blocks.GT_TileEntity_Ores; -import ic2.core.Ic2Items; - -public class GT_MetaTileEntity_AdvSeismicProspector extends GT_MetaTileEntity_BasicMachine { - - boolean ready = false; - final int radius; - final int step; - int cX; - int cZ; - - public GT_MetaTileEntity_AdvSeismicProspector(int aID, String aName, String aNameRegional, int aTier, int aRadius, - int aStep) { - super( - aID, - aName, - aNameRegional, - aTier, - 1, // amperage - "", - 1, // input slot count - 1, // output slot count - TextureFactory.of( - TextureFactory.of(OVERLAY_SIDE_ROCK_BREAKER_ACTIVE), - TextureFactory.builder() - .addIcon(OVERLAY_SIDE_ROCK_BREAKER_ACTIVE_GLOW) - .glow() - .build()), - TextureFactory.of( - TextureFactory.of(OVERLAY_SIDE_ROCK_BREAKER), - TextureFactory.builder() - .addIcon(OVERLAY_SIDE_ROCK_BREAKER_GLOW) - .glow() - .build()), - TextureFactory.of( - TextureFactory.of(OVERLAY_TOP_ROCK_BREAKER_ACTIVE), - TextureFactory.builder() - .addIcon(OVERLAY_TOP_ROCK_BREAKER_ACTIVE_GLOW) - .glow() - .build()), - TextureFactory.of( - TextureFactory.of(OVERLAY_TOP_ROCK_BREAKER), - TextureFactory.builder() - .addIcon(OVERLAY_TOP_ROCK_BREAKER_GLOW) - .glow() - .build()), - TextureFactory.of( - TextureFactory.of(OVERLAY_FRONT_ROCK_BREAKER_ACTIVE), - TextureFactory.builder() - .addIcon(OVERLAY_FRONT_ROCK_BREAKER_ACTIVE_GLOW) - .glow() - .build()), - TextureFactory.of( - TextureFactory.of(OVERLAY_FRONT_ROCK_BREAKER), - TextureFactory.builder() - .addIcon(OVERLAY_FRONT_ROCK_BREAKER_GLOW) - .glow() - .build()), - TextureFactory.of( - TextureFactory.of(OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE), - TextureFactory.builder() - .addIcon(OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE_GLOW) - .glow() - .build()), - TextureFactory.of( - TextureFactory.of(OVERLAY_BOTTOM_ROCK_BREAKER), - TextureFactory.builder() - .addIcon(OVERLAY_BOTTOM_ROCK_BREAKER_GLOW) - .glow() - .build())); - radius = aRadius; - step = aStep; - } - - @Override - public String[] getDescription() { - return new String[] { "Place, activate with explosives", - "2 Powderbarrels, " + "4 Glyceryl Trinitrate, " + "16 TNT, or " + "8 ITNT", - "Use Data Stick, Scan Data Stick, Print Data Stick, Bind Pages into Book", - "Ore prospecting area = " + radius * 2 + "x" + radius * 2 + " ONLY blocks below prospector", - "Oil prospecting area 3x3 oilfields, each is 8x8 chunks" }; - } - - protected GT_MetaTileEntity_AdvSeismicProspector(String aName, int aTier, String[] aDescription, - ITexture[][][] aTextures, int aRadius, int aStep) { - super(aName, aTier, 1, aDescription, aTextures, 1, 1); - radius = aRadius; - step = aStep; - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_AdvSeismicProspector( - this.mName, - this.mTier, - this.mDescriptionArray, - this.mTextures, - this.radius, - this.step); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isServerSide()) { - ItemStack aStack = aPlayer.getCurrentEquippedItem(); - - if (!ready && (GT_Utility.consumeItems(aPlayer, aStack, Item.getItemFromBlock(Blocks.tnt), 16) - || GT_Utility.consumeItems(aPlayer, aStack, Ic2Items.industrialTnt.getItem(), 8) - || GT_Utility.consumeItems(aPlayer, aStack, Materials.Glyceryl, 4) - || GT_Utility.consumeItems(aPlayer, aStack, ItemList.Block_Powderbarrel.getItem(), 2))) { - - this.ready = true; - this.mMaxProgresstime = (aPlayer.capabilities.isCreativeMode ? 20 : 800); - - } else if (ready && mMaxProgresstime == 0 - && aStack != null - && aStack.stackSize == 1 - && aStack.getItem() == ItemList.Tool_DataStick.getItem()) { - this.ready = false; - - // prospecting ores - HashMap tOres = new HashMap<>(36); - - prospectOres(tOres); - - // prospecting oils - ArrayList tOils = new ArrayList<>(); - prospectOils(tOils); - - GT_Utility.ItemNBT.setAdvancedProspectionData( - mTier, - aStack, - this.getBaseMetaTileEntity() - .getXCoord(), - this.getBaseMetaTileEntity() - .getYCoord(), - this.getBaseMetaTileEntity() - .getZCoord(), - this.getBaseMetaTileEntity() - .getWorld().provider.dimensionId, - tOils, - GT_Utility.sortByValueToList(tOres), - radius); - } - } - - return true; - } - - private void prospectOils(ArrayList aOils) { - - int xChunk = (getBaseMetaTileEntity().getXCoord() >> 7) << 3; // oil field aligned chunk coords - int zChunk = (getBaseMetaTileEntity().getZCoord() >> 7) << 3; - - LinkedHashMap tFluids = new LinkedHashMap<>(); - int oilFieldCount = 0; - - try { - final int oilfieldSize = 8; - for (int z = -1; z <= 1; ++z) { - for (int x = -1; x <= 1; ++x) { - ChunkCoordIntPair cInts = new ChunkCoordIntPair(x, z); - int min = Integer.MAX_VALUE; - int max = Integer.MIN_VALUE; - - for (int i = 0; i < oilfieldSize; i++) { - for (int j = 0; j < oilfieldSize; j++) { - Chunk tChunk = getBaseMetaTileEntity().getWorld() - .getChunkFromChunkCoords(xChunk + i + x * oilfieldSize, zChunk + j + z * oilfieldSize); - FluidStack tFluid = undergroundOilReadInformation(tChunk); - if (tFluid != null) { - if (tFluid.amount > max) max = tFluid.amount; - if (tFluid.amount < min) min = tFluid.amount; - if (!tFluids.containsKey(cInts)) { - tFluids.put(cInts, tFluid); - } - } - } - } - - aOils.add( - ++oilFieldCount + "," - + min - + "-" - + max - + "," - + tFluids.get(cInts) - .getLocalizedName()); - } - } - } catch (Exception ignored) {} - } - - private void prospectOres(Map aOres) { - int tLeftXBound = this.getBaseMetaTileEntity() - .getXCoord() - radius; - int tRightXBound = tLeftXBound + 2 * radius; - - int tLeftZBound = this.getBaseMetaTileEntity() - .getZCoord() - radius; - int tRightZBound = tLeftZBound + 2 * radius; - - for (int i = tLeftXBound; i <= tRightXBound; i += step) { - if (Math.abs(i >> 4) % 3 != 1) continue; - for (int k = tLeftZBound; k <= tRightZBound; k += step) { - if (Math.abs(k >> 4) % 3 != 1) continue; - - cX = (i >> 4) << 4; - cZ = (k >> 4) << 4; - - String separator = (cX + 8) + "," + (cZ + 8) + " --------"; - aOres.put(separator, 1); - prospectHole(i, k, aOres); - } - } - } - - private void prospectHole(int i, int k, Map aOres) { - String tFoundOre; - for (int j = this.getBaseMetaTileEntity() - .getYCoord(); j > 0; j--) { - tFoundOre = checkForOre(i, j, k); - if (tFoundOre != null) countOre(aOres, tFoundOre, cX, cZ); - } - } - - private String checkForOre(int x, int y, int z) { - Block tBlock = this.getBaseMetaTileEntity() - .getBlock(x, y, z); - - if (tBlock instanceof GT_Block_Ores_Abstract) { - TileEntity tTileEntity = getBaseMetaTileEntity().getWorld() - .getTileEntity(x, y, z); - - if ((tTileEntity instanceof GT_TileEntity_Ores) && (((GT_TileEntity_Ores) tTileEntity).mMetaData < 16000)) { // Filtering - // small - // ores - Materials tMaterial = GregTech_API.sGeneratedMaterials[((GT_TileEntity_Ores) tTileEntity).mMetaData - % 1000]; - - if ((tMaterial != null) && (tMaterial != Materials._NULL)) return tMaterial.mDefaultLocalName; - } - } else { - int tMetaID = getBaseMetaTileEntity().getWorld() - .getBlockMetadata(x, y, z); - ItemStack is = new ItemStack(tBlock, 1, tMetaID); - ItemData association = GT_OreDictUnificator.getAssociation(is); - if ((association != null) && (association.mPrefix.toString() - .startsWith("ore"))) return association.mMaterial.mMaterial.mDefaultLocalName; - else if (GT_Utility.isOre(tBlock, tMetaID)) return tBlock.getLocalizedName(); - } - return null; - } - - private static void countOre(Map map, String ore, int cCX, int cCZ) { - ore = (cCX + 8) + "," + (cCZ + 8) + " has " + ore; - Integer oldCount = map.get(ore); - oldCount = (oldCount == null) ? 0 : oldCount; - - map.put(ore, oldCount + 1); - } -} diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_BetterJukebox.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_BetterJukebox.java deleted file mode 100644 index f9a9fba8f4..0000000000 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_BetterJukebox.java +++ /dev/null @@ -1,702 +0,0 @@ -package gregtech.common.tileentities.machines.basic; - -import static gregtech.api.enums.GT_Values.V; -import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SIDE_JUKEBOX; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TOP_JUKEBOX; -import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.List; -import java.util.Random; -import java.util.UUID; - -import net.minecraft.item.ItemRecord; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.MathHelper; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.util.Constants; -import net.minecraftforge.common.util.ForgeDirection; - -import org.joml.Vector4i; - -import com.google.common.collect.ImmutableList; -import com.gtnewhorizons.modularui.api.drawable.FallbackableUITexture; -import com.gtnewhorizons.modularui.api.drawable.UITexture; -import com.gtnewhorizons.modularui.api.math.Pos2d; -import com.gtnewhorizons.modularui.api.screen.ModularWindow; -import com.gtnewhorizons.modularui.api.screen.UIBuildContext; -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.ProgressBar; -import com.gtnewhorizons.modularui.common.widget.SliderWidget; -import com.gtnewhorizons.modularui.common.widget.SlotWidget; - -import appeng.api.implementations.tiles.ISoundP2PHandler; -import appeng.me.GridAccessException; -import appeng.me.cache.helpers.TunnelCollection; -import appeng.me.helpers.AENetworkProxy; -import appeng.parts.p2p.PartP2PSound; -import gregtech.api.enums.GTVoltageIndex; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.modularui.GT_UITextures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.modularui.IAddUIWidgets; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; -import gregtech.api.recipe.BasicUIProperties; -import gregtech.api.render.TextureFactory; -import gregtech.api.util.GT_MusicSystem; -import gregtech.common.gui.modularui.UIHelper; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; - -public class GT_MetaTileEntity_BetterJukebox extends GT_MetaTileEntity_BasicMachine - implements IAddUIWidgets, ISoundP2PHandler { - - // Stored state - public UUID jukeboxUuid = UNSET_UUID; - public boolean loopMode = true; - public boolean shuffleMode = false; - public int playbackSlot = 0; - public float playbackVolume = BalanceMath.VANILLA_JUKEBOX_RANGE; - public float p2pVolume = BalanceMath.VANILLA_JUKEBOX_RANGE; - public long discProgressMs = 0; - /** Makes all music discs play for 4 seconds */ - public boolean superFastDebugMode = false; - // Computed state - private final Vector4i interdimPositionCache = new Vector4i(); // XYZ, Dimension ID - private GT_MusicSystem.MusicSource musicSource = null; - private boolean powered = false; - private long discStartMs = 0; - public long discDurationMs = 1; - private ItemRecord currentlyPlaying = null; - - // Constants - public static final UUID UNSET_UUID = UUID.nameUUIDFromBytes(new byte[] { 0 }); - public static final int INPUT_SLOTS = 21; - private static final Random SHUFFLER = new Random(); - - public enum HeadphoneLimit { - - BLOCK_RANGE, - INSIDE_DIMENSION, - BETWEEN_DIMENSIONS; - - public static final ImmutableList ENTRIES = ImmutableList.copyOf(values()); - } - - public static final class BalanceMath { - - public static int MAX_TIER = GTVoltageIndex.IV; - public static float VANILLA_JUKEBOX_RANGE = 4.0f; // 64 blocks - - private static final float[] LISTENING_VOLUME = new float[] { // - VANILLA_JUKEBOX_RANGE, // ULV (unpowered fallback) - VANILLA_JUKEBOX_RANGE + 1.0f, // LV, 80 blocks - VANILLA_JUKEBOX_RANGE + 2.0f, // MV, 96 blocks - VANILLA_JUKEBOX_RANGE + 4.0f, // HV, 118 blocks - VANILLA_JUKEBOX_RANGE + 5.0f, // EV, 144 blocks - VANILLA_JUKEBOX_RANGE + 6.0f, // IV, 160 blocks, equivalent to default load distance of 10 chunks - }; - - private static final int[] HEADPHONE_BLOCK_RANGE = new int[] { // - 64, // ULV (unpowered fallback) - 128, // LV - 160, // MV - 320, // HV - 9001, // EV, alreadu unlimited here - this value is ignored - 9002, // IV, already unlimited here - this value is ignored - }; - - public static float listeningVolume(int tier) { - tier = MathHelper.clamp_int(tier, 0, MAX_TIER); - return LISTENING_VOLUME[tier]; - } - - public static int headphoneBlockRange(int tier) { - tier = MathHelper.clamp_int(tier, 0, MAX_TIER); - return HEADPHONE_BLOCK_RANGE[tier]; - } - - public static HeadphoneLimit headphoneLimit(int tier) { - if (tier <= GTVoltageIndex.HV) { - return HeadphoneLimit.BLOCK_RANGE; - } else if (tier == GTVoltageIndex.EV) { - return HeadphoneLimit.INSIDE_DIMENSION; - } else { - return HeadphoneLimit.BETWEEN_DIMENSIONS; - } - } - - public static float volumeToAttenuationDistance(float range) { - // SoundManager.playSound logic - return 16.0f * range; - } - - public static float attenuationDistanceToVolume(float blockRange) { - return blockRange / 16.0f; - } - - public static long eutUsage(int tier) { - tier = MathHelper.clamp_int(tier, 0, MAX_TIER); - return V[tier] / 16; - } - } - - private static String[] buildDescription(int aTier) { - ArrayList strings = new ArrayList<>(4); - strings.add("Plays music better than your average vanilla jukebox."); - if (BalanceMath.headphoneLimit(aTier) != HeadphoneLimit.BLOCK_RANGE) { - strings.add(EnumChatFormatting.BLUE + "The raw power of Hatsune Miku in your ears"); - } - strings.add( - String.format( - "Range: %s%.1f blocks", - EnumChatFormatting.WHITE, - BalanceMath.volumeToAttenuationDistance(BalanceMath.listeningVolume(aTier)))); - strings.add(switch (BalanceMath.headphoneLimit(aTier)) { - case BLOCK_RANGE -> String.format( - "Headphone signal range: %s%d blocks", - EnumChatFormatting.WHITE, - BalanceMath.headphoneBlockRange(aTier)); - case INSIDE_DIMENSION -> String - .format("Headphones work anywhere in %sthe same dimension", EnumChatFormatting.WHITE); - case BETWEEN_DIMENSIONS -> String - .format("Headphones work anywhere, in %sany dimension", EnumChatFormatting.WHITE); - }); - strings.add(String.format("Cost: %s%d EU/t", EnumChatFormatting.WHITE, BalanceMath.eutUsage(aTier))); - strings.add(GT_Values.AuthorEigenRaven); - return strings.toArray(new String[0]); - } - - public GT_MetaTileEntity_BetterJukebox(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 1, buildDescription(aTier), INPUT_SLOTS, 1); - playbackVolume = BalanceMath.listeningVolume(aTier); - } - - public GT_MetaTileEntity_BetterJukebox(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 1, aDescription, aTextures, INPUT_SLOTS, 1); - playbackVolume = BalanceMath.listeningVolume(aTier); - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_BetterJukebox(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); - } - - @Override - public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection sideDirection, - ForgeDirection facingDirection, int colorIndex, boolean active, boolean redstoneLevel) { - if (sideDirection == baseMetaTileEntity.getFrontFacing()) { - return new ITexture[] { MACHINE_CASINGS[mTier][colorIndex + 1], TextureFactory.of(OVERLAY_PIPE_OUT) }; - } - if (sideDirection != ForgeDirection.UP) { - return new ITexture[] { MACHINE_CASINGS[mTier][colorIndex + 1], TextureFactory.of(OVERLAY_SIDE_JUKEBOX) }; - } - return new ITexture[] { MACHINE_CASINGS[mTier][colorIndex + 1], TextureFactory.builder() - .addIcon(OVERLAY_TOP_JUKEBOX) - .extFacing() - .build() }; - } - - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - super.onFirstTick(aBaseMetaTileEntity); - if (aBaseMetaTileEntity.isClientSide()) { - return; - } - final Vector4i interdimPosition = interdimPositionCache; - interdimPosition.x = aBaseMetaTileEntity.getXCoord(); - interdimPosition.y = aBaseMetaTileEntity.getYCoord(); - interdimPosition.z = aBaseMetaTileEntity.getZCoord(); - interdimPosition.w = aBaseMetaTileEntity.getWorld().provider.dimensionId; - if (jukeboxUuid == UNSET_UUID) { - jukeboxUuid = UUID.randomUUID(); - markDirty(); - } - if (musicSource == null) { - musicSource = GT_MusicSystem.ServerSystem.registerOrGetMusicSource(jukeboxUuid); - musicSource.originPosition.set(interdimPosition); - musicSource.headphoneLimit = BalanceMath.headphoneLimit(mTier); - musicSource.headphoneBlockRange = BalanceMath.headphoneBlockRange(mTier); - musicSource.startedPlayingAtMs = System.currentTimeMillis(); - updateEmitterList(); - } - if (doesSlotContainValidRecord(playbackSlot) - && mInventory[playbackSlot].getItem() instanceof ItemRecord record) { - final ResourceLocation resource = record.getRecordResource(record.recordName); - currentlyPlaying = record; - // Assume a safe disc duration of 500 seconds if not known in the registry - discDurationMs = GT_MusicSystem.getMusicRecordDurations() - .getOrDefault(resource, 500_000); - discStartMs = System.currentTimeMillis() - discProgressMs; - musicSource.setRecord( - new ResourceLocation(resource.getResourceDomain(), "records." + resource.getResourcePath()), - discProgressMs); - } - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - try { - if (aBaseMetaTileEntity.isClientSide() || !aBaseMetaTileEntity.isAllowedToWork() || musicSource == null) { - if (currentlyPlaying != null) { - stopCurrentSong(System.currentTimeMillis()); - } - return; - } - final Vector4i interdimPosition = interdimPositionCache; - interdimPosition.x = aBaseMetaTileEntity.getXCoord(); - interdimPosition.y = aBaseMetaTileEntity.getYCoord(); - interdimPosition.z = aBaseMetaTileEntity.getZCoord(); - interdimPosition.w = aBaseMetaTileEntity.getWorld().provider.dimensionId; - final long now = System.currentTimeMillis(); - - if (superFastDebugMode && discDurationMs > 4000) { - discDurationMs = 4000; - } - - // power check - final boolean hasMinimumEU = aBaseMetaTileEntity.isUniversalEnergyStored(getMinimumStoredEU()); - if (currentlyPlaying != null && hasMinimumEU - && aBaseMetaTileEntity.decreaseStoredEnergyUnits(BalanceMath.eutUsage(mTier), false)) { - if (!powered) { // just got power again - powered = true; - musicSource.modified = true; - musicSource.headphoneLimit = BalanceMath.headphoneLimit(mTier); - musicSource.headphoneBlockRange = BalanceMath.headphoneBlockRange(mTier); - updateEmitterList(); - } - } else if ((!hasMinimumEU || currentlyPlaying != null) && powered) { // was powered, but no longer is - powered = false; - musicSource.modified = true; - musicSource.headphoneLimit = HeadphoneLimit.BLOCK_RANGE; - musicSource.headphoneBlockRange = BalanceMath.headphoneBlockRange(0); - updateEmitterList(); - } - - // check if current disc finished - if (currentlyPlaying != null) { - discProgressMs = now - discStartMs; - final boolean hasValidRecord = doesSlotContainValidRecord(playbackSlot); - final boolean wasDiscSwapped = hasValidRecord - && mInventory[getInputSlot() + playbackSlot].getItem() != currentlyPlaying; - if (discProgressMs >= discDurationMs || !hasValidRecord || wasDiscSwapped) { - stopCurrentSong(now); - if (!loopMode) { - // should be empty, but swap just in case it's not - final ItemStack oldOut = mInventory[getOutputSlot()]; - mInventory[getOutputSlot()] = mInventory[getInputSlot() + playbackSlot]; - mInventory[getInputSlot() + playbackSlot] = oldOut; - markDirty(); - } - if (!(hasValidRecord && wasDiscSwapped)) { - // don't switch slots if someone just put a new disc in the active slot - pickNextSlot(); - } - } else { - // keep on playing - return; - } - } - - if (playbackSlot < 0 || playbackSlot >= INPUT_SLOTS - || ((aTimer % 10) == 0 && !doesSlotContainValidRecord(playbackSlot))) { - pickNextSlot(); - } - - final boolean hasValidRecord = doesSlotContainValidRecord(playbackSlot); - final boolean canStartPlaying = loopMode || isOutputEmpty(); - if (!hasValidRecord) { - stopCurrentSong(now); - } else if (canStartPlaying - && mInventory[getInputSlot() + playbackSlot].getItem() instanceof ItemRecord record) { - final ResourceLocation resource = record.getRecordResource(record.recordName); - currentlyPlaying = record; - musicSource.setRecord( - new ResourceLocation(resource.getResourceDomain(), "records." + resource.getResourcePath())); - // Assume a safe disc duration of 500 seconds if not known in the registry - discDurationMs = GT_MusicSystem.getMusicRecordDurations() - .getOrDefault(resource, 500_000); - discProgressMs = 0; - discStartMs = now; - } - } finally { - super.onPostTick(aBaseMetaTileEntity, aTimer); - } - } - - private void stopCurrentSong(long nowMs) { - if (currentlyPlaying == null) { - return; - } - musicSource.setRecord(null); - currentlyPlaying = null; - discDurationMs = 1; - discProgressMs = 0; - discStartMs = nowMs; - markDirty(); - } - - private void pickNextSlot() { - playbackSlot = MathHelper.clamp_int(playbackSlot, 0, INPUT_SLOTS); - if (shuffleMode) { - final int[] validSlots = new int[INPUT_SLOTS]; - int validSlotCount = 0; - for (int i = 0; i < INPUT_SLOTS; i++) { - if (i != playbackSlot && doesSlotContainValidRecord(i)) { - validSlots[validSlotCount++] = i; - } - } - switch (validSlotCount) { - case 0 -> {} - case 1 -> { - playbackSlot = validSlots[0]; - } - default -> { - playbackSlot = validSlots[SHUFFLER.nextInt(validSlotCount)]; - } - } - } else { - int attempt = 0; - int nextSlot = playbackSlot; - do { - attempt++; - nextSlot = (nextSlot + 1) % INPUT_SLOTS; - } while (!doesSlotContainValidRecord(nextSlot) && attempt <= INPUT_SLOTS); - if (attempt <= INPUT_SLOTS) { - playbackSlot = nextSlot; - } - } - } - - public boolean doesSlotContainValidRecord(int slot) { - return mInventory[getInputSlot() + slot] != null - && mInventory[getInputSlot() + slot].getItem() instanceof ItemRecord; - } - - @Override - public void onRemoval() { - final IGregTechTileEntity baseTE = getBaseMetaTileEntity(); - if (baseTE == null) { - return; - } - if (!baseTE.isServerSide()) { - return; - } - if (jukeboxUuid == UNSET_UUID) { - return; - } - GT_MusicSystem.ServerSystem.removeMusicSource(jukeboxUuid); - } - - @Override - public long getMinimumStoredEU() { - return BalanceMath.eutUsage(mTier) * 20; - } - - @Override - public long maxEUStore() { - return 512L + BalanceMath.eutUsage(mTier) * 50; - } - - @Override - public long maxAmperesIn() { - return 1; - } - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - return null; - } - - public static final String NBTKEY_UUID_LOW = "jukeboxUUIDLow"; - public static final String NBTKEY_UUID_HIGH = "jukeboxUUIDHigh"; - public static final String NBTKEY_LOOP_MODE = "loopMode"; - public static final String NBTKEY_SHUFFLE_MODE = "shuffleMode"; - public static final String NBTKEY_PLAYBACK_SLOT = "playbackSlot"; - public static final String NBTKEY_VOLUME_PLAY = "playbackVolume"; - public static final String NBTKEY_VOLUME_P2P = "p2pVolume"; - public static final String NBTKEY_DISC_PROGRESS_MS = "discProgressMs"; - - @Override - public String[] getInfoData() { - return new String[] { "Jukebox UUID: " + ((jukeboxUuid == UNSET_UUID) ? "unset" : jukeboxUuid), - "Loop mode: " + loopMode, "Shuffle mode: " + shuffleMode, "Played the disc for [ms]: " + discProgressMs, - "Current disc duration [ms]: " + discDurationMs, - "Playback range [blocks]: " + BalanceMath.volumeToAttenuationDistance(playbackVolume), - "P2P range [blocks]: " + BalanceMath.volumeToAttenuationDistance(playbackVolume), - "Raw playback strength: " + playbackVolume, "Raw p2p strength: " + p2pVolume }; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - if (jukeboxUuid != UNSET_UUID) { - aNBT.setLong(NBTKEY_UUID_LOW, jukeboxUuid.getLeastSignificantBits()); - aNBT.setLong(NBTKEY_UUID_HIGH, jukeboxUuid.getMostSignificantBits()); - aNBT.setBoolean(NBTKEY_LOOP_MODE, loopMode); - aNBT.setBoolean(NBTKEY_SHUFFLE_MODE, shuffleMode); - aNBT.setInteger(NBTKEY_PLAYBACK_SLOT, playbackSlot); - aNBT.setFloat(NBTKEY_VOLUME_PLAY, playbackVolume); - aNBT.setFloat(NBTKEY_VOLUME_P2P, p2pVolume); - aNBT.setLong(NBTKEY_DISC_PROGRESS_MS, discProgressMs); - } - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - if (aNBT.hasKey(NBTKEY_UUID_LOW, Constants.NBT.TAG_ANY_NUMERIC) - && aNBT.hasKey(NBTKEY_UUID_HIGH, Constants.NBT.TAG_ANY_NUMERIC)) { - jukeboxUuid = new UUID(aNBT.getLong(NBTKEY_UUID_HIGH), aNBT.getLong(NBTKEY_UUID_LOW)); - } - if (aNBT.hasKey(NBTKEY_LOOP_MODE, Constants.NBT.TAG_ANY_NUMERIC)) { - loopMode = aNBT.getBoolean(NBTKEY_LOOP_MODE); - } - if (aNBT.hasKey(NBTKEY_SHUFFLE_MODE, Constants.NBT.TAG_ANY_NUMERIC)) { - shuffleMode = aNBT.getBoolean(NBTKEY_SHUFFLE_MODE); - } - if (aNBT.hasKey(NBTKEY_PLAYBACK_SLOT, Constants.NBT.TAG_ANY_NUMERIC)) { - playbackSlot = aNBT.getInteger(NBTKEY_PLAYBACK_SLOT); - } - if (aNBT.hasKey(NBTKEY_VOLUME_PLAY, Constants.NBT.TAG_ANY_NUMERIC)) { - playbackVolume = aNBT.getFloat(NBTKEY_VOLUME_PLAY); - } - if (aNBT.hasKey(NBTKEY_VOLUME_P2P, Constants.NBT.TAG_ANY_NUMERIC)) { - p2pVolume = aNBT.getFloat(NBTKEY_VOLUME_P2P); - } - if (aNBT.hasKey(NBTKEY_DISC_PROGRESS_MS, Constants.NBT.TAG_ANY_NUMERIC)) { - discProgressMs = aNBT.getLong(NBTKEY_DISC_PROGRESS_MS); - } - - final float maxVolume = BalanceMath.listeningVolume(mTier); - playbackVolume = MathHelper.clamp_float(playbackVolume, 0.0f, maxVolume); - p2pVolume = MathHelper.clamp_float(p2pVolume, 0.0f, maxVolume); - } - - @Override - protected BasicUIProperties getUIProperties() { - return super.getUIProperties().toBuilder() - .itemInputPositionsGetter(count -> UIHelper.getGridPositions(count, 7, 6, 7, 3)) - .itemOutputPositionsGetter(count -> UIHelper.getGridPositions(count, 153, 24, 1)) - .specialItemPositionGetter(() -> new Pos2d(115, 62)) - .progressBarPos(Pos2d.cartesian(133, 24)) - .progressBarTexture(new FallbackableUITexture(GT_UITextures.PROGRESSBAR_ARROW)) - .build(); - } - - @Override - protected void addProgressBar(ModularWindow.Builder builder, BasicUIProperties uiProperties) { - builder.widget( - setNEITransferRect( - new ProgressBar().setProgress(() -> discProgressMs / (float) Math.max(1, discDurationMs)) - .setTexture(uiProperties.progressBarTexture.get(), uiProperties.progressBarImageSize) - .setDirection(uiProperties.progressBarDirection) - .setPos(uiProperties.progressBarPos) - .setSize(uiProperties.progressBarSize) - .setUpdateTooltipEveryTick(true) - .attachSyncer( - new FakeSyncWidget.LongSyncer(() -> this.discProgressMs, val -> this.discProgressMs = val), - builder) - .attachSyncer( - new FakeSyncWidget.LongSyncer(() -> this.discDurationMs, val -> this.discDurationMs = val), - builder) - .dynamicTooltip( - () -> Collections.singletonList( - String.format("%,.2f / %,.2f", discProgressMs / 1000.0f, discDurationMs / 1000.0f))), - uiProperties.neiTransferRectId)); - addProgressBarSpecialTextures(builder, uiProperties); - } - - @Override - protected SlotWidget createChargerSlot(int x, int y) { - return super.createChargerSlot(97, 62); - } - - @Override - public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { - super.addUIWidgets(builder, buildContext); - final BasicUIProperties props = getUIProperties(); - final List inputSlots = props.itemInputPositionsGetter.apply(mInputSlotCount); - // Loop - builder.widget( - new CycleButtonWidget().setToggle(() -> loopMode, val -> loopMode = val) - .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_CYCLIC) - .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) - .setGTTooltip(() -> mTooltipCache.getData("GT5U.machines.betterjukebox.loop.tooltip")) - .setTooltipShowUpDelay(TOOLTIP_DELAY) - .setPos(153, 6) - .setSize(18, 18)); - // Shuffle - builder.widget(new CycleButtonWidget().setToggle(() -> shuffleMode, val -> { - shuffleMode = val; - if (shuffleMode) { - playbackSlot = -1; - } else { - playbackSlot = 0; - } - }) - .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_SHUFFLE) - .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) - .setGTTooltip(() -> mTooltipCache.getData("GT5U.machines.betterjukebox.shuffle.tooltip")) - .setTooltipShowUpDelay(TOOLTIP_DELAY) - .setPos(153, 42) - .setSize(18, 18)); - // Currently playing slot highlight using the hotbar active texture - final DrawableWidget slotHighlight = new DrawableWidget(); - builder.widget( - slotHighlight - .setDrawable( - new UITexture( - new ResourceLocation("minecraft", "textures/gui/widgets.png"), - 0.0f, - 22.0f / 256.0f, - 24.0f / 256.0f, - 46.0f / 256.0f)) - .setSize(24, 24) - .attachSyncer(new FakeSyncWidget.IntegerSyncer(() -> this.playbackSlot, val -> { - this.playbackSlot = val; - slotHighlight.checkNeedsRebuild(); - }), builder) - .setPosProvider( - (screenSize, window, parent) -> inputSlots.get(MathHelper.clamp_int(playbackSlot, 0, INPUT_SLOTS)) - .add(-3, -3))); - // Attenuation distance (controls internal "volume") - // Caching tooltip data caches the formatted p2p range value, so we have to use the uncached variant here. - builder.widget( - new SliderWidget() - .setBounds(0.0f, BalanceMath.volumeToAttenuationDistance(BalanceMath.listeningVolume(mTier))) - .setGetter(this::getPlaybackBlockRange) - .setSetter(this::setPlaybackBlockRange) - .dynamicTooltip( - () -> mTooltipCache.getUncachedTooltipData( - "GT5U.machines.betterjukebox.attenuationDistance.tooltip", - (int) getPlaybackBlockRange()).text) - .setUpdateTooltipEveryTick(true) - .setPos(44, 63) - .setSize(52, 8)); - builder.widget( - new SliderWidget() - .setBounds(0.0f, BalanceMath.volumeToAttenuationDistance(BalanceMath.listeningVolume(mTier))) - .setGetter(this::getP2PBlockRange) - .setSetter(this::setP2PBlockRange) - .dynamicTooltip( - () -> mTooltipCache.getUncachedTooltipData( - "GT5U.machines.betterjukebox.p2pAttenuationDistance.tooltip", - (int) getP2PBlockRange()).text) - .setUpdateTooltipEveryTick(true) - .setPos(44, 71) - .setSize(52, 8)); - } - - private float getPlaybackBlockRange() { - return BalanceMath.volumeToAttenuationDistance(playbackVolume); - } - - private float getP2PBlockRange() { - return BalanceMath.volumeToAttenuationDistance(p2pVolume); - } - - private void setPlaybackBlockRange(float blockRange) { - float volume = BalanceMath.attenuationDistanceToVolume(blockRange); - volume = MathHelper.clamp_float(volume, 0.0f, BalanceMath.listeningVolume(mTier)); - if (volume != playbackVolume) { - playbackVolume = volume; - if (getBaseMetaTileEntity().isServerSide()) { - updateEmitterList(); - } - } - } - - private void setP2PBlockRange(float blockRange) { - float volume = BalanceMath.attenuationDistanceToVolume(blockRange); - volume = MathHelper.clamp_float(volume, 0.0f, BalanceMath.listeningVolume(mTier)); - if (volume != p2pVolume) { - p2pVolume = volume; - if (getBaseMetaTileEntity().isServerSide()) { - updateEmitterList(); - } - } - } - - private final EnumMap attachedSoundP2P = new EnumMap<>(ForgeDirection.class); - private final ObjectArrayList combinedOutputsListCache = new ObjectArrayList<>(new PartP2PSound[0]); - - private void updateEmitterList() { - final GT_MusicSystem.MusicSource target = musicSource; - if (target == null) { - return; - } - final ObjectArrayList emitters = combinedOutputsListCache; - emitters.clear(); - - attachedSoundP2P.forEach((ignored, p2p) -> { - if (p2p != null) { - try { - p2p.getOutputs() - .forEach(emitters::add); - } catch (GridAccessException e) { - // skip - } - } - }); - - IGregTechTileEntity te = getBaseMetaTileEntity(); - if (te == null) { - return; - } - final Vector4i position = new Vector4i(); - target.resizeEmitterArray(1 + emitters.size()); - position.set(te.getXCoord(), te.getYCoord(), te.getZCoord(), te.getWorld().provider.dimensionId); - final float actualVolume = MathHelper - .clamp_float(playbackVolume, 0.0f, BalanceMath.listeningVolume(powered ? mTier : 0)); - target.setEmitter(0, position, actualVolume); - final float actualP2PVolume = MathHelper - .clamp_float(p2pVolume, 0.0f, powered ? BalanceMath.listeningVolume(mTier) : 0.0f); - for (int i = 0; i < emitters.size(); i++) { - final PartP2PSound p2p = emitters.get(i); - final AENetworkProxy proxy = p2p.getProxy(); - final TileEntity emitterTe = p2p.getTile(); - final ForgeDirection dir = p2p.getSide(); - position.set( - emitterTe.xCoord + dir.offsetX, - emitterTe.yCoord + dir.offsetY, - emitterTe.zCoord + dir.offsetZ, - emitterTe.getWorldObj().provider.dimensionId); - final boolean active = proxy.isActive(); - target.setEmitter(1 + i, position, active ? actualP2PVolume : 0); - } - } - - @Override - public boolean allowSoundProxying(PartP2PSound p2p) { - return false; // the jukebox proxies sounds by itself - } - - @Override - public void onSoundP2PAttach(PartP2PSound p2p) { - attachedSoundP2P.put(p2p.getSide(), p2p); - updateEmitterList(); - } - - @Override - public void onSoundP2PDetach(PartP2PSound p2p) { - attachedSoundP2P.put(p2p.getSide(), null); - updateEmitterList(); - } - - @Override - public void onSoundP2POutputUpdate(PartP2PSound p2p, TunnelCollection outputs) { - updateEmitterList(); - } - -} diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Boxinator.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Boxinator.java deleted file mode 100644 index 8d2e0959e1..0000000000 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Boxinator.java +++ /dev/null @@ -1,229 +0,0 @@ -package gregtech.common.tileentities.machines.basic; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.enums.ItemList; -import gregtech.api.enums.MachineType; -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; -import gregtech.api.recipe.RecipeMap; -import gregtech.api.recipe.RecipeMaps; -import gregtech.api.render.TextureFactory; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_Utility; - -public class GT_MetaTileEntity_Boxinator extends GT_MetaTileEntity_BasicMachine { - - ItemStack aInputCache; - ItemStack aOutputCache; - int aTypeCache = 0; - - public GT_MetaTileEntity_Boxinator(int aID, String aName, String aNameRegional, int aTier) { - super( - aID, - aName, - aNameRegional, - aTier, - 1, - MachineType.PACKAGER.tooltipDescription(), - 2, - 1, - TextureFactory.of( - TextureFactory - .of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_SIDE_BOXINATOR_ACTIVE")), - TextureFactory.builder() - .addIcon( - new Textures.BlockIcons.CustomIcon( - "basicmachines/boxinator/OVERLAY_SIDE_BOXINATOR_ACTIVE_GLOW")) - .glow() - .build()), - TextureFactory.of( - TextureFactory.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_SIDE_BOXINATOR")), - TextureFactory.builder() - .addIcon(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_SIDE_BOXINATOR_GLOW")) - .glow() - .build()), - TextureFactory.of( - TextureFactory - .of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_FRONT_BOXINATOR_ACTIVE")), - TextureFactory.builder() - .addIcon( - new Textures.BlockIcons.CustomIcon( - "basicmachines/boxinator/OVERLAY_FRONT_BOXINATOR_ACTIVE_GLOW")) - .glow() - .build()), - TextureFactory.of( - TextureFactory - .of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_FRONT_BOXINATOR")), - TextureFactory.builder() - .addIcon(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_FRONT_BOXINATOR_GLOW")) - .glow() - .build()), - TextureFactory.of( - TextureFactory - .of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_TOP_BOXINATOR_ACTIVE")), - TextureFactory.builder() - .addIcon( - new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_TOP_BOXINATOR_ACTIVE_GLOW")) - .glow() - .build()), - TextureFactory.of( - TextureFactory.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_TOP_BOXINATOR")), - TextureFactory.builder() - .addIcon(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_TOP_BOXINATOR_GLOW")) - .glow() - .build()), - TextureFactory.of( - TextureFactory - .of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_BOTTOM_BOXINATOR_ACTIVE")), - TextureFactory.builder() - .addIcon( - new Textures.BlockIcons.CustomIcon( - "basicmachines/boxinator/OVERLAY_BOTTOM_BOXINATOR_ACTIVE_GLOW")) - .glow() - .build()), - TextureFactory.of( - TextureFactory - .of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_BOTTOM_BOXINATOR")), - TextureFactory.builder() - .addIcon( - new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_BOTTOM_BOXINATOR_GLOW")) - .glow() - .build())); - } - - public GT_MetaTileEntity_Boxinator(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 1, aDescription, aTextures, 2, 1); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Boxinator(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); - } - - @Override - public RecipeMap getRecipeMap() { - return RecipeMaps.packagerRecipes; - } - - private boolean hasValidCache(ItemStack mItem, int mType, boolean mClearOnFailure) { - if (aInputCache != null && aOutputCache != null - && aTypeCache == mType - && aInputCache.isItemEqual(mItem) - && ItemStack.areItemStackTagsEqual(mItem, aInputCache)) return true; - // clear cache if it was invalid - if (mClearOnFailure) { - aInputCache = null; - aOutputCache = null; - aTypeCache = 0; - } - return false; - } - - private void cacheItem(ItemStack mInputItem, ItemStack mOutputItem, int mType) { - aTypeCache = mType; - aOutputCache = mOutputItem.copy(); - aInputCache = mInputItem.copy(); - } - - @Override - public int checkRecipe() { - int tCheck = super.checkRecipe(); - if (tCheck != DID_NOT_FIND_RECIPE) { - return tCheck; - } - ItemStack tSlot0 = getInputAt(0); - ItemStack tSlot1 = getInputAt(1); - if ((GT_Utility.isStackValid(tSlot0)) && (GT_Utility.isStackValid(tSlot1)) - && (GT_Utility.getContainerItem(tSlot0, true) == null)) { - if ((ItemList.Schematic_1by1.isStackEqual(tSlot1)) && (tSlot0.stackSize >= 1)) { - boolean tIsCached = hasValidCache(tSlot0, 1, true); - this.mOutputItems[0] = tIsCached ? aOutputCache.copy() : GT_ModHandler.getRecipeOutput(tSlot0); - if (this.mOutputItems[0] != null) { - if (canOutput(this.mOutputItems[0])) { - tSlot0.stackSize -= 1; - calculateOverclockedNess(30, 16); - // In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - if (!tIsCached) cacheItem(tSlot0, this.mOutputItems[0], 1); - return FOUND_AND_SUCCESSFULLY_USED_RECIPE; - } - } - return DID_NOT_FIND_RECIPE; - } - if ((ItemList.Schematic_2by2.isStackEqual(tSlot1)) && (getInputAt(0).stackSize >= 4)) { - boolean tIsCached = hasValidCache(tSlot0, 2, true); - this.mOutputItems[0] = tIsCached ? aOutputCache.copy() - : GT_ModHandler.getRecipeOutput(tSlot0, tSlot0, null, tSlot0, tSlot0); - if (this.mOutputItems[0] != null) { - if (canOutput(this.mOutputItems[0])) { - getInputAt(0).stackSize -= 4; - calculateOverclockedNess(30, 32); - // In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - if (!tIsCached) cacheItem(tSlot0, this.mOutputItems[0], 2); - return FOUND_AND_SUCCESSFULLY_USED_RECIPE; - } - } - return DID_NOT_FIND_RECIPE; - } - if ((ItemList.Schematic_3by3.isStackEqual(tSlot1)) && (getInputAt(0).stackSize >= 9)) { - boolean tIsCached = hasValidCache(tSlot0, 3, true); - this.mOutputItems[0] = tIsCached ? aOutputCache.copy() - : GT_ModHandler - .getRecipeOutput(tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0); - if (this.mOutputItems[0] != null) { - if (canOutput(this.mOutputItems[0])) { - getInputAt(0).stackSize -= 9; - calculateOverclockedNess(30, 64); - // In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - if (!tIsCached) cacheItem(tSlot0, this.mOutputItems[0], 3); - return FOUND_AND_SUCCESSFULLY_USED_RECIPE; - } - } - return DID_NOT_FIND_RECIPE; - } - } - return DID_NOT_FIND_RECIPE; - } - - @Override - protected boolean allowPutStackValidated(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, - ItemStack aStack) { - if (!super.allowPutStackValidated(aBaseMetaTileEntity, aIndex, side, aStack)) { - return false; - } - ItemStack tInput1 = getInputAt(1); - if ((ItemList.Schematic_1by1.isStackEqual(tInput1)) || (ItemList.Schematic_2by2.isStackEqual(tInput1)) - || (ItemList.Schematic_3by3.isStackEqual(tInput1))) { - if (hasValidCache(aStack, aTypeCache, false)) return true; - if (RecipeMaps.packagerRecipes.findRecipe( - getBaseMetaTileEntity(), - true, - gregtech.api.enums.GT_Values.V[mTier], - null, - GT_Utility.copyAmount(64, aStack), - tInput1) != null) { - return true; - } - if (ItemList.Schematic_1by1.isStackEqual(getInputAt(1)) && GT_ModHandler.getRecipeOutput(aStack) != null) - return true; - if (ItemList.Schematic_2by2.isStackEqual(getInputAt(1)) - && GT_ModHandler.getRecipeOutput(aStack, aStack, null, aStack, aStack) != null) { - return true; - } - return ItemList.Schematic_3by3.isStackEqual(getInputAt(1)) && (GT_ModHandler - .getRecipeOutput(aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack) != null); - } else { - return RecipeMaps.packagerRecipes.containsInput(aStack); - } - } -} diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Charger.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_Met