Skip to content

Commit

Permalink
Convert from ASM to Mixins (#2192)
Browse files Browse the repository at this point in the history
Co-authored-by: serenibyss <[email protected]>
Co-authored-by: Ghzdude <[email protected]>
  • Loading branch information
3 people committed Jun 20, 2024
1 parent 132a449 commit 5ff7cdb
Show file tree
Hide file tree
Showing 46 changed files with 1,257 additions and 267 deletions.
19 changes: 19 additions & 0 deletions addon.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}


21 changes: 4 additions & 17 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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"
}
}
18 changes: 7 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions src/main/java/gregtech/GregTechMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -48,9 +46,6 @@ public GregTechMod() {
FluidRegistry.enableUniversalBucket();
if (FMLCommonHandler.instance().getSide().isClient()) {
BloomEffectUtil.init();
if (Mods.Vintagium.isModLoaded()) {
BloomEffectVintagiumUtil.init();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gregtech/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 2 additions & 8 deletions src/main/java/gregtech/api/damagesources/DamageSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/items/metaitem/MusicDiscStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public SoundEvent getSound() {
return sound;
}

public String getName() {
return sound.getSoundName().getPath();
}

@Override
public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/util/Mods.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -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";
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/gregtech/asm/GregTechLoadingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -40,4 +44,19 @@ public void injectData(Map<String, Object> data) {}
public String getAccessTransformerClass() {
return null;
}

@Override
public List<String> getMixinConfigs() {
List<String> 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);
}
}
Loading

0 comments on commit 5ff7cdb

Please sign in to comment.