diff --git a/dependencies.gradle b/dependencies.gradle index 5e5bca1..e4030ef 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -34,7 +34,7 @@ * For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph */ dependencies { - api("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev") - api('com.github.GTNewHorizons:GT5-Unofficial:5.09.44.71:dev') + //api("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev") + //api('com.github.GTNewHorizons:GT5-Unofficial:5.09.44.71:dev') api('com.github.GTNewHorizons:NotEnoughIds:1.4.6:dev') } diff --git a/src/main/java/com/colen/postea/API/ChunkFixerUtility.java b/src/main/java/com/colen/postea/API/ChunkFixerUtility.java index fd77ff5..c6c8418 100644 --- a/src/main/java/com/colen/postea/API/ChunkFixerUtility.java +++ b/src/main/java/com/colen/postea/API/ChunkFixerUtility.java @@ -4,42 +4,15 @@ import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagByteArray; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import scala.Int; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; public class ChunkFixerUtility { - public static Chunk fixChunk(Chunk chunk) { - // Iterate over each ExtendedBlockStorage. Kinda ugly but does the job... - for (ExtendedBlockStorage storage : chunk.getBlockStorageArray()) { - if (storage != null) { // Always check if storage isn't null before using it - for (int x = 0; x < 16; x++) { - for (int y = 0; y < 16; y++) { // This is not a mistake, we do this on purpose because of how minecraft stores stuff. - for (int z = 0; z < 16; z++) { - - // Get the current block and metadata at the position - Block currentBlock = storage.getBlockByExtId(x, y, z); - int currentMeta = storage.getExtBlockMetadata(x, y, z); - - // Check if there's a replacement for this block+metadata combination - BlockKey replacement = BlockReplacementManager.getBlockReplacement(currentBlock, currentMeta); - - // If there's a replacement, set the new block and metadata - if (replacement != null) { - storage.func_150818_a(x, y, z, replacement.getBlock()); - storage.setExtBlockMetadata(x, y, z, replacement.getDamage()); - } - } - } - } - } - } - return chunk; - } public static void processCode(NBTTagCompound compound) { System.out.println(compound.toString()); @@ -98,8 +71,6 @@ public class ChunkFixerUtility { final List conversionInfoList = removeTileEntities(level.getTagList("TileEntities", 10)); NBTTagList sections = level.getTagList("Sections", 10); - List blockDataList = new ArrayList<>(); - int chunkXPos = level.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis int chunkZPos = level.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis @@ -110,13 +81,12 @@ public class ChunkFixerUtility { byte y = section.getByte("Y"); List filteredList = conversionInfoList.stream() - .filter(info -> info.y >= y * 16 && info.y < (y + 1) * 16) - .collect(Collectors.toList()); + .filter(info -> info.y >= y * 16 && info.y < (y + 1) * 16).collect(Collectors.toList()); for (ConversionInfo info : filteredList) { - int tileX = info.x - chunkXPos; // Convert global x-coordinate to local x-coordinate within the chunk - int tileY = info.y - y * 16; // Convert global y-coordinate to local y-coordinate within the section - int tileZ = info.z - chunkZPos; // Convert global z-coordinate to local z-coordinate within the chunk + int tileX = info.x - chunkXPos; // Convert global x-coordinate to local x-coordinate within the chunk. + int tileY = info.y - y * 16; // Convert global y-coordinate to local y-coordinate within the section. + int tileZ = info.z - chunkZPos; // Convert global z-coordinate to local z-coordinate within the chunk. int index = tileY * 256 + tileZ * 16 + tileX; @@ -144,12 +114,11 @@ public class ChunkFixerUtility { } - - private static List removeTileEntities(NBTTagList tileEntities) { List conversionInfo = new ArrayList<>(); String targetTileEntityId = "GT_TileEntity_Ores"; + List indicesToRemove = new ArrayList<>(); // List to store indices of tileEntities to be removed // Loop through each tile entity to check for matches for (int i = 0; i < tileEntities.tagCount(); i++) { @@ -163,18 +132,23 @@ public class ChunkFixerUtility { int z = tileEntity.getInteger("z"); Function transformationFunction = TileEntityReplacementManager.getTileEntityToNormalBlockTransformerFunction(tileEntityId); - BlockInfo blockInfo = transformationFunction.apply(tileEntity); conversionInfo.add(new ConversionInfo(x, y, z, blockInfo)); - - tileEntities.removeTag(i); + indicesToRemove.add(i); // Add the index to the list for removal } } + // Now remove the tile entities in reverse order to avoid index shifts + Collections.reverse(indicesToRemove); + for (int index : indicesToRemove) { + tileEntities.removeTag(index); + } + return conversionInfo; } + private static void fixTileEntities(NBTTagCompound compound) { NBTTagList tileEntities = compound.getCompoundTag("Level").getTagList("TileEntities", 10); for (int i = 0; i < tileEntities.tagCount(); i++) { @@ -193,7 +167,7 @@ public class ChunkFixerUtility { public final int x; public final int y; public final int z; - final BlockInfo blockInfo; + public final BlockInfo blockInfo; public ConversionInfo(int x, int y, int z, BlockInfo blockInfo) { this.x = x; @@ -204,8 +178,8 @@ public class ChunkFixerUtility { } public static class BlockInfo { - final Block block; - final int metadata; + public final Block block; + public final int metadata; public BlockInfo(Block block, int metadata) { this.block = block; @@ -213,29 +187,4 @@ public class ChunkFixerUtility { } } - public static class ChunkBlockData { - private int blockID; // Block ID (2 bytes or 16 bits) - private byte metadata; // Metadata (4 bits) - - public ChunkBlockData(int blockID, byte metadata) { - this.blockID = blockID; - this.metadata = metadata; - } - - public int getBlockID() { - return blockID; - } - - public void setBlockID(int blockID) { - this.blockID = blockID; - } - - public byte getMetadata() { - return metadata; - } - - public void setMetadata(byte metadata) { - this.metadata = metadata; - } - } } diff --git a/src/main/java/com/colen/postea/Postea.java b/src/main/java/com/colen/postea/Postea.java index f0fd642..1a73c01 100644 --- a/src/main/java/com/colen/postea/Postea.java +++ b/src/main/java/com/colen/postea/Postea.java @@ -1,14 +1,11 @@ package com.colen.postea; -import com.colen.postea.API.BlockReplacementManager; import com.colen.postea.API.ChunkFixerUtility; import com.colen.postea.API.TileEntityReplacementManager; -import com.colen.postea.API.TileTransformer; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import net.minecraft.init.Blocks; -import gregtech.api.GregTech_API; import net.minecraft.nbt.NBTTagCompound; import java.util.function.Function; @@ -36,15 +33,15 @@ public class Postea { //TileEntityReplacementManager.tileEntityFixer("GT_TileEntity_Ores", myTransformer); TileEntityReplacementManager.tileEntityToNormalBlockTransformer("GT_TileEntity_Ores", (tag) -> { if (tag.getInteger("m") == 86) { - return new ChunkFixerUtility.BlockInfo(Blocks.bedrock, 0); + return new ChunkFixerUtility.BlockInfo(Blocks.wool, 5); } - return new ChunkFixerUtility.BlockInfo(Blocks.brick_block, 0); + return new ChunkFixerUtility.BlockInfo(Blocks.wool, 1); }); } @Mod.EventHandler public void postInit(FMLPostInitializationEvent event) { - BlockReplacementManager.addBlockReplacement(GregTech_API.sBlockOres1, 0, Blocks.chest, 0); + //BlockReplacementManager.addBlockReplacement(GregTech_API.sBlockOres1, 0, Blocks.chest, 0); } }