Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-NBT/MCA code cleanups #374

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ sourceCompatibility = JavaLanguageVersion.of(17)
targetCompatibility = JavaLanguageVersion.of(17)
compileJava.options.encoding = 'UTF-8'
application.mainClass = 'net.querz.mcaselector.Main'
configurations.implementation.canBeResolved = true

javafx {
version = "$sourceCompatibility"
Expand Down Expand Up @@ -44,17 +43,6 @@ dependencies {
implementation 'me.tongfei:progressbar:0.9.3'
implementation 'org.codehaus.groovy:groovy-jsr223:3.0.11'

shadow 'com.github.Querz:NBT:f279a237fb'
shadow 'org.json:json:20220320'
shadow 'ar.com.hjg:pngj:2.1.0'
shadow 'org.xerial:sqlite-jdbc:3.36.0.3'
shadow 'it.unimi.dsi:fastutil:8.5.8'
shadow 'org.apache.logging.log4j:log4j-api:2.17.2'
shadow 'org.apache.logging.log4j:log4j-core:2.17.2'
shadow 'commons-cli:commons-cli:1.5.0'
shadow 'me.tongfei:progressbar:0.9.3'
shadow 'org.codehaus.groovy:groovy-jsr223:3.0.11'

testImplementation 'junit:junit:4.13.2'
testImplementation 'commons-io:commons-io:2.11.0'
}
Expand Down Expand Up @@ -82,11 +70,9 @@ jar {
'Class-Path': configurations.shadow.files.stream()
.filter($it -> !$it.name.startsWith('javafx')).collect{"lib/$it.name"}.join(' ')
)
exclude 'licenses/'
from 'LICENSE'
dependsOn minifyCss
dependsOn copyRuntimeLibs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyRuntimeLibs needs to be adjusted too, because it still references configurations.shadow.

Those libs are needed for the *-min.jar as well as for bundling with the Windows Installer.

finalizedBy shadowJar
}

