mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-12 00:17:47 +00:00
Progress
This commit is contained in:
1 parent
d41aff53e0
commit
bb895ca93f
3 files changed
+96
-16
No files matched your search
@@ -6,6 +6,10 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ChunkFixerUtility {
|
||||
public static Chunk fixChunk(Chunk chunk) {
|
||||
// Iterate over each ExtendedBlockStorage. Kinda ugly but does the job...
|
||||
@@ -38,20 +42,83 @@ public class ChunkFixerUtility {
|
||||
public static void processCode(NBTTagCompound compound) {
|
||||
System.out.println(compound.toString());
|
||||
|
||||
swapTileEntities(compound);
|
||||
fixTileEntities(compound);
|
||||
replaceTileEntitiesWithDumbBlock(compound, "GT_TileEntity_Ores", (byte) 7, (byte) 0);
|
||||
}
|
||||
|
||||
private static void swapTileEntities(NBTTagCompound compound) {
|
||||
/**
|
||||
* Replaces specified tile entities with a block in the chunk NBT data.
|
||||
*
|
||||
* @param chunkNBT The chunk's NBT data.
|
||||
* @param targetTileEntityId The ID of the tile entity to be replaced.
|
||||
* @param newBlockId The ID of the block to replace the tile entity with.
|
||||
* @param newBlockMetadata The metadata of the new block.
|
||||
*/
|
||||
public static void replaceTileEntitiesWithDumbBlock(NBTTagCompound chunkNBT, String targetTileEntityId, byte newBlockId, byte newBlockMetadata) {
|
||||
|
||||
List<ConversionInfo> conversionInfoList = new ArrayList<>();
|
||||
|
||||
NBTTagCompound level = chunkNBT.getCompoundTag("Level");
|
||||
NBTTagList tileEntities = level.getTagList("TileEntities", 10);
|
||||
NBTTagList sections = level.getTagList("Sections", 10);
|
||||
|
||||
// Loop through each tile entity to check for matches
|
||||
for (int i = 0; i < tileEntities.tagCount(); i++) {
|
||||
NBTTagCompound tileEntity = tileEntities.getCompoundTagAt(i);
|
||||
String tileEntityId = tileEntity.getString("id");
|
||||
|
||||
// If the tile entity matches the target
|
||||
if (tileEntityId.equals(targetTileEntityId)) {
|
||||
int x = tileEntity.getInteger("x");
|
||||
int y = tileEntity.getInteger("y");
|
||||
int z = tileEntity.getInteger("z");
|
||||
|
||||
Function<NBTTagCompound, BlockInfo> transformationFunction = TileEntityReplacementManager.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
|
||||
|
||||
BlockInfo blockInfo = transformationFunction.apply(tileEntity);
|
||||
|
||||
conversionInfoList.add(new ConversionInfo(x, y, z, blockInfo));
|
||||
|
||||
tileEntities.removeTag(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void fixTileEntities(NBTTagCompound compound) {
|
||||
NBTTagList tileEntities = compound.getCompoundTag("Level").getTagList("TileEntities", 10);
|
||||
for (int i = 0; i < tileEntities.tagCount(); i++) {
|
||||
NBTTagCompound tileEntity = tileEntities.getCompoundTagAt(i);
|
||||
String tileEntityStringName = tileEntity.getString("id");
|
||||
TileTransformer tileTransformer = TileEntityReplacementManager.getTileReplacementTransformer(tileEntityStringName);
|
||||
Function<NBTTagCompound, NBTTagCompound> tileFixer = TileEntityReplacementManager.getTileEntityFixer(tileEntityStringName);
|
||||
|
||||
if (tileTransformer != null) {
|
||||
tileTransformer.modifyNBT(tileEntity);
|
||||
if (tileFixer != null) {
|
||||
tileFixer.apply(tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConversionInfo {
|
||||
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int z;
|
||||
final BlockInfo blockInfo;
|
||||
|
||||
public ConversionInfo(int x, int y, int z, BlockInfo blockInfo) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.blockInfo = blockInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockInfo {
|
||||
final Block block;
|
||||
final int metadata;
|
||||
|
||||
public BlockInfo(Block block, int metadata) {
|
||||
this.block = block;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,30 @@
|
||||
package com.colen.postea.API;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class TileEntityReplacementManager {
|
||||
|
||||
private static final Map<String, TileTransformer> replacementMap = new HashMap<>();
|
||||
private static final Map<String, Function<NBTTagCompound, NBTTagCompound>> tileEntityFixMap = new HashMap<>();
|
||||
private static final HashMap<String, Function<NBTTagCompound, ChunkFixerUtility.BlockInfo>> tileEntityToNormalBlockTransformer = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void tileEntityReplacement(String tileName , TileTransformer tileReplacer) {
|
||||
replacementMap.put(tileName, tileReplacer);
|
||||
public static void tileEntityFixer(String tileName , Function<NBTTagCompound, NBTTagCompound> fixerFunction) {
|
||||
tileEntityFixMap.put(tileName, fixerFunction);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static TileTransformer getTileReplacementTransformer(String tileName) {
|
||||
return replacementMap.getOrDefault(tileName, null);
|
||||
public static Function<NBTTagCompound, NBTTagCompound> getTileEntityFixer(String tileName) {
|
||||
return tileEntityFixMap.getOrDefault(tileName, null);
|
||||
}
|
||||
|
||||
public static void tileEntityToNormalBlockTransformer(String tileEntityId, Function<NBTTagCompound, ChunkFixerUtility.BlockInfo> transformerFunction) {
|
||||
tileEntityToNormalBlockTransformer.put(tileEntityId, transformerFunction);
|
||||
}
|
||||
|
||||
public static Function<NBTTagCompound, ChunkFixerUtility.BlockInfo> getTileEntityToNormalBlockTransformerFunction(String tileEntityId) {
|
||||
return tileEntityToNormalBlockTransformer.getOrDefault(tileEntityId, null);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,15 @@
|
||||
package com.colen.postea;
|
||||
|
||||
import appeng.block.networking.BlockController;
|
||||
import appeng.core.Api;
|
||||
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.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import gregtech.api.GregTech_API;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -36,8 +33,14 @@ public class Postea {
|
||||
return tag;
|
||||
};
|
||||
|
||||
TileEntityReplacementManager.tileEntityReplacement("GT_TileEntity_Ores", new TileTransformer("GT_TileEntity_Ores", myTransformer));
|
||||
//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.brick_block, 0);
|
||||
});
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
||||
Reference in new issue
Block a user