World usage working

This commit is contained in:
Connor Colenso committed 2023-10-30 20:02:08 +00:00
1 parent 4baacc0cfd
commit 40b70bfec3
5 files changed
+42 -33

No files matched your search

@@ -1,6 +1,7 @@
package com.colen.postea.API;
import akka.japi.Pair;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
@@ -22,7 +23,7 @@ public class BlockReplacementManager {
@SuppressWarnings("unused")
public static Pair<Integer, Integer> getBlockReplacement(int blockID, int metadataIn) {
Block block = Block.getBlockById(blockID);
String blockName = block.getUnlocalizedName();
String blockName = GameRegistry.findUniqueIdentifierFor(block).toString();
Function<BlockKey, Pair<Integer, Integer>> transformer = blockReplacementMap.getOrDefault(new BlockKey(blockName, metadataIn), null);
@@ -4,21 +4,22 @@ import akka.japi.Pair;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
public class ChunkFixerUtility {
public static void processChunkNBT(NBTTagCompound compound) {
transformTileEntities(compound);
transformNormalBlocks(compound);
public static void processChunkNBT(NBTTagCompound compound, World world) {
transformTileEntities(compound, world);
transformNormalBlocks(compound, world);
}
private static void transformNormalBlocks(NBTTagCompound compound) {
private static void transformNormalBlocks(NBTTagCompound compound, World world) {
NBTTagCompound level = compound.getCompoundTag("Level");
NBTTagList sections = level.getTagList("Sections", 10);
for (int i = 0; i < sections.tagCount(); i++) {
@@ -32,8 +33,19 @@ public class ChunkFixerUtility {
Pair<Integer, Integer> output = BlockReplacementManager.getBlockReplacement(blockId, metadata);
if (output != null) {
setBlockInfo(Block.getBlockById(output.first()), index, blockArray);
setMetadata(output.second(), index, metadataArray);
int newBlockId = output.first();
int newMetadata = output.second();
blockArray[index * 2] = (byte) ((newBlockId >> 8) & 0xFF);
blockArray[index * 2 + 1] = (byte) (newBlockId & 0xFF);
if ((index & 1) == 0) { // Even
metadataArray[index / 2] &= 0xF0;
metadataArray[index / 2] |= (newMetadata & 0x0F);
} else { // Odd
metadataArray[index / 2] &= 0x0F;
metadataArray[index / 2] |= ((newMetadata << 4) & 0xF0);
}
}
}
}
@@ -44,10 +56,10 @@ public class ChunkFixerUtility {
*
* @param chunkNBT The chunk's NBT data.
*/
public static void transformTileEntities(NBTTagCompound chunkNBT) {
public static void transformTileEntities(NBTTagCompound chunkNBT, World world) {
NBTTagCompound level = chunkNBT.getCompoundTag("Level");
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(level.getTagList("TileEntities", 10));
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(level.getTagList("TileEntities", 10), world);
List<ConversionInfo> conversionInfoList = output.first();
NBTTagList tileEntities = output.second();
@@ -118,7 +130,7 @@ public class ChunkFixerUtility {
metadataArray[metadataIndex] = currentMetadataByte;
}
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities) {
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world) {
List<ConversionInfo> conversionInfo = new ArrayList<>();
NBTTagList tileEntitiesCopy = new NBTTagList();
@@ -128,14 +140,14 @@ public class ChunkFixerUtility {
String tileEntityId = tileEntity.getString("id");
// Check if we have a transformer registered for this tile entity ID
Function<NBTTagCompound, BlockInfo> transformationFunction = TileEntityReplacementManager.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
BiFunction<NBTTagCompound, World, BlockInfo> transformationFunction = TileEntityReplacementManager.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
if (transformationFunction != null) {
int x = tileEntity.getInteger("x");
int y = tileEntity.getInteger("y");
int z = tileEntity.getInteger("z");
BlockInfo blockInfo = transformationFunction.apply(tileEntity);
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world);
if (blockInfo.tileTransformer != null) {
tileEntitiesCopy.appendTag(blockInfo.tileTransformer.apply(tileEntity));
@@ -1,30 +1,22 @@
package com.colen.postea.API;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
public class TileEntityReplacementManager {
private static final Map<String, Function<NBTTagCompound, NBTTagCompound>> tileEntityFixMap = new HashMap<>();
private static final HashMap<String, Function<NBTTagCompound, ChunkFixerUtility.BlockInfo>> tileEntityToNormalBlockTransformer = new HashMap<>();
private static final HashMap<String, BiFunction<NBTTagCompound, World, ChunkFixerUtility.BlockInfo>> tileEntityToNormalBlockTransformer = new HashMap<>();
@SuppressWarnings("unused")
public static void tileEntityFixer(String tileName , Function<NBTTagCompound, NBTTagCompound> fixerFunction) {
tileEntityFixMap.put(tileName, fixerFunction);
}
public static Function<NBTTagCompound, NBTTagCompound> getTileEntityFixer(String tileName) {
return tileEntityFixMap.getOrDefault(tileName, null);
}
public static void tileEntityTransformer(String tileEntityId, Function<NBTTagCompound, ChunkFixerUtility.BlockInfo> transformerFunction) {
public static void tileEntityTransformer(String tileEntityId, BiFunction<NBTTagCompound, World, ChunkFixerUtility.BlockInfo> transformerFunction) {
tileEntityToNormalBlockTransformer.put(tileEntityId, transformerFunction);
}
public static Function<NBTTagCompound, ChunkFixerUtility.BlockInfo> getTileEntityToNormalBlockTransformerFunction(String tileEntityId) {
public static BiFunction<NBTTagCompound, World, ChunkFixerUtility.BlockInfo> getTileEntityToNormalBlockTransformerFunction(String tileEntityId) {
return tileEntityToNormalBlockTransformer.getOrDefault(tileEntityId, null);
}
}
+10 -6
View File
@@ -35,12 +35,16 @@ public class Postea {
};*/
//TileEntityReplacementManager.tileEntityFixer("GT_TileEntity_Ores", myTransformer);
TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag) -> {
if (tag.getInteger("m") == 86) {
return new ChunkFixerUtility.BlockInfo(Blocks.wool, 5);
TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, world) -> {
if (world.provider.dimensionId == -1) {
return new ChunkFixerUtility.BlockInfo(Blocks.wool, 1);
}
return new ChunkFixerUtility.BlockInfo(Blocks.wool, 1);
if (world.provider.dimensionId == 1) {
return new ChunkFixerUtility.BlockInfo(Blocks.wool, 2);
}
return new ChunkFixerUtility.BlockInfo(Blocks.wool, 3);
});
@@ -70,7 +74,7 @@ public class Postea {
return new ChunkFixerUtility.BlockInfo(Blocks.chest, 0, chestTransformer);
});*/
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag) -> {
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world) -> {
Function<NBTTagCompound, NBTTagCompound> chestTransformer = (oldTag) -> {
@@ -105,7 +109,7 @@ public class Postea {
return new Pair<>(7, 0);
};
BlockReplacementManager.addBlockReplacement("grass", 0, blockTransformer);
BlockReplacementManager.addBlockReplacement("minecraft:grass", 0, blockTransformer);
}
@@ -92,7 +92,7 @@ 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) {
// Your injection code here
processChunkNBT(compound);
processChunkNBT(compound, world);
}
}