Compare commits

...
18 Commits
Author SHA1 Message Date
GTNH-Colen a79bb55395 Fix mixins 2024-01-16 19:25:04 +00:00
GTNH-Colen 0fda010523 Rename to gtnewhorizons 2024-01-15 15:20:26 +00:00
GTNH-Colen 1f6f4605b1 Rename to gtnewhorizons 2024-01-15 15:10:18 +00:00
Connor-Colenso 99c887e67e Merge pull request #1 from GTNewHorizons/item-fixer-utility-null-item
Fix crash caused by processing null item
2024-01-15 15:06:32 +00:00
miozune 374cad1e5c Fix crash caused by processing null item 2024-01-16 00:01:59 +09:00
GTNH-Colen 4d247eb701 Rename to lower case 2024-01-15 14:59:07 +00:00
Martin Robertz 7b885b8eda sa 2024-01-12 23:13:42 +01:00
Connor Colenso 318af9da8c Spotless + remove debug code 2024-01-12 22:06:07 +00:00
Connor Colenso 152b8d4dc5 Spotless 2024-01-12 21:03:45 +00:00
Connor Colenso b2d44c9654 Optimise block conversion 2024-01-12 20:43:34 +00:00
Connor Colenso b5be252e9e Update README.md 2024-01-12 20:43:20 +00:00
GTNH-Colen 0bb9b56e6d Spotless 2024-01-12 03:40:06 +00:00
GTNH-Colen ad46bc37da BS Update 2024-01-12 03:36:01 +00:00
GTNH-Colen e15b0f35ff double chunk processing protection seems to work. 2024-01-12 03:33:40 +00:00
Martin Robertz 32b04a0408 update bs+sa 2024-01-11 22:09:01 +01:00
GTNH-Colen a67d392b49 Getting there, but postea codes are all 0 2024-01-11 16:32:13 +00:00
Connor Colenso 06350f82ac Saving world data 2024-01-05 15:40:11 +00:00
Connor Colenso f693ca75b9 Revert "Fix bug"
This reverts commit 2e8ce92f66.
2023-12-24 01:38:45 +00:00
21 changed files with 290 additions and 122 deletions

No files matched your search

