|
| 1 | +package gregtech.datafix.migration.impl; |
| 2 | + |
| 3 | +import net.minecraft.block.Block; |
| 4 | +import net.minecraft.nbt.NBTTagCompound; |
| 5 | +import net.minecraft.nbt.NBTTagList; |
| 6 | +import net.minecraft.util.datafix.IFixableData; |
| 7 | + |
| 8 | +import net.minecraft.util.math.BlockPos; |
| 9 | +import net.minecraft.util.math.ChunkPos; |
| 10 | +import net.minecraft.world.chunk.NibbleArray; |
| 11 | +import net.minecraftforge.common.util.Constants; |
| 12 | +import net.minecraftforge.fml.common.registry.ForgeRegistries; |
| 13 | +import net.minecraftforge.registries.ForgeRegistry; |
| 14 | +import net.minecraftforge.registries.GameData; |
| 15 | + |
| 16 | +import org.jetbrains.annotations.NotNull; |
| 17 | + |
| 18 | +import static gregtech.datafix.util.DataFixConstants.*; |
| 19 | + |
| 20 | +public class MigrateMaterialBlock implements IFixableData { |
| 21 | + |
| 22 | + @Override |
| 23 | + public int getFixVersion() { |
| 24 | + return 2; |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public @NotNull NBTTagCompound fixTagCompound(@NotNull NBTTagCompound compound) { |
| 29 | + var blockStateIDMap = GameData.getBlockStateIDMap(); |
| 30 | + var r = ((ForgeRegistry<Block>) ForgeRegistries.BLOCKS); |
| 31 | + NBTTagCompound level = compound.getCompoundTag(LEVEL_TAG); |
| 32 | + ChunkPos chunkPos = new ChunkPos(level.getInteger(LEVEL_CHUNK_X_POS), level.getInteger(LEVEL_CHUNK_Z_POS)); |
| 33 | + NBTTagList sectionTagList = level.getTagList(SECTIONS, Constants.NBT.TAG_COMPOUND); |
| 34 | + for (int i = 0; i < sectionTagList.tagCount(); i++) { |
| 35 | + NBTTagCompound chunkSectionTag = sectionTagList.getCompoundTagAt(i); |
| 36 | + |
| 37 | + int sectionY = chunkSectionTag.getByte(CHUNK_SECTION_Y); |
| 38 | + byte[] blockIDs = chunkSectionTag.getByteArray(CHUNK_SECTION_BLOCKS); |
| 39 | + NibbleArray blockData = new NibbleArray(chunkSectionTag.getByteArray(CHUNK_SECTION_DATA)); |
| 40 | + NibbleArray extendedIDs = chunkSectionTag.hasKey(CHUNK_SECTION_ADD, Constants.NBT.TAG_BYTE_ARRAY) ? |
| 41 | + new NibbleArray(chunkSectionTag.getByteArray(CHUNK_SECTION_ADD)) : null; |
| 42 | + for (int j = 0; j < BLOCKS_PER_SECTION; j++) { |
| 43 | + int x = j & 0x0F; |
| 44 | + int y = j >> 8 & 0x0F; |
| 45 | + int z = j >> 4 & 0x0F; |
| 46 | + |
| 47 | + BlockPos pos = chunkPos.getBlock(x, sectionY << 4 | y, z); |
| 48 | + |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + return compound; |
| 53 | + } |
| 54 | +} |
0 commit comments