Skip to content

Commit

Permalink
Fix imports following GT5u pollution refactor (GTNewHorizons#1050)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
Alexdoru and Dream-Master authored Oct 21, 2024
1 parent 88e1518 commit dfb3674
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 103 deletions.
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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 }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,15 +38,16 @@
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<GT_MetaTileEntity_AirFilterBase> {

protected int baseEff = 0;
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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<ChunkCoordinates> pollutedChunkList = new ArrayList<>();
for (ChunkCoordinates chunk : chunkList) {
if (chunk.getPollution() > 0) {
pollutedChunkList.add(chunk);
ArrayList<Integer> 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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit dfb3674

Please sign in to comment.