+2 -2
View File
@@ -29,7 +29,7 @@ TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, w
#### b. We do the same here, but now we convert a Furnace TE to a chest TE. We also need to convert the underlying block to a chest. In addtion to this we can provide a transformer that can edit the NBTTagCompound of the TE. This is useful for converting NBT data from one format to another. Here we simply edit the NBT to place stone in the middle slot. #### b. We do the same here, but now we convert a Furnace TE to a chest TE. We also need to convert the underlying block to a chest. In addtion to this we can provide a transformer that can edit the NBTTagCompound of the TE. This is useful for converting NBT data from one format to another. Here we simply edit the NBT to place stone in the middle slot.
```java ```java
TileEntityReplacementManager.tileEntityTransformer("Furnace", (tag, world) -> { TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world) -> {
return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer); return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer);
}); });
@@ -58,7 +58,7 @@ private static NBTTagCompound chestTransformer(NBTTagCompound oldTag) {
#### a. The following example will replace all grass blocks with even x-coordinates with orange wool blocks. #### a. The following example will replace all grass blocks with even x-coordinates with orange wool blocks.
```java ```java
Function<BlockConversionInfo, BlockConversionInfo> blockTransformer = (blockConversionInfoOld) -> { BiFunction<BlockConversionInfo, World, BlockConversionInfo> blockTransformer = (blockConversionInfoOld, world) -> {
BlockConversionInfo blockConversionInfoNew = new BlockConversionInfo(); BlockConversionInfo blockConversionInfoNew = new BlockConversionInfo();
+15 -20
View File
@@ -1,4 +1,4 @@
//version: 1702141377 //version: 1704751096
/* /*
DO NOT CHANGE THIS FILE! DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available. Also, you may replace this file at any time if there is an update available.
@@ -31,8 +31,7 @@ buildscript {
maven { maven {
// GTNH RetroFuturaGradle and ASM Fork // GTNH RetroFuturaGradle and ASM Fork
name "GTNH Maven" name "GTNH Maven"
url "http://jenkins.usrv.eu:8081/nexus/content/groups/public/" url "https://nexus.gtnewhorizons.com/repository/public/"
allowInsecureProtocol = true
} }
mavenLocal() mavenLocal()
} }
@@ -49,12 +48,12 @@ plugins {
id 'org.ajoberstar.grgit' version '4.1.1' // 4.1.1 is the last jvm8 supporting version, unused, available for addon.gradle id 'org.ajoberstar.grgit' version '4.1.1' // 4.1.1 is the last jvm8 supporting version, unused, available for addon.gradle
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
id 'com.palantir.git-version' version '3.0.0' apply false id 'com.palantir.git-version' version '3.0.0' apply false
id 'de.undercouch.download' version '5.4.0' id 'de.undercouch.download' version '5.5.0'
id 'com.github.gmazzo.buildconfig' version '3.1.0' apply false // Unused, available for addon.gradle id 'com.github.gmazzo.buildconfig' version '3.1.0' apply false // Unused, available for addon.gradle
id 'com.diffplug.spotless' version '6.13.0' apply false // 6.13.0 is the last jvm8 supporting version id 'com.diffplug.spotless' version '6.13.0' apply false // 6.13.0 is the last jvm8 supporting version
id 'com.modrinth.minotaur' version '2.+' apply false id 'com.modrinth.minotaur' version '2.+' apply false
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.26' id 'com.gtnewhorizons.retrofuturagradle' version '1.3.27'
} }
print("You might want to check out './gradlew :faq' if your build fails.\n") print("You might want to check out './gradlew :faq' if your build fails.\n")
@@ -118,7 +117,7 @@ propertyDefaultIfUnset("forceEnableMixins", false)
propertyDefaultIfUnset("channel", "stable") propertyDefaultIfUnset("channel", "stable")
propertyDefaultIfUnset("mappingsVersion", "12") propertyDefaultIfUnset("mappingsVersion", "12")
propertyDefaultIfUnset("usesMavenPublishing", true) propertyDefaultIfUnset("usesMavenPublishing", true)
propertyDefaultIfUnset("mavenPublishUrl", "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases") propertyDefaultIfUnset("mavenPublishUrl", "https://nexus.gtnewhorizons.com/repository/releases/")
propertyDefaultIfUnset("modrinthProjectId", "") propertyDefaultIfUnset("modrinthProjectId", "")
propertyDefaultIfUnset("modrinthRelations", "") propertyDefaultIfUnset("modrinthRelations", "")
propertyDefaultIfUnset("curseForgeProjectId", "") propertyDefaultIfUnset("curseForgeProjectId", "")
@@ -573,13 +572,15 @@ afterEvaluate {
repositories { repositories {
maven { maven {
name 'Overmind forge repo mirror' name = "GTNH Maven"
url 'https://gregtech.overminddl1.com/' url = "https://nexus.gtnewhorizons.com/repository/public/"
// Links for convenience:
// Simple HTML browsing: https://nexus.gtnewhorizons.com/service/rest/repository/browse/releases/
// Rich web UI browsing: https://nexus.gtnewhorizons.com/#browse/browse:releases
} }
maven { maven {
name = "GTNH Maven" name 'Overmind forge repo mirror'
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/" url 'https://gregtech.overminddl1.com/'
allowInsecureProtocol = true
} }
maven { maven {
name 'sonatype' name 'sonatype'
@@ -785,7 +786,7 @@ dependencies {
java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}") java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}")
} }
if (modId != 'hodgepodge') { if (modId != 'hodgepodge') {
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.3.35') java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.4.4')
} }
java17PatchDependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}:forgePatches") {transitive = false} java17PatchDependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}:forgePatches") {transitive = false}
@@ -960,8 +961,7 @@ if (usesShadowedDependencies.toBoolean()) {
configurations.runtimeElements.outgoing.artifact(tasks.named("shadowJar", ShadowJar)) configurations.runtimeElements.outgoing.artifact(tasks.named("shadowJar", ShadowJar))
configurations.apiElements.outgoing.artifact(tasks.named("shadowJar", ShadowJar)) configurations.apiElements.outgoing.artifact(tasks.named("shadowJar", ShadowJar))
tasks.named("jar", Jar) { tasks.named("jar", Jar) {
enabled = false archiveClassifier.set('dev-preshadow')
finalizedBy(tasks.shadowJar)
} }
tasks.named("reobfJar", ReobfuscatedJar) { tasks.named("reobfJar", ReobfuscatedJar) {
inputJar.set(tasks.named("shadowJar", ShadowJar).flatMap({it.archiveFile})) inputJar.set(tasks.named("shadowJar", ShadowJar).flatMap({it.archiveFile}))
@@ -970,11 +970,6 @@ if (usesShadowedDependencies.toBoolean()) {
javaComponent.withVariantsFromConfiguration(configurations.shadowRuntimeElements) { javaComponent.withVariantsFromConfiguration(configurations.shadowRuntimeElements) {
skip() skip()
} }
for (runTask in ["runClient", "runServer", "runClient17", "runServer17"]) {
tasks.named(runTask).configure {
dependsOn("shadowJar")
}
}
} }
ext.publishableDevJar = usesShadowedDependencies.toBoolean() ? tasks.shadowJar : tasks.jar ext.publishableDevJar = usesShadowedDependencies.toBoolean() ? tasks.shadowJar : tasks.jar
ext.publishableObfJar = tasks.reobfJar ext.publishableObfJar = tasks.reobfJar
@@ -1178,7 +1173,7 @@ publishing {
if (usesMavenPublishing.toBoolean() && System.getenv("MAVEN_USER") != null) { if (usesMavenPublishing.toBoolean() && System.getenv("MAVEN_USER") != null) {
maven { maven {
url = mavenPublishUrl url = mavenPublishUrl
allowInsecureProtocol = mavenPublishUrl.startsWith("http://") // Mostly for the GTNH maven allowInsecureProtocol = mavenPublishUrl.startsWith("http://")
credentials { credentials {
username = System.getenv("MAVEN_USER") ?: "NONE" username = System.getenv("MAVEN_USER") ?: "NONE"
password = System.getenv("MAVEN_PASSWORD") ?: "NONE" password = System.getenv("MAVEN_PASSWORD") ?: "NONE"
+2 -2
View File
@@ -3,7 +3,7 @@ modName = Postea
# This is a case-sensitive string to identify your mod. Convention is to use lower case. # This is a case-sensitive string to identify your mod. Convention is to use lower case.
modId = postea modId = postea
modGroup = com.colen.postea modGroup = com.gtnewhorizons.postea
# WHY is there no version field? # WHY is there no version field?
# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the # The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
@@ -37,7 +37,7 @@ enableModernJavaSyntax = true
enableGenericInjection = false enableGenericInjection = false
# Generate a class with String fields for the mod id, name, version and group name named with the fields below # Generate a class with String fields for the mod id, name, version and group name named with the fields below
generateGradleTokenClass = com.colen.postea.Tags generateGradleTokenClass = com.gtnewhorizons.postea.Tags
gradleTokenModId = MODID gradleTokenModId = MODID
gradleTokenModName = MODNAME gradleTokenModName = MODNAME
gradleTokenVersion = VERSION gradleTokenVersion = VERSION
@@ -1,15 +0,0 @@
package com.colen.postea;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
@SuppressWarnings("unused")
public class Postea {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
}
}
@@ -1,24 +0,0 @@
package com.colen.postea.Utility;
import net.minecraft.nbt.NBTTagCompound;
public abstract class PosteaUtilities {
@SuppressWarnings("unused")
public static NBTTagCompound cleanseNBT(String newTileEntityID, NBTTagCompound tag) {
// Cleans the NBT, so that it replaces the ID and adds the x, y, z coordinates.
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setString("id", newTileEntityID);
// This part is for tile entities only.
if (tag.hasKey("x") && tag.hasKey("y") && tag.hasKey("z")) {
tagCompound.setInteger("x", tag.getInteger("x"));
tagCompound.setInteger("y", tag.getInteger("y"));
tagCompound.setInteger("z", tag.getInteger("z"));
}
return tagCompound;
}
}
@@ -1,24 +0,0 @@
package com.colen.postea.mixins.early;
import static com.colen.postea.Utility.ChunkFixerUtility.processChunkNBT;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(AnvilChunkLoader.class)
@SuppressWarnings("unused")
public abstract class MixinAnvilChunkLoader {
@Inject(method = "checkedReadChunkFromNBT__Async", at = @At("HEAD"), remap = false)
private void onCheckedReadChunkFromNBT__Async(World world, int x, int z, NBTTagCompound compound,
CallbackInfoReturnable<Object[]> cir) {
processChunkNBT(compound, world);
}
}
@@ -0,0 +1,36 @@
package com.gtnewhorizons.postea;
import static com.gtnewhorizons.postea.api.BlockReplacementManager.blockReplacementMap;
import static com.gtnewhorizons.postea.api.BlockReplacementManager.posteaMarkedIDs;
import net.minecraft.block.Block;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
@SuppressWarnings("unused")
public class Postea {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {}
@Mod.EventHandler
public void onServerStarting(FMLServerAboutToStartEvent event) {
for (String name : blockReplacementMap.keySet()) {
Block block = Block.getBlockFromName(name);
if (block != null) {
int id = Block.getIdFromBlock(block);
posteaMarkedIDs.add(id);
}
}
}
@Mod.EventHandler
public void onServerStopping(FMLServerStoppingEvent event) {
posteaMarkedIDs.clear();
}
}
@@ -1,16 +1,18 @@
package com.colen.postea.API; package com.gtnewhorizons.postea.api;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import net.minecraft.world.World; import net.minecraft.world.World;
import com.colen.postea.Utility.BlockConversionInfo; import com.gtnewhorizons.postea.utility.BlockConversionInfo;
public class BlockReplacementManager { public class BlockReplacementManager {
private static final Map<String, BiFunction<BlockConversionInfo, World, BlockConversionInfo>> blockReplacementMap = new HashMap<>(); public static final Map<String, BiFunction<BlockConversionInfo, World, BlockConversionInfo>> blockReplacementMap = new HashMap<>();
public static final HashSet<Integer> posteaMarkedIDs = new HashSet<>();
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void addBlockReplacement(String blockNameIn, public static void addBlockReplacement(String blockNameIn,
@@ -30,4 +32,9 @@ public class BlockReplacementManager {
} }
} }
// We need this to save reprocessing blocks.
public static boolean blockNotConvertible(int blockID) {
return !posteaMarkedIDs.contains(blockID);
}
} }
@@ -1,4 +1,4 @@
package com.colen.postea.API; package com.gtnewhorizons.postea.api;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -1,4 +1,4 @@
package com.colen.postea.API; package com.gtnewhorizons.postea.api;
import java.util.HashMap; import java.util.HashMap;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@@ -6,7 +6,7 @@ import java.util.function.BiFunction;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
import com.colen.postea.Utility.BlockInfo; import com.gtnewhorizons.postea.utility.BlockInfo;
public class TileEntityReplacementManager { public class TileEntityReplacementManager {
@@ -1,4 +1,4 @@
package com.colen.postea.mixins; package com.gtnewhorizons.postea.mixins;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -44,6 +44,7 @@ public final class PosteaLoadingPlugin implements IEarlyMixinLoader, IFMLLoading
public List<String> getMixins(Set<String> loadedCoreMods) { public List<String> getMixins(Set<String> loadedCoreMods) {
final List<String> mixins = new ArrayList<>(); final List<String> mixins = new ArrayList<>();
mixins.add("MixinItemStack"); mixins.add("MixinItemStack");
mixins.add("MixinChunk");
mixins.add("MixinAnvilChunkLoader"); mixins.add("MixinAnvilChunkLoader");
return mixins; return mixins;
} }
@@ -0,0 +1,49 @@
package com.gtnewhorizons.postea.mixins.early;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
@Mixin(AnvilChunkLoader.class)
public abstract class MixinAnvilChunkLoader {
@Inject(method = "checkedReadChunkFromNBT__Async", at = @At("HEAD"), remap = false)
private void onCheckedReadChunkFromNBT__Async(World world, int x, int z, NBTTagCompound compound,
CallbackInfoReturnable<Object[]> cir) {
ChunkFixerUtility.processChunkNBT(compound, world);
}
@Inject(method = "readChunkFromNBT", at = @At("RETURN"))
private Chunk onReadChunkFromNBT(World world, NBTTagCompound nbtTagCompound, CallbackInfoReturnable<Chunk> cir) {
Chunk chunk = cir.getReturnValue();
if (chunk instanceof IChunkMixin iChunkMixin) {
if (nbtTagCompound.hasKey("POSTEA")) {
long posteaCode = nbtTagCompound.getLong("POSTEA");
iChunkMixin.Postea$setPosteaCode(posteaCode);
// Chunk has been updated with Postea, so we will mark it to save later.
if (posteaCode != ChunkFixerUtility.POSTEA_UPDATE_CODE) chunk.setChunkModified();
}
}
return chunk;
}
@Inject(method = "writeChunkToNBT", at = @At("HEAD"))
private void onWriteChunkToNBT(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
if (chunk instanceof IChunkMixin iChunkMixin) {
nbtTagCompound.setLong("POSTEA", iChunkMixin.Postea$getPosteaCode());
}
}
}
@@ -0,0 +1,27 @@
package com.gtnewhorizons.postea.mixins.early;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
@Mixin(Chunk.class)
public class MixinChunk implements IChunkMixin {
// This new field will store the hash of mod name + versions. We use this to check
// if we need to reprocess this chunk.
@Unique
private long postea_GTNH$posteaID;
@Unique
public long Postea$getPosteaCode() {
return postea_GTNH$posteaID;
}
@Unique
public void Postea$setPosteaCode(long POSTEA_ID) {
this.postea_GTNH$posteaID = POSTEA_ID;
}
}
@@ -1,6 +1,6 @@
package com.colen.postea.mixins.early; package com.gtnewhorizons.postea.mixins.early;
import static com.colen.postea.Utility.ItemFixerUtility.fixItemStack; import static com.gtnewhorizons.postea.utility.ItemFixerUtility.fixItemStack;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -0,0 +1,8 @@
package com.gtnewhorizons.postea.mixins.interfaces;
public interface IChunkMixin {
long Postea$getPosteaCode();
void Postea$setPosteaCode(long posteaID);
}
@@ -1,4 +1,4 @@
package com.colen.postea.Utility; package com.gtnewhorizons.postea.utility;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
@@ -1,4 +1,4 @@
package com.colen.postea.Utility; package com.gtnewhorizons.postea.utility;
import java.util.function.Function; import java.util.function.Function;
@@ -1,6 +1,10 @@
package com.colen.postea.Utility; package com.gtnewhorizons.postea.utility;
import static com.gtnewhorizons.postea.api.BlockReplacementManager.blockNotConvertible;
import static com.gtnewhorizons.postea.utility.PosteaUtilities.getModListHash;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -10,8 +14,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World; import net.minecraft.world.World;
import com.colen.postea.API.BlockReplacementManager; import com.gtnewhorizons.postea.api.BlockReplacementManager;
import com.colen.postea.API.TileEntityReplacementManager; import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
import akka.japi.Pair; import akka.japi.Pair;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
@@ -19,16 +23,36 @@ import cpw.mods.fml.common.registry.GameRegistry;
public class ChunkFixerUtility { public class ChunkFixerUtility {
public static void processChunkNBT(NBTTagCompound compound, World world) { public static void processChunkNBT(NBTTagCompound compound, World world) {
transformTileEntities(compound, world); NBTTagCompound levelCompoundTag = compound.getCompoundTag("Level");
transformNormalBlocks(compound, world);
if (processChunk(levelCompoundTag)) {
transformTileEntities(levelCompoundTag, world);
transformNormalBlocks(levelCompoundTag, world);
levelCompoundTag.setInteger("POSTEA", POSTEA_UPDATE_CODE);
}
} }
private static void transformNormalBlocks(NBTTagCompound compound, World world) { // This will not change between runs, unless a mod is updated or added.
NBTTagCompound level = compound.getCompoundTag("Level"); public static final int POSTEA_UPDATE_CODE = getModListHash();
NBTTagList sections = level.getTagList("Sections", 10);
int chunkXPos = level.getInteger("xPos") * 16; // If a chunk has the same postea code, then do not update it. Return false.
int chunkZPos = level.getInteger("zPos") * 16; private static boolean processChunk(NBTTagCompound compound) {
// I'm minimising the string length here since this
// will be on every single chunk in every world... Rather not duplicate too much.
if (compound.hasKey("POSTEA")) {
return compound.getInteger("POSTEA") != POSTEA_UPDATE_CODE;
}
return true;
}
private static final int AIR_ID = 0;
private static final HashMap<Block, String> loadedBlocks = new HashMap<>();
private static void transformNormalBlocks(NBTTagCompound levelCompoundTag, World world) {
NBTTagList sections = levelCompoundTag.getTagList("Sections", 10);
int chunkXPos = levelCompoundTag.getInteger("xPos") * 16;
int chunkZPos = levelCompoundTag.getInteger("zPos") * 16;
for (int i = 0; i < sections.tagCount(); i++) { for (int i = 0; i < sections.tagCount(); i++) {
NBTTagCompound section = sections.getCompoundTagAt(i); NBTTagCompound section = sections.getCompoundTagAt(i);
@@ -40,12 +64,21 @@ public class ChunkFixerUtility {
byte sectionY = section.getByte("Y"); byte sectionY = section.getByte("Y");
for (int index = 0; index < blockArray.length / 2; index++) { for (int index = 0; index < blockArray.length / 2; index++) {
// Horrible bit jank to recreate the actual IDs, because the array is just a byte array.
int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF); int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF);
int metadata = ((metadataArray[index * 2] & 0xFF) << 8) | (metadataArray[index * 2 + 1] & 0xFF); int metadata = ((metadataArray[index * 2] & 0xFF) << 8) | (metadataArray[index * 2 + 1] & 0xFF);
// Skip air.
if (blockId == AIR_ID) continue;
// If this block has no registered Postea conversion, skip it.
if (blockNotConvertible(blockId)) continue;
// Cache block names to improve performance, as findUniqueIdentifierFor is expensive.
Block block = Block.getBlockById(blockId); Block block = Block.getBlockById(blockId);
String blockName = GameRegistry.findUniqueIdentifierFor(block) String blockName = loadedBlocks.computeIfAbsent(
.toString(); block,
b -> GameRegistry.findUniqueIdentifierFor(b)
.toString());
BlockConversionInfo blockConversionInfo = new BlockConversionInfo(); BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
blockConversionInfo.blockName = blockName; blockConversionInfo.blockName = blockName;
@@ -77,19 +110,22 @@ public class ChunkFixerUtility {
} }
} }
public static void transformTileEntities(NBTTagCompound chunkNBT, World world) { private static void transformTileEntities(NBTTagCompound levelCompoundTag, World world) {
NBTTagCompound level = chunkNBT.getCompoundTag("Level");
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(level.getTagList("TileEntities", 10), world); Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(
levelCompoundTag.getTagList("TileEntities", 10),
world);
List<ConversionInfo> conversionInfoList = output.first(); List<ConversionInfo> conversionInfoList = output.first();
NBTTagList tileEntities = output.second(); NBTTagList tileEntities = output.second();
level.setTag("TileEntities", tileEntities);
int chunkXPos = level.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis if (tileEntities.tagCount() > 0) {
int chunkZPos = level.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis levelCompoundTag.setTag("TileEntities", tileEntities);
}
NBTTagList sections = level.getTagList("Sections", 10); int chunkXPos = levelCompoundTag.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
int chunkZPos = levelCompoundTag.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
NBTTagList sections = levelCompoundTag.getTagList("Sections", 10);
for (int i = 0; i < sections.tagCount(); i++) { for (int i = 0; i < sections.tagCount(); i++) {
NBTTagCompound section = sections.getCompoundTagAt(i); NBTTagCompound section = sections.getCompoundTagAt(i);
processSection(section, conversionInfoList, chunkXPos, chunkZPos); processSection(section, conversionInfoList, chunkXPos, chunkZPos);
@@ -169,13 +205,15 @@ public class ChunkFixerUtility {
} // Otherwise they are removed, therefore not appended. } // Otherwise they are removed, therefore not appended.
conversionInfo.add(new ConversionInfo(x, y, z, blockInfo)); conversionInfo.add(new ConversionInfo(x, y, z, blockInfo));
} else {
tileEntitiesCopy.appendTag(tileEntity);
} }
} }
return new Pair<>(conversionInfo, tileEntitiesCopy); return new Pair<>(conversionInfo, tileEntitiesCopy);
} }
public static class ConversionInfo { private static class ConversionInfo {
public final int x; public final int x;
public final int y; public final int y;
@@ -1,11 +1,11 @@
package com.colen.postea.Utility; package com.gtnewhorizons.postea.utility;
import java.util.function.Function; import java.util.function.Function;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import com.colen.postea.API.ItemStackReplacementManager; import com.gtnewhorizons.postea.api.ItemStackReplacementManager;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
@@ -18,6 +18,7 @@ public abstract class ItemFixerUtility {
if (tag.hasKey("id")) { if (tag.hasKey("id")) {
short id = tag.getShort("id"); short id = tag.getShort("id");
Item item = Item.getItemById(id); Item item = Item.getItemById(id);
if (item == null) return;
String itemNameInternal = GameRegistry.findUniqueIdentifierFor(item).modId + ":" String itemNameInternal = GameRegistry.findUniqueIdentifierFor(item).modId + ":"
+ GameRegistry.findUniqueIdentifierFor(item).name; + GameRegistry.findUniqueIdentifierFor(item).name;
@@ -0,0 +1,68 @@
package com.gtnewhorizons.postea.utility;
import java.util.ArrayList;
import java.util.Collections;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
public abstract class PosteaUtilities {
@SuppressWarnings("unused")
public static NBTTagCompound cleanseNBT(String newTileEntityID, NBTTagCompound tag) {
// Cleans the NBT, so that it replaces the ID and adds the x, y, z coordinates.
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setString("id", newTileEntityID);
// This part is for tile entities only.
if (tag.hasKey("x") && tag.hasKey("y") && tag.hasKey("z")) {
tagCompound.setInteger("x", tag.getInteger("x"));
tagCompound.setInteger("y", tag.getInteger("y"));
tagCompound.setInteger("z", tag.getInteger("z"));
}
return tagCompound;
}
public static int getModListHash() {
// We iterate over every mod, get its version and put it into a giant list.
// This is done so we can see if our mods have actually changed, if so, we
// will recheck every chunk for Postea adjustments.
ArrayList<String> modList = new ArrayList<>();
for (ModContainer mod : Loader.instance()
.getActiveModList()) {
modList.add(mod.getModId() + ":" + mod.getVersion());
}
// Sort this first.
Collections.sort(modList);
// Step 2: Append all elements into one string
StringBuilder combinedModStringSortedBuilder = new StringBuilder();
for (String element : modList) {
combinedModStringSortedBuilder.append(element);
}
String combinedModStringSorted = combinedModStringSortedBuilder.toString();
return combinedModStringSorted.hashCode();
}
public static void markChunkAsDirty(World world, int chunkX, int chunkZ) {
if (!world.isRemote) { // Check to make sure we're on the server side.
Chunk chunk = world.getChunkFromChunkCoords(chunkX, chunkZ);
if (chunk == null) return;
chunk.setChunkModified();
}
}
}
+2 -1
View File
@@ -1,12 +1,13 @@
{ {
"required": true, "required": true,
"minVersion": "0.8.5-GTNH", "minVersion": "0.8.5-GTNH",
"package": "com.colen.postea.mixins.early", "package": "com.gtnewhorizons.postea.mixins.early",
"refmap": "mixins.postea.refmap.json", "refmap": "mixins.postea.refmap.json",
"target": "@env(DEFAULT)", "target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_8",
"mixins": [ "mixins": [
"MixinAnvilChunkLoader", "MixinAnvilChunkLoader",
"MixinChunk",
"MixinItemStack" "MixinItemStack"
], ],
"client": [], "client": [],