diff --git a/dependencies.gradle b/dependencies.gradle index 887118868..46be6614c 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,7 +1,7 @@ // Add your dependencies here dependencies { - api("com.github.GTNewHorizons:GT5-Unofficial:5.09.50.44:dev") + api("com.github.GTNewHorizons:GT5-Unofficial:5.09.50.49:dev") api("com.github.GTNewHorizons:Yamcl:0.6.0:dev") api("com.github.GTNewHorizons:Baubles:1.0.4:dev") @@ -18,7 +18,7 @@ dependencies { compileOnly rfg.deobf("curse.maven:witchery-69673:2234410") compileOnly("com.github.GTNewHorizons:Chisel:2.15.2-GTNH:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:Botania:1.11.5-GTNH:dev") { transitive = false } - compileOnly("com.github.GTNewHorizons:BloodMagic:1.6.6:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:BloodMagic:1.6.7:dev") { transitive = false } compileOnly rfg.deobf("curse.maven:extra-utilities-225561:2264384") compileOnly("TGregworks:TGregworks:1.7.10-GTNH-1.0.26:deobf") { transitive = false } compileOnly("com.github.GTNewHorizons:amunra:0.7.0:dev") { transitive = false } diff --git a/src/main/java/com/dreammaster/gthandler/multiAirFilter/ChunkCoordinates.java b/src/main/java/com/dreammaster/gthandler/multiAirFilter/ChunkCoordinates.java deleted file mode 100644 index eed1f9324..000000000 --- a/src/main/java/com/dreammaster/gthandler/multiAirFilter/ChunkCoordinates.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.dreammaster.gthandler.multiAirFilter; - -import net.minecraft.world.World; - -import gregtech.common.Pollution; - -public class ChunkCoordinates { - - private int chunkX, chunkZ; - private World world; - - public ChunkCoordinates(int chunkX, int chunkZ, World world) { - this.chunkX = chunkX; - this.chunkZ = chunkZ; - this.world = world; - } - - public int getChunkX() { - return chunkX; - } - - public int getChunkZ() { - return chunkZ; - } - - public World getWorld() { - return world; - } - - public int getPollution() { - return Pollution.getPollution(world, chunkX, chunkZ); - } - - public void removePollution(int amount) { - Pollution.addPollution(world, chunkX, chunkZ, -amount); - } -} diff --git a/src/main/java/com/dreammaster/gthandler/multiAirFilter/GT_MetaTileEntity_AirFilterBase.java b/src/main/java/com/dreammaster/gthandler/multiAirFilter/GT_MetaTileEntity_AirFilterBase.java index 5938ade64..e5c42452c 100644 --- a/src/main/java/com/dreammaster/gthandler/multiAirFilter/GT_MetaTileEntity_AirFilterBase.java +++ b/src/main/java/com/dreammaster/gthandler/multiAirFilter/GT_MetaTileEntity_AirFilterBase.java @@ -1,8 +1,7 @@ package com.dreammaster.gthandler.multiAirFilter; import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static gregtech.api.enums.GTValues.*; +import static gregtech.api.enums.GTValues.VN; import static gregtech.api.util.GTStructureUtility.ofHatchAdder; import static gregtech.api.util.GTStructureUtility.ofHatchAdderOptional; import static gregtech.api.util.GTUtility.filterValidMTEs; @@ -39,7 +38,9 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.common.items.MetaGeneratedTool01; +import gregtech.common.pollution.Pollution; +// TODO move this multi to GT5u public abstract class GT_MetaTileEntity_AirFilterBase extends MTEEnhancedMultiBlockBase { @@ -47,7 +48,6 @@ public abstract class GT_MetaTileEntity_AirFilterBase protected int multiTier = 0; protected int chunkIndex = 0; protected boolean hasPollution = false; - protected ChunkCoordinates[] chunkList; // list of the chunks in the working area protected int mode = 0; // 0 for processing chunks in order, 1 for processing chunks randomly protected int size; // current working size of the multi, max is 2*multiTier + 1 protected boolean isFilterLoaded = false; @@ -155,45 +155,24 @@ public GT_MetaTileEntity_AirFilterBase(String aName) { super(aName); } - protected void populateChunkList() { - chunkList = new ChunkCoordinates[size * size]; - World world = this.getBaseMetaTileEntity().getWorld(); - int xCoordMulti = this.getBaseMetaTileEntity().getXCoord(); - int zCoordMulti = this.getBaseMetaTileEntity().getZCoord(); - - for (int i = 0; i < size * size; i++) { - int xCoordChunk = (xCoordMulti - 16 * (size / 2 - (i % (size)))) >> 4; - int zCoordChunk = (zCoordMulti + 16 * (size / 2 - (i / (size)))) >> 4; - chunkList[i] = new ChunkCoordinates(xCoordChunk, zCoordChunk, world); - } - } - public abstract GTRecipe getRecipe(); public String getCasingString() { - switch (getCasingMeta()) { - case 0: - return "Air Filter Turbine Casing"; - case 3: - return "Advanced Air Filter Turbine Casing"; - case 5: - return "Super Air Filter Turbine Casing"; - default: - return "fill a ticket on github if you read this"; - } + return switch (getCasingMeta()) { + case 0 -> "Air Filter Turbine Casing"; + case 3 -> "Advanced Air Filter Turbine Casing"; + case 5 -> "Super Air Filter Turbine Casing"; + default -> "fill a ticket on github if you read this"; + }; } public String getPipeString() { - switch (getPipeMeta()) { - case 1: - return "Air Filter Vent Casing"; - case 4: - return "Advanced Air Filter Vent Casing"; - case 6: - return "Super Air Filter Vent Casing"; - default: - return "fill a ticket on github if you read this"; - } + return switch (getPipeMeta()) { + case 1 -> "Air Filter Vent Casing"; + case 4 -> "Advanced Air Filter Vent Casing"; + case 6 -> "Super Air Filter Vent Casing"; + default -> "fill a ticket on github if you read this"; + }; } @Override @@ -371,40 +350,48 @@ public void loadNBTData(NBTTagCompound aNBT) { } public void cleanPollution() { - int pollutionCleaningRatePerSecond = getPollutionCleaningRatePerSecond( - baseEff / 10000f, - mEfficiency / 10000f, - isFilterLoaded); - if (pollutionCleaningRatePerSecond > 0) { + int cleaningRate = getPollutionCleaningRatePerSecond(baseEff / 10000f, mEfficiency / 10000f, isFilterLoaded); + if (cleaningRate > 0) { + World world = this.getBaseMetaTileEntity().getWorld(); if (mode == 0) { // processing chunk normally - chunkList[chunkIndex].removePollution(pollutionCleaningRatePerSecond); + removePollutionFromChunk(cleaningRate, world, chunkIndex); chunkIndex += 1; - if (chunkIndex == chunkList.length) { + if (chunkIndex >= size * size) { chunkIndex = 0; } } else { // process chunks randomly - // list all the polluted chunks - ArrayList pollutedChunkList = new ArrayList<>(); - for (ChunkCoordinates chunk : chunkList) { - if (chunk.getPollution() > 0) { - pollutedChunkList.add(chunk); + ArrayList pollutedChunks = new ArrayList<>(); + for (int index = 0; index < size * size; index++) { + if (getPollutionInChunk(world, index) > 0) { + pollutedChunks.add(index); } } - // pick the chunk randomly - ChunkCoordinates pollutedChunk; - if (pollutedChunkList.size() > 1) { - pollutedChunk = pollutedChunkList.get(MainRegistry.Rnd.nextInt(pollutedChunkList.size())); - pollutedChunk.removePollution(pollutionCleaningRatePerSecond); - } else if (pollutedChunkList.size() == 1) { // no random on only one element - pollutedChunk = pollutedChunkList.get(0); - pollutedChunk.removePollution(pollutionCleaningRatePerSecond); + if (!pollutedChunks.isEmpty()) { + int index = pollutedChunks.get(MainRegistry.Rnd.nextInt(pollutedChunks.size())); + removePollutionFromChunk(cleaningRate, world, index); } } } } + protected final int getPollutionInChunk(World world, int chunkIndexIn) { + final int xCoordMulti = this.getBaseMetaTileEntity().getXCoord(); + final int zCoordMulti = this.getBaseMetaTileEntity().getZCoord(); + final int chunkX = xCoordMulti - 16 * (size / 2 - chunkIndexIn % size) >> 4; + final int chunkZ = zCoordMulti + 16 * (size / 2 - chunkIndexIn / size) >> 4; + return Pollution.getPollution(world, chunkX, chunkZ); + } + + protected final void removePollutionFromChunk(int amount, World world, int chunkIndexIn) { + final int xCoordMulti = this.getBaseMetaTileEntity().getXCoord(); + final int zCoordMulti = this.getBaseMetaTileEntity().getZCoord(); + final int chunkX = xCoordMulti - 16 * (size / 2 - chunkIndexIn % size) >> 4; + final int chunkZ = zCoordMulti + 16 * (size / 2 - chunkIndexIn / size) >> 4; + Pollution.addPollution(world, chunkX, chunkZ, -amount); + } + public abstract int getPipeMeta(); public abstract int getCasingMeta(); @@ -416,19 +403,18 @@ public int getMaxEfficiency(ItemStack aStack) { @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (chunkList == null) { - if (size == 0) { // here in case it's not set by NBT loading - size = 2 * multiTier + 1; - } - populateChunkList(); + if (size == 0) { // here in case it's not set by NBT loading + size = 2 * multiTier + 1; } super.onPreTick(aBaseMetaTileEntity, aTick); } public int getTotalPollution() { int pollutionAmount = 0; - for (ChunkCoordinates chunk : chunkList) { - pollutionAmount += chunk.getPollution(); + World world = this.getBaseMetaTileEntity().getWorld(); + for (int i = 0; i < size * size; i++) { + pollutionAmount += getPollutionInChunk(world, i); + } return pollutionAmount; } @@ -493,7 +479,6 @@ public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, f size -= 2; // always get odd number } chunkIndex = 0; - populateChunkList(); PlayerChatHelper .SendInfo(aPlayer, "Electric air filter is now working in a " + size + "x" + size + " area"); }