From 5ff7cdb47a063d262041b16c5581a780d4daab95 Mon Sep 17 00:00:00 2001 From: ALongStringOfNumbers <31759736+ALongStringOfNumbers@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:55:15 -0700 Subject: [PATCH] Convert from ASM to Mixins (#2192) Co-authored-by: serenibyss <10861407+serenibyss@users.noreply.github.com> Co-authored-by: Ghzdude <44148655+ghzdude@users.noreply.github.com> --- addon.gradle | 19 + dependencies.gradle | 21 +- gradle.properties | 18 +- .../render/cache/LayeredRenderBoxCache.java | 4 - .../client/render/tile/LittleRenderBox.java | 5 - src/main/java/gregtech/GregTechMod.java | 5 - src/main/java/gregtech/api/GTValues.java | 3 +- .../api/damagesources/DamageSources.java | 10 +- .../api/items/metaitem/MusicDiscStats.java | 4 + src/main/java/gregtech/api/util/Mods.java | 2 + .../gregtech/asm/GregTechLoadingPlugin.java | 21 +- .../gregtech/asm/GregTechTransformer.java | 414 ++++++++++-------- .../utils/BloomEffectVintagiumUtil.java | 23 +- .../GregTechLateMixinLoadingPlugin.java | 37 ++ .../mixins/ccl/CCLDescriptionMixin.java | 17 + .../ctm/AbstractCTMBakedModelMixin.java | 28 ++ .../mixins/ctm/CTMRenderInLayerMixin.java | 28 ++ .../forge/ModelLoaderRegistryMixin.java | 20 + .../forge/SpecialArmorPropertiesMixin.java | 38 ++ .../gregtech/mixins/jei/JEITooltipMixin.java | 32 ++ .../LittleTilesRenderMangerMixin.java | 28 ++ .../minecraft/BlockConcretePowderMixin.java | 24 + .../gregtech/mixins/minecraft/BlockMixin.java | 33 ++ .../mixins/minecraft/DamageSourceMixin.java | 25 ++ .../minecraft/EnchantmentCanApplyMixin.java | 23 + .../mixins/minecraft/EntityRendererMixin.java | 26 ++ .../mixins/minecraft/LayerArmorBaseMixin.java | 79 ++++ .../minecraft/LayerCustomHeadMixin.java | 38 ++ .../mixins/minecraft/MinecraftMixin.java | 22 + .../minecraft/RecipeRepairItemMixin.java | 102 +++++ .../RegionRenderCacheBuilderMixin.java | 26 ++ .../mixins/minecraft/RenderChunkMixin.java | 30 ++ .../mixins/minecraft/RenderGlobalMixin.java | 50 +++ .../mixins/minecraft/RenderItemMixin.java | 38 ++ .../mixins/theoneprobe/TheOneProbeMixin.java | 40 ++ .../vintagium/BlockRenderManagerMixin.java | 33 ++ .../vintagium/BlockRenderPassMixin.java | 46 ++ .../resources/assets/gregtech/lang/en_us.lang | 2 + src/main/resources/mixins.gregtech.ccl.json | 12 + src/main/resources/mixins.gregtech.ctm.json | 13 + src/main/resources/mixins.gregtech.forge.json | 13 + src/main/resources/mixins.gregtech.jei.json | 12 + .../mixins.gregtech.littletiles.json | 12 + .../resources/mixins.gregtech.minecraft.json | 25 ++ .../mixins.gregtech.theoneprobe.json | 10 + .../resources/mixins.gregtech.vintagium.json | 13 + 46 files changed, 1257 insertions(+), 267 deletions(-) create mode 100644 addon.gradle delete mode 100644 src/api/java/com/creativemd/littletiles/client/render/cache/LayeredRenderBoxCache.java delete mode 100644 src/api/java/com/creativemd/littletiles/client/render/tile/LittleRenderBox.java create mode 100644 src/main/java/gregtech/mixins/GregTechLateMixinLoadingPlugin.java create mode 100644 src/main/java/gregtech/mixins/ccl/CCLDescriptionMixin.java create mode 100644 src/main/java/gregtech/mixins/ctm/AbstractCTMBakedModelMixin.java create mode 100644 src/main/java/gregtech/mixins/ctm/CTMRenderInLayerMixin.java create mode 100644 src/main/java/gregtech/mixins/forge/ModelLoaderRegistryMixin.java create mode 100644 src/main/java/gregtech/mixins/forge/SpecialArmorPropertiesMixin.java create mode 100644 src/main/java/gregtech/mixins/jei/JEITooltipMixin.java create mode 100644 src/main/java/gregtech/mixins/littletiles/LittleTilesRenderMangerMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/BlockConcretePowderMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/BlockMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/DamageSourceMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/EnchantmentCanApplyMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/EntityRendererMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/LayerArmorBaseMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/LayerCustomHeadMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/MinecraftMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/RegionRenderCacheBuilderMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/RenderChunkMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/RenderGlobalMixin.java create mode 100644 src/main/java/gregtech/mixins/minecraft/RenderItemMixin.java create mode 100644 src/main/java/gregtech/mixins/theoneprobe/TheOneProbeMixin.java create mode 100644 src/main/java/gregtech/mixins/vintagium/BlockRenderManagerMixin.java create mode 100644 src/main/java/gregtech/mixins/vintagium/BlockRenderPassMixin.java create mode 100644 src/main/resources/mixins.gregtech.ccl.json create mode 100644 src/main/resources/mixins.gregtech.ctm.json create mode 100644 src/main/resources/mixins.gregtech.forge.json create mode 100644 src/main/resources/mixins.gregtech.jei.json create mode 100644 src/main/resources/mixins.gregtech.littletiles.json create mode 100644 src/main/resources/mixins.gregtech.minecraft.json create mode 100644 src/main/resources/mixins.gregtech.theoneprobe.json create mode 100644 src/main/resources/mixins.gregtech.vintagium.json diff --git a/addon.gradle b/addon.gradle new file mode 100644 index 00000000000..51789b691e1 --- /dev/null +++ b/addon.gradle @@ -0,0 +1,19 @@ + +minecraft { + injectedTags.put('DEP_VERSION_STRING', "required-after:gregtech@[${modVersion},);") +} + +configurations { + compileOnly { + // exclude GNU trove, FastUtil is superior and still updated + exclude group: "net.sf.trove4j", module: "trove4j" + // exclude javax.annotation from findbugs, jetbrains annotations are superior + exclude group: "com.google.code.findbugs", module: "jsr305" + // exclude scala as we don't use it for anything and causes import confusion + exclude group: "org.scala-lang" + exclude group: "org.scala-lang.modules" + exclude group: "org.scala-lang.plugins" + } +} + + diff --git a/dependencies.gradle b/dependencies.gradle index 70fa763ed88..0b938ad49e1 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -69,6 +69,10 @@ dependencies { dest: "libs") compileOnly(files("libs/vintagium-mc1.12.2-0.1-dev.jar")) + compileOnly rfg.deobf("curse.maven:littletiles-257818:4750222") // LittleTiles 1.5.82-1.12.2 + compileOnly rfg.deobf("curse.maven:creativecore-257814:4722163") // Creative Core 1.10.71 + + // Mods with Soft compat but which have no need to be in code, such as isModLoaded() checks and getModItem() recipes. // Uncomment any of these to test them in-game. @@ -79,20 +83,3 @@ dependencies { // runtimeOnlyNonPublishable rfg.deobf("curse.maven:gendustry-70492:2516215") // Gendustry 1.6.5.8 // runtimeOnlyNonPublishable rfg.deobf("curse.maven:bdlib-70496:2518031") // BdLib 1.14.3.12 } - -minecraft { - injectedTags.put('DEP_VERSION_STRING', "required-after:gregtech@[${modVersion},);") -} - -configurations { - compileOnly { - // exclude GNU trove, FastUtil is superior and still updated - exclude group: "net.sf.trove4j", module: "trove4j" - // exclude javax.annotation from findbugs, jetbrains annotations are superior - exclude group: "com.google.code.findbugs", module: "jsr305" - // exclude scala as we don't use it for anything and causes import confusion - exclude group: "org.scala-lang" - exclude group: "org.scala-lang.modules" - exclude group: "org.scala-lang.plugins" - } -} diff --git a/gradle.properties b/gradle.properties index 9de88c6bf58..7c35906e44c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -51,29 +51,25 @@ useSrcApiPath=false accessTransformersFile = gregtech_at.cfg # Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled! -usesMixins = false +usesMixins = true # Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail! -mixinsPackage = +mixinsPackage = mixins # Automatically generates a mixin config json if enabled, with the name mixins.modid.json -generateMixinConfig=false +generateMixinConfig = false # Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin! # Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin coreModClass = asm.GregTechLoadingPlugin # If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod (meaning that # there is no class annotated with @Mod) you want this to be true. When in doubt: leave it on false! -containsMixinsAndOrCoreModOnly = false - +containsMixinsAndOrCoreModOnly=false # Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins. -forceEnableMixins = true - +forceEnableMixins=false # Outputs pre-transformed and post-transformed loaded classes to run/CLASSLOADER_TEMP. Can be used in combination with # diff to see exactly what your ASM or Mixins are changing in the target file. # Optionally can be specified with the 'CORE_MOD_DEBUG' env var. Will output a lot of files! -enableCoreModDebug = false - +enableCoreModDebug=false # Adds CurseMaven, Modrinth Maven, BlameJared maven, and some more well-known 1.12.2 repositories -includeWellKnownRepositories = true - +includeWellKnownRepositories=true # Adds JEI and TheOneProbe to your development environment. Adds them as 'implementation', meaning they will # be available at compiletime and runtime for your mod (in-game and in-code). # Overrides the above setting to be always true, as these repositories are needed to fetch the mods diff --git a/src/api/java/com/creativemd/littletiles/client/render/cache/LayeredRenderBoxCache.java b/src/api/java/com/creativemd/littletiles/client/render/cache/LayeredRenderBoxCache.java deleted file mode 100644 index 5bba9443bfb..00000000000 --- a/src/api/java/com/creativemd/littletiles/client/render/cache/LayeredRenderBoxCache.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.creativemd.littletiles.client.render.cache; - -public class LayeredRenderBoxCache { -} diff --git a/src/api/java/com/creativemd/littletiles/client/render/tile/LittleRenderBox.java b/src/api/java/com/creativemd/littletiles/client/render/tile/LittleRenderBox.java deleted file mode 100644 index 10987d58d48..00000000000 --- a/src/api/java/com/creativemd/littletiles/client/render/tile/LittleRenderBox.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.creativemd.littletiles.client.render.tile; - -public class LittleRenderBox { - public boolean needsResorting; -} diff --git a/src/main/java/gregtech/GregTechMod.java b/src/main/java/gregtech/GregTechMod.java index 97350a1a009..b0afab8f2d6 100644 --- a/src/main/java/gregtech/GregTechMod.java +++ b/src/main/java/gregtech/GregTechMod.java @@ -4,9 +4,7 @@ import gregtech.api.GregTechAPI; import gregtech.api.modules.ModuleContainerRegistryEvent; import gregtech.api.persistence.PersistentData; -import gregtech.api.util.Mods; import gregtech.client.utils.BloomEffectUtil; -import gregtech.client.utils.BloomEffectVintagiumUtil; import gregtech.modules.GregTechModules; import gregtech.modules.ModuleManager; @@ -48,9 +46,6 @@ public GregTechMod() { FluidRegistry.enableUniversalBucket(); if (FMLCommonHandler.instance().getSide().isClient()) { BloomEffectUtil.init(); - if (Mods.Vintagium.isModLoaded()) { - BloomEffectVintagiumUtil.init(); - } } } diff --git a/src/main/java/gregtech/api/GTValues.java b/src/main/java/gregtech/api/GTValues.java index 006f9444117..2048c61affe 100644 --- a/src/main/java/gregtech/api/GTValues.java +++ b/src/main/java/gregtech/api/GTValues.java @@ -170,7 +170,8 @@ public class GTValues { MODID_PROJRED_CORE = "projectred-core", MODID_RC = "railcraft", MODID_CHISEL = "chisel", - MODID_RS = "refinedstorage"; + MODID_RS = "refinedstorage", + MODID_LITTLETILES = "littletiles"; private static Boolean isClient; diff --git a/src/main/java/gregtech/api/damagesources/DamageSources.java b/src/main/java/gregtech/api/damagesources/DamageSources.java index 2283c396139..423b0417b63 100644 --- a/src/main/java/gregtech/api/damagesources/DamageSources.java +++ b/src/main/java/gregtech/api/damagesources/DamageSources.java @@ -49,23 +49,17 @@ public static DamageSource getTurbineDamage() { return TURBINE; } - // accessed via ASM - @SuppressWarnings("unused") public static DamageSource getPlayerDamage(@Nullable EntityPlayer source) { ItemStack stack = source != null ? source.getHeldItemMainhand() : ItemStack.EMPTY; - if (!stack.isEmpty() && stack.getItem() instanceof IGTTool) { - IGTTool tool = (IGTTool) stack.getItem(); + if (!stack.isEmpty() && stack.getItem() instanceof IGTTool tool) { return new DamageSourceTool("player", source, String.format("death.attack.%s", tool.getToolId())); } return new EntityDamageSource("player", source); } - // accessed via ASM - @SuppressWarnings("unused") public static DamageSource getMobDamage(@Nullable EntityLivingBase source) { ItemStack stack = source != null ? source.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND) : ItemStack.EMPTY; - if (!stack.isEmpty() && stack.getItem() instanceof IGTTool) { - IGTTool tool = (IGTTool) stack.getItem(); + if (!stack.isEmpty() && stack.getItem() instanceof IGTTool tool) { return new DamageSourceTool("mob", source, String.format("death.attack.%s", tool.getToolId())); } return new EntityDamageSource("mob", source); diff --git a/src/main/java/gregtech/api/items/metaitem/MusicDiscStats.java b/src/main/java/gregtech/api/items/metaitem/MusicDiscStats.java index a505896cb24..b90f1ce5f88 100644 --- a/src/main/java/gregtech/api/items/metaitem/MusicDiscStats.java +++ b/src/main/java/gregtech/api/items/metaitem/MusicDiscStats.java @@ -31,6 +31,10 @@ public SoundEvent getSound() { return sound; } + public String getName() { + return sound.getSoundName().getPath(); + } + @Override public ActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { diff --git a/src/main/java/gregtech/api/util/Mods.java b/src/main/java/gregtech/api/util/Mods.java index 609f71c1008..b62a262856d 100644 --- a/src/main/java/gregtech/api/util/Mods.java +++ b/src/main/java/gregtech/api/util/Mods.java @@ -54,6 +54,7 @@ public enum Mods { InventoryTweaks(Names.INVENTORY_TWEAKS), JourneyMap(Names.JOURNEY_MAP), JustEnoughItems(Names.JUST_ENOUGH_ITEMS), + LittleTiles(Names.LITTLE_TILES), MagicBees(Names.MAGIC_BEES), Nothirium(Names.NOTHIRIUM), NuclearCraft(Names.NUCLEAR_CRAFT, versionExcludes("2o")), @@ -124,6 +125,7 @@ public static class Names { public static final String INVENTORY_TWEAKS = "inventorytweaks"; public static final String JOURNEY_MAP = "journeymap"; public static final String JUST_ENOUGH_ITEMS = "jei"; + public static final String LITTLE_TILES = "littletiles"; public static final String MAGIC_BEES = "magicbees"; public static final String NOTHIRIUM = "nothirium"; public static final String NUCLEAR_CRAFT = "nuclearcraft"; diff --git a/src/main/java/gregtech/asm/GregTechLoadingPlugin.java b/src/main/java/gregtech/asm/GregTechLoadingPlugin.java index b1e461c7954..ab48a079c83 100644 --- a/src/main/java/gregtech/asm/GregTechLoadingPlugin.java +++ b/src/main/java/gregtech/asm/GregTechLoadingPlugin.java @@ -8,14 +8,18 @@ import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions; import org.jetbrains.annotations.Nullable; +import zone.rong.mixinbooter.IEarlyMixinLoader; +import java.util.ArrayList; +import java.util.List; import java.util.Map; @Name("GregTechLoadingPlugin") @MCVersion(ForgeVersion.mcVersion) @TransformerExclusions("gregtech.asm.") @SortingIndex(1001) -public class GregTechLoadingPlugin implements IFMLLoadingPlugin { +// TODO, move to mixin package +public class GregTechLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader { @Override public String[] getASMTransformerClass() { @@ -40,4 +44,19 @@ public void injectData(Map data) {} public String getAccessTransformerClass() { return null; } + + @Override + public List getMixinConfigs() { + List configs = new ArrayList<>(); + + configs.add("mixins.gregtech.forge.json"); + configs.add("mixins.gregtech.minecraft.json"); + + return configs; + } + + @Override + public boolean shouldMixinConfigQueue(String mixinConfig) { + return IEarlyMixinLoader.super.shouldMixinConfigQueue(mixinConfig); + } } diff --git a/src/main/java/gregtech/asm/GregTechTransformer.java b/src/main/java/gregtech/asm/GregTechTransformer.java index 5f9d5e1ba3f..9a13badeaf5 100644 --- a/src/main/java/gregtech/asm/GregTechTransformer.java +++ b/src/main/java/gregtech/asm/GregTechTransformer.java @@ -1,20 +1,8 @@ package gregtech.asm; -import gregtech.asm.util.ObfMapping; -import gregtech.asm.util.TargetClassVisitor; -import gregtech.asm.visitors.*; -import gregtech.common.ConfigHolder; - import net.minecraft.launchwrapper.IClassTransformer; -import net.minecraft.launchwrapper.Launch; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; - -import java.util.Iterator; public class GregTechTransformer implements IClassTransformer, Opcodes { @@ -22,189 +10,229 @@ public class GregTechTransformer implements IClassTransformer, Opcodes { public byte[] transform(String name, String transformedName, byte[] basicClass) { String internalName = transformedName.replace('.', '/'); switch (internalName) { - case JEIVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(0); - classReader.accept(new TargetClassVisitor(classWriter, JEIVisitor.TARGET_METHOD, JEIVisitor::new), 0); - return classWriter.toByteArray(); - } - case ConcretePowderVisitor.TARGET_CLASS_NAME: - if (ConfigHolder.recipes.disableConcreteInWorld) { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new TargetClassVisitor(classWriter, ConcretePowderVisitor.TARGET_METHOD, - ConcretePowderVisitor::new), 0); - return classWriter.toByteArray(); - } - break; - case LayerCustomHeadVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new TargetClassVisitor(classWriter, LayerCustomHeadVisitor.TARGET_METHOD, - LayerCustomHeadVisitor::new), 0); - return classWriter.toByteArray(); - } - case SpecialArmorApplyVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new SpecialArmorClassVisitor(classWriter, SpecialArmorApplyVisitor.TARGET_METHOD, - SpecialArmorApplyVisitor::new), 0); - return classWriter.toByteArray(); - } - case LayerArmorBaseVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new TargetClassVisitor(classWriter, LayerArmorBaseVisitor.TARGET_METHOD, - LayerArmorBaseVisitor::new), 0); - return classWriter.toByteArray(); - } - case RegionRenderCacheBuilderVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new TargetClassVisitor(classWriter, RegionRenderCacheBuilderVisitor.TARGET_METHOD, - RegionRenderCacheBuilderVisitor::new), 0); - return classWriter.toByteArray(); - } - case RenderChunkVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept( - new TargetClassVisitor(classWriter, RenderChunkVisitor.TARGET_METHOD, RenderChunkVisitor::new), - 0); - return classWriter.toByteArray(); - } - case EntityRendererVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new TargetClassVisitor(classWriter, EntityRendererVisitor.TARGET_METHOD, - EntityRendererVisitor::new), 0); - return classWriter.toByteArray(); - } - case BlockVisitor.TARGET_CLASS_NAME: { - try { - // must use Class#forName because CTM is client side only, and there is no other way to check - Class.forName("team.chisel.ctm.CTM", false, Launch.classLoader); - } catch (ClassNotFoundException ignored) { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - ClassNode classNode = new ClassNode(); - classReader.accept(classNode, 0); - BlockVisitor.handleClassNode(classNode).accept(classWriter); - return classWriter.toByteArray(); - } - break; - } - case WorldVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new TargetClassVisitor(classWriter, WorldVisitor.TARGET_METHOD, WorldVisitor::new), - 0); - return classWriter.toByteArray(); - } - case ModelCTMVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept( - new TargetClassVisitor(classWriter, ModelCTMVisitor.TARGET_METHOD, ModelCTMVisitor::new), 0); - return classWriter.toByteArray(); - } - case AbstractCTMBakedModelVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new TargetClassVisitor(classWriter, AbstractCTMBakedModelVisitor.TARGET_METHOD, - AbstractCTMBakedModelVisitor::new), 0); - return classWriter.toByteArray(); - } - case LittleTilesVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept( - new TargetClassVisitor(classWriter, LittleTilesVisitor.TARGET_METHOD, LittleTilesVisitor::new), - 0); - return classWriter.toByteArray(); - } - case CCLVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new TargetClassVisitor(classWriter, CCLVisitor.TARGET_METHOD, CCLVisitor::new), 0); - return classWriter.toByteArray(); - } - case RenderItemVisitor.TARGET_CLASS_NAME: { - ClassNode classNode = new ClassNode(); - ClassReader classReader = new ClassReader(basicClass); - classReader.accept(classNode, 0); - Iterator methods = classNode.methods.iterator(); - RenderItemVisitor.transform(methods); - ClassWriter classWriter = new ClassWriter(0); - classNode.accept(classWriter); - return classWriter.toByteArray(); - } - case RecipeRepairItemVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - ClassNode classNode = new ClassNode(); - classReader.accept(classNode, 0); - RecipeRepairItemVisitor.handleClassNode(classNode).accept(classWriter); - return classWriter.toByteArray(); - } - case DamageSourceVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - ClassNode classNode = new ClassNode(); - classReader.accept(classNode, 0); - DamageSourceVisitor.handleClassNode(classNode).accept(classWriter); - return classWriter.toByteArray(); - } - case TheOneProbeVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(0); - classReader.accept( - new TargetClassVisitor(classWriter, TheOneProbeVisitor.TARGET_METHOD, TheOneProbeVisitor::new), - 0); - return classWriter.toByteArray(); - } - case MinecraftVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(0); - classReader.accept( - new TargetClassVisitor(classWriter, MinecraftVisitor.PROCESS_KEY_F3, MinecraftVisitor::new), - ClassReader.EXPAND_FRAMES); - return classWriter.toByteArray(); - } - case ModelLoaderRegistryVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(0); - classReader.accept(new TargetClassVisitor(classWriter, ModelLoaderRegistryVisitor.TARGET_METHOD, - ModelLoaderRegistryVisitor::new), ClassReader.EXPAND_FRAMES); - return classWriter.toByteArray(); - } + /* + * case JEIVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(0); + * classReader.accept(new TargetClassVisitor(classWriter, JEIVisitor.TARGET_METHOD, JEIVisitor::new), 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case ConcretePowderVisitor.TARGET_CLASS_NAME: + * if (ConfigHolder.recipes.disableConcreteInWorld) { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new TargetClassVisitor(classWriter, ConcretePowderVisitor.TARGET_METHOD, + * ConcretePowderVisitor::new), 0); + * return classWriter.toByteArray(); + * } + * break; + */ + /* + * case LayerCustomHeadVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new TargetClassVisitor(classWriter, LayerCustomHeadVisitor.TARGET_METHOD, + * LayerCustomHeadVisitor::new), 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case SpecialArmorApplyVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new SpecialArmorClassVisitor(classWriter, SpecialArmorApplyVisitor.TARGET_METHOD, + * SpecialArmorApplyVisitor::new), 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case LayerArmorBaseVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new TargetClassVisitor(classWriter, LayerArmorBaseVisitor.TARGET_METHOD, + * LayerArmorBaseVisitor::new), 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case RegionRenderCacheBuilderVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new TargetClassVisitor(classWriter, RegionRenderCacheBuilderVisitor.TARGET_METHOD, + * RegionRenderCacheBuilderVisitor::new), 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case RenderChunkVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept( + * new TargetClassVisitor(classWriter, RenderChunkVisitor.TARGET_METHOD, RenderChunkVisitor::new), + * 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case EntityRendererVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new TargetClassVisitor(classWriter, EntityRendererVisitor.TARGET_METHOD, + * EntityRendererVisitor::new), 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case BlockVisitor.TARGET_CLASS_NAME: { + * try { + * // must use Class#forName because CTM is client side only, and there is no other way to check + * Class.forName("team.chisel.ctm.CTM", false, Launch.classLoader); + * } catch (ClassNotFoundException ignored) { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * ClassNode classNode = new ClassNode(); + * classReader.accept(classNode, 0); + * BlockVisitor.handleClassNode(classNode).accept(classWriter); + * return classWriter.toByteArray(); + * } + * break; + * } + */ + /* + * case WorldVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new TargetClassVisitor(classWriter, WorldVisitor.TARGET_METHOD, WorldVisitor::new), + * 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case ModelCTMVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept( + * new TargetClassVisitor(classWriter, ModelCTMVisitor.TARGET_METHOD, ModelCTMVisitor::new), 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case AbstractCTMBakedModelVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new TargetClassVisitor(classWriter, AbstractCTMBakedModelVisitor.TARGET_METHOD, + * AbstractCTMBakedModelVisitor::new), 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case LittleTilesVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept( + * new TargetClassVisitor(classWriter, LittleTilesVisitor.TARGET_METHOD, LittleTilesVisitor::new), + * 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case CCLVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new TargetClassVisitor(classWriter, CCLVisitor.TARGET_METHOD, CCLVisitor::new), 0); + * return classWriter.toByteArray(); + * } + * case RenderItemVisitor.TARGET_CLASS_NAME: { + * ClassNode classNode = new ClassNode(); + * ClassReader classReader = new ClassReader(basicClass); + * classReader.accept(classNode, 0); + * Iterator methods = classNode.methods.iterator(); + * RenderItemVisitor.transform(methods); + * ClassWriter classWriter = new ClassWriter(0); + * classNode.accept(classWriter); + * return classWriter.toByteArray(); + * } + */ + /* + * case RecipeRepairItemVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * ClassNode classNode = new ClassNode(); + * classReader.accept(classNode, 0); + * RecipeRepairItemVisitor.handleClassNode(classNode).accept(classWriter); + * return classWriter.toByteArray(); + * } + */ + /* + * case DamageSourceVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * ClassNode classNode = new ClassNode(); + * classReader.accept(classNode, 0); + * DamageSourceVisitor.handleClassNode(classNode).accept(classWriter); + * return classWriter.toByteArray(); + * } + */ + /* + * case TheOneProbeVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(0); + * classReader.accept( + * new TargetClassVisitor(classWriter, TheOneProbeVisitor.TARGET_METHOD, TheOneProbeVisitor::new), + * 0); + * return classWriter.toByteArray(); + * } + */ + /* + * case MinecraftVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(0); + * classReader.accept( + * new TargetClassVisitor(classWriter, MinecraftVisitor.PROCESS_KEY_F3, MinecraftVisitor::new), + * ClassReader.EXPAND_FRAMES); + * return classWriter.toByteArray(); + * } + */ + /* + * case ModelLoaderRegistryVisitor.TARGET_CLASS_NAME: { + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(0); + * classReader.accept(new TargetClassVisitor(classWriter, ModelLoaderRegistryVisitor.TARGET_METHOD, + * ModelLoaderRegistryVisitor::new), ClassReader.EXPAND_FRAMES); + * return classWriter.toByteArray(); + * } + */ // TODO: Remove when vintagium has proper support for other rendering layers - case VintagiumPassManagerVisitor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept( - new TargetClassVisitor(classWriter, VintagiumPassManagerVisitor.TARGET_METHOD, - VintagiumPassManagerVisitor::new), - ClassReader.EXPAND_FRAMES); - return classWriter.toByteArray(); - } - case VintagiumManagerVistor.TARGET_CLASS_NAME: { - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept( - new VintagiumManagerVistor(classWriter), - 0); - return classWriter.toByteArray(); - } - } - if (EnchantmentCanApplyVisitor.CLASS_TO_MAPPING_MAP.containsKey(internalName)) { - ObfMapping methodMapping = EnchantmentCanApplyVisitor.CLASS_TO_MAPPING_MAP.get(internalName); - ClassReader classReader = new ClassReader(basicClass); - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classReader.accept(new TargetClassVisitor(classWriter, methodMapping, - mv -> new EnchantmentCanApplyVisitor(mv, methodMapping)), ClassReader.EXPAND_FRAMES); - return classWriter.toByteArray(); + // case VintagiumPassManagerVisitor.TARGET_CLASS_NAME: { + // ClassReader classReader = new ClassReader(basicClass); + // ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + // classReader.accept( + // new TargetClassVisitor(classWriter, VintagiumPassManagerVisitor.TARGET_METHOD, + // VintagiumPassManagerVisitor::new), + // ClassReader.EXPAND_FRAMES); + // return classWriter.toByteArray(); + // } + // case VintagiumManagerVistor.TARGET_CLASS_NAME: { + // ClassReader classReader = new ClassReader(basicClass); + // ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + // classReader.accept( + // new VintagiumManagerVistor(classWriter), + // 0); + // return classWriter.toByteArray(); + // } } + /* + * if (EnchantmentCanApplyVisitor.CLASS_TO_MAPPING_MAP.containsKey(internalName)) { + * ObfMapping methodMapping = EnchantmentCanApplyVisitor.CLASS_TO_MAPPING_MAP.get(internalName); + * ClassReader classReader = new ClassReader(basicClass); + * ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + * classReader.accept(new TargetClassVisitor(classWriter, methodMapping, + * mv -> new EnchantmentCanApplyVisitor(mv, methodMapping)), ClassReader.EXPAND_FRAMES); + * return classWriter.toByteArray(); + * } + */ return basicClass; } } diff --git a/src/main/java/gregtech/client/utils/BloomEffectVintagiumUtil.java b/src/main/java/gregtech/client/utils/BloomEffectVintagiumUtil.java index ced8de12e03..0d63f22a2d4 100644 --- a/src/main/java/gregtech/client/utils/BloomEffectVintagiumUtil.java +++ b/src/main/java/gregtech/client/utils/BloomEffectVintagiumUtil.java @@ -1,38 +1,17 @@ package gregtech.client.utils; -import net.minecraft.util.BlockRenderLayer; -import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass; -import me.jellysquid.mods.sodium.client.util.BufferSizeUtil; -import me.jellysquid.mods.sodium.client.util.EnumUtil; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Field; import java.util.Objects; @SideOnly(Side.CLIENT) public class BloomEffectVintagiumUtil { - private static BlockRenderPass bloom; - - public static void init() { - EnumUtil.LAYERS = BlockRenderLayer.values(); - BufferSizeUtil.BUFFER_SIZES.put(BloomEffectUtil.getBloomLayer(), 131072); - bloom = EnumHelper.addEnum(BlockRenderPass.class, "BLOOM", - new Class[] { BlockRenderLayer.class, boolean.class }, BloomEffectUtil.getBloomLayer(), true); - - try { - Field values = BlockRenderPass.class.getField("VALUES"); - values.set(null, BlockRenderPass.values()); - Field count = BlockRenderPass.class.getField("COUNT"); - count.set(null, BlockRenderPass.values().length); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new RuntimeException(e); - } - } + public static BlockRenderPass bloom; /** * @return {@link BlockRenderPass} instance for the bloom render layer. diff --git a/src/main/java/gregtech/mixins/GregTechLateMixinLoadingPlugin.java b/src/main/java/gregtech/mixins/GregTechLateMixinLoadingPlugin.java new file mode 100644 index 00000000000..a582e924088 --- /dev/null +++ b/src/main/java/gregtech/mixins/GregTechLateMixinLoadingPlugin.java @@ -0,0 +1,37 @@ +package gregtech.mixins; + +import gregtech.api.util.Mods; + +import zone.rong.mixinbooter.ILateMixinLoader; + +import java.util.ArrayList; +import java.util.List; + +public class GregTechLateMixinLoadingPlugin implements ILateMixinLoader { + + @Override + public List getMixinConfigs() { + List configs = new ArrayList<>(); + + configs.add("mixins.gregtech.theoneprobe.json"); + configs.add("mixins.gregtech.jei.json"); + configs.add("mixins.gregtech.ctm.json"); + configs.add("mixins.gregtech.ccl.json"); + configs.add("mixins.gregtech.littletiles.json"); + configs.add("mixins.gregtech.vintagium.json"); + + return configs; + } + + @Override + public boolean shouldMixinConfigQueue(String mixinConfig) { + return switch (mixinConfig) { + case "mixins.gregtech.theoneprobe.json" -> Mods.TheOneProbe.isModLoaded(); + case "mixins.gregtech.jei.json" -> Mods.JustEnoughItems.isModLoaded(); + case "mixin.gregtech.ctm.json" -> Mods.CTM.isModLoaded(); + case "mixins.gregtech.littletiles.json" -> Mods.LittleTiles.isModLoaded(); + case "mixins.gregtech.vintagium.json" -> Mods.Vintagium.isModLoaded(); + default -> true; + }; + } +} diff --git a/src/main/java/gregtech/mixins/ccl/CCLDescriptionMixin.java b/src/main/java/gregtech/mixins/ccl/CCLDescriptionMixin.java new file mode 100644 index 00000000000..ffd11f06b6e --- /dev/null +++ b/src/main/java/gregtech/mixins/ccl/CCLDescriptionMixin.java @@ -0,0 +1,17 @@ +package gregtech.mixins.ccl; + +import codechicken.lib.internal.ModDescriptionEnhancer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +// CCL's supporter stuff is broken, the link no longer works +@Mixin(ModDescriptionEnhancer.class) +public class CCLDescriptionMixin { + + @Inject(method = "init", at = @At("HEAD"), remap = false, cancellable = true) + private static void stopDescriptionEnhancement(CallbackInfo ci) { + ci.cancel(); + } +} diff --git a/src/main/java/gregtech/mixins/ctm/AbstractCTMBakedModelMixin.java b/src/main/java/gregtech/mixins/ctm/AbstractCTMBakedModelMixin.java new file mode 100644 index 00000000000..038f9d90023 --- /dev/null +++ b/src/main/java/gregtech/mixins/ctm/AbstractCTMBakedModelMixin.java @@ -0,0 +1,28 @@ +package gregtech.mixins.ctm; + +import gregtech.asm.hooks.CTMHooks; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.sugar.Local; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import team.chisel.ctm.client.model.AbstractCTMBakedModel; + +import java.util.List; + +@Mixin(AbstractCTMBakedModel.class) +public class AbstractCTMBakedModelMixin { + + @ModifyReturnValue(method = "getQuads", at = @At(value = "RETURN", ordinal = 1)) + private List getQuadsWithOptifine(List original, @Local(ordinal = 0) BlockRenderLayer layer, + @Local(ordinal = 0) IBlockState state, + @Local(ordinal = 0) EnumFacing side, @Local(ordinal = 0) long rand) { + return CTMHooks.getQuadsWithOptiFine(original, layer, (IBakedModel) this, state, side, rand); + } +} diff --git a/src/main/java/gregtech/mixins/ctm/CTMRenderInLayerMixin.java b/src/main/java/gregtech/mixins/ctm/CTMRenderInLayerMixin.java new file mode 100644 index 00000000000..12914a5cc5f --- /dev/null +++ b/src/main/java/gregtech/mixins/ctm/CTMRenderInLayerMixin.java @@ -0,0 +1,28 @@ +package gregtech.mixins.ctm; + +import gregtech.asm.hooks.CTMModHooks; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.util.BlockRenderLayer; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.sugar.Local; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import team.chisel.ctm.client.asm.CTMCoreMethods; +import team.chisel.ctm.client.model.AbstractCTMBakedModel; + +@Mixin(CTMCoreMethods.class) +public class CTMRenderInLayerMixin { + + @ModifyExpressionValue(method = "canRenderInLayer", + at = @At(value = "INVOKE_ASSIGN", + target = "Lteam/chisel/ctm/api/model/IModelCTM;canRenderInLayer(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/util/BlockRenderLayer;)Z"), + remap = false) + private static Boolean checkRenderInLayer(Boolean originalResult, @NotNull IBlockState state, + @NotNull BlockRenderLayer layer, @Local(ordinal = 0) IBakedModel model) { + return CTMModHooks.canRenderInLayer(((AbstractCTMBakedModel) model).getModel(), state, layer); + } +} diff --git a/src/main/java/gregtech/mixins/forge/ModelLoaderRegistryMixin.java b/src/main/java/gregtech/mixins/forge/ModelLoaderRegistryMixin.java new file mode 100644 index 00000000000..85cc8d099e8 --- /dev/null +++ b/src/main/java/gregtech/mixins/forge/ModelLoaderRegistryMixin.java @@ -0,0 +1,20 @@ +package gregtech.mixins.forge; + +import gregtech.api.unification.material.info.MaterialIconType; + +import net.minecraft.client.resources.IResourceManager; +import net.minecraftforge.client.model.ModelLoaderRegistry; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ModelLoaderRegistry.class) +public class ModelLoaderRegistryMixin { + + @Inject(method = "clearModelCache", at = @At("TAIL"), remap = false) + private static void clearCache(IResourceManager manager, CallbackInfo ci) { + MaterialIconType.clearCache(); + } +} diff --git a/src/main/java/gregtech/mixins/forge/SpecialArmorPropertiesMixin.java b/src/main/java/gregtech/mixins/forge/SpecialArmorPropertiesMixin.java new file mode 100644 index 00000000000..668335c9b4c --- /dev/null +++ b/src/main/java/gregtech/mixins/forge/SpecialArmorPropertiesMixin.java @@ -0,0 +1,38 @@ +package gregtech.mixins.forge; + +import gregtech.api.items.armor.IArmorItem; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.NonNullList; +import net.minecraftforge.common.ISpecialArmor; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ISpecialArmor.ArmorProperties.class) +public class SpecialArmorPropertiesMixin { + + @ModifyExpressionValue(method = "applyArmor", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/util/CombatRules;getDamageAfterAbsorb(FFF)F"), + remap = false) + private static float adjustArmorAbsorption(float originalDamage, EntityLivingBase entity, + NonNullList inventory, + DamageSource damageSource, double damage) { + double armorDamage = Math.max(1.0F, damage / 4.0F); + for (int i = 0; i < inventory.size(); i++) { + ItemStack itemStack = inventory.get(i); + if (itemStack.getItem() instanceof IArmorItem) { + ((IArmorItem) itemStack.getItem()).damageArmor(entity, itemStack, damageSource, (int) armorDamage, i); + if (inventory.get(i).getCount() == 0) { + inventory.set(i, ItemStack.EMPTY); + } + } + } + + return originalDamage; + } +} diff --git a/src/main/java/gregtech/mixins/jei/JEITooltipMixin.java b/src/main/java/gregtech/mixins/jei/JEITooltipMixin.java new file mode 100644 index 00000000000..aa971bfd814 --- /dev/null +++ b/src/main/java/gregtech/mixins/jei/JEITooltipMixin.java @@ -0,0 +1,32 @@ +package gregtech.mixins.jei; + +import gregtech.api.util.FluidTooltipUtil; + +import net.minecraftforge.fluids.FluidStack; + +import mezz.jei.api.ingredients.IIngredientHelper; +import mezz.jei.startup.ForgeModIdHelper; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(ForgeModIdHelper.class) +public class JEITooltipMixin { + + @Inject(method = "addModNameToIngredientTooltip", at = @At("HEAD"), remap = false) + public void addTooltip(List tooltip, Object ingredient, IIngredientHelper ingredientHelper, + CallbackInfoReturnable> cir) { + if (ingredient instanceof FluidStack) { + List formula = FluidTooltipUtil.getFluidTooltip((FluidStack) ingredient); + if (formula != null) { + for (String s : formula) { + if (s.isEmpty()) continue; + tooltip.add(s); + } + } + } + } +} diff --git a/src/main/java/gregtech/mixins/littletiles/LittleTilesRenderMangerMixin.java b/src/main/java/gregtech/mixins/littletiles/LittleTilesRenderMangerMixin.java new file mode 100644 index 00000000000..8f09a26d1fa --- /dev/null +++ b/src/main/java/gregtech/mixins/littletiles/LittleTilesRenderMangerMixin.java @@ -0,0 +1,28 @@ +package gregtech.mixins.littletiles; + +import gregtech.asm.hooks.LittleTilesHooks; + +import com.creativemd.littletiles.client.render.cache.LayeredRenderBoxCache; +import com.creativemd.littletiles.client.render.world.TileEntityRenderManager; +import com.creativemd.littletiles.common.tileentity.TileEntityLittleTiles; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = TileEntityRenderManager.class, remap = false) +public class LittleTilesRenderMangerMixin { + + @Mutable + @Shadow + @Final + private LayeredRenderBoxCache boxCache; + + @Inject(method = "", at = @At("TAIL"), remap = false) + public void adjustRenderLayerdBox(TileEntityLittleTiles te, CallbackInfo ci) { + boxCache = LittleTilesHooks.initLayeredRenderBoxCache(); + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/BlockConcretePowderMixin.java b/src/main/java/gregtech/mixins/minecraft/BlockConcretePowderMixin.java new file mode 100644 index 00000000000..4106a70e1c1 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/BlockConcretePowderMixin.java @@ -0,0 +1,24 @@ +package gregtech.mixins.minecraft; + +import gregtech.common.ConfigHolder; + +import net.minecraft.block.BlockConcretePowder; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(BlockConcretePowder.class) +public class BlockConcretePowderMixin { + + @Inject(method = "tryTouchWater", at = @At("HEAD"), cancellable = true) + public void disableConversion(World worldIn, BlockPos pos, IBlockState state, CallbackInfoReturnable cir) { + if (ConfigHolder.recipes.disableConcreteInWorld) { + cir.setReturnValue(false); + } + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/BlockMixin.java b/src/main/java/gregtech/mixins/minecraft/BlockMixin.java new file mode 100644 index 00000000000..f2271c71f49 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/BlockMixin.java @@ -0,0 +1,33 @@ +package gregtech.mixins.minecraft; + +import gregtech.api.util.Mods; +import gregtech.asm.hooks.BlockHooks; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.BlockRenderLayer; +import net.minecraftforge.fml.common.Loader; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +/** + * Apply our block hooks for our custom models when CTM is not loaded + */ +@Mixin(Block.class) +public class BlockMixin { + + @Inject(method = "canRenderInLayer", at = @At("HEAD"), cancellable = true, remap = false) + private void canRenderInLayer(IBlockState state, BlockRenderLayer layer, CallbackInfoReturnable cir) { + if (!Loader.instance().getIndexedModList().containsKey(Mods.Names.CONNECTED_TEXTURES_MOD)) { + Boolean result = BlockHooks.canRenderInLayer(state, layer); + + if (result != null) { + cir.setReturnValue(result); + cir.cancel(); + } + } + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/DamageSourceMixin.java b/src/main/java/gregtech/mixins/minecraft/DamageSourceMixin.java new file mode 100644 index 00000000000..9247f2ab945 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/DamageSourceMixin.java @@ -0,0 +1,25 @@ +package gregtech.mixins.minecraft; + +import gregtech.api.damagesources.DamageSources; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.DamageSource; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(DamageSource.class) +public class DamageSourceMixin { + + @ModifyReturnValue(method = "causePlayerDamage", at = @At("RETURN")) + private static DamageSource modifyPlayerDamageWithTool(DamageSource originalReturnValue, EntityPlayer source) { + return DamageSources.getPlayerDamage(source); + } + + @ModifyReturnValue(method = "causeMobDamage", at = @At("RETURN")) + private static DamageSource modifyMobDamageWithTool(DamageSource originalReturnValue, EntityLivingBase source) { + return DamageSources.getMobDamage(source); + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/EnchantmentCanApplyMixin.java b/src/main/java/gregtech/mixins/minecraft/EnchantmentCanApplyMixin.java new file mode 100644 index 00000000000..3f97d2b66f4 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/EnchantmentCanApplyMixin.java @@ -0,0 +1,23 @@ +package gregtech.mixins.minecraft; + +import gregtech.api.items.toolitem.IGTTool; + +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.sugar.Local; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(Enchantment.class) +public class EnchantmentCanApplyMixin { + + @ModifyReturnValue(method = "canApply", at = @At("RETURN")) + private boolean enchantmentCanApply(boolean originalResult, @Local(ordinal = 0) ItemStack stack) { + if (stack.getItem() instanceof IGTTool) { + return originalResult && stack.getItem().canApplyAtEnchantingTable(stack, ((Enchantment) (Object) this)); + } + return originalResult; + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/EntityRendererMixin.java b/src/main/java/gregtech/mixins/minecraft/EntityRendererMixin.java new file mode 100644 index 00000000000..472f1d98c45 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/EntityRendererMixin.java @@ -0,0 +1,26 @@ +package gregtech.mixins.minecraft; + +import gregtech.client.utils.BloomEffectUtil; + +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.entity.Entity; +import net.minecraft.util.BlockRenderLayer; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(EntityRenderer.class) +public class EntityRendererMixin { + + @WrapOperation(method = "renderWorldPass", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/renderer/RenderGlobal;renderBlockLayer(Lnet/minecraft/util/BlockRenderLayer;DILnet/minecraft/entity/Entity;)I", + ordinal = 3)) + public int renderBloomBlockLayer(RenderGlobal instance, BlockRenderLayer layer, double partialTicks, int pass, + Entity entity, Operation original) { + return BloomEffectUtil.renderBloomBlockLayer(instance, layer, partialTicks, pass, entity); + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/LayerArmorBaseMixin.java b/src/main/java/gregtech/mixins/minecraft/LayerArmorBaseMixin.java new file mode 100644 index 00000000000..7363d82d575 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/LayerArmorBaseMixin.java @@ -0,0 +1,79 @@ +package gregtech.mixins.minecraft; + +import gregtech.api.items.armor.IArmorItem; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelBiped; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.layers.LayerArmorBase; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.ForgeHooksClient; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LayerArmorBase.class) +public class LayerArmorBaseMixin { + + @Inject(method = "renderArmorLayer", at = @At("TAIL")) + public void renderGTArmor(EntityLivingBase entityLivingBaseIn, float limbSwing, float limbSwingAmount, + float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale, + EntityEquipmentSlot slotIn, CallbackInfo ci) { + ItemStack itemStack = entityLivingBaseIn.getItemStackFromSlot(slotIn); + + if ((itemStack.getItem() instanceof IArmorItem armorItem && + itemStack.getItem().getEquipmentSlot(itemStack) == slotIn)) { + @SuppressWarnings("unchecked") + LayerArmorBase layer = (LayerArmorBase) (Object) this; + ModelBase armorModel = layer.getModelFromSlot(slotIn); + if (armorModel instanceof ModelBiped) { + armorModel = ForgeHooksClient.getArmorModel(entityLivingBaseIn, itemStack, slotIn, + (ModelBiped) armorModel); + } + armorModel.setModelAttributes(layer.renderer.getMainModel()); + armorModel.setLivingAnimations(entityLivingBaseIn, limbSwing, limbSwingAmount, partialTicks); + layer.setModelSlotVisible(armorModel, slotIn); + + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + + int layers = armorItem.getArmorLayersAmount(itemStack); + for (int layerIndex = 0; layerIndex < layers; layerIndex++) { + int i = armorItem.getArmorLayerColor(itemStack, layerIndex); + float f = (float) (i >> 16 & 255) / 255.0F; + float f1 = (float) (i >> 8 & 255) / 255.0F; + float f2 = (float) (i & 255) / 255.0F; + GlStateManager.color(f, f1, f2, 1.0f); + String type = layerIndex == 0 ? null : "layer_" + layerIndex; + layer.renderer.bindTexture(gregTechCEu$getArmorTexture(entityLivingBaseIn, itemStack, slotIn, type)); + armorModel.render(entityLivingBaseIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, + scale); + } + if (itemStack.hasEffect()) { + LayerArmorBase.renderEnchantedGlint(layer.renderer, entityLivingBaseIn, armorModel, limbSwing, + limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale); + } + } + } + + @Unique + private static ResourceLocation gregTechCEu$getArmorTexture(EntityLivingBase entity, ItemStack itemStack, + EntityEquipmentSlot slot, String type) { + ResourceLocation registryName = itemStack.getItem().getRegistryName(); + if (registryName == null) { + throw new IllegalArgumentException( + "ItemStack " + itemStack.getTranslationKey() + "has a null registry name"); + } + + String s1 = String.format("%s:textures/models/armor/%s_layer_%d%s.png", registryName.getNamespace(), + registryName.getPath(), + (slot == EntityEquipmentSlot.LEGS ? 2 : 1), type == null ? "" : String.format("_%s", type)); + return new ResourceLocation(ForgeHooksClient.getArmorTexture(entity, itemStack, s1, slot, type)); + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/LayerCustomHeadMixin.java b/src/main/java/gregtech/mixins/minecraft/LayerCustomHeadMixin.java new file mode 100644 index 00000000000..d6f69a7d3bb --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/LayerCustomHeadMixin.java @@ -0,0 +1,38 @@ +package gregtech.mixins.minecraft; + +import gregtech.api.items.armor.IArmorItem; + +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.entity.layers.LayerCustomHead; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(LayerCustomHead.class) +public class LayerCustomHeadMixin { + + @WrapOperation(method = "doRenderLayer", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/renderer/ItemRenderer;renderItem(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/renderer/block/model/ItemCameraTransforms$TransformType;)V")) + public void shouldNotRenderHead(ItemRenderer instance, EntityLivingBase entitylivingbaseIn, ItemStack itemstack, + ItemCameraTransforms.TransformType transformType, Operation original) { + if (gregTechCEu$shouldNotRenderHeadItem(entitylivingbaseIn)) { + return; + } + original.call(instance, entitylivingbaseIn, itemstack, transformType); + } + + @Unique + private static boolean gregTechCEu$shouldNotRenderHeadItem(EntityLivingBase entityLivingBase) { + ItemStack itemStack = entityLivingBase.getItemStackFromSlot(EntityEquipmentSlot.HEAD); + return (itemStack.getItem() instanceof IArmorItem && + itemStack.getItem().getEquipmentSlot(itemStack) == EntityEquipmentSlot.HEAD); + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/MinecraftMixin.java b/src/main/java/gregtech/mixins/minecraft/MinecraftMixin.java new file mode 100644 index 00000000000..31ada3545f0 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/MinecraftMixin.java @@ -0,0 +1,22 @@ +package gregtech.mixins.minecraft; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.text.TextComponentTranslation; + +import org.lwjgl.input.Keyboard; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Minecraft.class) +public class MinecraftMixin { + + @Inject(method = "processKeyF3", at = @At("HEAD")) + public void addGregTechDebugMessage(int auxKey, CallbackInfoReturnable cir) { + if (auxKey == Keyboard.KEY_H && !Minecraft.getMinecraft().gameSettings.advancedItemTooltips) { + Minecraft.getMinecraft().ingameGUI.getChatGUI() + .printChatMessage(new TextComponentTranslation("gregtech.debug.f3_h.enabled")); + } + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java b/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java new file mode 100644 index 00000000000..5cd275b6cf8 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java @@ -0,0 +1,102 @@ +package gregtech.mixins.minecraft; + +import gregtech.api.items.toolitem.IGTTool; +import gregtech.api.items.toolitem.ToolHelper; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.RecipeRepairItem; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.NonNullList; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.event.ForgeEventFactory; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(RecipeRepairItem.class) +public class RecipeRepairItemMixin { + + @Inject(method = "matches(Lnet/minecraft/inventory/InventoryCrafting;Lnet/minecraft/world/World;)Z", + at = @At(value = "INVOKE", + target = "Ljava/util/List;get(I)Ljava/lang/Object;", + shift = At.Shift.AFTER), + cancellable = true) + public void gregtechCEu$matches(InventoryCrafting inv, World worldIn, CallbackInfoReturnable cir, + @Local(ordinal = 0) ItemStack itemstack, @Local(ordinal = 0) List list) { + ItemStack itemstack1 = list.get(0); + if (itemstack.getItem() instanceof IGTTool first && + itemstack1.getItem() instanceof IGTTool second) { + if (first.isElectric() || second.isElectric()) { + cir.setReturnValue(false); + } else { + cir.setReturnValue(first.getToolMaterial(itemstack) == second.getToolMaterial(itemstack1)); + } + } + } + + @Inject(method = "getCraftingResult(Lnet/minecraft/inventory/InventoryCrafting;)Lnet/minecraft/item/ItemStack;", + at = @At(value = "INVOKE_ASSIGN", + target = "Ljava/util/List;get(I)Ljava/lang/Object;", + ordinal = 0, + shift = At.Shift.BY, + by = 2), + cancellable = true) + public void gregtechCEu$getCraftingResultFirst(InventoryCrafting inv, CallbackInfoReturnable cir, + @Local(ordinal = 0) ItemStack itemstack, + @Local(ordinal = 1) ItemStack itemstack1) { + if (itemstack.getItem() instanceof IGTTool tool && tool.isElectric()) { + cir.setReturnValue(ItemStack.EMPTY); + } else if (itemstack1.getItem() instanceof IGTTool tool && tool.isElectric()) { + cir.setReturnValue(ItemStack.EMPTY); + } + } + + /* + * @Inject(method = "getCraftingResult(Lnet/minecraft/inventory/InventoryCrafting;)Lnet/minecraft/item/ItemStack;", + * at = @At(value = "RETURN", ordinal = 1), + * cancellable = true) + */ + @ModifyReturnValue(method = "getCraftingResult", at = @At(value = "RETURN", ordinal = 1)) + public ItemStack gregtechCEu$getCraftingResultSecond(ItemStack originalResult, InventoryCrafting inv, + @Local(ordinal = 3) int itemDamage, + @Local(ordinal = 0) ItemStack itemstack2, + @Local(ordinal = 1) ItemStack itemstack3) { + if (itemstack2.getItem() instanceof IGTTool first && itemstack3.getItem() instanceof IGTTool) { + // do not allow repairing tools if both are full durability + if (itemstack2.getItemDamage() == 0 && itemstack3.getItemDamage() == 0) { + return ItemStack.EMPTY; + } else { + ItemStack output = first.get(first.getToolMaterial(itemstack2)); + NBTTagCompound outputTag = ToolHelper.getToolTag(output); + outputTag.setInteger(ToolHelper.DURABILITY_KEY, itemDamage); + return output; + } + } + + return originalResult; + } + + @WrapOperation(method = "getRemainingItems", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/util/NonNullList;set(ILjava/lang/Object;)Ljava/lang/Object;")) + public Object gregtechCEU$getRemainingItemsWrap(NonNullList instance, int index, Object newValue, + Operation original, + @Local(ordinal = 0) ItemStack itemStack) { + if (itemStack.getItem() instanceof IGTTool) { + ForgeEventFactory.onPlayerDestroyItem(ForgeHooks.getCraftingPlayer(), itemStack, null); + return instance.get(index); + } else { + return instance.set(index, newValue); + } + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/RegionRenderCacheBuilderMixin.java b/src/main/java/gregtech/mixins/minecraft/RegionRenderCacheBuilderMixin.java new file mode 100644 index 00000000000..52b73576d86 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/RegionRenderCacheBuilderMixin.java @@ -0,0 +1,26 @@ +package gregtech.mixins.minecraft; + +import gregtech.client.utils.BloomEffectUtil; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.RegionRenderCacheBuilder; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(RegionRenderCacheBuilder.class) +public class RegionRenderCacheBuilderMixin { + + @Final + @Shadow + private BufferBuilder[] worldRenderers; + + @Inject(method = "", at = @At("TAIL")) + public void initBloom(CallbackInfo ci) { + worldRenderers[BloomEffectUtil.getBloomLayer().ordinal()] = new BufferBuilder(131072); + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/RenderChunkMixin.java b/src/main/java/gregtech/mixins/minecraft/RenderChunkMixin.java new file mode 100644 index 00000000000..5c18f5ad4ea --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/RenderChunkMixin.java @@ -0,0 +1,30 @@ +package gregtech.mixins.minecraft; + +import gregtech.api.metatileentity.MetaTileEntityHolder; + +import net.minecraft.client.renderer.chunk.RenderChunk; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(RenderChunk.class) +public class RenderChunkMixin { + + @WrapOperation(method = "rebuildChunk", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher;getRenderer(Lnet/minecraft/tileentity/TileEntity;)Lnet/minecraft/client/renderer/tileentity/TileEntitySpecialRenderer;")) + public TileEntitySpecialRenderer adjustMTERenderer(TileEntityRendererDispatcher original, + TileEntity tileentity, + Operation> originalRenderer) { + // TODO, adjust when implementing second part of IGregTileEntity + if (tileentity instanceof MetaTileEntityHolder && !((MetaTileEntityHolder) tileentity).hasTESR()) { + return null; + } + return originalRenderer.call(original, tileentity); + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/RenderGlobalMixin.java b/src/main/java/gregtech/mixins/minecraft/RenderGlobalMixin.java new file mode 100644 index 00000000000..1a12dcb82d0 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/RenderGlobalMixin.java @@ -0,0 +1,50 @@ +package gregtech.mixins.minecraft; + +import gregtech.api.items.metaitem.MetaItem; +import gregtech.api.items.metaitem.MusicDiscStats; +import gregtech.api.items.metaitem.stats.IItemBehaviour; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.BlockPos; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(RenderGlobal.class) +public class RenderGlobalMixin { + + @Shadow + private WorldClient world; + + @Final + @Shadow + private Minecraft mc; + + @Inject(method = "playEvent", at = @At("HEAD"), cancellable = true) + public void playMusicDisc(EntityPlayer player, int type, BlockPos blockPosIn, int data, CallbackInfo ci) { + if (type == MusicDiscStats.SOUND_TYPE) { + for (MetaItem metaItem : MetaItem.getMetaItems()) { + MetaItem.MetaValueItem valueItem = metaItem.getItem((short) data); + if (valueItem != null) { + for (IItemBehaviour behavior : valueItem.getBehaviours()) { + if (behavior instanceof MusicDiscStats musicBehavior) { + world.playRecord(blockPosIn, musicBehavior.getSound()); + this.mc.ingameGUI.setRecordPlayingMessage(I18n.format(musicBehavior.getName())); + ci.cancel(); + return; + } + } + + } + } + } + } +} diff --git a/src/main/java/gregtech/mixins/minecraft/RenderItemMixin.java b/src/main/java/gregtech/mixins/minecraft/RenderItemMixin.java new file mode 100644 index 00000000000..5bbea635153 --- /dev/null +++ b/src/main/java/gregtech/mixins/minecraft/RenderItemMixin.java @@ -0,0 +1,38 @@ +package gregtech.mixins.minecraft; + +import gregtech.api.util.Mods; +import gregtech.asm.hooks.RenderItemHooks; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.RenderItem; +import net.minecraft.item.ItemStack; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(RenderItem.class) +public class RenderItemMixin { + + // The easy part of translating the item render stuff + @Inject(method = "renderItemOverlayIntoGUI", at = @At(value = "HEAD")) + private void renderItemOverlayIntoGUIInject(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, + String text, CallbackInfo ci) { + if (!stack.isEmpty()) { + RenderItemHooks.renderLampOverlay(stack, xPosition, yPosition); + } + } + + @Inject(method = "renderItemOverlayIntoGUI", + at = @At(value = "INVOKE_ASSIGN", + target = "Lnet/minecraft/client/Minecraft;getMinecraft()Lnet/minecraft/client/Minecraft;", + shift = At.Shift.BEFORE, + ordinal = 0)) + public void showDurabilityBarMixin(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text, + CallbackInfo ci) { + if (!Mods.EnderCore.isModLoaded()) { + RenderItemHooks.renderElectricBar(stack, xPosition, yPosition); + } + } +} diff --git a/src/main/java/gregtech/mixins/theoneprobe/TheOneProbeMixin.java b/src/main/java/gregtech/mixins/theoneprobe/TheOneProbeMixin.java new file mode 100644 index 00000000000..7f92a7526cd --- /dev/null +++ b/src/main/java/gregtech/mixins/theoneprobe/TheOneProbeMixin.java @@ -0,0 +1,40 @@ +package gregtech.mixins.theoneprobe; + +import gregtech.api.block.machines.BlockMachine; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import mcjty.theoneprobe.api.ProbeMode; +import mcjty.theoneprobe.network.PacketGetInfo; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +/** + * Makes TheOneProbe call {@link IBlockState#getActualState(IBlockAccess, BlockPos)} when + * looking at GT machines to show the correct harvest tool and level + */ +@Mixin(PacketGetInfo.class) +@SuppressWarnings("deprecation") +public class TheOneProbeMixin { + + @ModifyExpressionValue(method = "getProbeInfo", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;")) + private static IBlockState getActualState(IBlockState originalState, EntityPlayer player, ProbeMode mode, + World world, BlockPos blockPos, EnumFacing sideHit, Vec3d hitVec, + ItemStack pickBlock) { + IBlockState modifiedState = world.getBlockState(blockPos); + if (modifiedState.getBlock() instanceof BlockMachine) { + return modifiedState.getBlock().getActualState(modifiedState, world, blockPos); + } + return originalState; + } +} diff --git a/src/main/java/gregtech/mixins/vintagium/BlockRenderManagerMixin.java b/src/main/java/gregtech/mixins/vintagium/BlockRenderManagerMixin.java new file mode 100644 index 00000000000..2e35000111b --- /dev/null +++ b/src/main/java/gregtech/mixins/vintagium/BlockRenderManagerMixin.java @@ -0,0 +1,33 @@ +package gregtech.mixins.vintagium; + +import gregtech.client.utils.BloomEffectUtil; +import gregtech.client.utils.BloomEffectVintagiumUtil; + +import net.minecraft.util.BlockRenderLayer; + +import com.llamalad7.mixinextras.sugar.Local; +import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass; +import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPassManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(BlockRenderPassManager.class) +public abstract class BlockRenderManagerMixin { + + @Shadow(remap = false) + protected abstract void addMapping(BlockRenderLayer layer, BlockRenderPass type); + + @Unique + @Inject(method = "createDefaultMappings", + at = @At(value = "RETURN"), + remap = false) + private static void gregtech$addMapping(CallbackInfoReturnable cir, + @Local BlockRenderPassManager mapper) { + ((BlockRenderManagerMixin) (Object) mapper).addMapping(BloomEffectUtil.getBloomLayer(), + BloomEffectVintagiumUtil.getBloomPass()); + } +} diff --git a/src/main/java/gregtech/mixins/vintagium/BlockRenderPassMixin.java b/src/main/java/gregtech/mixins/vintagium/BlockRenderPassMixin.java new file mode 100644 index 00000000000..4b1f3034887 --- /dev/null +++ b/src/main/java/gregtech/mixins/vintagium/BlockRenderPassMixin.java @@ -0,0 +1,46 @@ +package gregtech.mixins.vintagium; + +import gregtech.client.utils.BloomEffectUtil; +import gregtech.client.utils.BloomEffectVintagiumUtil; + +import net.minecraft.util.BlockRenderLayer; +import net.minecraftforge.common.util.EnumHelper; + +import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass; +import me.jellysquid.mods.sodium.client.util.BufferSizeUtil; +import me.jellysquid.mods.sodium.client.util.EnumUtil; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(BlockRenderPass.class) +public abstract class BlockRenderPassMixin { + + @Final + @Mutable + @Shadow(remap = false) + public static BlockRenderPass[] VALUES; + + @Final + @Mutable + @Shadow(remap = false) + public static int COUNT; + + @Inject(method = "", + at = @At(value = "TAIL"), + remap = false) + private static void init(CallbackInfo ci) { + EnumUtil.LAYERS = BlockRenderLayer.values(); + BufferSizeUtil.BUFFER_SIZES.put(BloomEffectUtil.getBloomLayer(), 131072); + + var params = new Class[] { BlockRenderLayer.class, boolean.class }; + var values = new Object[] { BloomEffectUtil.getBloomLayer(), true }; + BloomEffectVintagiumUtil.bloom = EnumHelper.addEnum(BlockRenderPass.class, "BLOOM", params, values); + VALUES = BlockRenderPass.values(); + COUNT = VALUES.length; + } +} diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 48cc639c08c..8e9b4091db2 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -6292,3 +6292,5 @@ gregtech.scanner.forestry.pollen=§oScanned Pollen # Mutation gregtech.mutation.block_of=Block of %s + +record.sus=Leonz - Among Us Drip diff --git a/src/main/resources/mixins.gregtech.ccl.json b/src/main/resources/mixins.gregtech.ccl.json new file mode 100644 index 00000000000..696d44a7275 --- /dev/null +++ b/src/main/resources/mixins.gregtech.ccl.json @@ -0,0 +1,12 @@ +{ + "package" : "gregtech.mixins.ccl", + "refmap" : "mixins.gregtech.refmap.json", + "target" : "@env(DEFAULT)", + "minVersion" : "0.8", + "compatibilityLevel" : "JAVA_8", + "mixins" : [ + "CCLDescriptionMixin" + ], + "client" : [], + "server" : [] +} diff --git a/src/main/resources/mixins.gregtech.ctm.json b/src/main/resources/mixins.gregtech.ctm.json new file mode 100644 index 00000000000..7e46fde66ab --- /dev/null +++ b/src/main/resources/mixins.gregtech.ctm.json @@ -0,0 +1,13 @@ +{ + "package" : "gregtech.mixins.ctm", + "refmap" : "mixins.gregtech.refmap.json", + "target" : "@env(DEFAULT)", + "minVersion" : "0.8", + "compatibilityLevel" : "JAVA_8", + "mixins" : [ + "AbstractCTMBakedModelMixin", + "CTMRenderInLayerMixin" + ], + "client" : [], + "server" : [] +} diff --git a/src/main/resources/mixins.gregtech.forge.json b/src/main/resources/mixins.gregtech.forge.json new file mode 100644 index 00000000000..81605c0c9dc --- /dev/null +++ b/src/main/resources/mixins.gregtech.forge.json @@ -0,0 +1,13 @@ +{ + "package": "gregtech.mixins.forge", + "refmap": "mixins.gregtech.refmap.json", + "target": "@env(DEFAULT)", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins" : [ + "ModelLoaderRegistryMixin", + "SpecialArmorPropertiesMixin" + ], + "client": [], + "server": [] +} diff --git a/src/main/resources/mixins.gregtech.jei.json b/src/main/resources/mixins.gregtech.jei.json new file mode 100644 index 00000000000..2520843c7d6 --- /dev/null +++ b/src/main/resources/mixins.gregtech.jei.json @@ -0,0 +1,12 @@ +{ + "package" : "gregtech.mixins.jei", + "refmap" : "mixins.gregtech.refmap.json", + "target" : "@env(DEFAULT)", + "minVersion" : "0.8", + "compatibilityLevel" : "JAVA_8", + "mixins" : [ + "JEITooltipMixin" + ], + "client" : [], + "server" : [] +} diff --git a/src/main/resources/mixins.gregtech.littletiles.json b/src/main/resources/mixins.gregtech.littletiles.json new file mode 100644 index 00000000000..6671ea6d5b6 --- /dev/null +++ b/src/main/resources/mixins.gregtech.littletiles.json @@ -0,0 +1,12 @@ +{ + "package" : "gregtech.mixins.littletiles", + "refmap" : "mixins.gregtech.refmap.json", + "target" : "@env(DEFAULT)", + "minVersion" : "0.8", + "compatibilityLevel" : "JAVA_8", + "mixins" : [ + "LittleTilesRenderMangerMixin" + ], + "client": [], + "server" : [] +} diff --git a/src/main/resources/mixins.gregtech.minecraft.json b/src/main/resources/mixins.gregtech.minecraft.json new file mode 100644 index 00000000000..03573dc0d14 --- /dev/null +++ b/src/main/resources/mixins.gregtech.minecraft.json @@ -0,0 +1,25 @@ +{ + "package": "gregtech.mixins.minecraft", + "refmap": "mixins.gregtech.refmap.json", + "target": "@env(DEFAULT)", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "BlockConcretePowderMixin", + "DamageSourceMixin", + "EnchantmentCanApplyMixin", + "MinecraftMixin" + ], + "client": [ + "BlockMixin", + "EntityRendererMixin", + "LayerArmorBaseMixin", + "LayerCustomHeadMixin", + "RecipeRepairItemMixin", + "RegionRenderCacheBuilderMixin", + "RenderChunkMixin", + "RenderGlobalMixin", + "RenderItemMixin" + ], + "server": [] +} diff --git a/src/main/resources/mixins.gregtech.theoneprobe.json b/src/main/resources/mixins.gregtech.theoneprobe.json new file mode 100644 index 00000000000..0f7038d94c4 --- /dev/null +++ b/src/main/resources/mixins.gregtech.theoneprobe.json @@ -0,0 +1,10 @@ +{ + "package": "gregtech.mixins.theoneprobe", + "refmap": "mixins.gregtech.refmap.json", + "target": "@env(DEFAULT)", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": ["TheOneProbeMixin"], + "client": [], + "server": [] +} diff --git a/src/main/resources/mixins.gregtech.vintagium.json b/src/main/resources/mixins.gregtech.vintagium.json new file mode 100644 index 00000000000..7058a0de4da --- /dev/null +++ b/src/main/resources/mixins.gregtech.vintagium.json @@ -0,0 +1,13 @@ +{ + "package": "gregtech.mixins.vintagium", + "refmap": "mixins.gregtech.refmap.json", + "target": "@env(DEFAULT)", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": [], + "client": [ + "BlockRenderManagerMixin", + "BlockRenderPassMixin" + ], + "server": [] +}