Skip to content

Commit

Permalink
Rework updater
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Jan 8, 2025
1 parent bd5fdc1 commit 8c80dfc
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mixin_booter_version = 10.2
# You should change package root once they are generated
generate_mixins_json = true
# Delimit configs with spaces. Should only put configs name instead of full file name
mixin_configs = fix.capability bridge.explosion bridge.explosion.mohist bridge.permission fix.capability.mohist perf.eventbus perf.server perf.timings.v1 misc.command bukkit.plugin
mixin_configs = fix.respawn bridge.explosion bridge.explosion.mohist bridge.permission fix.respawn.mohist perf.eventbus perf.server perf.timings.v1 misc.command bukkit.plugin
# A refmap is a json that denotes mapping conversions, this json is generated automatically, with the name `mixins.mod_id.refmap.json`
# Use the property `mixin_refmap` if you want it to use a different name, only one name is accepted
mixin_refmap = mixins.${mod_id}.refmap.json
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/wdsj/hybridfix/HybridFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class HybridFix {
public static final String DEPENDENCY = "required-after:mixinbooter@[7.1,);required-after:configanytime;";
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);
public static final boolean IS_HYBRID_ENV = Utils.hasBukkit();
public static final boolean HAS_CLEANROOM = Utils.isClassLoaded("com.cleanroommc.common.CleanroomContainer");
public static final boolean HAS_CLEANROOM = Utils.isClassExists("com.cleanroommc.common.CleanroomContainer");

@Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent event) {
Expand All @@ -34,6 +34,9 @@ public void onPreInit(FMLPreInitializationEvent event) {

@Mod.EventHandler
public void onServerStartComplete(FMLServerStartedEvent event) {
if (!IS_HYBRID_ENV) {
return;
}
HybridFixServer.onStartComplete();
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/wdsj/hybridfix/HybridFixPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class HybridFixPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader {
{
{
if (!HAS_CLEANROOM) {
put("mixins.fix.capability.json", () -> Settings.fixCapabilityReset || Settings.simulateVanillaRespawn);
put("mixins.fix.respawn.json", () -> Settings.fixCapabilityReset || Settings.simulateVanillaRespawn);
if (Utils.isMohist) {
put("mixins.fix.capability.mohist.json", () -> Settings.fixCapabilityReset || Settings.simulateVanillaRespawn);
put("mixins.fix.respawn.mohist.json", () -> Settings.fixCapabilityReset || Settings.simulateVanillaRespawn);
}
put("mixins.bridge.explosion.json", () -> Settings.passExplosionEventToBukkit);
if (Utils.isMohist) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wdsj/hybridfix/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Settings {
@Config.RequiresMcRestart
public static boolean checkForUpdates = true;

@Config.Comment("Re-gather capabilities on respawn, will fix Simple Difficulty(And other similar mods) thirst not getting reset on respawn.")
@Config.Comment("Re-gather capabilities on respawn, will fix Simple Difficulty(And other similar mods) thirst not getting reset on respawn.\nAnd fix dupe bug in The Betweenlands.")
@Config.RequiresMcRestart
public static boolean fixCapabilityReset = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public PluginLogger getLogger() {
@Override
public PluginLoader getPluginLoader() {
if (loader == null) {
//noinspection deprecation
loader = new JavaPluginLoader(Bukkit.getServer());
}
return loader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.wdsj.hybridfix.logic.respawn;

import io.wdsj.hybridfix.mixin.fix.capability.EntityCapabilityAccessor;
import io.wdsj.hybridfix.mixin.fix.respawn.EntityCapabilityAccessor;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityEvent;

public class CBRespawnFixLogic {
private CBRespawnFixLogic() {
Expand Down Expand Up @@ -66,7 +68,7 @@ public static void simulateVanillaRespawn(EntityPlayerMP playerIn) {
dataManager.register(EntityPlayer.LEFT_SHOULDER_ENTITY, capturedLeftShoulder);
dataManager.register(EntityPlayer.RIGHT_SHOULDER_ENTITY, capturedRightShoulder);

net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(playerIn));
MinecraftForge.EVENT_BUS.post(new EntityEvent.EntityConstructing(playerIn));
}
public static void regatherCapabilities(EntityPlayerMP playerIn) {
((EntityCapabilityAccessor) (Entity) playerIn).setCapabilities(net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(playerIn));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import org.spongepowered.asm.mixin.Mixin;

@Mixin(Entity.class)
public abstract class EntityMixin implements IEntityGetter {
public abstract class EntityMixin implements IEntityGetter { // Method impl is provided by hybrids
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import org.spongepowered.asm.mixin.Mixin;

@Mixin(World.class)
public abstract class WorldMixin implements IWorldGetter {
public abstract class WorldMixin implements IWorldGetter { // Method impl is provided by hybrids
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.wdsj.hybridfix.mixin.fix.capability;
package io.wdsj.hybridfix.mixin.fix.respawn;

import net.minecraft.entity.Entity;
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.wdsj.hybridfix.mixin.fix.capability;
package io.wdsj.hybridfix.mixin.fix.respawn;

import io.wdsj.hybridfix.config.Settings;
import io.wdsj.hybridfix.logic.respawn.CBRespawnFixLogic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.wdsj.hybridfix.mixin.fix.capability.mohist;
package io.wdsj.hybridfix.mixin.fix.respawn.mohist;

import io.wdsj.hybridfix.config.Settings;
import io.wdsj.hybridfix.logic.respawn.CBRespawnFixLogic;
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/io/wdsj/hybridfix/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

public class Utils {
public static final String OBC_PACKAGE = "org.bukkit.craftbukkit.v1_12_R1";
public static final boolean isMohist = isClassLoaded("com.mohistmc.MohistMC");
public static final boolean isMohist = isClassExists("com.mohistmc.MohistMC");
private static final boolean hasBukkit = isClassExists("org.bukkit.Bukkit");
private static final ExecutorService ioWorker = Executors.newCachedThreadPool(
new ThreadFactoryBuilder()
.setNameFormat("HybridFix I/O worker-%d")
Expand All @@ -28,6 +29,15 @@ public static boolean isClassLoaded(String className) {
}
}

public static boolean isClassExists(String className) {
String classPath = className.replace('.', '/') + ".class";
try {
return Thread.currentThread().getContextClassLoader().getResource(classPath) != null;
} catch (Throwable e) {
return false;
}
}

public static boolean isAnyClassLoaded(String... classNames) {
for (String className : classNames) {
if (isClassLoaded(className)) {
Expand All @@ -38,6 +48,6 @@ public static boolean isAnyClassLoaded(String... classNames) {
}

public static boolean hasBukkit() {
return isClassLoaded("org.bukkit.Bukkit");
return hasBukkit;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"package": "io.wdsj.hybridfix.mixin.fix.capability",
"package": "io.wdsj.hybridfix.mixin.fix.respawn",
"required": true,
"refmap": "${mixin_refmap}",
"target": "@env(DEFAULT)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"package": "io.wdsj.hybridfix.mixin.fix.capability.mohist",
"package": "io.wdsj.hybridfix.mixin.fix.respawn.mohist",
"required": true,
"refmap": "${mixin_refmap}",
"target": "@env(DEFAULT)",
Expand Down

0 comments on commit 8c80dfc

Please sign in to comment.