Skip to content

Commit

Permalink
2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
westernat committed Jan 25, 2024
1 parent 9a9fd76 commit 72611ed
Show file tree
Hide file tree
Showing 25 changed files with 414 additions and 182 deletions.
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Configure Advancements by KubeJS

```js
ServerEvents.advancement((event) => {
const { BOUNDS, PREDICATE, TRIGGER } = event;
const { PREDICATE, TRIGGER } = event;

// Define trigger
const jump5times = TRIGGER.tick((triggerBuilder) =>
triggerBuilder.addStat(Stats.JUMP, Stats.CUSTOM, BOUNDS.min$Integer(5)));
triggerBuilder.addStat(Stats.JUMP, Stats.CUSTOM, { min: 5 }));
const bred_in_nether = TRIGGER.bredAnimals((triggerBuilder) => {
triggerBuilder.setChild(PREDICATE.entity({
triggerBuilder.setChildByPredicate(PREDICATE.entityFromJson({
stepping_on: {
dimension: "the_nether"
}
Expand Down Expand Up @@ -55,25 +55,29 @@ ServerEvents.advancement((event) => {
// Check if parent done, else it will not be done
.requireParentDone()
});

// Remove an exist advancement by RemoveFilter, available filter was writen in doc.
// you can also remove like this: 'event.remove("minecraft:story/lava_bucket");'
event.remove({
icon: "minecraft:lava_bucket"
});

// Modify an exist advancement
event.get("minecraft:story/smelt_iron")
// Apply offset to display
.displayOffset(1, 1, true)
.modifyDisplay((displayBuilder) => displayBuilder.setIcon("diamond_pickaxe"))
.addChild("child2", (childBuilder) => {
childBuilder
.display((displayBuilder) => {
displayBuilder.setTitle('A nice one!')
displayBuilder.setDescription(Text.green("Good luck"))
// You can also apply offset at here
displayBuilder.offset(-1, 0)
})
.criteria((criteriaBuilder) => criteriaBuilder.add("jump", jump5times))
});

// Lock recipe by advancement
event.lock("stone_slab", "minecraft:story/smelt_iron");
})
Expand All @@ -84,16 +88,22 @@ Just use ```/reload```

# Features
- Custom trigger
- blockDestroyed: triggers when the player breaks a block.
- playerTouch: triggers when the player touch an entity.
- bossEvent: triggers when the play joins a boss fight.
- More idea...
- blockDestroyed: triggers when the player breaks a block.
- playerTouch: triggers when the player touch an entity.
- bossEvent: triggers when the play joins a boss fight.
- increasedKillScore: triggers when the player killed an entity.
- More idea...
- Custom reward
- addEffect: to give effect.
- More idea...
- Custom condition
- requireParentDone: check if parent done, else it will not be done
- More idea...
- addEffect: to give effect.
- More idea...
- Custom method
- displayOffset(offsetX: number, offsetY: number, modifyChildren?: boolean)
- apply offset to advancement display and its children
- requireParentDone()
- check if parent done, else it will not be done.
- requireOthersDone(requires[]: ResourceLocation...)
- check if advancements that you put in had done.
- More idea...

# TODO
- More non-vanilla triggers
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10
loader_version=0.15.3

# Mod Properties
mod_version=2001fabric-2.3.0
mod_version=2001fabric-2.4.0
maven_group=org.mesdag.advjs
archives_base_name=AdvJS

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/mesdag/advjs/AdvJSPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
import dev.latvian.mods.kubejs.util.ConsoleJS;
import dev.latvian.mods.rhino.util.wrap.TypeWrappers;
import org.mesdag.advjs.command.AdvCommand;
import org.mesdag.advjs.util.Bounds;
import org.mesdag.advjs.util.FrameTypeWrapper;
import org.mesdag.advjs.util.GameTypeWrapper;
import org.mesdag.advjs.util.RequirementsStrategyWrapper;
import org.mesdag.advjs.util.*;

import java.nio.file.Files;

import static org.mesdag.advjs.configure.Data.*;
import static org.mesdag.advjs.util.Data.*;

public class AdvJSPlugin extends KubeJSPlugin {
public static boolean DEBUG;
Expand All @@ -24,11 +21,13 @@ public void registerBindings(BindingsEvent event) {
event.add("FrameType", FrameTypeWrapper.class);
event.add("RequirementsStrategy", RequirementsStrategyWrapper.class);
event.add("GameType", GameTypeWrapper.class);
event.add("Bounds", Bounds.class);
}

@Override
public void registerTypeWrappers(ScriptType type, TypeWrappers typeWrappers) {
typeWrappers.registerSimple(Bounds.class, Bounds::of);
typeWrappers.registerSimple(AdvRemoveFilter.class, AdvRemoveFilter::of);
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/mesdag/advjs/command/AdvCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
.then(CommandManager.literal("adventure").executes(context -> run(context.getSource(), AdvJS.ADVENTURE, ADVENTURE)))
.then(CommandManager.literal("nether").executes(context -> run(context.getSource(), AdvJS.NETHER, NETHER)))
.then(CommandManager.literal("husbandry").executes(context -> run(context.getSource(), AdvJS.HUSBANDRY, HUSBANDRY)))
.then(CommandManager.literal("end").executes(context -> run(context.getSource(), AdvJS.END, END)))
.then(CommandManager.literal("end").executes(context -> run(context.getSource(), AdvJS.END, END)))
.then(CommandManager.literal("all").executes(context -> {
ServerCommandSource source = context.getSource();
run(source, AdvJS.EXAMPLE, EXAMPLE);
Expand Down Expand Up @@ -1856,7 +1856,7 @@ function lookAtThroughSpyglass(entityType) {
""";
STORY = """
ServerEvents.advancement(event => {
const { PREDICATE, TRIGGER } = event;
const { TRIGGER } = event;
const story = event
.create("advjs:story")
Expand Down Expand Up @@ -2160,9 +2160,10 @@ function lookAtThroughSpyglass(entityType) {
.display((displayBuilder) => {
displayBuilder.setTitle('A nice one!')
displayBuilder.setDescription(Text.green("Good luck"))
// You can also apply offset at here
displayBuilder.offset(-1, 0)
})
.criteria((criteriaBuilder) => criteriaBuilder.add("jump", jump5times))
.displayOffset(-1, 0)
});
// Lock recipe by advancement
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/org/mesdag/advjs/configure/AdvBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.UUID;
import java.util.function.Consumer;

import static org.mesdag.advjs.configure.Data.*;
import static org.mesdag.advjs.util.Data.*;

public class AdvBuilder {
@Nullable
Expand All @@ -37,7 +37,7 @@ public AdvBuilder(@Nullable Identifier parent, String name, Identifier rootPath,
this.name = name;
this.rootPath = rootPath;
this.warn = warn;
this.id = getSavePath();
this.id = generateId();
}

@Info("Add a nameless child to this advancement, just for test. Returns child.")
Expand Down Expand Up @@ -89,7 +89,13 @@ public AdvBuilder sendsTelemetryEvent() {

@Info("It will check if parent done. Defaults do not check.")
public AdvBuilder requireParentDone() {
REQUIRE_DONE.add(id);
REQUIRE_DONE.put(id, new Identifier[0]);
return this;
}

@Info("It will check if advancements that you put in had done.")
public AdvBuilder requireOthersDone(Identifier... requires) {
REQUIRE_DONE.put(id, requires);
return this;
}

Expand Down Expand Up @@ -123,7 +129,7 @@ private void update() {
return parent;
}

private Identifier getSavePath() {
private Identifier generateId() {
if (name.contains(":")) {
return new Identifier(name);
}
Expand Down Expand Up @@ -166,13 +172,16 @@ public WarnType getWarn() {
}

@HideFromJS
public void setWarn(WarnType warn) {
public AdvBuilder setWarn(WarnType warn) {
this.warn = warn;
return this;
}

public enum WarnType {
NONE(Text.empty()),
NAMELESS(Text.translatable("advjs.attention.nameless"));
NAMELESS(Text.translatable("advjs.attention.nameless")),
NO_SPACE(Text.translatable("advjs.attention.no_space")),
NO_PARENT(Text.translatable("advjs.attention.no_parent"));

public final Text msg;

Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/mesdag/advjs/configure/AdvConfigureEvent.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.mesdag.advjs.configure;

import com.google.gson.JsonElement;
import dev.latvian.mods.kubejs.event.EventJS;
import dev.latvian.mods.kubejs.typings.Info;
import dev.latvian.mods.kubejs.typings.Param;
Expand All @@ -9,11 +8,12 @@
import net.minecraft.util.Identifier;
import org.mesdag.advjs.predicate.Predicate;
import org.mesdag.advjs.trigger.Trigger;
import org.mesdag.advjs.util.AdvRemoveFilter;
import org.mesdag.advjs.util.Condition;
import org.mesdag.advjs.util.Provider;

import static org.mesdag.advjs.configure.Data.FILTERS;
import static org.mesdag.advjs.configure.Data.LOCK_MAP;
import static org.mesdag.advjs.util.Data.FILTERS;
import static org.mesdag.advjs.util.Data.LOCK_MAP;

public class AdvConfigureEvent extends EventJS {
@Info("""
Expand All @@ -31,6 +31,9 @@ public class AdvConfigureEvent extends EventJS {

@Info("Create a new advancement root")
public AdvBuilder create(Identifier rootPath) {
if (rootPath.getNamespace().equals("minecraft")) {
new AdvBuilder(null, "root", rootPath, AdvBuilder.WarnType.NO_SPACE);
}
return new AdvBuilder(null, "root", rootPath, AdvBuilder.WarnType.NONE);
}

Expand All @@ -46,10 +49,9 @@ public AdvBuilder create(Identifier rootPath) {
frame: type of frame for the icon. Available value is 'challenge', 'goal' or 'task'.
parent: the parent advancement path of this advancement.
""")
public void remove(JsonElement jsonElement) {
RemoveFilter filter = RemoveFilter.of(jsonElement);
public void remove(AdvRemoveFilter filter) {
if (filter.fail()) {
ConsoleJS.SERVER.warn("AdvJS/AdvConfigureEvent: Failed create a filter");
ConsoleJS.SERVER.warn("AdvJS/remove: Failed create a filter");
} else {
FILTERS.add(filter);
}
Expand All @@ -60,7 +62,7 @@ public AdvGetter get(Identifier path) {
return new AdvGetter(path);
}

@Info(value = "Lock recipe by advancement.",
@Info(value = "Lock recipe by advancement. It will only deny player take the result from GUI.",
params = {
@Param(name = "toLock"),
@Param(name = "lockBy")
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/mesdag/advjs/configure/AdvGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.UUID;
import java.util.function.Consumer;

import static org.mesdag.advjs.configure.Data.*;
import static org.mesdag.advjs.util.Data.*;

public class AdvGetter {
private final Identifier id;
Expand Down Expand Up @@ -77,7 +77,13 @@ private static Identifier getRootPath(Identifier savePath) {

@Info("It will check if parent done. Defaults do not check.")
public AdvGetter requireParentDone() {
REQUIRE_DONE.add(id);
REQUIRE_DONE.put(id, new Identifier[0]);
return this;
}

@Info("It will check if advancements that you put in had done.")
public AdvGetter requireOthersDone(Identifier... requires) {
REQUIRE_DONE.put(id, requires);
return this;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/mesdag/advjs/configure/DisplayBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jetbrains.annotations.Nullable;
import org.mesdag.advjs.util.DisplayOffset;

import static org.mesdag.advjs.configure.Data.DISPLAY_OFFSET;
import static org.mesdag.advjs.util.Data.DISPLAY_OFFSET;

public class DisplayBuilder {
private ItemStack icon;
Expand Down Expand Up @@ -104,7 +104,7 @@ public void setHidden(boolean hidden) {
@Param(name = "offsetX", value = "The offset x of display."),
@Param(name = "offsetY", value = "The offset y of display.")
})
public void displayOffset(float x, float y) {
public void offset(float x, float y) {
DISPLAY_OFFSET.put(source, new DisplayOffset(x, y, false));
}

Expand All @@ -114,7 +114,7 @@ public void displayOffset(float x, float y) {
@Param(name = "offsetY", value = "The offset y of display."),
@Param(name = "modifyChildren", value = "Determine should its children apply the same offset.")
})
public void displayOffset(float x, float y, boolean modifyChildren) {
public void offset(float x, float y, boolean modifyChildren) {
DISPLAY_OFFSET.put(source, new DisplayOffset(x, y, modifyChildren));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public abstract class AdvancementRewardsMixin implements RewardsAccessor {

@Inject(method = "apply", at = @At("HEAD"))
private void advJS$grant(ServerPlayerEntity serverPlayer, CallbackInfo ci) {
if (advJS$mobEffectInstances != null) {
for (StatusEffectInstance mobEffectInstance : advJS$mobEffectInstances) {
if (mobEffectInstance != null) {
serverPlayer.addStatusEffect(mobEffectInstance);
}
if (advJS$mobEffectInstances == null) {
return;
}

for (StatusEffectInstance mobEffectInstance : advJS$mobEffectInstances) {
if (mobEffectInstance != null) {
serverPlayer.addStatusEffect(mobEffectInstance);
}
}
}
Expand Down
Loading

0 comments on commit 72611ed

Please sign in to comment.