Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Boze Client Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekiplay committed Apr 9, 2024
1 parent b0991b3 commit 7e7d5d2
Show file tree
Hide file tree
Showing 29 changed files with 711 additions and 100 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ repositories {
maven {
url = uri("https://maven.jackf.red/releases/")
}

// Boze
maven {
name = "boze-maven"
url = "https://maven.boze.dev/releases"
}
}

dependencies {
Expand Down Expand Up @@ -64,6 +70,9 @@ dependencies {
modImplementation("red.jackf:whereisit:${project.where_is_it_version}")

include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.2.2")))

// Boze
modImplementation "dev.boze:boze-api:${project.boze_api_version}"
}

loom {
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ where_is_it_version=2.3.4+1.20.4
# MaLiLib (https://www.curseforge.com/minecraft/mc-mods/malilib/files/all?page=1&pageSize=20)
malilib_fileid=4946328
malilib_projectid=303119


boze_api_version=1.2.0+1.20.4
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package nekiplay.meteorplus;
package nekiplay;

import nekiplay.bozeplus.BozePlusAddon;
import nekiplay.meteorplus.items.ModItems;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static nekiplay.meteorplus.MeteorPlusAddon.LOGPREFIX;

public class MeteorPlusMain implements ModInitializer {
public static final Logger LOG = LoggerFactory.getLogger(MeteorPlusMain.class);
public class Main implements ModInitializer {
public static final Logger LOG = LoggerFactory.getLogger(Main.class);
@Override
public void onInitialize() {
LOG.info(LOGPREFIX + " initializing items...");
ModItems.Initialize();
LOG.info(LOGPREFIX + " loaded items");

if (MixinPlugin.isBozeAPI) {
BozePlusAddon bozePlusMain = new BozePlusAddon();
bozePlusMain.onInitialize();
}
}
}
101 changes: 101 additions & 0 deletions src/main/java/nekiplay/MixinPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package nekiplay;

import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import java.util.List;
import java.util.Set;

public class MixinPlugin implements IMixinConfigPlugin {
public static final Logger LOG = LoggerFactory.getLogger(MixinPlugin.class);
public static final String LOGPREFIX = "[Meteor+ Mixins]";

private static final String mixinPackageMeteorPlus = "nekiplay.meteorplus.mixin";
private static final String mixinPackageBozePlus = "nekiplay.bozeplus.mixin";
public static boolean isMeteorClient = false;
public static boolean isBaritonePresent = false;
public static boolean isJourneyMapPresent = false;
public static boolean isXaeroWorldMapresent = false;
public static boolean isXaeroMiniMapresent= false;
public static boolean isXaeroPlusMapresent = false;
public static boolean isLitematicaMapresent = false;
public static boolean isWhereIsIt = false;
public static boolean isMeteorRejects= false;

public static boolean isBozeAPI= false;

@Override
public void onLoad(String mixinPackage) {
FabricLoader loader = FabricLoader.getInstance();

isMeteorClient = loader.isModLoaded("meteor-client");
isBozeAPI = loader.isModLoaded("boze-api");

isMeteorRejects = loader.isModLoaded("meteor-rejects");

isBaritonePresent = loader.isModLoaded("baritone");
isJourneyMapPresent = loader.isModLoaded("journeymap");
isXaeroWorldMapresent = loader.isModLoaded("xaeroworldmap");
isXaeroMiniMapresent = loader.isModLoaded("xaerominimap");
isXaeroPlusMapresent = loader.isModLoaded("xaeroplus");
isLitematicaMapresent = loader.isModLoaded("litematica");
isWhereIsIt = loader.isModLoaded("whereisit");
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (!mixinClassName.startsWith(mixinPackageMeteorPlus)) {
throw new RuntimeException(LOGPREFIX + " " + mixinClassName + " is not in the mixin package");
}
else if (mixinClassName.startsWith(mixinPackageMeteorPlus + ".meteorclient")) {
if (mixinClassName.contains("FreecamMixin") || mixinClassName.contains("WaypointsModuleMixin")) {
return isBaritonePresent && isMeteorClient;
}
return isMeteorClient;
}
else if (mixinClassName.startsWith(mixinPackageMeteorPlus + ".journeymap")) {
return isBaritonePresent && isJourneyMapPresent && isMeteorClient;
}
else if (mixinClassName.startsWith(mixinPackageMeteorPlus + ".xaero.minimap")) {
return isXaeroWorldMapresent && isMeteorClient;
}
else if (mixinClassName.startsWith(mixinPackageMeteorPlus + ".xaero.worldmap")) {
return isBaritonePresent && isXaeroWorldMapresent && isMeteorClient;
}
else if (mixinClassName.startsWith(mixinPackageMeteorPlus + ".whereisit")) {
return isWhereIsIt && isMeteorClient;
}
else if (mixinClassName.startsWith(mixinPackageMeteorPlus + ".minecraft")) {
return isMeteorClient;
}

else if (mixinClassName.startsWith(mixinPackageBozePlus + ".minecraft")) {
return isBozeAPI;
}

return false;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}

}
107 changes: 107 additions & 0 deletions src/main/java/nekiplay/bozeplus/BozePlusAddon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package nekiplay.bozeplus;

import com.google.gson.JsonObject;
import dev.boze.api.BozeInstance;
import dev.boze.api.Globals;
import dev.boze.api.addon.Addon;
import dev.boze.api.addon.AddonMetadata;
import dev.boze.api.addon.AddonVersion;
import dev.boze.api.addon.command.AddonDispatcher;
import dev.boze.api.addon.module.AddonModule;
import dev.boze.api.config.Serializable;
import dev.boze.api.exception.AddonInitializationException;
import meteordevelopment.orbit.EventBus;
import meteordevelopment.orbit.IEventBus;
import nekiplay.MixinPlugin;
import nekiplay.bozeplus.features.modules.movement.spider.SpiderPlus;
import nekiplay.bozeplus.impl.BozePlusDispatcher;
import nekiplay.bozeplus.impl.BozePlusModule;
import net.fabricmc.loader.impl.util.log.Log;
import net.fabricmc.loader.impl.util.log.LogCategory;

import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;

public class BozePlusAddon implements Addon, Serializable<BozePlusAddon> {
public static final IEventBus EVENT_BUS = new EventBus();

private static BozePlusAddon instance;

public static BozePlusAddon getInstance() {
return instance;
}

public final AddonMetadata metadata = new AddonMetadata(
"boze-plus",
"Boze Plus",
"An example addon for Boze",
new AddonVersion(1, 0, 0));

private final ArrayList<AddonModule> modules = new ArrayList<>();
private BozePlusDispatcher dispatcher;

public void onInitialize() {
try {
BozeInstance.INSTANCE.registerAddon(this);
} catch (AddonInitializationException e) {
Log.error(LogCategory.LOG, "Failed to initialize addon: " + getMetadata().id(), e);
}
}

@Override
public AddonMetadata getMetadata() {
return metadata;
}

@Override
public boolean initialize() {
instance = this;
BozeInstance.INSTANCE.registerPackage("nekiplay.bozeplus");
EVENT_BUS.registerLambdaFactory("nekiplay.bozeplus" , (lookupInMethod, klass) -> (MethodHandles.Lookup) lookupInMethod.invoke(null, klass, MethodHandles.lookup()));

// Load config
Globals.getJsonTools().loadObject(this, "config", this);

SpiderPlus spiderPlus = new SpiderPlus();

modules.add(spiderPlus);
EVENT_BUS.subscribe(spiderPlus);

return true;
}

@Override
public void shutdown() {
Globals.getJsonTools().saveObject(this, "config", this);
}

@Override
public List<AddonModule> getModules() {
return modules;
}

@Override
public AddonDispatcher getDispatcher() {
return dispatcher;
}

@Override
public JsonObject toJson() {
JsonObject object = new JsonObject();
for (AddonModule module : modules) {
object.add(module.getInfo().getName(), ((BozePlusModule) module).toJson());
}
return object;
}

@Override
public BozePlusAddon fromJson(JsonObject jsonObject) {
for (AddonModule module : modules) {
if (jsonObject.has(module.getInfo().getName())) {
((BozePlusModule) module).fromJson(jsonObject.getAsJsonObject(module.getInfo().getName()));
}
}
return this;
}
}
17 changes: 17 additions & 0 deletions src/main/java/nekiplay/bozeplus/events/Cancellable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package nekiplay.bozeplus.events;

import meteordevelopment.orbit.ICancellable;

public class Cancellable implements ICancellable {
private boolean cancelled = false;

@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}

@Override
public boolean isCancelled() {
return cancelled;
}
}
44 changes: 44 additions & 0 deletions src/main/java/nekiplay/bozeplus/events/packets/PacketEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package nekiplay.bozeplus.events.packets;

import nekiplay.bozeplus.events.Cancellable;
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.Packet;

public class PacketEvent {
public static class Receive extends Cancellable {
private static final Receive INSTANCE = new Receive();

public Packet<?> packet;
public PacketListener packetListener;

public static Receive get(Packet<?> packet, PacketListener listener) {
INSTANCE.setCancelled(false);
INSTANCE.packet = packet;
INSTANCE.packetListener = listener;
return INSTANCE;
}
}

public static class Send extends Cancellable {
private static final Send INSTANCE = new Send();

public Packet<?> packet;

public static Send get(Packet<?> packet) {
INSTANCE.setCancelled(false);
INSTANCE.packet = packet;
return INSTANCE;
}
}

public static class Sent {
private static final Sent INSTANCE = new Sent();

public Packet<?> packet;

public static Sent get(Packet<?> packet) {
INSTANCE.packet = packet;
return INSTANCE;
}
}
}
Loading

0 comments on commit 7e7d5d2

Please sign in to comment.