Skip to content

Commit

Permalink
Made WithPersistentData extend MessageSenderKJS
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Oct 17, 2023
1 parent 8630497 commit ea2856e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions common/src/main/java/dev/latvian/mods/kubejs/core/LevelKJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.latvian.mods.rhino.util.RemapPrefixForJS;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand All @@ -32,6 +33,47 @@ public interface LevelKJS extends WithAttachedData<Level>, ScriptTypeHolder {
throw new NoMixinException();
}

@Override
default Component kjs$getName() {
return Component.literal(kjs$getDimension().toString());
}

@Override
default void kjs$tell(Component message) {
for (var entity : kjs$self().players()) {
entity.kjs$tell(message);
}
}

@Override
default void kjs$setStatusMessage(Component message) {
for (var entity : kjs$self().players()) {
entity.kjs$setStatusMessage(message);
}
}

@Override
default int kjs$runCommand(String command) {
var m = 0;

for (var entity : kjs$self().players()) {
m = Math.max(m, entity.kjs$runCommand(command));
}

return m;
}

@Override
default int kjs$runCommandSilent(String command) {
var m = 0;

for (var entity : kjs$self().players()) {
m = Math.max(m, entity.kjs$runCommandSilent(command));
}

return m;
}

default ResourceLocation kjs$getDimension() {
return kjs$self().dimension().location();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dev.latvian.mods.kubejs.util.AttachedData;
import dev.latvian.mods.rhino.util.RemapForJS;

public interface WithAttachedData<T> {
public interface WithAttachedData<T> extends MessageSenderKJS {
@RemapForJS("getData")
AttachedData<T> kjs$getData();
}

0 comments on commit ea2856e

Please sign in to comment.