mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-18 03:25:07 +00:00
Some progress for block -> block
This commit is contained in:
1 parent
d112fd627f
commit
4399159661
4 files changed
+57
-37
No files matched your search
@@ -7,11 +7,11 @@ import net.minecraft.item.Item;
|
||||
|
||||
public class BlockKey {
|
||||
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
public final String blockName;
|
||||
public final int meta;
|
||||
|
||||
public BlockKey(Block block, int meta) {
|
||||
this.block = block;
|
||||
public BlockKey(String blockName, int meta) {
|
||||
this.blockName = blockName;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@@ -19,20 +19,13 @@ public class BlockKey {
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
if (o instanceof BlockKey that) {
|
||||
return (this.meta == that.meta) && (this.block == that.block);
|
||||
return (this.meta == that.meta) && (this.blockName.equals(that.blockName));
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(block, meta);
|
||||
return Objects.hash(blockName, meta);
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,36 @@
|
||||
package com.colen.postea.API;
|
||||
|
||||
import akka.japi.Pair;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.colen.postea.API.ItemStackReplacementManager.addItemReplacement;
|
||||
|
||||
public class BlockReplacementManager {
|
||||
|
||||
private static final Map<BlockKey, BlockKey> blockReplacementMap = new HashMap<>();
|
||||
private static final Map<BlockKey, Function<BlockKey, Pair<Integer, Integer>>> blockReplacementMap = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void addBlockReplacement(Block blockIn, int metadataIn, Block blockOut, int metadataOut) {
|
||||
blockReplacementMap.put(new BlockKey(blockIn, metadataIn), new BlockKey(blockOut, metadataOut));
|
||||
addItemReplacement(Item.getItemFromBlock(blockIn), metadataIn, Item.getItemFromBlock(blockOut), metadataOut);
|
||||
public static void addBlockReplacement(String blockNameIn, int metadataIn, Function<BlockKey, Pair<Integer, Integer>> transformer) {
|
||||
blockReplacementMap.put(new BlockKey(blockNameIn, metadataIn), transformer);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static BlockKey getBlockReplacement(Block blockIn, int metadataIn) {
|
||||
return blockReplacementMap.getOrDefault(new BlockKey(blockIn, metadataIn), null);
|
||||
public static Pair<Integer, Integer> getBlockReplacement(int blockID, int metadataIn) {
|
||||
Block block = Block.getBlockById(blockID);
|
||||
String blockName = block.getUnlocalizedName();
|
||||
|
||||
Function<BlockKey, Pair<Integer, Integer>> transformer = blockReplacementMap.getOrDefault(new BlockKey(blockName, metadataIn), null);
|
||||
|
||||
if (transformer == null) {
|
||||
return null;
|
||||
} else {
|
||||
return transformer.apply(new BlockKey(blockName, metadataIn));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,30 @@ import java.util.stream.Collectors;
|
||||
public class ChunkFixerUtility {
|
||||
|
||||
public static void processChunkNBT(NBTTagCompound compound) {
|
||||
replaceTileEntitiesWithNormalBlock(compound);
|
||||
transformTileEntities(compound);
|
||||
transformNormalBlocks(compound);
|
||||
|
||||
}
|
||||
|
||||
private static void transformNormalBlocks(NBTTagCompound compound) {
|
||||
NBTTagCompound level = compound.getCompoundTag("Level");
|
||||
NBTTagList sections = level.getTagList("Sections", 10);
|
||||
for (int i = 0; i < sections.tagCount(); i++) {
|
||||
NBTTagCompound section = sections.getCompoundTagAt(i);
|
||||
byte[] blockArray = section.getByteArray("Blocks16");
|
||||
byte[] metadataArray = section.getByteArray("Data");
|
||||
|
||||
for (int index = 0; index < blockArray.length / 2; index++) {
|
||||
int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF);
|
||||
byte metadata = (byte) ((index & 1) == 0 ? (metadataArray[index / 2] & 0x0F) : ((metadataArray[index / 2] & 0xF0) >> 4));
|
||||
|
||||
Pair<Integer, Integer> output = BlockReplacementManager.getBlockReplacement(blockId, metadata);
|
||||
if (output != null) {
|
||||
setBlockInfo(Block.getBlockById(output.first()), index, blockArray);
|
||||
setMetadata(output.second(), index, metadataArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,7 +44,7 @@ public class ChunkFixerUtility {
|
||||
*
|
||||
* @param chunkNBT The chunk's NBT data.
|
||||
*/
|
||||
public static void replaceTileEntitiesWithNormalBlock(NBTTagCompound chunkNBT) {
|
||||
public static void transformTileEntities(NBTTagCompound chunkNBT) {
|
||||
NBTTagCompound level = chunkNBT.getCompoundTag("Level");
|
||||
|
||||
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(level.getTagList("TileEntities", 10));
|
||||
@@ -127,19 +150,6 @@ public class ChunkFixerUtility {
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
Function<NBTTagCompound, NBTTagCompound> tileFixer = TileEntityReplacementManager.getTileEntityFixer(tileEntityStringName);
|
||||
|
||||
if (tileFixer != null) {
|
||||
tileFixer.apply(tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConversionInfo {
|
||||
|
||||
public final int x;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.colen.postea;
|
||||
|
||||
import akka.japi.Pair;
|
||||
import com.colen.postea.API.BlockKey;
|
||||
import com.colen.postea.API.BlockReplacementManager;
|
||||
import com.colen.postea.API.ChunkFixerUtility;
|
||||
import com.colen.postea.API.TileEntityReplacementManager;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
@@ -98,9 +101,12 @@ public class Postea {
|
||||
return new ChunkFixerUtility.BlockInfo(Blocks.chest, 0, chestTransformer);
|
||||
});
|
||||
|
||||
// TileEntityReplacementManager.tileEntityToNormalBlockTransformer("Chest", (tag) -> {
|
||||
// return new ChunkFixerUtility.BlockInfo(Blocks.coal_block, 0);
|
||||
// });
|
||||
Function<BlockKey, Pair<Integer, Integer>> blockTransformer = (blockKey) -> {
|
||||
return new Pair<>(7, 0);
|
||||
};
|
||||
|
||||
BlockReplacementManager.addBlockReplacement("grass", 0, blockTransformer);
|
||||
|
||||
}
|
||||
|
||||
private NBTTagCompound cleanseNBT(String newTileEntityID, NBTTagCompound tag) {
|
||||
|
||||
Reference in new issue
Block a user