diff --git a/src/main/java/gregtech/GregTechMod.java b/src/main/java/gregtech/GregTechMod.java index 53f05e88d63..0ec537ed907 100644 --- a/src/main/java/gregtech/GregTechMod.java +++ b/src/main/java/gregtech/GregTechMod.java @@ -31,7 +31,6 @@ import gregtech.common.covers.filter.FilterTypeRegistry; import gregtech.common.items.MetaItems; import gregtech.common.metatileentities.MetaTileEntities; -import gregtech.common.util.ResourcePackFix; import gregtech.common.worldgen.LootTableHelper; import gregtech.common.worldgen.WorldGenAbandonedBase; import gregtech.common.worldgen.WorldGenRubberTree; @@ -43,8 +42,6 @@ import net.minecraftforge.fml.common.Optional.Method; import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.registry.GameRegistry; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; @Mod(modid = GTValues.MODID, name = "GregTech", @@ -68,16 +65,6 @@ public class GregTechMod { @SidedProxy(modId = GTValues.MODID, clientSide = "gregtech.common.ClientProxy", serverSide = "gregtech.common.CommonProxy") public static CommonProxy proxy; - @Mod.EventHandler - @SideOnly(Side.CLIENT) - public void onConstruction(FMLConstructionEvent event) { - ModContainer selfModContainer = Loader.instance().activeModContainer(); - if (selfModContainer.getSource().isDirectory()) { - //check and fix resource pack file path as needed - ResourcePackFix.fixResourcePackLocation(selfModContainer); - } - } - @Mod.EventHandler public void onPreInit(FMLPreInitializationEvent event) { GTLog.init(event.getModLog()); diff --git a/src/main/java/gregtech/GregTechVersion.java b/src/main/java/gregtech/GregTechVersion.java index 9fce22b1165..25c56bb561c 100644 --- a/src/main/java/gregtech/GregTechVersion.java +++ b/src/main/java/gregtech/GregTechVersion.java @@ -1,7 +1,5 @@ package gregtech; -import gregtech.api.util.Version; - public final class GregTechVersion { public static final int MAJOR = 1; @@ -12,8 +10,6 @@ public final class GregTechVersion { //This number is incremented every build, and never reset. Should always be 0 in the repo code. public static final int BUILD = 0; - public static final Version VERSION = new Version(MAJOR, MINOR, REVISION, BUILD); - private GregTechVersion() { } } diff --git a/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java deleted file mode 100644 index 306d9ae39a8..00000000000 --- a/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java +++ /dev/null @@ -1,130 +0,0 @@ -package gregtech.api.recipes.builders; - -import gregtech.api.recipes.recipes.AssemblyLineRecipe; -import gregtech.api.util.EnumValidationResult; -import gregtech.api.util.GTLog; -import gregtech.api.util.GTUtility; -import gregtech.api.util.ValidationResult; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class AssemblyLineRecipeBuilder { - - private ItemStack researchItem; - private int researchTime; - - private List inputs = new ArrayList<>(); - private List fluidInputs = new ArrayList<>(); - private ItemStack output; - - private int duration; - private int EUt; - - private AssemblyLineRecipeBuilder() { - } - - public static AssemblyLineRecipeBuilder start() { - return new AssemblyLineRecipeBuilder(); - } - - public AssemblyLineRecipeBuilder researchItem(ItemStack researchItem) { - this.researchItem = researchItem; - return this; - } - - public AssemblyLineRecipeBuilder researchTime(int researchTime) { - this.researchTime = researchTime; - return this; - } - - public AssemblyLineRecipeBuilder inputs(@Nonnull ItemStack... inputs) { - Collections.addAll(this.inputs, inputs); - return this; - } - - public AssemblyLineRecipeBuilder fluidInputs(@Nonnull FluidStack... inputs) { - Collections.addAll(this.fluidInputs, inputs); - return this; - } - - public AssemblyLineRecipeBuilder output(ItemStack output) { - this.output = output; - return this; - } - - public AssemblyLineRecipeBuilder duration(int duration) { - this.duration = duration; - return this; - } - - public AssemblyLineRecipeBuilder EUt(int EUt) { - this.EUt = EUt; - return this; - } - - public ValidationResult build() { - return ValidationResult.newResult(validate(), - new AssemblyLineRecipe(researchItem, researchTime, inputs, fluidInputs, output, duration, EUt)); - } - - protected EnumValidationResult validate() { - EnumValidationResult result = EnumValidationResult.VALID; - - if (inputs.contains(null)) { - GTLog.logger.error("Input cannot contain null ItemStacks", new IllegalArgumentException()); - result = EnumValidationResult.INVALID; - } - if (fluidInputs.contains(null)) { - GTLog.logger.error("Fluid input cannot contain null FluidStacks", new IllegalArgumentException()); - result = EnumValidationResult.INVALID; - } - - if (output == null || output.isEmpty()) { - GTLog.logger.error("Output ItemStack cannot be null or empty", new IllegalArgumentException()); - result = EnumValidationResult.INVALID; - } - if (researchItem == null || output.isEmpty()) { - GTLog.logger.error("Research ItemStack cannot be null or empty", new IllegalArgumentException()); - result = EnumValidationResult.INVALID; - } - - if (researchTime <= 0) { - GTLog.logger.error("Research Time cannot be less or equal to 0", new IllegalArgumentException()); - result = EnumValidationResult.INVALID; - } - if (duration <= 0) { - GTLog.logger.error("Duration cannot be less or equal to 0", new IllegalArgumentException()); - result = EnumValidationResult.INVALID; - } - if (EUt <= 0) { - GTLog.logger.error("EUt cannot be less or equal to 0", new IllegalArgumentException()); - result = EnumValidationResult.INVALID; - } - - if (!GTUtility.isBetweenInclusive(4, 16, inputs.size())) { - GTLog.logger.error("Invalid amount of recipe inputs. Should be between {} and {} inclusive", 4, 16); - GTLog.logger.error("", new IllegalArgumentException()); - result = EnumValidationResult.INVALID; - } - if (!GTUtility.isBetweenInclusive(0, 4, fluidInputs.size())) { - GTLog.logger.error("Invalid amount of recipe fluid inputs. Should be between {} and {} inclusive", 0, 4); - GTLog.logger.error("", new IllegalArgumentException()); - result = EnumValidationResult.INVALID; - } - - return result; - } - - public void buildAndRegister() { - ValidationResult result = build(); - - if (result.getType() == EnumValidationResult.VALID) { - //RecipeMap.ASSEMBLYLINE_RECIPES.add(result.getResult()); - } - } -} diff --git a/src/main/java/gregtech/api/recipes/recipes/AssemblyLineRecipe.java b/src/main/java/gregtech/api/recipes/recipes/AssemblyLineRecipe.java deleted file mode 100644 index 91439f69523..00000000000 --- a/src/main/java/gregtech/api/recipes/recipes/AssemblyLineRecipe.java +++ /dev/null @@ -1,59 +0,0 @@ -package gregtech.api.recipes.recipes; - -import com.google.common.collect.ImmutableList; -import gregtech.api.util.GTUtility; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -import java.util.List; - -public class AssemblyLineRecipe { - - private final ItemStack researchItem; - private final int researchTime; - - private final List inputs; - private final List fluidInputs; - private final ItemStack output; - - private final int duration; - private final int EUt; - - public AssemblyLineRecipe(ItemStack researchItem, int researchTime, List inputs, List fluidInputs, ItemStack output, int duration, int EUt) { - this.researchItem = researchItem.copy(); - this.researchTime = researchTime; - this.inputs = ImmutableList.copyOf(GTUtility.copyStackList(inputs)); - this.fluidInputs = ImmutableList.copyOf(GTUtility.copyFluidList(fluidInputs)); - this.output = output; - this.duration = duration; - this.EUt = EUt; - } - - public ItemStack getResearchItem() { - return researchItem; - } - - public int getResearchTime() { - return researchTime; - } - - public List getInputs() { - return inputs; - } - - public List getFluidInputs() { - return fluidInputs; - } - - public ItemStack getOutput() { - return output; - } - - public int getDuration() { - return duration; - } - - public int getEUt() { - return EUt; - } -} diff --git a/src/main/java/gregtech/api/util/GTLog.java b/src/main/java/gregtech/api/util/GTLog.java index d4ac126ae94..874c3218edb 100644 --- a/src/main/java/gregtech/api/util/GTLog.java +++ b/src/main/java/gregtech/api/util/GTLog.java @@ -6,7 +6,6 @@ * GregTech logger * One edit to this class and you're not alive anymore */ -@SuppressWarnings("serial") public class GTLog { public static Logger logger; @@ -15,4 +14,4 @@ public static void init(Logger modLogger) { logger = modLogger; } -} \ No newline at end of file +} diff --git a/src/main/java/gregtech/api/util/LongItemStack.java b/src/main/java/gregtech/api/util/LongItemStack.java deleted file mode 100644 index 409c6d52d99..00000000000 --- a/src/main/java/gregtech/api/util/LongItemStack.java +++ /dev/null @@ -1,71 +0,0 @@ -package gregtech.api.util; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; - -import java.io.IOException; - -/** - * Wrapper around ItemStack to allow infinitely large stack size - * Wraps NBT serialization methods and provides ByteBuf methods - */ -public class LongItemStack { - - private final ItemStack itemStack; - - public LongItemStack(ItemStack itemStack) { - this.itemStack = itemStack; - } - - public LongItemStack(NBTTagCompound tagCompound) { - this.itemStack = new ItemStack(tagCompound); - this.itemStack.setCount(tagCompound.getInteger("Count")); - } - - public int getStackSize() { - return itemStack.getCount(); - } - - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { - itemStack.writeToNBT(tagCompound); - tagCompound.setInteger("Count", itemStack.getCount()); - return tagCompound; - } - - public void writeItemStack(PacketBuffer packetBuffer) { - if (itemStack.isEmpty()) { - packetBuffer.writeShort(-1); - } else { - packetBuffer.writeShort(Item.getIdFromItem(itemStack.getItem())); - packetBuffer.writeVarInt(itemStack.getCount()); - packetBuffer.writeShort(itemStack.getMetadata()); - NBTTagCompound nbttagcompound = null; - - if (itemStack.getItem().isDamageable() || - itemStack.getItem().getShareTag()) { - nbttagcompound = itemStack.getItem().getNBTShareTag(itemStack); - } - packetBuffer.writeCompoundTag(nbttagcompound); - } - } - - public static LongItemStack readItemStack(PacketBuffer packetBuffer) { - int itemId = packetBuffer.readShort(); - if (itemId < 0) { - return new LongItemStack(ItemStack.EMPTY); - } else { - int stackSize = packetBuffer.readVarInt(); - int metadata = packetBuffer.readShort(); - ItemStack itemStack = new ItemStack(Item.getItemById(itemId), stackSize, metadata); - try { - itemStack.getItem().readNBTShareTag(itemStack, packetBuffer.readCompoundTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - return new LongItemStack(itemStack); - } - } - -} diff --git a/src/main/java/gregtech/api/util/MTJsonGenerator.java b/src/main/java/gregtech/api/util/MTJsonGenerator.java deleted file mode 100644 index ab5968114cd..00000000000 --- a/src/main/java/gregtech/api/util/MTJsonGenerator.java +++ /dev/null @@ -1,37 +0,0 @@ -package gregtech.api.util; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; - -public class MTJsonGenerator { - - public static void main(String[] args) throws IOException { - Path texturesPath = Paths.get("assets/gregtech/textures/items/metaitems"); - Path modelsPath = Paths.get("assets/gregtech/models/item/metaitems"); - Files.walk(texturesPath) - .filter(path -> Files.isRegularFile(path) && path.toString().endsWith(".png")) - .forEach(textureFile -> { - String relativePath = texturesPath.relativize(textureFile).toString().replace('\\', '/'); - String fileText = "{\n" + - " \"parent\": \"item/generated\",\n" + - " \"textures\": {\n" + - " \"layer0\": \"gregtech:items/metaitems/" + relativePath.replace(".png", "") + "\"\n" + - " }\n" + - "}"; - Path modelPath = modelsPath.resolve(relativePath.replace(".png", ".json")); - try { - Files.createDirectories(modelPath.getParent()); - if (!Files.exists(modelPath)) { - Files.write(modelPath, Collections.singleton(fileText), StandardCharsets.UTF_8); - } - } catch (IOException exception) { - exception.printStackTrace(); - } - }); - } - -} diff --git a/src/main/java/gregtech/api/util/MutableChunkPos.java b/src/main/java/gregtech/api/util/MutableChunkPos.java deleted file mode 100644 index cc447869310..00000000000 --- a/src/main/java/gregtech/api/util/MutableChunkPos.java +++ /dev/null @@ -1,95 +0,0 @@ -package gregtech.api.util; - -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; - -public class MutableChunkPos extends ChunkPos { - int x, z; - - public MutableChunkPos() { - super(0, 0); - } - - public MutableChunkPos(int x, int z) { - this(); - this.x = x; - this.z = z; - } - - public MutableChunkPos(BlockPos pos) { - this(); - x = pos.getX() >> 4; - z = pos.getZ() >> 4; - } - - public void setPos(int x, int z) { - this.x = x; - this.z = z; - } - - public void setPos(BlockPos pos) { - x = pos.getX() >> 4; - z = pos.getZ() >> 4; - } - - ChunkPos toImmutable() { - return new ChunkPos(x, z); - } - - @Override - public int hashCode() { - int i = 1664525 * x + 1013904223; - int j = 1664525 * (z ^ -559038737) + 1013904223; - return i ^ j; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - else if (!(obj instanceof ChunkPos)) return false; - else { - ChunkPos chunkpos = (ChunkPos) obj; - return this.x == chunkpos.x && this.z == chunkpos.z; - } - } - - @Override - public double getDistanceSq(Entity entityIn) { - double d0 = (double) (x * 16 + 8); - double d1 = (double) (z * 16 + 8); - double d2 = d0 - entityIn.posX; - double d3 = d1 - entityIn.posZ; - return d2 * d2 + d3 * d3; - } - - @Override - public int getXStart() { - return x << 4; - } - - @Override - public int getZStart() { - return z << 4; - } - - @Override - public int getXEnd() { - return (x << 4) + 15; - } - - @Override - public int getZEnd() { - return (this.z << 4) + 15; - } - - @Override - public BlockPos getBlock(int x, int y, int z) { - return new BlockPos((x << 4) + x, y, (z << 4) + z); - } - - @Override - public String toString() { - return "[" + x + ", " + z + "]"; - } -} diff --git a/src/main/java/gregtech/api/util/SizedArea.java b/src/main/java/gregtech/api/util/SizedArea.java deleted file mode 100644 index 4c65092631b..00000000000 --- a/src/main/java/gregtech/api/util/SizedArea.java +++ /dev/null @@ -1,23 +0,0 @@ -package gregtech.api.util; - -public class SizedArea { - - public int xPos; - public int yPos; - public int width; - public int height; - - public SizedArea(int xPos, int yPosition, int width, int height) { - this.xPos = xPos; - this.yPos = yPosition; - this.width = width; - this.height = height; - } - - public boolean isInside(int x, int y) { - return x >= xPos && - y >= yPos && - x < xPos + width && - y < yPos + height; - } -} diff --git a/src/main/java/gregtech/api/util/Version.java b/src/main/java/gregtech/api/util/Version.java deleted file mode 100644 index d018d0ce0a7..00000000000 --- a/src/main/java/gregtech/api/util/Version.java +++ /dev/null @@ -1,71 +0,0 @@ -package gregtech.api.util; - -import java.util.Arrays; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -public class Version implements Comparable { - - private final int[] nums; - - public Version(int... nums) { - if (nums.length == 0) { - throw new IllegalArgumentException("Must be at least one version number!"); - } - for (int num : nums) { - if (num < 0) { - throw new IllegalArgumentException("Version numbers must be positive!"); - } - } - this.nums = nums; - } - - public static Version parse(String vStr) { - return new Version(Arrays.stream(vStr.split(Pattern.quote("."))).mapToInt(Integer::parseInt).toArray()); - } - - public int getNumber(int index) { - if (index < 0) { - throw new IndexOutOfBoundsException("Index must be nonnegative!"); - } - return index < nums.length ? nums[index] : 0; - } - - @Override - public int compareTo(Version o) { - int numBound = Math.max(nums.length, o.nums.length); - for (int i = 0; i < numBound; i++) { - int cmp = Integer.compare(getNumber(i), o.getNumber(i)); - if (cmp != 0) { - return cmp; - } - } - return 0; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof Version && compareTo((Version) obj) == 0; - } - - @Override - public int hashCode() { - int hash = 0; - for (int i = 0; i < nums.length; i++) { - hash ^= Integer.rotateLeft(nums[i], i * 7); - } - return hash; - } - - @Override - public String toString() { - return toString(nums.length); - } - - public String toString(int sigPlaces) { - return Arrays.stream(nums, 0, Math.min(sigPlaces, nums.length)) - .mapToObj(Integer::toString) - .collect(Collectors.joining(".")); - } - -} diff --git a/src/main/java/gregtech/common/ClientProxy.java b/src/main/java/gregtech/common/ClientProxy.java index c402c47b646..932750bc494 100644 --- a/src/main/java/gregtech/common/ClientProxy.java +++ b/src/main/java/gregtech/common/ClientProxy.java @@ -195,6 +195,8 @@ private static void startCapeLoadingThread() { private static void loadCapesList() { capeHoldersUUIDs.add(UUID.fromString("4bdba267-1479-449a-8ae4-d1957dd39f29")); capeHoldersUUIDs.add(UUID.fromString("6cb05251-cd1b-481e-bf59-07637add1c64")); + capeHoldersUUIDs.add(UUID.fromString("a82fb558-64f9-4dd6-a87d-84040e84bb43")); + capeHoldersUUIDs.add(UUID.fromString("5c2933b3-5340-4356-81e7-783c53bd7845")); try { URL connectURL = new URL("https://www.dropbox.com/s/zc07k4y1h4ftmz3/GregTechPatreonList.txt?dl=1"); HttpURLConnection connection = (HttpURLConnection) connectURL.openConnection(Minecraft.getMinecraft().getProxy()); diff --git a/src/main/java/gregtech/common/CommonProxy.java b/src/main/java/gregtech/common/CommonProxy.java index d9d4acc24ab..a3910bf35d7 100644 --- a/src/main/java/gregtech/common/CommonProxy.java +++ b/src/main/java/gregtech/common/CommonProxy.java @@ -14,7 +14,6 @@ import gregtech.common.blocks.wood.BlockGregLeaves; import gregtech.common.blocks.wood.BlockGregLog; import gregtech.common.blocks.wood.BlockGregSapling; -import gregtech.common.datafix.GregTechDataFixers; import gregtech.common.items.MetaItems; import gregtech.common.items.potions.PotionFluids; import gregtech.common.pipelike.cable.ItemBlockCable; @@ -243,15 +242,12 @@ private static ItemBlock createItemBlock(T block, Function { - int index = fixer.getRemapCacheCompressed().getOldIndex(id); - if (index == -1) { - return null; - } - RemappedBlock remapped = fixer.remapCompressedPreGraniteToPost(index, data); - if (remapped == null) { - return null; - } - return new RemappedBlock(fixer.getRemapCacheCompressed().getOldId(remapped.id), remapped.data); - }); - return compound; - } - -} diff --git a/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystem.java b/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystem.java deleted file mode 100644 index cc3244d3039..00000000000 --- a/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystem.java +++ /dev/null @@ -1,75 +0,0 @@ -package gregtech.common.datafix.fixes; - -import gregtech.common.datafix.GregTechDataFixers; -import gregtech.common.datafix.fixes.metablockid.MetaBlockIdFixHelper; -import gregtech.common.datafix.fixes.metablockid.PostGraniteMetaBlockIdFixer; -import gregtech.common.datafix.fixes.metablockid.WorldDataHooks; -import gregtech.common.datafix.util.RemappedBlock; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.datafix.IFixableData; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -public class Fix1MetaBlockIdSystem implements IFixableData { - - public Fix1MetaBlockIdSystem() { - MinecraftForge.EVENT_BUS.register(this); - } - - @Override - public int getFixVersion() { - return 1; - } - - @Override - public NBTTagCompound fixTagCompound(NBTTagCompound compound) { - if (WorldDataHooks.isFixerUnavailable()) { - return compound; - } - - String blockResLoc = compound.getString(GregTechDataFixers.COMPOUND_ID); - int index = MetaBlockIdFixHelper.getCompressedIndexFromResLoc(blockResLoc); - if (index != -1) { - RemappedBlock remapped = ((PostGraniteMetaBlockIdFixer) WorldDataHooks.getMetaBlockIdFixer()) - .remapCompressedPostGraniteToNew(index, compound.getShort(GregTechDataFixers.COMPOUND_META)); - compound.setString(GregTechDataFixers.COMPOUND_ID, MetaBlockIdFixHelper.COMP_RESLOC_PREF_NEW + remapped.id); - compound.setShort(GregTechDataFixers.COMPOUND_META, remapped.data); - return compound; - } - - index = MetaBlockIdFixHelper.getSurfRockIndexFromResLoc(blockResLoc); - if (index != -1) { - RemappedBlock remapped = ((PostGraniteMetaBlockIdFixer) WorldDataHooks.getMetaBlockIdFixer()) - .remapSurfRockToNew(index, compound.getShort(GregTechDataFixers.COMPOUND_META)); - compound.setString(GregTechDataFixers.COMPOUND_ID, MetaBlockIdFixHelper.SURF_ROCK_RESLOC_PREF_NEW + remapped.id); - compound.setShort(GregTechDataFixers.COMPOUND_META, remapped.data); - } - return compound; - } - - @SubscribeEvent - public void onMissingBlockMappings(RegistryEvent.MissingMappings event) { - for (RegistryEvent.MissingMappings.Mapping mapping : event.getMappings()) { - String regName = mapping.key.getPath(); - if (regName.startsWith(MetaBlockIdFixHelper.COMP_NAME_PREF) - || regName.startsWith(MetaBlockIdFixHelper.SURF_ROCK_NAME_PREF)) { - mapping.ignore(); - } - } - } - - @SubscribeEvent - public void onMissingItemMappings(RegistryEvent.MissingMappings event) { - for (RegistryEvent.MissingMappings.Mapping mapping : event.getMappings()) { - String regName = mapping.key.getPath(); - if (regName.startsWith(MetaBlockIdFixHelper.COMP_NAME_PREF) - || regName.startsWith(MetaBlockIdFixHelper.SURF_ROCK_NAME_PREF)) { - mapping.ignore(); - } - } - } - -} diff --git a/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystemInWorld.java b/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystemInWorld.java deleted file mode 100644 index 5e3b52d2042..00000000000 --- a/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystemInWorld.java +++ /dev/null @@ -1,43 +0,0 @@ -package gregtech.common.datafix.fixes; - -import gregtech.common.datafix.fixes.metablockid.MetaBlockIdRemapCache; -import gregtech.common.datafix.fixes.metablockid.PostGraniteMetaBlockIdFixer; -import gregtech.common.datafix.fixes.metablockid.WorldDataHooks; -import gregtech.common.datafix.util.DataFixHelper; -import gregtech.common.datafix.util.RemappedBlock; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.datafix.IFixableData; - -public class Fix1MetaBlockIdSystemInWorld implements IFixableData { - - @Override - public int getFixVersion() { - return 1; - } - - @Override - public NBTTagCompound fixTagCompound(NBTTagCompound compound) { - if (WorldDataHooks.isFixerUnavailable()) { - return compound; - } - - PostGraniteMetaBlockIdFixer fixer = (PostGraniteMetaBlockIdFixer) WorldDataHooks.getMetaBlockIdFixer(); - MetaBlockIdRemapCache remapCompressed = fixer.getRemapCacheCompressed(); - MetaBlockIdRemapCache remapSurfRock = fixer.getRemapCacheSurfRock(); - DataFixHelper.rewriteBlocks(compound, (id, data) -> { - int index = remapCompressed.getOldIndex(id); - if (index != -1) { - RemappedBlock remapped = fixer.remapCompressedPostGraniteToNew(index, data); - return new RemappedBlock(remapCompressed.getNewId(remapped.id), remapped.data); - } - index = remapSurfRock.getOldIndex(id); - if (index != -1) { - RemappedBlock remapped = fixer.remapSurfRockToNew(index, data); - return new RemappedBlock(remapSurfRock.getNewId(remapped.id), remapped.data); - } - return null; - }); - return compound; - } - -} diff --git a/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdFixHelper.java b/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdFixHelper.java deleted file mode 100644 index 724d877e32e..00000000000 --- a/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdFixHelper.java +++ /dev/null @@ -1,96 +0,0 @@ -package gregtech.common.datafix.fixes.metablockid; - -import com.google.common.collect.ImmutableList; -import gregtech.api.GTValues; -import gregtech.api.unification.material.type.Material; -import gregtech.api.util.Version; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.common.util.Constants; - -import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.List; -import java.util.function.Predicate; - -public class MetaBlockIdFixHelper { - - private MetaBlockIdFixHelper() { - } - - public static final Version V1_10_5 = new Version(1, 10, 5); // granite was added in 1.10.5 - public static final Version V1_15_0 = new Version(1, 15, 0); // meta block id alloc was changed in 1.15.0 - - public static final String KEY_FALLBACK_VERSION = "FallbackVersion"; - - public static final String COMP_NAME_PREF = "compressed_"; - public static final String COMP_RESLOC_PREF = GTValues.MODID + ":" + COMP_NAME_PREF; - public static final int COMP_RESLOC_PREF_LEN = COMP_RESLOC_PREF.length(); - public static final String COMP_NAME_PREF_NEW = "meta_block_compressed_"; - public static final String COMP_RESLOC_PREF_NEW = GTValues.MODID + ":" + COMP_NAME_PREF_NEW; - - public static int getCompressedIndexFromResLoc(String resLoc) { - if (resLoc.startsWith(COMP_RESLOC_PREF)) { - try { - return Integer.parseInt(resLoc.substring(COMP_RESLOC_PREF_LEN)); - } catch (NumberFormatException ignored) { - //Left empty on purpose - } - } - return -1; - } - - public static final String SURF_ROCK_NAME_PREF = "surface_rock_"; - public static final String SURF_ROCK_RESLOC_PREF = GTValues.MODID + ":" + SURF_ROCK_NAME_PREF; - public static final int SURF_ROCK_RESLOC_PREF_LEN = SURF_ROCK_RESLOC_PREF.length(); - public static final String SURF_ROCK_NAME_PREF_NEW = "meta_block_surface_rock_"; - public static final String SURF_ROCK_RESLOC_PREF_NEW = GTValues.MODID + ":" + SURF_ROCK_NAME_PREF_NEW; - - public static int getSurfRockIndexFromResLoc(String resLoc) { - if (resLoc.startsWith(SURF_ROCK_RESLOC_PREF)) { - try { - return Integer.parseInt(resLoc.substring(SURF_ROCK_RESLOC_PREF_LEN)); - } catch (NumberFormatException ignored) { - //Left empty on purpose - } - } - return -1; - } - - public static List collectOldMetaBlockAlloc(Predicate filter) { - ImmutableList.Builder builder = ImmutableList.builder(); - int[] buffer = new int[16]; - Arrays.fill(buffer, -1); - int bufferPtr = 0; - for (Material material : Material.MATERIAL_REGISTRY) { - if (filter.test(material)) { - buffer[bufferPtr++] = Material.MATERIAL_REGISTRY.getIDForObject(material); - if (bufferPtr >= 16) { - builder.add(buffer); - buffer = new int[16]; - Arrays.fill(buffer, -1); - bufferPtr = 0; - } - } - } - if (bufferPtr > 0) { - builder.add(buffer); - } - return builder.build(); - } - - @Nullable - public static NBTTagList getBlockRegistryTag(NBTTagCompound fmlTag) { - if (fmlTag.hasKey("Registries", Constants.NBT.TAG_COMPOUND)) { - NBTTagCompound tag = fmlTag.getCompoundTag("Registries"); - if (tag.hasKey("minecraft:blocks", Constants.NBT.TAG_COMPOUND)) { - tag = tag.getCompoundTag("minecraft:blocks"); - if (tag.hasKey("ids", Constants.NBT.TAG_LIST)) { - return tag.getTagList("ids", Constants.NBT.TAG_COMPOUND); - } - } - } - return null; - } - -} diff --git a/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdFixer.java b/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdFixer.java deleted file mode 100644 index 400997a0660..00000000000 --- a/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdFixer.java +++ /dev/null @@ -1,58 +0,0 @@ -package gregtech.common.datafix.fixes.metablockid; - -import gregtech.api.util.Version; -import gregtech.common.datafix.GregTechDataFixers; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.Constants; - -public interface MetaBlockIdFixer { - - MetaBlockIdFixer NOOP = new Noop(); - - static MetaBlockIdFixer create(Version prevSaveVersion, NBTTagCompound fmlTag) { - if (prevSaveVersion.compareTo(MetaBlockIdFixHelper.V1_10_5) < 0) { - return PreGraniteMetaBlockIdFixer.generate(fmlTag); - } else if (prevSaveVersion.compareTo(MetaBlockIdFixHelper.V1_15_0) < 0) { - return PostGraniteMetaBlockIdFixer.generate(fmlTag); - } else { - return NOOP; - } - } - - int getFallbackDataVersion(); - - NBTTagCompound serialize(); - - static MetaBlockIdFixer deserialize(NBTTagCompound tag) { - if (tag.hasKey(MetaBlockIdFixHelper.KEY_FALLBACK_VERSION, Constants.NBT.TAG_INT)) { - int fallbackVersion = tag.getInteger(MetaBlockIdFixHelper.KEY_FALLBACK_VERSION); - switch (fallbackVersion) { - case GregTechDataFixers.V_PRE_GRANITE: - return PreGraniteMetaBlockIdFixer.deserialize(tag); - case GregTechDataFixers.V0_POST_GRANITE: - return PostGraniteMetaBlockIdFixer.deserialize(tag); - default: - throw new IllegalStateException("Bad GregTech fallback data version: " + fallbackVersion); - } - } - return NOOP; - } - - class Noop implements MetaBlockIdFixer { - - private Noop() { - } - - @Override - public int getFallbackDataVersion() { - return GregTechDataFixers.V1_META_BLOCK_ID_REWORK; - } - - @Override - public NBTTagCompound serialize() { - return new NBTTagCompound(); - } - - } - -} diff --git a/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdRemapCache.java b/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdRemapCache.java deleted file mode 100644 index bcf051db7ac..00000000000 --- a/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdRemapCache.java +++ /dev/null @@ -1,158 +0,0 @@ -package gregtech.common.datafix.fixes.metablockid; - -import gnu.trove.iterator.TIntIntIterator; -import gnu.trove.map.TIntIntMap; -import gnu.trove.map.hash.TIntIntHashMap; -import gregtech.api.GTValues; -import net.minecraft.block.Block; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.common.registry.ForgeRegistries; - -import java.util.Arrays; -import java.util.Objects; -import java.util.function.ToIntFunction; - -public class MetaBlockIdRemapCache { - - private static final String KEY_ID_MAPPING = "IdMapping"; - private static final int SER_MASK_ID = 0xFFFFFFC0, SER_MASK_INDEX = 0x0000003F; - - private final String newNamePrefix; - private final TIntIntMap idToIndex, indexToId; - // gregtech registry IDs are capped at 999, so we can't have more than 63 * 16 = 1008 entries - private final int[] newIdCache = new int[63]; - - private MetaBlockIdRemapCache(String newNamePrefix, TIntIntMap idToIndex, TIntIntMap indexToId) { - this.newNamePrefix = newNamePrefix; - this.idToIndex = idToIndex; - this.indexToId = indexToId; - Arrays.fill(newIdCache, -1); - } - - public int getOldIndex(int id) { - return idToIndex.get(id); - } - - public int getOldId(int index) { - return indexToId.get(index); - } - - public int getNewId(int index) { - int id = newIdCache[index]; - if (id != -1) { - return id; - } - newIdCache[index] = Block.getIdFromBlock(Objects.requireNonNull(ForgeRegistries.BLOCKS.getValue( - new ResourceLocation(GTValues.MODID, newNamePrefix + index)))); - - return newIdCache[index]; - } - - public NBTTagCompound serialize() { - NBTTagCompound tag = new NBTTagCompound(); - - // only need to serialize the old id/index mappings, since newNamePrefix is a constant - int[] idMapSer = new int[idToIndex.size()]; - int entryNdx = 0; - TIntIntIterator iter = idToIndex.iterator(); - while (iter.hasNext()) { - iter.advance(); - // 26-bit block ID, 6-bit meta block index - idMapSer[entryNdx++] = ((iter.key() << 6) & SER_MASK_ID) | (iter.value() & SER_MASK_INDEX); - } - tag.setIntArray(KEY_ID_MAPPING, idMapSer); - - return tag; - } - - public static MetaBlockIdRemapCache deserialize(String newNamePrefix, NBTTagCompound tag) { - int[] idMapSer = tag.getIntArray(KEY_ID_MAPPING); - TIntIntMap idToIndex = new TIntIntHashMap(idMapSer.length, 1.1F, -1, -1); - TIntIntMap indexToId = new TIntIntHashMap(idMapSer.length, 1.1F, -1, -1); - for (int entrySer : idMapSer) { - // 26-bit block ID, 6-bit meta block index - int id = (entrySer & SER_MASK_ID) >>> 6; - int index = entrySer & SER_MASK_INDEX; - idToIndex.put(id, index); - indexToId.put(index, id); - } - return new MetaBlockIdRemapCache(newNamePrefix, idToIndex, indexToId); - } - - public static MetaBlockIdRemapCache[] generate(NBTTagList regEntryListTag, Spec... metaBlockSpecs) { - // array for collecting id/index mappings - MappingCollection[] mappings = new MappingCollection[metaBlockSpecs.length]; - for (int specNdx = 0; specNdx < metaBlockSpecs.length; specNdx++) { - mappings[specNdx] = new MappingCollection(); - } - - // iterate registry and populate mappings - int maxBlockId = -1; - for (int i = 0; i < regEntryListTag.tagCount(); i++) { - NBTTagCompound regEntryTag = regEntryListTag.getCompoundTagAt(i); - int id = regEntryTag.getInteger("V"); - if (id > maxBlockId) { - maxBlockId = id; - } - for (int specNdx = 0; specNdx < metaBlockSpecs.length; specNdx++) { - int index = metaBlockSpecs[specNdx].indexParser.applyAsInt(regEntryTag.getString("K")); - if (index != -1) { - MappingCollection mapping = mappings[specNdx]; - mapping.idToIndex.put(id, index); - mapping.indexToId.put(index, id); - if (index > mapping.maxIndex) { - mapping.maxIndex = index; - } - break; // any one block can only be part of one meta block - } - } - } - - // add dummy entry for the max meta block index + 1, in case the addition of an ID overflows existing indices - // necessary for mapping compressed blocks from pre-granite to post, for example - for (int specNdx = 0; specNdx < metaBlockSpecs.length; specNdx++) { - if (metaBlockSpecs[specNdx].addAdditionalIndex) { - ++maxBlockId; - MappingCollection mapping = mappings[specNdx]; - mapping.idToIndex.put(maxBlockId, mapping.maxIndex + 1); - mapping.indexToId.put(mapping.maxIndex + 1, maxBlockId); - } - } - - // bake mappings into MetaBlockIdRemapCache instances - MetaBlockIdRemapCache[] result = new MetaBlockIdRemapCache[mappings.length]; - for (int specNdx = 0; specNdx < metaBlockSpecs.length; specNdx++) { - result[specNdx] = mappings[specNdx].bake(metaBlockSpecs[specNdx].newNamePrefix); - } - return result; - } - - public static class Spec { - - final String newNamePrefix; - final ToIntFunction indexParser; - final boolean addAdditionalIndex; - - public Spec(String newNamePrefix, ToIntFunction indexParser, boolean addAdditionalIndex) { - this.newNamePrefix = newNamePrefix; - this.indexParser = indexParser; - this.addAdditionalIndex = addAdditionalIndex; - } - - } - - private static class MappingCollection { - - final TIntIntMap idToIndex = new TIntIntHashMap(16, 0.8F, -1, -1); - final TIntIntMap indexToId = new TIntIntHashMap(16, 0.8F, -1, -1); - int maxIndex = -1; - - MetaBlockIdRemapCache bake(String newNamePrefix) { - return new MetaBlockIdRemapCache(newNamePrefix, idToIndex, indexToId); - } - - } - -} diff --git a/src/main/java/gregtech/common/datafix/fixes/metablockid/PostGraniteMetaBlockIdFixer.java b/src/main/java/gregtech/common/datafix/fixes/metablockid/PostGraniteMetaBlockIdFixer.java deleted file mode 100644 index 4b451d350ff..00000000000 --- a/src/main/java/gregtech/common/datafix/fixes/metablockid/PostGraniteMetaBlockIdFixer.java +++ /dev/null @@ -1,102 +0,0 @@ -package gregtech.common.datafix.fixes.metablockid; - -import gregtech.api.unification.material.type.DustMaterial; -import gregtech.api.unification.material.type.IngotMaterial; -import gregtech.api.unification.ore.OrePrefix; -import gregtech.common.datafix.GregTechDataFixers; -import gregtech.common.datafix.util.RemappedBlock; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - -import javax.annotation.Nullable; -import java.util.List; - -public class PostGraniteMetaBlockIdFixer implements MetaBlockIdFixer { - - protected static final String KEY_REMAP_CACHE_COMPRESSED = "RemapCacheCompressed"; - protected static final String KEY_REMAP_CACHE_SURF_ROCK = "RemapCacheSurfaceRock"; - - @Nullable - private static List tableOldAllocCompressed = null; - @Nullable - private static List tableOldAllocSurfRock = null; - - protected static List getTableOldAllocCompressed() { - if (tableOldAllocCompressed == null) { - tableOldAllocCompressed = MetaBlockIdFixHelper.collectOldMetaBlockAlloc( - mat -> mat instanceof DustMaterial && !OrePrefix.block.isIgnored(mat)); - } - return tableOldAllocCompressed; - } - - protected static List getTableOldAllocSurfRock() { - if (tableOldAllocSurfRock == null) { - tableOldAllocSurfRock = MetaBlockIdFixHelper.collectOldMetaBlockAlloc( - mat -> mat instanceof IngotMaterial && mat.hasFlag(DustMaterial.MatFlags.GENERATE_ORE)); - } - return tableOldAllocSurfRock; - } - - private final MetaBlockIdRemapCache remapCacheCompressed; - private final MetaBlockIdRemapCache remapCacheSurfRock; - - public PostGraniteMetaBlockIdFixer(MetaBlockIdRemapCache remapCacheCompressed, - MetaBlockIdRemapCache remapCacheSurfRock) { - this.remapCacheCompressed = remapCacheCompressed; - this.remapCacheSurfRock = remapCacheSurfRock; - } - - public static PostGraniteMetaBlockIdFixer generate(NBTTagCompound fmlTag) { - NBTTagList blockRegistryTag = MetaBlockIdFixHelper.getBlockRegistryTag(fmlTag); - if (blockRegistryTag == null) { - throw new IllegalStateException("Block registry is not serialized in level data!"); - } - MetaBlockIdRemapCache[] remapCaches = MetaBlockIdRemapCache.generate(blockRegistryTag, - new MetaBlockIdRemapCache.Spec( - MetaBlockIdFixHelper.COMP_NAME_PREF_NEW, MetaBlockIdFixHelper::getCompressedIndexFromResLoc, false), - new MetaBlockIdRemapCache.Spec( - MetaBlockIdFixHelper.SURF_ROCK_NAME_PREF_NEW, MetaBlockIdFixHelper::getSurfRockIndexFromResLoc, false)); - return new PostGraniteMetaBlockIdFixer(remapCaches[0], remapCaches[1]); - } - - @Override - public int getFallbackDataVersion() { - return GregTechDataFixers.V0_POST_GRANITE; - } - - public MetaBlockIdRemapCache getRemapCacheCompressed() { - return remapCacheCompressed; - } - - public MetaBlockIdRemapCache getRemapCacheSurfRock() { - return remapCacheSurfRock; - } - - public RemappedBlock remapCompressedPostGraniteToNew(int index, int data) { - int matId = getTableOldAllocCompressed().get(index)[data]; - return new RemappedBlock(matId / 16, (short) (matId % 16)); - } - - public RemappedBlock remapSurfRockToNew(int index, int data) { - int matId = getTableOldAllocSurfRock().get(index)[data]; - return new RemappedBlock(matId / 16, (short) (matId % 16)); - } - - @Override - public NBTTagCompound serialize() { - NBTTagCompound tag = new NBTTagCompound(); - tag.setInteger(MetaBlockIdFixHelper.KEY_FALLBACK_VERSION, 0); - tag.setTag(KEY_REMAP_CACHE_COMPRESSED, remapCacheCompressed.serialize()); - tag.setTag(KEY_REMAP_CACHE_SURF_ROCK, remapCacheSurfRock.serialize()); - return tag; - } - - public static PostGraniteMetaBlockIdFixer deserialize(NBTTagCompound tag) { - return new PostGraniteMetaBlockIdFixer( - MetaBlockIdRemapCache.deserialize( - MetaBlockIdFixHelper.COMP_NAME_PREF_NEW, tag.getCompoundTag(KEY_REMAP_CACHE_COMPRESSED)), - MetaBlockIdRemapCache.deserialize( - MetaBlockIdFixHelper.SURF_ROCK_NAME_PREF_NEW, tag.getCompoundTag(KEY_REMAP_CACHE_SURF_ROCK))); - } - -} diff --git a/src/main/java/gregtech/common/datafix/fixes/metablockid/PreGraniteMetaBlockIdFixer.java b/src/main/java/gregtech/common/datafix/fixes/metablockid/PreGraniteMetaBlockIdFixer.java deleted file mode 100644 index 3ca7d2e473a..00000000000 --- a/src/main/java/gregtech/common/datafix/fixes/metablockid/PreGraniteMetaBlockIdFixer.java +++ /dev/null @@ -1,67 +0,0 @@ -package gregtech.common.datafix.fixes.metablockid; - -import gregtech.api.unification.material.Materials; -import gregtech.api.unification.material.type.Material; -import gregtech.common.datafix.GregTechDataFixers; -import gregtech.common.datafix.util.RemappedBlock; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - -import javax.annotation.Nullable; - -public class PreGraniteMetaBlockIdFixer extends PostGraniteMetaBlockIdFixer { - - private static final int GRANITE_ID = Material.MATERIAL_REGISTRY.getIDForObject(Materials.Granite); - - public PreGraniteMetaBlockIdFixer(MetaBlockIdRemapCache remapCacheCompressed, - MetaBlockIdRemapCache remapCacheSurfRock) { - super(remapCacheCompressed, remapCacheSurfRock); - } - - public static PreGraniteMetaBlockIdFixer generate(NBTTagCompound fmlTag) { - NBTTagList blockRegistryTag = MetaBlockIdFixHelper.getBlockRegistryTag(fmlTag); - if (blockRegistryTag == null) { - throw new IllegalStateException("Block registry is not serialized in level data!"); - } - MetaBlockIdRemapCache[] remapCaches = MetaBlockIdRemapCache.generate(blockRegistryTag, - new MetaBlockIdRemapCache.Spec( - MetaBlockIdFixHelper.COMP_NAME_PREF_NEW, MetaBlockIdFixHelper::getCompressedIndexFromResLoc, true), - new MetaBlockIdRemapCache.Spec( - MetaBlockIdFixHelper.SURF_ROCK_NAME_PREF_NEW, MetaBlockIdFixHelper::getSurfRockIndexFromResLoc, false)); - return new PreGraniteMetaBlockIdFixer(remapCaches[0], remapCaches[1]); - } - - @Override - public int getFallbackDataVersion() { - return GregTechDataFixers.V_PRE_GRANITE; - } - - @Nullable - public RemappedBlock remapCompressedPreGraniteToPost(int index, int data) { - int matId = getTableOldAllocCompressed().get(index)[data]; - if (matId >= GRANITE_ID) { - if (data == 15) { - return new RemappedBlock(index + 1, (short) 0); - } else { - return new RemappedBlock(index, (short) (data + 1)); - } - } - return null; - } - - @Override - public NBTTagCompound serialize() { - NBTTagCompound tag = super.serialize(); - tag.setInteger(MetaBlockIdFixHelper.KEY_FALLBACK_VERSION, -1); - return tag; - } - - public static PreGraniteMetaBlockIdFixer deserialize(NBTTagCompound tag) { - return new PreGraniteMetaBlockIdFixer( - MetaBlockIdRemapCache.deserialize( - MetaBlockIdFixHelper.COMP_NAME_PREF_NEW, tag.getCompoundTag(KEY_REMAP_CACHE_COMPRESSED)), - MetaBlockIdRemapCache.deserialize( - MetaBlockIdFixHelper.SURF_ROCK_NAME_PREF_NEW, tag.getCompoundTag(KEY_REMAP_CACHE_SURF_ROCK))); - } - -} diff --git a/src/main/java/gregtech/common/datafix/fixes/metablockid/WorldDataHooks.java b/src/main/java/gregtech/common/datafix/fixes/metablockid/WorldDataHooks.java deleted file mode 100644 index b01a7700c67..00000000000 --- a/src/main/java/gregtech/common/datafix/fixes/metablockid/WorldDataHooks.java +++ /dev/null @@ -1,150 +0,0 @@ -package gregtech.common.datafix.fixes.metablockid; - -import gregtech.GregTechVersion; -import gregtech.api.GTValues; -import gregtech.api.util.GTLog; -import gregtech.api.util.Version; -import gregtech.common.datafix.GregTechDataFixers; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.world.storage.SaveHandler; -import net.minecraftforge.common.util.Constants; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.StartupQuery; -import net.minecraftforge.fml.common.ZipperUtil; -import net.minecraftforge.fml.relauncher.Side; - -import javax.annotation.Nullable; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Objects; - -public class WorldDataHooks { - - private static final String MAP_STORAGE_NAME = "gregtech_data"; - private static final String KEY_META_BLOCK_ID_FIXER = "MetaBlockIdFixer"; - - @Nullable - private static MetaBlockIdFixer metaBlockIdFixer = null; - - private WorldDataHooks() { - } - - public static boolean isFixerUnavailable() { - return metaBlockIdFixer == null; - } - - public static MetaBlockIdFixer getMetaBlockIdFixer() { - return Objects.requireNonNull(metaBlockIdFixer); - } - - @SuppressWarnings("unused") - public static void onWorldLoad(SaveHandler saveHandler, NBTTagCompound levelTag) { - // the meta block ID fix only matters on the server side - if (FMLCommonHandler.instance().getEffectiveSide() != Side.SERVER) { - return; - } - - metaBlockIdFixer = null; // we want to get our hands on one of these - boolean firstTimeFixing = false; // is it the first time running an old world with fixers? - - File mapStorageFile = saveHandler.getMapFileFromName(MAP_STORAGE_NAME); - NBTTagCompound wsdDataTag = null; - boolean wsdNeedsWrite = true; // do we need to serialize the fixer instance to the WSD? - - // load fixer instance from gt world-saved data - if (mapStorageFile.exists()) { - try (FileInputStream mapStorageIn = new FileInputStream(mapStorageFile)) { - wsdDataTag = CompressedStreamTools.readCompressed(mapStorageIn).getCompoundTag("data"); - if (wsdDataTag.hasKey(KEY_META_BLOCK_ID_FIXER, Constants.NBT.TAG_COMPOUND)) { - metaBlockIdFixer = MetaBlockIdFixer.deserialize(wsdDataTag.getCompoundTag(KEY_META_BLOCK_ID_FIXER)); - GTLog.logger.info("Using fallback data version {} from WSD", metaBlockIdFixer.getFallbackDataVersion()); - wsdNeedsWrite = false; // we just loaded it, so there's no need to write it back - } - } catch (IOException e) { - throw new IllegalStateException("Failed to read GregTech world-saved data!", e); - } - } - - // that failing, create a new one by reading the level NBT - if (metaBlockIdFixer == null && levelTag.hasKey("FML", Constants.NBT.TAG_COMPOUND)) { - NBTTagCompound fmlTag = levelTag.getCompoundTag("FML"); - if (fmlTag.hasKey("ModList", Constants.NBT.TAG_LIST)) { - NBTTagList modListTag = fmlTag.getTagList("ModList", Constants.NBT.TAG_COMPOUND); - for (int i = 0; i < modListTag.tagCount(); i++) { - NBTTagCompound modEntryTag = modListTag.getCompoundTagAt(i); - if (modEntryTag.getString("ModId").equals(GTValues.MODID)) { - Version prevSaveVersion = Version.parse(modEntryTag.getString("ModVersion")); - metaBlockIdFixer = MetaBlockIdFixer.create(prevSaveVersion, fmlTag); - GTLog.logger.info("Using fallback data version {} from previous GregTech version {}", - metaBlockIdFixer.getFallbackDataVersion(), prevSaveVersion); - if (metaBlockIdFixer.getFallbackDataVersion() < GregTechDataFixers.V1_META_BLOCK_ID_REWORK) { - firstTimeFixing = true; - } - } - } - } - } - - // that failing, assume world has never been played with gt before, so we're already up-to-date - if (metaBlockIdFixer == null) { - metaBlockIdFixer = MetaBlockIdFixer.NOOP; - GTLog.logger.info("Using fallback data version 1 by default"); - } - - // if needed, serialize the fixer instance to world-saved data - if (wsdNeedsWrite) { - if (wsdDataTag == null) { - wsdDataTag = new NBTTagCompound(); - } - - wsdDataTag.setTag(KEY_META_BLOCK_ID_FIXER, metaBlockIdFixer.serialize()); - NBTTagCompound wsdTag = new NBTTagCompound(); - wsdTag.setTag("data", wsdDataTag); - try (FileOutputStream mapStorageOut = new FileOutputStream(mapStorageFile)) { - CompressedStreamTools.writeCompressed(wsdTag, mapStorageOut); - } catch (IOException e) { - throw new IllegalStateException("Failed to write GregTech world-saved data!", e); - } - } - - // prompt to create a backup if it's the first time an old world is being loaded with fixers - if (firstTimeFixing) { - promptWorldBackup(metaBlockIdFixer.getFallbackDataVersion()); - } - } - - public static void promptWorldBackup(int prevDataVersion) { - String text = "GregTech detected a required registry remapping!\n\n" - + "Updating from before " + TextFormatting.AQUA + (prevDataVersion == -1 ? MetaBlockIdFixHelper.V1_10_5 : MetaBlockIdFixHelper.V1_15_0) + TextFormatting.RESET - + " to " + TextFormatting.AQUA + GregTechVersion.VERSION.toString(3) + TextFormatting.RESET + ".\n" - + "It is " + TextFormatting.UNDERLINE + "strongly" + TextFormatting.RESET + " recommended that you perform a backup. Create backup?"; - - if (StartupQuery.confirm(text)) { - try { - GTLog.logger.info("Creating world backup before starting registry remapping..."); - ZipperUtil.backupWorld(); - } catch (IOException e) { - GTLog.logger.error(e); - StartupQuery.notify("Encountered an error while creating the backup!\n" + - "See the game log for more details."); - StartupQuery.abort(); - } - } else { - String reconfirm = "No backup will be created. Proceed with the remapping without a backup?"; - if (!StartupQuery.confirm(reconfirm)) - StartupQuery.abort(); - } - } - - @SuppressWarnings("unused") - public static int getFallbackModVersion(String modId) { - return metaBlockIdFixer != null && modId.equals(GTValues.MODID) - ? metaBlockIdFixer.getFallbackDataVersion() : -1; - } - -} diff --git a/src/main/java/gregtech/common/datafix/util/DataFixHelper.java b/src/main/java/gregtech/common/datafix/util/DataFixHelper.java deleted file mode 100644 index 102c80bd5a1..00000000000 --- a/src/main/java/gregtech/common/datafix/util/DataFixHelper.java +++ /dev/null @@ -1,94 +0,0 @@ -package gregtech.common.datafix.util; - -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.world.chunk.NibbleArray; -import net.minecraftforge.common.util.Constants; - -import javax.annotation.Nullable; - -public class DataFixHelper { - - public static void rewriteCompoundTags(NBTTagCompound tag, CompoundRewriter rewriter) { - for (String key : tag.getKeySet()) { - NBTBase childTag = tag.getTag(key); - switch (childTag.getId()) { - case Constants.NBT.TAG_LIST: - rewriteCompoundTags((NBTTagList) childTag, rewriter); - break; - case Constants.NBT.TAG_COMPOUND: - NBTTagCompound childTagCompound = (NBTTagCompound) childTag; - rewriteCompoundTags(childTagCompound, rewriter); - childTagCompound = rewriter.rewrite(childTagCompound); - if (childTagCompound != null) { - tag.setTag(key, childTagCompound); - } - break; - } - } - } - - public static void rewriteCompoundTags(NBTTagList tag, CompoundRewriter rewriter) { - for (int i = 0; i < tag.tagCount(); i++) { - NBTBase childTag = tag.get(i); - switch (childTag.getId()) { - case Constants.NBT.TAG_LIST: - rewriteCompoundTags((NBTTagList) childTag, rewriter); - break; - case Constants.NBT.TAG_COMPOUND: - NBTTagCompound childTagCompound = (NBTTagCompound) childTag; - rewriteCompoundTags(childTagCompound, rewriter); - childTagCompound = rewriter.rewrite(childTagCompound); - if (childTagCompound != null) { - tag.set(i, childTagCompound); - } - break; - } - } - } - - @FunctionalInterface - public interface CompoundRewriter { - - @Nullable - NBTTagCompound rewrite(NBTTagCompound tag); - - } - - public static void rewriteBlocks(NBTTagCompound chunkSectionTag, BlockRewriter rewriter) { - byte[] blockIds = chunkSectionTag.getByteArray("Blocks"); - NibbleArray blockData = new NibbleArray(chunkSectionTag.getByteArray("Data")); - NibbleArray extendedIds = chunkSectionTag.hasKey("Add", Constants.NBT.TAG_BYTE_ARRAY) - ? new NibbleArray(chunkSectionTag.getByteArray("Add")) : null; - for (int i = 0; i < 4096; ++i) { - int x = i & 0x0F, y = i >> 8 & 0x0F, z = i >> 4 & 0x0F; - int id = extendedIds == null ? (blockIds[i] & 0xFF) - : ((blockIds[i] & 0xFF) | (extendedIds.get(x, y, z) << 8)); - RemappedBlock remapped = rewriter.rewrite(id, (short) blockData.get(x, y, z)); - if (remapped != null) { - blockIds[i] = (byte) (remapped.id & 0xFF); - int idExt = (remapped.id >> 8) & 0x0F; - if (idExt != 0) { - if (extendedIds == null) { - extendedIds = new NibbleArray(); - } - extendedIds.set(x, y, z, idExt); - } - blockData.set(x, y, z, remapped.data & 0x0F); - } - } - if (extendedIds != null) { - chunkSectionTag.setByteArray("Add", extendedIds.getData()); - } - } - - @FunctionalInterface - public interface BlockRewriter { - - @Nullable - RemappedBlock rewrite(int id, short data); - - } - -} diff --git a/src/main/java/gregtech/common/datafix/util/RemappedBlock.java b/src/main/java/gregtech/common/datafix/util/RemappedBlock.java deleted file mode 100644 index 2e798ede6da..00000000000 --- a/src/main/java/gregtech/common/datafix/util/RemappedBlock.java +++ /dev/null @@ -1,13 +0,0 @@ -package gregtech.common.datafix.util; - -public class RemappedBlock { - - public final int id; - public final short data; - - public RemappedBlock(int id, short data) { - this.id = id; - this.data = data; - } - -} diff --git a/src/main/java/gregtech/common/datafix/walker/WalkChunkSection.java b/src/main/java/gregtech/common/datafix/walker/WalkChunkSection.java deleted file mode 100644 index f6c50bcd527..00000000000 --- a/src/main/java/gregtech/common/datafix/walker/WalkChunkSection.java +++ /dev/null @@ -1,27 +0,0 @@ -package gregtech.common.datafix.walker; - -import gregtech.common.datafix.GregTechFixType; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.datafix.IDataFixer; -import net.minecraft.util.datafix.IDataWalker; -import net.minecraftforge.common.util.Constants; - -public class WalkChunkSection implements IDataWalker { - - @Override - public NBTTagCompound process(IDataFixer fixer, NBTTagCompound compound, int versionIn) { - if (compound.hasKey("Level", Constants.NBT.TAG_COMPOUND)) { - NBTTagCompound levelTag = compound.getCompoundTag("Level"); - if (levelTag.hasKey("Sections", Constants.NBT.TAG_LIST)) { - NBTTagList sectionListTag = levelTag.getTagList("Sections", Constants.NBT.TAG_COMPOUND); - for (int i = 0; i < sectionListTag.tagCount(); i++) { - sectionListTag.set(i, fixer.process( - GregTechFixType.CHUNK_SECTION, sectionListTag.getCompoundTagAt(i), versionIn)); - } - } - } - return compound; - } - -} diff --git a/src/main/java/gregtech/common/datafix/walker/WalkItemStackLike.java b/src/main/java/gregtech/common/datafix/walker/WalkItemStackLike.java deleted file mode 100644 index 857819d2506..00000000000 --- a/src/main/java/gregtech/common/datafix/walker/WalkItemStackLike.java +++ /dev/null @@ -1,24 +0,0 @@ -package gregtech.common.datafix.walker; - -import gregtech.common.datafix.util.DataFixHelper; -import gregtech.common.datafix.GregTechFixType; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.datafix.IDataFixer; -import net.minecraft.util.datafix.IDataWalker; -import net.minecraftforge.common.util.Constants; - -public class WalkItemStackLike implements IDataWalker { - - @Override - public NBTTagCompound process(IDataFixer fixer, NBTTagCompound compound, int versionIn) { - DataFixHelper.rewriteCompoundTags(compound, tag -> { - if (tag.hasKey("id", Constants.NBT.TAG_STRING) && tag.hasKey("Count", Constants.NBT.TAG_BYTE) - && tag.hasKey("Damage", Constants.NBT.TAG_SHORT)) { - return fixer.process(GregTechFixType.ITEM_STACK_LIKE, tag, versionIn); - } - return null; - }); - return compound; - } - -} diff --git a/src/main/java/gregtech/common/util/ResourcePackFix.java b/src/main/java/gregtech/common/util/ResourcePackFix.java deleted file mode 100644 index 9bd5231b2f0..00000000000 --- a/src/main/java/gregtech/common/util/ResourcePackFix.java +++ /dev/null @@ -1,75 +0,0 @@ -package gregtech.common.util; - -import com.google.common.base.Preconditions; -import gregtech.GregTechMod; -import net.minecraft.client.resources.AbstractResourcePack; -import net.minecraft.client.resources.IResourcePack; -import net.minecraft.client.resources.LegacyV2Adapter; -import net.minecraftforge.fml.client.FMLClientHandler; -import net.minecraftforge.fml.common.ModContainer; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import java.io.File; -import java.net.URL; -import java.util.List; -import java.util.Map; - -/** - * Fixes resource pack path in development environment for unpacked mod - * Because, you know, i don't like waiting 5 minutes and wasting SSD resources on copying resources every - * time i want to hot-swap code, and forge is too stupid to properly detect separated resource folder - * in development configuration - */ -@SideOnly(Side.CLIENT) -public class ResourcePackFix { - - private static AbstractResourcePack getModResourcePack(String modid) { - IResourcePack rawPack = FMLClientHandler.instance().getResourcePackFor(modid); - AbstractResourcePack resourcePack; - if (rawPack instanceof LegacyV2Adapter) { - resourcePack = ObfuscationReflectionHelper.getPrivateValue(LegacyV2Adapter.class, (LegacyV2Adapter) rawPack, 0); - } else if (rawPack instanceof AbstractResourcePack) { - resourcePack = (AbstractResourcePack) rawPack; - } else { - throw new UnsupportedOperationException("Unknown resource pack class " + rawPack.getClass()); - } - return resourcePack; - } - - private static void setModResourcePack(String modid, AbstractResourcePack newPack) { - FMLClientHandler clientHandler = FMLClientHandler.instance(); - IResourcePack oldPack = clientHandler.getResourcePackFor(modid); - Map resourcePackMap = ObfuscationReflectionHelper.getPrivateValue(FMLClientHandler.class, clientHandler, "resourcePackMap"); - resourcePackMap.put(modid, newPack); - List resourcePackList = ObfuscationReflectionHelper.getPrivateValue(FMLClientHandler.class, clientHandler, "resourcePackList"); - resourcePackList.remove(oldPack); - resourcePackList.add(newPack); - } - - private static File getGTCEResourcePackRoot() { - URL mcModURL = GregTechMod.class.getResource("/mcmod.info"); - Preconditions.checkState(mcModURL.getProtocol().equals("file"), "Protocol is not file"); - return new File(mcModURL.getPath()).getParentFile(); - } - - public static void fixResourcePackLocation(ModContainer selfContainer) { - File sourceFile = selfContainer.getSource(); - if (sourceFile.isDirectory()) { - AbstractResourcePack resourcePack = getModResourcePack(selfContainer.getModId()); - File actualPackRoot = ObfuscationReflectionHelper.getPrivateValue(AbstractResourcePack.class, resourcePack, "field_110597_b"); - File expectedPackRoot = getGTCEResourcePackRoot(); - - if (!expectedPackRoot.getAbsolutePath().equals(actualPackRoot.getAbsolutePath())) { - System.out.println("[GTCE] Found unexpected resource pack path in dev environment"); - System.out.println("[GTCE] Expected path: " + expectedPackRoot.getAbsolutePath()); - System.out.println("[GTCE] Actual path: " + actualPackRoot.getAbsolutePath()); - System.out.println("[GTCE] Fixed resource pack patch automatically."); - ObfuscationReflectionHelper.setPrivateValue(AbstractResourcePack.class, resourcePack, expectedPackRoot, "field_110597_b"); - setModResourcePack(selfContainer.getModId(), resourcePack); - } - } - } - -}