Use mixins instead of registry replacement (#37)

This commit is contained in:
ah-OOG-ah authored and GitHub committed 2025-04-30 01:31:10 -05:00
1 parent d5142e677a
commit e95aea0c7d
16 files changed
+164 -94

No files matched your search

+5 -5
View File
@@ -3,14 +3,14 @@
dependencies {
api('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev')
api('com.github.GTNewHorizons:Baubles:1.0.4:dev')
api("com.github.GTNewHorizons:GTNHLib:0.6.0:dev")
api("com.github.GTNewHorizons:GTNHLib:0.6.21:dev")
api('com.github.GTNewHorizons:ThaumicEnergistics:1.7.0-GTNH:dev')
api('com.github.GTNewHorizons:ThaumicEnergistics:1.7.7-GTNH:dev')
compileOnly('com.github.GTNewHorizons:waila:1.8.2:dev') {transitive=false}
compileOnly('com.github.GTNewHorizons:ThaumicHorizons:1.6.5:dev') {transitive=false}
compileOnly('com.github.GTNewHorizons:waila:1.8.4:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ThaumicHorizons:1.7.3:dev') { transitive = false }
compileOnly('curse.maven:automagy-222153:2285272')
compileOnly('curse.maven:mystcraft-224599:2417044')
runtimeOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.7.8-GTNH:dev')
runtimeOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.7.40-GTNH:dev')
}
+8 -8
View File
@@ -14,7 +14,7 @@ modId = gadomancy
modGroup = makeo.gadomancy
# Whether to use modGroup as the maven publishing group.
# Due to a history of using JitPack, the default is com.github.GTNewHorizons for all mods.
# When false, com.github.GTNewHorizons is used.
useModGroupForPublishing = false
# Updates your build.gradle and settings.gradle automatically whenever an update is available.
@@ -41,19 +41,19 @@ developmentEnvironmentUserName = Developer
# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = false
enableModernJavaSyntax = true
# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
enableGenericInjection = false
enableGenericInjection = true
# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
# If gradleTokenVersion is empty or missing, the field will not be present in the class.
generateGradleTokenClass =
generateGradleTokenClass = makeo.gadomancy.common.Tags
# Name of the token containing the project's current version to generate/replace.
gradleTokenVersion = GRADLETOKEN_VERSION
gradleTokenVersion = VERSION
# [DEPRECATED] Mod ID replacement token.
gradleTokenModId =
@@ -70,7 +70,7 @@ gradleTokenGroupName =
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...]).
# Leave these properties empty to skip individual token replacements.
replaceGradleTokenInFile = Gadomancy.java
replaceGradleTokenInFile =
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
@@ -83,7 +83,7 @@ apiPackage =
accessTransformersFile = gadomancy_at.cfg
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
usesMixins = true
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
@@ -97,7 +97,7 @@ usesMixinDebug = false
mixinPlugin =
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
mixinsPackage =
mixinsPackage = coremod.mixins
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.30'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.38'
}
@@ -65,8 +65,6 @@ public class CommonProxy implements IGuiHandler {
RegisteredBlocks.init();
RegisteredItems.init();
RegisteredGolemStuff.init();
ModSubstitutions.preInit();
}
public void initalize() {
@@ -83,7 +81,6 @@ public class CommonProxy implements IGuiHandler {
RegisteredRecipes.init();
SyncDataHolder.initialize();
ModSubstitutions.init();
RegisteredEntities.init();
@@ -1,5 +1,7 @@
package makeo.gadomancy.common;
import java.io.File;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
@@ -34,7 +36,7 @@ public class Gadomancy {
public static final String MODID = "gadomancy";
public static final String NAME = "Gadomancy";
public static final String VERSION = "GRADLETOKEN_VERSION";
public static final String VERSION = Tags.VERSION;
private static final String PROXY_CLIENT = "makeo.gadomancy.client.ClientProxy";
private static final String PROXY_SERVER = "makeo.gadomancy.common.CommonProxy";
@@ -68,13 +70,13 @@ public class Gadomancy {
@Mod.EventHandler
public void onConstruct(FMLConstructionEvent event) {
GadomancyApi.setInstance(new DefaultApiHandler());
ModConfig.init(new File("./config/gadomancy.cfg"));
Gadomancy.proxy.onConstruct();
}
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
event.getModMetadata().version = Gadomancy.VERSION;
ModConfig.init(event.getSuggestedConfigurationFile());
Gadomancy.proxy.preInitalize();
}
@@ -162,16 +162,14 @@ public class TileBlockProtector extends TileJarFillable {
}
}
if (this.range > 0) {
for (EntityLivingBase entity : (List<EntityCreeper>) this.worldObj
.getEntitiesWithinAABB(EntityLivingBase.class, this.getProtectedAABB())) {
if (entity instanceof EntityCreeper) {
((EntityCreeper) entity).timeSinceIgnited = 0;
}
if (this.range <= 0) return;
for (EntityLivingBase entity : worldObj.getEntitiesWithinAABB(EntityLivingBase.class, getProtectedAABB())) {
if (entity instanceof EntityCreeper creeper) {
creeper.timeSinceIgnited = 0;
}
if (this.worldObj.isRemote && !(entity instanceof EntityPlayer)) {
this.spawnEntityParticles(entity);
}
if (this.worldObj.isRemote && !(entity instanceof EntityPlayer)) {
this.spawnEntityParticles(entity);
}
}
}
@@ -1,7 +1,5 @@
package makeo.gadomancy.common.events;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
@@ -112,7 +110,7 @@ public class EventHandlerRedirect {
if (stack != null) {
MinecraftServer server = MinecraftServer.getServer();
if (server != null && server.getConfigurationManager() != null) {
for (EntityPlayer player : (List<EntityPlayer>) server.getConfigurationManager().playerEntityList) {
for (EntityPlayer player : server.getConfigurationManager().playerEntityList) {
if (player != null && player.getHeldItem() == stack) {
possiblePlayer = player;
break;
@@ -48,27 +48,9 @@ public class PotionAchromatic extends PotionCustomTexture {
}
@Override
public void performEffect(EntityLivingBase entity, int p_76394_2_) {
/*
* if(entity.boundingBox != null) { List<Entity> projectiles =
* entity.worldObj.getEntitiesWithinAABB(IProjectile.class, entity.boundingBox.expand(3, 3, 3)); for(Entity e :
* projectiles) { AxisAlignedBB boundingBox = e.boundingBox != null ? e.boundingBox :
* AxisAlignedBB.getBoundingBox(e.posX, e.posY, e.posZ, e.posX, e.posY, e.posZ);
* if(entity.boundingBox.expand(1.5, 1.5, 1.5).intersectsWith(boundingBox)) { double pMaxDist = new
* Vector3(entity.boundingBox.minX, entity.boundingBox.minY, entity.boundingBox.minZ).distance(new
* Vector3(entity.boundingBox.maxX, entity.boundingBox.maxY, entity.boundingBox.maxZ)); double eMaxDist = new
* Vector3(boundingBox.minX, boundingBox.minY, boundingBox.minZ).distance(new Vector3(boundingBox.maxX,
* boundingBox.maxY, boundingBox.maxZ)); double timeoutDist = pMaxDist + eMaxDist*2 + 4.5; Vector3 vec = new
* Vector3(e.motionX, e.motionY, e.motionZ).normalize(); float dist = 0; boolean success = false; boolean state
* = true; Vector3 temp; do { temp = vec.clone().multiply(dist); if(state) {
* if(entity.boundingBox.intersectsWith(boundingBox.copy().offset(temp.getX(), temp.getY(), temp.getZ()))) {
* state = false; } } else { if(!entity.boundingBox.intersectsWith(boundingBox.copy().offset(temp.getX(),
* temp.getY(), temp.getZ()))) { success = true; break; } } dist += 0.1; } while(dist < timeoutDist); temp =
* vec.clone().multiply(dist + 1.25); if(success) { e.posX += temp.getX(); e.posY += temp.getY(); e.posZ +=
* temp.getZ(); } } } }
*/
public void performEffect(EntityLivingBase entity, int strength) {
List<Entity> projectiles = entity.worldObj.getEntitiesWithinAABB(
List<IProjectile> projectiles = entity.worldObj.getEntitiesWithinAABB(
IProjectile.class,
AxisAlignedBB.getBoundingBox(
entity.posX - 4.0D,
@@ -77,7 +59,8 @@ public class PotionAchromatic extends PotionCustomTexture {
entity.posX + 3.0D,
entity.posY + 3.0D,
entity.posZ + 3.0D));
for (Entity e : projectiles) {
for (IProjectile p : projectiles) {
final Entity e = (Entity) p;
Vector3 motionVec = new Vector3(e.motionX, e.motionY, e.motionZ).normalize().multiply(
Math.sqrt(
(e.posX - entity.posX) * (e.posX - entity.posX)
@@ -1,17 +1,9 @@
package makeo.gadomancy.common.registration;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import com.google.common.collect.BiMap;
import cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry;
import cpw.mods.fml.common.registry.GameData;
import makeo.gadomancy.common.CommonProxy;
import makeo.gadomancy.common.data.config.ModConfig;
import thaumcraft.common.config.ConfigBlocks;
/**
* This class is part of the Gadomancy Mod Gadomancy is Open Source and distributed under the GNU LESSER GENERAL PUBLIC
@@ -21,33 +13,6 @@ import thaumcraft.common.config.ConfigBlocks;
*/
public class ModSubstitutions {
public static void preInit() {
if (ModConfig.enableAdditionalNodeTypes) {
try {
ItemBlock item = (ItemBlock) Item.getItemFromBlock(ConfigBlocks.blockAiry);
item.field_150939_a = RegisteredBlocks.blockNode;
// Hacky way
FMLControlledNamespacedRegistry<Block> registry = GameData.getBlockRegistry();
registry.underlyingIntegerMap.field_148749_a
.put(RegisteredBlocks.blockNode, Block.getIdFromBlock(ConfigBlocks.blockAiry));
registry.underlyingIntegerMap.field_148748_b
.set(Block.getIdFromBlock(ConfigBlocks.blockAiry), RegisteredBlocks.blockNode);
((BiMap) registry.field_148758_b)
.forcePut(RegisteredBlocks.blockNode, registry.field_148758_b.get(ConfigBlocks.blockAiry));
registry.underlyingIntegerMap.field_148749_a.remove(ConfigBlocks.blockAiry);
ConfigBlocks.blockAiry = RegisteredBlocks.blockNode;
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void init() {}
public static void postInit() {
if (ModConfig.enableAdditionalNodeTypes) {
CommonProxy.unregisterWandHandler("Thaumcraft", Blocks.glass, -1);
@@ -18,7 +18,6 @@ import makeo.gadomancy.common.blocks.BlockEssentiaCompressor;
import makeo.gadomancy.common.blocks.BlockExtendedNodeJar;
import makeo.gadomancy.common.blocks.BlockInfusionClaw;
import makeo.gadomancy.common.blocks.BlockKnowledgeBook;
import makeo.gadomancy.common.blocks.BlockNode;
import makeo.gadomancy.common.blocks.BlockNodeManipulator;
import makeo.gadomancy.common.blocks.BlockRemoteJar;
import makeo.gadomancy.common.blocks.BlockStickyJar;
@@ -39,7 +38,6 @@ import makeo.gadomancy.common.blocks.tiles.TileManipulatorPillar;
import makeo.gadomancy.common.blocks.tiles.TileNodeManipulator;
import makeo.gadomancy.common.blocks.tiles.TileRemoteJar;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import makeo.gadomancy.common.data.config.ModConfig;
import makeo.gadomancy.common.items.ItemBlockAdditionalEldritchPortal;
import makeo.gadomancy.common.items.ItemBlockAuraPylon;
import makeo.gadomancy.common.items.ItemBlockEssentiaCompressor;
@@ -69,7 +67,7 @@ public class RegisteredBlocks {
public static BlockArcaneDropper blockArcaneDropper;
public static BlockInfusionClaw blockInfusionClaw;
public static BlockRemoteJar blockRemoteJar;
public static BlockAiry blockNode = (BlockAiry) ConfigBlocks.blockAiry;
public static BlockAiry blockNode;
public static BlockExtendedNodeJar blockExtendedNodeJar;
public static BlockNodeManipulator blockNodeManipulator;
public static BlockStoneMachine blockStoneMachine;
@@ -94,9 +92,7 @@ public class RegisteredBlocks {
RegisteredBlocks.blockInfusionClaw = RegisteredBlocks.registerBlock(new BlockInfusionClaw());
RegisteredBlocks.blockRemoteJar = RegisteredBlocks
.registerBlock(new BlockRemoteJar(), ItemBlockRemoteJar.class);
RegisteredBlocks.blockNode = ModConfig.enableAdditionalNodeTypes
? (BlockAiry) new BlockNode().setBlockName("blockAiry")
: (BlockAiry) ConfigBlocks.blockAiry;
RegisteredBlocks.blockNode = (BlockAiry) ConfigBlocks.blockAiry;
RegisteredBlocks.blockExtendedNodeJar = RegisteredBlocks.registerBlock(new BlockExtendedNodeJar());
RegisteredBlocks.blockNodeManipulator = RegisteredBlocks
.registerBlock(new BlockNodeManipulator(), ItemNodeManipulator.class);
@@ -0,0 +1,24 @@
package makeo.gadomancy.coremod;
import java.util.List;
import java.util.Set;
import com.gtnewhorizon.gtnhlib.mixin.IMixins;
import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
import com.gtnewhorizon.gtnhmixins.LateMixin;
import makeo.gadomancy.coremod.mixins.Mixins;
@LateMixin
public class GadomancyLateMixins implements ILateMixinLoader {
@Override
public String getMixinConfig() {
return "mixins.gadomancy.late.json";
}
@Override
public List<String> getMixins(Set<String> loadedMods) {
return IMixins.getLateMixins(Mixins.class, loadedMods);
}
}
@@ -0,0 +1,72 @@
package makeo.gadomancy.coremod.mixins;
import static com.gtnewhorizon.gtnhlib.mixin.TargetedMod.THAUMCRAFT;
import java.util.List;
import java.util.function.Supplier;
import com.gtnewhorizon.gtnhlib.mixin.IMixins;
import com.gtnewhorizon.gtnhlib.mixin.ITargetedMod;
import com.gtnewhorizon.gtnhlib.mixin.MixinBuilder;
import com.gtnewhorizon.gtnhlib.mixin.Phase;
import com.gtnewhorizon.gtnhlib.mixin.Side;
public enum Mixins implements IMixins {
// Config for this one is in the mixin itself, as it may not be present at apply time
ADD_ADDITIONAL_NODES(
new MixinBuilder("Replaces Thaumcraft's blockAiry with more nodes").setPhase(Phase.LATE).setSide(Side.BOTH)
.addTargetedMod(THAUMCRAFT).addMixinClasses("thaumcraft.MixinConfigBlocks").setApplyIf(() -> true));
private final List<String> mixinClasses;
private final List<ITargetedMod> targetedMods;
private final List<ITargetedMod> excludedMods;
private final Supplier<Boolean> applyIf;
private final Phase phase;
private final Side side;
Mixins(MixinBuilder builder) {
mixinClasses = builder.mixinClasses;
targetedMods = builder.targetedMods;
excludedMods = builder.excludedMods;
applyIf = builder.applyIf;
phase = builder.phase;
side = builder.side;
if (mixinClasses.isEmpty()) throw new RuntimeException("No mixin class specified for Mixin : " + name());
if (targetedMods.isEmpty()) throw new RuntimeException("No targeted mods specified for Mixin : " + name());
if (applyIf == null) throw new RuntimeException("No ApplyIf function specified for Mixin : " + name());
if (phase == null) throw new RuntimeException("No Phase specified for Mixin : " + name());
if (side == null) throw new RuntimeException("No Side function specified for Mixin : " + name());
}
@Override
public List<String> getMixinClasses() {
return mixinClasses;
}
@Override
public Supplier<Boolean> getApplyIf() {
return applyIf;
}
@Override
public Phase getPhase() {
return phase;
}
@Override
public Side getSide() {
return side;
}
@Override
public List<ITargetedMod> getTargetedMods() {
return targetedMods;
}
@Override
public List<ITargetedMod> getExcludedMods() {
return excludedMods;
}
}
@@ -0,0 +1,20 @@
package makeo.gadomancy.coremod.mixins.late.thaumcraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import makeo.gadomancy.common.blocks.BlockNode;
import makeo.gadomancy.common.data.config.ModConfig;
import thaumcraft.common.blocks.BlockAiry;
import thaumcraft.common.config.ConfigBlocks;
@SuppressWarnings("UnusedMixin")
@Mixin(value = ConfigBlocks.class, remap = false)
public class MixinConfigBlocks {
@Redirect(method = "initializeBlocks", at = @At(value = "NEW", target = "()Lthaumcraft/common/blocks/BlockAiry;"))
private static BlockAiry gadomancy$replaceBlockAiry() {
return ModConfig.enableAdditionalNodeTypes ? new BlockNode() : new BlockAiry();
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"required": true,
"minVersion": "0.8.3-GTNH",
"refmap": "mixins.gadomancy.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8"
}
@@ -0,0 +1,8 @@
{
"required": true,
"minVersion": "0.8.3-GTNH",
"package": "makeo.gadomancy.coremod.mixins.late",
"refmap": "mixins.gadomancy.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8"
}