Skip to content

Commit

Permalink
Compat KubeJs
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoHuNao committed Nov 7, 2023
1 parent 3f8ca96 commit 8bf819c
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 2 deletions.
23 changes: 23 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ minecraft {
client {
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', mod_id

property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
}

server {
Expand Down Expand Up @@ -138,6 +141,20 @@ repositories {
// flatDir {
// dir 'libs'
// }
maven {
// Shedaniel's maven (Architectury API)
url = "https://maven.architectury.dev"
content {
includeGroup "dev.architectury"
}
}
maven {
// saps.dev Maven (KubeJS and Rhino)
url = "https://maven.saps.dev/releases"
content {
includeGroup "dev.latvian.mods"
}
}
}

dependencies {
Expand All @@ -148,6 +165,12 @@ dependencies {
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"


implementation fg.deobf("dev.latvian.mods:kubejs-forge:${kubejs_version}")

// these two are unfortunately needed since fg.deobf doesn't respect transitive dependencies yet
implementation fg.deobf("dev.latvian.mods:rhino-forge:${rhino_version}")
implementation fg.deobf("dev.architectury:architectury-forge:${architectury_version}")
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
-Net.minecraftforge.gradle.check.certs=false


# The Minecraft version must agree with the Forge version to get a valid artifact
Expand Down Expand Up @@ -51,3 +52,7 @@ mod_group_id=com.pancake
mod_authors=
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=

kubejs_version=2001.6.3-build.89
rhino_version=2001.2.2-build.11
architectury_version=9.1.12
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public static void onBlock(BlockEvent.PortalSpawnEvent event) {
}
}
@SubscribeEvent
public static void onRaidStart(AftermathEvent.Start event) {
public static void onRaidStart(AftermathEvent.Start event)
{
event.getPlayers().forEach(uuid -> {
Player player = event.getLevel().getPlayerByUUID(uuid);
if (player != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String getUniqueIdentifier() {

@SubscribeEvent
public void updatePlayer(AftermathEvent.Ongoing event) {
ServerLevel level = event.getLevel();
Level level = event.getLevel();
Set<UUID> uuids = Sets.newHashSet();
Set<UUID> eventPlayers = event.getPlayers();
for (UUID uuid : players) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import com.pancake.surviving_the_aftermath.api.AftermathState;
import com.pancake.surviving_the_aftermath.api.base.BaseAftermath;
import com.pancake.surviving_the_aftermath.common.event.AftermathEvent;
import com.pancake.surviving_the_aftermath.compat.kubejs.event.AftermathEventJS;
import com.pancake.surviving_the_aftermath.compat.kubejs.event.AftermathEvents;
import dev.latvian.mods.kubejs.event.EventResult;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.MinecraftForge;

import java.util.List;
Expand All @@ -17,37 +21,45 @@ public class AftermathEventUtil {
public static void start(BaseAftermath aftermath, Set<UUID> players, ServerLevel level) {
aftermath.setState(AftermathState.START);
MinecraftForge.EVENT_BUS.post(new AftermathEvent.Start(aftermath,players, level));
AftermathEvents.START.post(new AftermathEventJS.StartJS(aftermath, players, level));

}
//post ready
public static void ready(BaseAftermath aftermath, Set<UUID> players, ServerLevel level) {
aftermath.setState(AftermathState.READY);
MinecraftForge.EVENT_BUS.post(new AftermathEvent.Ready(aftermath,players, level));
AftermathEvents.READY.post(new AftermathEventJS.ReadyJS(aftermath, players, level));
}
//post ongoing
public static void ongoing(BaseAftermath aftermath, Set<UUID> players, ServerLevel level) {
aftermath.setState(AftermathState.ONGOING);
MinecraftForge.EVENT_BUS.post(new AftermathEvent.Ongoing(aftermath,players, level));
AftermathEvents.ONGOING.post(new AftermathEventJS.OngoingJS(aftermath, players, level));
}

//post victory
public static void victory(BaseAftermath aftermath, Set<UUID> players, ServerLevel level) {
aftermath.setState(AftermathState.VICTORY);
MinecraftForge.EVENT_BUS.post(new AftermathEvent.Victory(aftermath,players, level));
AftermathEvents.VICTORY.post(new AftermathEventJS.VictoryJS(aftermath, players, level));
}
//post celebrating
public static void celebrating(BaseAftermath aftermath, Set<UUID> players, ServerLevel level) {
aftermath.setState(AftermathState.CELEBRATING);
SimpleWeightedRandomList<Item> rewardList = aftermath.getModule().getRewardList();
MinecraftForge.EVENT_BUS.post(new AftermathEvent.Celebrating(aftermath,players, level,rewardList));
AftermathEvents.CELEBRATING.post(new AftermathEventJS.CelebratingJS(aftermath, players, level,rewardList));
}
//post lose
public static void lose(BaseAftermath aftermath, Set<UUID> players, ServerLevel level) {
aftermath.setState(AftermathState.LOSE);
MinecraftForge.EVENT_BUS.post(new AftermathEvent.Lose(aftermath,players, level));
AftermathEvents.LOSE.post(new AftermathEventJS.LoseJS(aftermath, players, level));
}
//post end
public static void end(BaseAftermath aftermath, Set<UUID> players, ServerLevel level) {
aftermath.setState(AftermathState.END);
MinecraftForge.EVENT_BUS.post(new AftermathEvent.End(aftermath,players, level));
AftermathEvents.END.post(new AftermathEventJS.EndJS(aftermath, players, level));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pancake.surviving_the_aftermath.compat.kubejs;

import com.pancake.surviving_the_aftermath.compat.kubejs.event.AftermathEvents;
import dev.latvian.mods.kubejs.KubeJSPlugin;

public class ModKubeJSPlugin extends KubeJSPlugin {

@Override
public void registerEvents() {
AftermathEvents.register();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.pancake.surviving_the_aftermath.compat.kubejs.event;

import com.pancake.surviving_the_aftermath.api.base.BaseAftermath;
import com.pancake.surviving_the_aftermath.api.base.BaseAftermathModule;
import dev.latvian.mods.kubejs.event.EventJS;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraftforge.eventbus.api.Cancelable;

import java.util.Set;
import java.util.UUID;

public class AftermathEventJS extends EventJS {
private final BaseAftermath<BaseAftermathModule> aftermath;
private final Set<UUID> players;
private final ServerLevel level;

public Set<UUID> getPlayers() {
return players;
}

public ServerLevel getLevel() {
return level;
}

public AftermathEventJS(BaseAftermath<BaseAftermathModule> aftermath, Set<UUID> players, ServerLevel level) {
this.aftermath = aftermath;
this.players = players;
this.level = level;
}

public static class StartJS extends AftermathEventJS {
public StartJS(BaseAftermath<BaseAftermathModule> aftermath,Set<UUID> players, ServerLevel level) {
super(aftermath,players, level);
}
}
public static class EndJS extends AftermathEventJS {

public EndJS(BaseAftermath<BaseAftermathModule> aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}
public static class ReadyJS extends AftermathEventJS {

public ReadyJS(BaseAftermath<BaseAftermathModule> aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}

public static class OngoingJS extends AftermathEventJS {

public OngoingJS(BaseAftermath<BaseAftermathModule> aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}
public static class VictoryJS extends AftermathEventJS {

public VictoryJS(BaseAftermath<BaseAftermathModule> aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}
public static class LoseJS extends AftermathEventJS {

public LoseJS(BaseAftermath<BaseAftermathModule> aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}
@Cancelable
public static class CelebratingJS extends AftermathEventJS {
private SimpleWeightedRandomList<Item> rewardList;

public CelebratingJS(BaseAftermath<BaseAftermathModule> aftermath, Set<UUID> players, ServerLevel level,SimpleWeightedRandomList<Item> rewardList) {
super(aftermath, players, level);
this.rewardList = rewardList;
}
public SimpleWeightedRandomList<Item> getRewardList() {
return rewardList;
}

public void setRewardList(SimpleWeightedRandomList<Item> rewardList) {
this.rewardList = rewardList;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.pancake.surviving_the_aftermath.compat.kubejs.event;

import dev.latvian.mods.kubejs.event.EventGroup;
import dev.latvian.mods.kubejs.event.EventHandler;

public interface AftermathEvents {
EventGroup GROUP = EventGroup.of("AftermathEvents");

//Start
EventHandler START = GROUP.server("start", () -> AftermathEventJS.StartJS.class);

//End
EventHandler END = GROUP.server("end", () -> AftermathEventJS.EndJS.class);

//Ready
EventHandler READY = GROUP.server("ready", () -> AftermathEventJS.ReadyJS.class);

//Ongoing
EventHandler ONGOING = GROUP.server("ongoing", () -> AftermathEventJS.OngoingJS.class);

//Victory
EventHandler VICTORY = GROUP.server("victory", () -> AftermathEventJS.VictoryJS.class);

//Lose
EventHandler LOSE = GROUP.server("lose", () -> AftermathEventJS.LoseJS.class);

//Celebrating
EventHandler CELEBRATING = GROUP.server("celebrating", () -> AftermathEventJS.CelebratingJS.class);

static void register() {
GROUP.register();
}

}
1 change: 1 addition & 0 deletions src/main/resources/kubejs.plugins.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.pancake.surviving_the_aftermath.compat.kubejs.ModKubeJSPlugin

0 comments on commit 8bf819c

Please sign in to comment.