mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-27 15:23:22 +00:00
Use mixins instead of registry replacement (#37)
This commit is contained in:
1 parent
d5142e677a
commit
e95aea0c7d
16 files changed
+164
-94
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user