shadowJar {
Expand All @@ -98,7 +84,6 @@ shadowJar {
exclude(dependency(':javafx.*:.*'))
}
archiveFileName = "${project.name}-${project.version}.jar"
configurations = [project.configurations.shadow]
from 'LICENSE'
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/querz/mcaselector/changer/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public boolean parseNewValue(String s) {
return false;
}

public abstract void change(ChunkData root);
public abstract void change(ChunkData root, boolean force);

public abstract void force(ChunkData root);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.querz.mcaselector.changer.FieldType;
import net.querz.mcaselector.io.registry.BiomeRegistry;
import net.querz.mcaselector.io.mca.ChunkData;
import net.querz.mcaselector.version.ChunkFilter;
import net.querz.mcaselector.version.VersionController;

public class BiomeField extends Field<BiomeRegistry.BiomeIdentifier> {
Expand Down Expand Up @@ -56,12 +57,13 @@ public BiomeRegistry.BiomeIdentifier getOldValue(ChunkData data) {
}

@Override
public void change(ChunkData data) {
VersionController.getChunkFilter(data.region().getData().getInt("DataVersion")).changeBiome(data.region().getData(), getNewValue());
public void change(ChunkData data, boolean force) {
ChunkFilter filter = VersionController.getChunkFilter(data.getDataVersion());
if (force) {
filter.forceBiome(data.region().getData(), getNewValue());
} else {
filter.changeBiome(data.region().getData(), getNewValue());
}
}

@Override
public void force(ChunkData data) {
VersionController.getChunkFilter(data.region().getData().getInt("DataVersion")).forceBiome(data.region().getData(), getNewValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData root) {
public void change(ChunkData root, boolean force) {
// this needs to be thread safe because all threads use the same ScriptEngine
synchronized (lock) {
engine.put("region", root.region() != null && root.region().getData() != null ? root.region().getData() : null);
Expand All @@ -64,8 +64,4 @@ public void change(ChunkData root) {
}
}

@Override
public void force(ChunkData root) {
change(root);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public DataVersionField() {

@Override
public Integer getOldValue(ChunkData data) {
return ValidationHelper.withDefault(() -> data.region().getData().getInt("DataVersion"), null);
return ValidationHelper.withDefault(data::getDataVersion, null);
}

@Override
Expand All @@ -31,37 +31,25 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData data) {
public void change(ChunkData data, boolean force) {
IntTag tag = data.region().getData().getIntTag("DataVersion");
if (tag != null) {
if (tag != null || force) {
data.region().getData().putInt("DataVersion", getNewValue());
}

if (data.poi() != null) {
tag = data.poi().getData().getIntTag("DataVersion");
if (tag != null) {
if (tag != null || force) {
data.region().getData().putInt("DataVersion", getNewValue());
}
}

if (data.entities() != null) {
tag = data.entities().getData().getIntTag("DataVersion");
if (tag != null) {
if (tag != null || force) {
data.region().getData().putInt("DataVersion", getNewValue());
}
}
}

@Override
public void force(ChunkData data) {
data.region().getData().putInt("DataVersion", getNewValue());

if (data.poi() != null) {
data.poi().getData().putInt("DataVersion", getNewValue());
}

if (data.entities() != null) {
data.entities().getData().putInt("DataVersion", getNewValue());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData data) {
VersionController.getEntityFilter(data.region().getData().getInt("DataVersion")).deleteEntities(data, null);
public void change(ChunkData data, boolean force) {
VersionController.getEntityFilter(data.getDataVersion()).deleteEntities(data, null);
}

@Override
public void force(ChunkData data) {
change(data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,18 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData data) {
public void change(ChunkData data, boolean force) {
if (data.region() != null && data.region().getData() != null) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
chunkFilter.deleteSections(data.region().getData(), getNewValue());
}
// delete entities and poi as well
if (data.entities() != null && data.entities().getData() != null) {
EntityFilter entityFilter = VersionController.getEntityFilter(data.entities().getData().getInt("DataVersion"));
EntityFilter entityFilter = VersionController.getEntityFilter(data.getDataVersion());
entityFilter.deleteEntities(data, getNewValue());
}
}

@Override
public void force(ChunkData data) {
change(data);
}

@Override
public String toString() {
if (getNewValue().size() == 1 && getNewValue().get(0).isMaxRange()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
public void change(ChunkData data, boolean force) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
CompoundTag references = chunkFilter.getStructureReferences(data.region().getData());
CompoundTag starts = chunkFilter.getStructureStarts(data.region().getData());
for (String structure : getNewValue()) {
Expand All @@ -63,11 +63,6 @@ public void change(ChunkData data) {
}
}

@Override
public void force(ChunkData data) {
change(data);
}

@Override
public String toString() {
StringJoiner sj = new StringJoiner(", ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
public void change(ChunkData data, boolean force) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
StringTag status = chunkFilter.getStatus(data.region().getData());

if ("empty".equals(status.getValue())) {
Expand All @@ -44,8 +44,4 @@ public void change(ChunkData data) {
}
}

@Override
public void force(ChunkData data) {
change(data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData root) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(root.region().getData().getInt("DataVersion"));
public void change(ChunkData root, boolean force) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(root.getDataVersion());
chunkFilter.forceBlending(root.region().getData());
}

@Override
public void force(ChunkData root) {
change(root);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public InhabitedTimeField() {

@Override
public Long getOldValue(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
LongTag inhabitedTime = chunkFilter.getInhabitedTime(data.region().getData());
return inhabitedTime == null ? null : inhabitedTime.asLong();
}
Expand All @@ -31,17 +31,12 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
public void change(ChunkData data, boolean force) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
LongTag tag = chunkFilter.getInhabitedTime(data.region().getData());
if (tag != null) {
if (tag != null || force) {
chunkFilter.setInhabitedTime(data.region().getData(), getNewValue());
}
}

@Override
public void force(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
chunkFilter.setInhabitedTime(data.region().getData(), getNewValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public LastUpdateField() {

@Override
public Long getOldValue(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
LongTag lastUpdate = chunkFilter.getLastUpdate(data.region().getData());
return lastUpdate == null ? null : lastUpdate.asLong();
}
Expand All @@ -31,17 +31,12 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
public void change(ChunkData data, boolean force) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
LongTag tag = chunkFilter.getLastUpdate(data.region().getData());
if (tag != null) {
if (tag != null || force) {
chunkFilter.setLastUpdate(data.region().getData(), getNewValue());
}
}

@Override
public void force(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
chunkFilter.setLastUpdate(data.region().getData(), getNewValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public LightPopulatedField() {

@Override
public Byte getOldValue(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
ByteTag lightPopulated = chunkFilter.getLightPopulated(data.region().getData());
return lightPopulated == null ? null : lightPopulated.asByte();
}
Expand All @@ -34,17 +34,12 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
public void change(ChunkData data, boolean force) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
ByteTag tag = chunkFilter.getLightPopulated(data.region().getData());
if (tag != null) {
if (tag != null || force) {
chunkFilter.setLightPopulated(data.region().getData(), getNewValue());
}
}

@Override
public void force(ChunkData data) {
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
chunkFilter.setLightPopulated(data.region().getData(), getNewValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@ public boolean parseNewValue(String s) {
}

@Override
public void change(ChunkData data) {
public void change(ChunkData data, boolean force) {
if (data.region() == null || data.region().getData() == null) {
return;
}
data.region().getData().remove("below_zero_retrogen");
data.region().getData().putString("Status", "full");
}

@Override
public void force(ChunkData data) {
change(data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public Boolean getOldValue(ChunkData data) {
}

@Override
public void change(ChunkData data) {
public void change(ChunkData data, boolean force) {
if (!getNewValue()) {
return;
}

// attempt to fix chunk coordinates of structure references

ChunkFilter chunkFilter = VersionController.getChunkFilter(data.region().getData().getInt("DataVersion"));
ChunkFilter chunkFilter = VersionController.getChunkFilter(data.getDataVersion());
CompoundTag references = chunkFilter.getStructureReferences(data.region().getData());
int xPos = chunkFilter.getXPos(data.region().getData()).asInt();
int zPos = chunkFilter.getZPos(data.region().getData()).asInt();
Expand All @@ -57,8 +57,4 @@ public void change(ChunkData data) {
}
}

@Override
public void force(ChunkData data) {
change(data);
}
}
Loading