mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-24 05:54:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef42dfc91f | ||
|
|
361c851706 | ||
|
|
ebb2517488 | ||
|
|
ff97e8841c | ||
|
|
b60e19b434 | ||
|
|
cb9de2d290 | ||
|
|
ec2b6a9007 | ||
|
|
d9ceee01b5 | ||
|
|
d1817ea4c2 |
No files matched your search
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api('com.github.GTNewHorizons:NotEnoughIds:1.5.4-pre:dev')
|
api('com.github.GTNewHorizons:NotEnoughIds:2.1.0:dev')
|
||||||
}
|
}
|
||||||
+17
-5
@@ -33,7 +33,7 @@ channel = stable
|
|||||||
mappingsVersion = 12
|
mappingsVersion = 12
|
||||||
|
|
||||||
# Defines other MCP mappings for dependency deobfuscation.
|
# Defines other MCP mappings for dependency deobfuscation.
|
||||||
remoteMappings = https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
|
remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
|
||||||
|
|
||||||
# Select a default username for testing your mod. You can always override this per-run by running
|
# Select a default username for testing your mod. You can always override this per-run by running
|
||||||
# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE.
|
# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE.
|
||||||
@@ -61,6 +61,9 @@ gradleTokenModId = MODID
|
|||||||
# [DEPRECATED] Mod name replacement token.
|
# [DEPRECATED] Mod name replacement token.
|
||||||
gradleTokenModName = MODNAME
|
gradleTokenModName = MODNAME
|
||||||
|
|
||||||
|
# [DEPRECATED] Mod Group replacement token.
|
||||||
|
gradleTokenGroupName = GROUPNAME
|
||||||
|
|
||||||
# [DEPRECATED]
|
# [DEPRECATED]
|
||||||
# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java
|
# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java
|
||||||
# public static final String VERSION = "GRADLETOKEN_VERSION";
|
# public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||||
@@ -82,6 +85,11 @@ accessTransformersFile =
|
|||||||
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
|
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
|
||||||
usesMixins = true
|
usesMixins = true
|
||||||
|
|
||||||
|
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
|
||||||
|
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
|
||||||
|
# Mixin classes will have access to "main" classes, but not the other way around.
|
||||||
|
separateMixinSourceSet =
|
||||||
|
|
||||||
# Adds some debug arguments like verbose output and class export.
|
# Adds some debug arguments like verbose output and class export.
|
||||||
usesMixinDebug = true
|
usesMixinDebug = true
|
||||||
|
|
||||||
@@ -114,16 +122,22 @@ minimizeShadowedDependencies = true
|
|||||||
# If disabled, won't rename the shadowed classes.
|
# If disabled, won't rename the shadowed classes.
|
||||||
relocateShadowedDependencies = true
|
relocateShadowedDependencies = true
|
||||||
|
|
||||||
# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories.
|
# Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
|
||||||
includeWellKnownRepositories = true
|
includeWellKnownRepositories = true
|
||||||
|
|
||||||
|
# A list of repositories to exclude from the includeWellKnownRepositories setting. Should be a space separated
|
||||||
|
# list of strings, with the acceptable keys being(case does not matter):
|
||||||
|
# cursemaven
|
||||||
|
# modrinth
|
||||||
|
excludeWellKnownRepositories =
|
||||||
|
|
||||||
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
|
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
|
||||||
# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables.
|
# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables.
|
||||||
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
|
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
|
||||||
usesMavenPublishing = true
|
usesMavenPublishing = true
|
||||||
|
|
||||||
# Maven repository to publish the mod to.
|
# Maven repository to publish the mod to.
|
||||||
# mavenPublishUrl = https://nexus.gtnewhorizons.com/repository/releases/
|
# mavenPublishUrl = https\://nexus.gtnewhorizons.com/repository/releases/
|
||||||
|
|
||||||
# Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token.
|
# Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token.
|
||||||
#
|
#
|
||||||
@@ -187,5 +201,3 @@ curseForgeRelations =
|
|||||||
# This is meant to be set in $HOME/.gradle/gradle.properties.
|
# This is meant to be set in $HOME/.gradle/gradle.properties.
|
||||||
# ideaCheckSpotlessOnBuild = true
|
# ideaCheckSpotlessOnBuild = true
|
||||||
|
|
||||||
# Non-GTNH properties
|
|
||||||
gradleTokenGroupName = GROUPNAME
|
|
||||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -84,7 +86,8 @@ done
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||||
|
' "$PWD" ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
|
|||||||
Vendored
+2
@@ -13,6 +13,8 @@
|
|||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.8'
|
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -4,6 +4,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
|
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
|
||||||
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -13,34 +14,72 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
|
|
||||||
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
|
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
|
||||||
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
|
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
|
|
||||||
@Mixin(AnvilChunkLoader.class)
|
@Mixin(AnvilChunkLoader.class)
|
||||||
public abstract class MixinAnvilChunkLoader {
|
public abstract class MixinAnvilChunkLoader {
|
||||||
|
|
||||||
@Inject(method = "checkedReadChunkFromNBT__Async", at = @At("HEAD"), remap = false)
|
@Inject(
|
||||||
private void onCheckedReadChunkFromNBT__Async(World world, int x, int z, NBTTagCompound compound,
|
method = "readChunkFromNBT",
|
||||||
CallbackInfoReturnable<Object[]> cir) {
|
at = @At(
|
||||||
ChunkFixerUtility.processChunkNBT(compound, world);
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/nbt/NBTTagCompound;getIntArray(Ljava/lang/String;)[I",
|
||||||
|
ordinal = 0),
|
||||||
|
require = 1)
|
||||||
|
private void postea$readPosteaChunkCode(CallbackInfoReturnable<Chunk> cir, @Local Chunk chunk,
|
||||||
|
@Local(ordinal = 0) NBTTagCompound tag) {
|
||||||
|
IChunkMixin chunkMixin = (IChunkMixin) chunk;
|
||||||
|
chunkMixin.Postea$setPosteaCode(-1);
|
||||||
|
if (tag.hasKey("POSTEA")) {
|
||||||
|
chunkMixin.Postea$setPosteaCode(tag.getLong("POSTEA"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "readChunkFromNBT", at = @At("RETURN"))
|
@Inject(
|
||||||
private Chunk onReadChunkFromNBT(World world, NBTTagCompound nbtTagCompound, CallbackInfoReturnable<Chunk> cir) {
|
method = "readChunkFromNBT",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;setBlockMetadataArray(Lnet/minecraft/world/chunk/NibbleArray;)V",
|
||||||
|
shift = At.Shift.AFTER),
|
||||||
|
require = 1)
|
||||||
|
private void postea$transformBlocks(CallbackInfoReturnable<Chunk> cir, @Local World world, @Local Chunk chunk,
|
||||||
|
@Local ExtendedBlockStorage ebs) {
|
||||||
|
IChunkMixin chunkMixin = (IChunkMixin) chunk;
|
||||||
|
// This checks if the chunk has been run with the current POSTEA_UPDATE_CODE and skips it if so.
|
||||||
|
if (chunkMixin.Postea$getPosteaCode() == ChunkFixerUtility.POSTEA_UPDATE_CODE) return;
|
||||||
|
|
||||||
|
ChunkFixerUtility.transformNormalBlocks(chunk, ebs, world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "loadEntities",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/nbt/NBTTagCompound;getTagList(Ljava/lang/String;I)Lnet/minecraft/nbt/NBTTagList;",
|
||||||
|
ordinal = 1),
|
||||||
|
require = 1)
|
||||||
|
private void postea$transformTileEntities(CallbackInfo ci, @Local(ordinal = 0) NBTTagCompound tag,
|
||||||
|
@Local World world, @Local Chunk chunk) {
|
||||||
|
IChunkMixin chunkMixin = (IChunkMixin) chunk;
|
||||||
|
// This checks if the chunk has been run with the current POSTEA_UPDATE_CODE and skips it if so.
|
||||||
|
if (chunkMixin.Postea$getPosteaCode() == ChunkFixerUtility.POSTEA_UPDATE_CODE) return;
|
||||||
|
|
||||||
|
ChunkFixerUtility.transformTileEntities(tag, chunk, world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "loadChunk", at = @At("RETURN"))
|
||||||
|
private void postea$updatePosteaChunkCode(World world, int i, int j, CallbackInfoReturnable<Chunk> cir) {
|
||||||
Chunk chunk = cir.getReturnValue();
|
Chunk chunk = cir.getReturnValue();
|
||||||
if (chunk instanceof IChunkMixin iChunkMixin) {
|
if (chunk instanceof IChunkMixin iChunkMixin) {
|
||||||
if (nbtTagCompound.hasKey("POSTEA")) {
|
if (iChunkMixin.Postea$getPosteaCode() != ChunkFixerUtility.POSTEA_UPDATE_CODE) {
|
||||||
long posteaCode = nbtTagCompound.getLong("POSTEA");
|
iChunkMixin.Postea$setPosteaCode(ChunkFixerUtility.POSTEA_UPDATE_CODE);
|
||||||
iChunkMixin.Postea$setPosteaCode(posteaCode);
|
chunk.setChunkModified();
|
||||||
|
|
||||||
// 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"))
|
@Inject(method = "writeChunkToNBT", at = @At("HEAD"))
|
||||||
private void onWriteChunkToNBT(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
|
private void postea$writePosteaChunkCode(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
|
||||||
if (chunk instanceof IChunkMixin iChunkMixin) {
|
if (chunk instanceof IChunkMixin iChunkMixin) {
|
||||||
nbtTagCompound.setLong("POSTEA", iChunkMixin.Postea$getPosteaCode());
|
nbtTagCompound.setLong("POSTEA", iChunkMixin.Postea$getPosteaCode());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
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 net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.neid.mixins.interfaces.IExtendedBlockStorageMixin;
|
||||||
import com.gtnewhorizons.postea.api.BlockReplacementManager;
|
import com.gtnewhorizons.postea.api.BlockReplacementManager;
|
||||||
import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
|
import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
|
||||||
|
|
||||||
@@ -22,95 +25,64 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
|||||||
|
|
||||||
public class ChunkFixerUtility {
|
public class ChunkFixerUtility {
|
||||||
|
|
||||||
public static void processChunkNBT(NBTTagCompound compound, World world) {
|
|
||||||
NBTTagCompound levelCompoundTag = compound.getCompoundTag("Level");
|
|
||||||
|
|
||||||
if (processChunk(levelCompoundTag)) {
|
|
||||||
transformTileEntities(levelCompoundTag, world);
|
|
||||||
transformNormalBlocks(levelCompoundTag, world);
|
|
||||||
levelCompoundTag.setInteger("POSTEA", POSTEA_UPDATE_CODE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This will not change between runs, unless a mod is updated or added.
|
// This will not change between runs, unless a mod is updated or added.
|
||||||
public static final int POSTEA_UPDATE_CODE = getModListHash();
|
public static final int POSTEA_UPDATE_CODE = getModListHash();
|
||||||
|
|
||||||
// If a chunk has the same postea code, then do not update it. Return false.
|
|
||||||
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 int AIR_ID = 0;
|
||||||
private static final HashMap<Block, String> loadedBlocks = new HashMap<>();
|
private static final HashMap<Block, String> loadedBlocks = new HashMap<>();
|
||||||
|
|
||||||
private static void transformNormalBlocks(NBTTagCompound levelCompoundTag, World world) {
|
public static void transformNormalBlocks(Chunk chunk, ExtendedBlockStorage ebs, World world) {
|
||||||
NBTTagList sections = levelCompoundTag.getTagList("Sections", 10);
|
|
||||||
|
|
||||||
int chunkXPos = levelCompoundTag.getInteger("xPos") * 16;
|
int chunkXPos = chunk.xPosition * 16;
|
||||||
int chunkZPos = levelCompoundTag.getInteger("zPos") * 16;
|
int chunkZPos = chunk.zPosition * 16;
|
||||||
|
|
||||||
for (int i = 0; i < sections.tagCount(); i++) {
|
int sectionY = ebs.getYLocation();
|
||||||
NBTTagCompound section = sections.getCompoundTagAt(i);
|
|
||||||
|
|
||||||
// Blocks16 and Data16 exist only because of NEID.
|
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin) ebs;
|
||||||
byte[] blockArray = section.getByteArray("Blocks16");
|
short[] blockArray = ebsMixin.getBlock16BArray();
|
||||||
byte[] metadataArray = section.getByteArray("Data16");
|
short[] metadataArray = ebsMixin.getBlock16BMetaArray();
|
||||||
|
|
||||||
byte sectionY = section.getByte("Y");
|
for (int index = 0; index < blockArray.length; index++) {
|
||||||
|
int blockId = blockArray[index];
|
||||||
|
int metadata = metadataArray[index];
|
||||||
|
|
||||||
for (int index = 0; index < blockArray.length / 2; index++) {
|
// Skip air.
|
||||||
// Horrible bit jank to recreate the actual IDs, because the array is just a byte array.
|
if (blockId == AIR_ID) continue;
|
||||||
int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF);
|
// If this block has no registered Postea conversion, skip it.
|
||||||
int metadata = ((metadataArray[index * 2] & 0xFF) << 8) | (metadataArray[index * 2 + 1] & 0xFF);
|
if (blockNotConvertible(blockId)) continue;
|
||||||
|
|
||||||
// Skip air.
|
// Cache block names to improve performance, as findUniqueIdentifierFor is expensive.
|
||||||
if (blockId == AIR_ID) continue;
|
Block block = Block.getBlockById(blockId);
|
||||||
// If this block has no registered Postea conversion, skip it.
|
String blockName = loadedBlocks.computeIfAbsent(
|
||||||
if (blockNotConvertible(blockId)) continue;
|
block,
|
||||||
|
b -> GameRegistry.findUniqueIdentifierFor(b)
|
||||||
|
.toString());
|
||||||
|
|
||||||
// Cache block names to improve performance, as findUniqueIdentifierFor is expensive.
|
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
|
||||||
Block block = Block.getBlockById(blockId);
|
blockConversionInfo.blockName = blockName;
|
||||||
String blockName = loadedBlocks.computeIfAbsent(
|
blockConversionInfo.blockID = blockId;
|
||||||
block,
|
blockConversionInfo.metadata = (byte) metadata; // Updated
|
||||||
b -> GameRegistry.findUniqueIdentifierFor(b)
|
|
||||||
.toString());
|
|
||||||
|
|
||||||
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
|
blockConversionInfo.world = world;
|
||||||
blockConversionInfo.blockName = blockName;
|
|
||||||
blockConversionInfo.blockID = blockId;
|
|
||||||
blockConversionInfo.metadata = (byte) metadata; // Updated
|
|
||||||
blockConversionInfo.world = world;
|
|
||||||
|
|
||||||
int x = index % 16;
|
int x = index % 16;
|
||||||
int y = (index / 256) + (sectionY * 16);
|
int y = (index / 256) + (sectionY * 16);
|
||||||
int z = (index / 16) % 16;
|
int z = (index / 16) % 16;
|
||||||
|
|
||||||
blockConversionInfo.x = x + chunkXPos + 1;
|
blockConversionInfo.x = x + chunkXPos + 1;
|
||||||
blockConversionInfo.y = y;
|
blockConversionInfo.y = y;
|
||||||
blockConversionInfo.z = z + chunkZPos + 1;
|
blockConversionInfo.z = z + chunkZPos + 1;
|
||||||
|
|
||||||
BlockConversionInfo output = BlockReplacementManager.getBlockReplacement(blockConversionInfo, world);
|
BlockConversionInfo output = BlockReplacementManager.getBlockReplacement(blockConversionInfo, world);
|
||||||
|
|
||||||
if (output != null) {
|
if (output != null) {
|
||||||
int newBlockId = output.blockID;
|
blockArray[index] = (short) output.blockID;
|
||||||
int newMetadata = output.metadata;
|
metadataArray[index] = (short) output.metadata;
|
||||||
|
|
||||||
blockArray[index * 2] = (byte) ((newBlockId >> 8) & 0xFF);
|
|
||||||
blockArray[index * 2 + 1] = (byte) (newBlockId & 0xFF);
|
|
||||||
|
|
||||||
metadataArray[index * 2] = (byte) ((newMetadata >> 8) & 0xFF);
|
|
||||||
metadataArray[index * 2 + 1] = (byte) (newMetadata & 0xFF);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void transformTileEntities(NBTTagCompound levelCompoundTag, World world) {
|
public static void transformTileEntities(NBTTagCompound levelCompoundTag, Chunk chunk, World world) {
|
||||||
|
|
||||||
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(
|
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(
|
||||||
levelCompoundTag.getTagList("TileEntities", 10),
|
levelCompoundTag.getTagList("TileEntities", 10),
|
||||||
@@ -122,64 +94,33 @@ public class ChunkFixerUtility {
|
|||||||
levelCompoundTag.setTag("TileEntities", tileEntities);
|
levelCompoundTag.setTag("TileEntities", tileEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
int chunkXPos = levelCompoundTag.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
|
int chunkXPos = chunk.xPosition * 16;
|
||||||
int chunkZPos = levelCompoundTag.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
|
int chunkZPos = chunk.zPosition * 16;
|
||||||
|
|
||||||
NBTTagList sections = levelCompoundTag.getTagList("Sections", 10);
|
for (ExtendedBlockStorage ebs : chunk.getBlockStorageArray()) {
|
||||||
for (int i = 0; i < sections.tagCount(); i++) {
|
processSection(ebs, conversionInfoList, chunkXPos, chunkZPos);
|
||||||
NBTTagCompound section = sections.getCompoundTagAt(i);
|
|
||||||
processSection(section, conversionInfoList, chunkXPos, chunkZPos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processSection(NBTTagCompound section, List<ConversionInfo> conversionInfoList, int chunkXPos,
|
private static void processSection(ExtendedBlockStorage ebs, List<ConversionInfo> conversionInfoList, int chunkXPos,
|
||||||
int chunkZPos) {
|
int chunkZPos) {
|
||||||
byte[] blockArray = section.getByteArray("Blocks16");
|
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin) ebs;
|
||||||
byte[] metadataArray = section.getByteArray("Data16"); // Updated to use Data16
|
short[] blockArray = ebsMixin.getBlock16BArray();
|
||||||
byte y = section.getByte("Y");
|
short[] metadataArray = ebsMixin.getBlock16BMetaArray();
|
||||||
|
|
||||||
List<ConversionInfo> filteredList = filterConversionInfosByY(conversionInfoList, y);
|
int sectionY = ebs.getYLocation();
|
||||||
|
|
||||||
|
List<ConversionInfo> filteredList = conversionInfoList.stream()
|
||||||
|
.filter(info -> info.y >= sectionY * 16 && info.y < (sectionY + 1) * 16)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
for (ConversionInfo info : filteredList) {
|
for (ConversionInfo info : filteredList) {
|
||||||
int[] localCoords = convertToChunkLocalCoordinates(info, y, chunkXPos, chunkZPos);
|
int index = (info.y - sectionY * 16) * 256 + (info.z - chunkZPos) * 16 + (info.x - chunkXPos);
|
||||||
int index = computeBlockIndex(localCoords);
|
blockArray[index] = (short) Block.getIdFromBlock(info.blockInfo.block);
|
||||||
setBlockInfo(info.blockInfo.block, index, blockArray);
|
metadataArray[index] = (short) info.blockInfo.metadata;
|
||||||
setMetadata(info.blockInfo.metadata, index, metadataArray); // This uses the updated setMetadata
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ConversionInfo> filterConversionInfosByY(List<ConversionInfo> conversionInfoList, byte y) {
|
|
||||||
return conversionInfoList.stream()
|
|
||||||
.filter(info -> info.y >= y * 16 && info.y < (y + 1) * 16)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int[] convertToChunkLocalCoordinates(ConversionInfo info, byte y, int chunkXPos, int chunkZPos) {
|
|
||||||
int tileX = info.x - chunkXPos;
|
|
||||||
int tileY = info.y - y * 16;
|
|
||||||
int tileZ = info.z - chunkZPos;
|
|
||||||
return new int[] { tileX, tileY, tileZ };
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int computeBlockIndex(int[] localCoords) {
|
|
||||||
return localCoords[1] * 256 + localCoords[2] * 16 + localCoords[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setBlockInfo(Block block, int index, byte[] blockArray) {
|
|
||||||
int blockID = Block.getIdFromBlock(block);
|
|
||||||
blockArray[index * 2] = (byte) ((blockID >> 8) & 0xFF);
|
|
||||||
blockArray[index * 2 + 1] = (byte) (blockID & 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setMetadata(int metadata, int index, byte[] metadataArray) {
|
|
||||||
// Since each metadata is now two bytes, multiply the index by 2 to get the correct position.
|
|
||||||
int metadataStartIndex = index * 2;
|
|
||||||
|
|
||||||
// Split the 16-bit metadata into two bytes and store them in the array.
|
|
||||||
metadataArray[metadataStartIndex] = (byte) ((metadata >> 8) & 0xFF); // Higher 8 bits
|
|
||||||
metadataArray[metadataStartIndex + 1] = (byte) (metadata & 0xFF); // Lower 8 bits
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world) {
|
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world) {
|
||||||
List<ConversionInfo> conversionInfo = new ArrayList<>();
|
List<ConversionInfo> conversionInfo = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user