Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Aug 26, 2024
1 parent 2fa602c commit 94895bc
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 42 deletions.
19 changes: 3 additions & 16 deletions src/main/java/dev/latvian/mods/kubejs/core/ClientPlayerKJS.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package dev.latvian.mods.kubejs.core;

import dev.latvian.mods.kubejs.KubeJS;
import dev.latvian.mods.kubejs.net.SendDataFromClientPayload;
import dev.latvian.mods.kubejs.player.PlayerStatsJS;
import dev.latvian.mods.kubejs.util.NotificationToastData;
import dev.latvian.mods.rhino.util.RemapPrefixForJS;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.nbt.CompoundTag;
import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.Nullable;

@RemapPrefixForJS("kjs$")
Expand All @@ -20,32 +15,24 @@ public interface ClientPlayerKJS extends PlayerKJS {
}

default boolean isSelf() {
return kjs$self() == KubeJS.PROXY.getClientPlayer();
return false;
}

@Override
default void kjs$sendData(String channel, @Nullable CompoundTag data) {
if (!channel.isEmpty()) {
PacketDistributor.sendToServer(new SendDataFromClientPayload(channel, data));
}
}

@Override
default PlayerStatsJS kjs$getStats() {
if (!isSelf()) {
throw new IllegalStateException("Can't access other client player stats!");
}

return new PlayerStatsJS(kjs$self(), ((LocalPlayer) kjs$self()).getStats());
throw new IllegalStateException("Can't access other client player stats!");
}

@Override
default boolean kjs$isMiningBlock() {
return isSelf() && Minecraft.getInstance().gameMode.isDestroying();
return false;
}

@Override
default void kjs$notify(NotificationToastData notification) {
notification.show();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package dev.latvian.mods.kubejs.core;

import dev.latvian.mods.kubejs.client.KubeSessionData;
import dev.latvian.mods.kubejs.net.SendDataFromClientPayload;
import dev.latvian.mods.kubejs.player.PlayerStatsJS;
import dev.latvian.mods.kubejs.util.NotificationToastData;
import dev.latvian.mods.rhino.util.RemapPrefixForJS;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.Nullable;

@RemapPrefixForJS("kjs$")
public interface LocalClientPlayerKJS extends ClientPlayerKJS {
@Override
default LocalPlayer kjs$self() {
return (LocalPlayer) this;
}

default Minecraft kjs$getMinecraft() {
return Minecraft.getInstance();
}

@Override
default void kjs$runCommand(String command) {
kjs$self().connection.sendCommand(command);
}

@Override
default void kjs$runCommandSilent(String command) {
kjs$self().connection.sendCommand(command);
}

@Override
default boolean isSelf() {
return true;
}

@Override
default void kjs$sendData(String channel, @Nullable CompoundTag data) {
if (!channel.isEmpty()) {
PacketDistributor.sendToServer(new SendDataFromClientPayload(channel, data));
}
}

@Override
default PlayerStatsJS kjs$getStats() {
return new PlayerStatsJS(kjs$self(), kjs$self().getStats());
}

@Override
default boolean kjs$isMiningBlock() {
return Minecraft.getInstance().gameMode.isDestroying();
}

@Override
default void kjs$notify(NotificationToastData notification) {
notification.show();
}

@Override
default void kjs$setActivePostShader(@Nullable ResourceLocation id) {
var sessionData = KubeSessionData.of(kjs$self().connection);

if (sessionData != null) {
sessionData.activePostShader = id;
var mc = kjs$getMinecraft();
mc.gameRenderer.checkEntityPostEffect(mc.options.getCameraType().isFirstPerson() ? mc.getCameraEntity() : null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package dev.latvian.mods.kubejs.core.mixin;

import com.mojang.authlib.GameProfile;
import dev.latvian.mods.kubejs.client.KubeSessionData;
import dev.latvian.mods.kubejs.core.LocalClientPlayerKJS;
import dev.latvian.mods.kubejs.kgui.action.ClientKGUIActions;
import dev.latvian.mods.kubejs.kgui.action.KGUIActions;
import dev.latvian.mods.rhino.util.RemapForJS;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.stats.StatsCounter;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Map;

@Mixin(LocalPlayer.class)
public abstract class LocalPlayerMixin extends AbstractClientPlayerMixin {
public abstract class LocalPlayerMixin extends AbstractClientPlayerMixin implements LocalClientPlayerKJS {
@Unique
private KGUIActions kjs$kguiActions;

Expand All @@ -42,24 +41,8 @@ public LocalPlayerMixin(Level level, BlockPos blockPos, float f, GameProfile gam
protected Minecraft minecraft;

@Override
public void kjs$runCommand(String command) {
connection.sendCommand(command);
}

@Override
public void kjs$runCommandSilent(String command) {
connection.sendCommand(command);
}

@Override
public void kjs$setActivePostShader(@Nullable ResourceLocation id) {
var sessionData = KubeSessionData.of(connection);

if (sessionData != null) {
sessionData.activePostShader = id;
minecraft.gameRenderer.checkEntityPostEffect(minecraft.options.getCameraType().isFirstPerson() ? minecraft.getCameraEntity() : null);
}
}
@Accessor("minecraft")
public abstract Minecraft kjs$getMinecraft();

@Override
public KGUIActions kjs$getKgui() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import dev.latvian.mods.kubejs.web.KJSWSSession;
import dev.latvian.mods.kubejs.web.LocalWebServer;
import dev.latvian.mods.kubejs.web.LocalWebServerRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.neoforged.fml.ModList;
import net.neoforged.neoforge.server.ServerLifecycleHooks;

import java.util.ArrayList;
import java.util.Optional;
Expand Down Expand Up @@ -81,10 +81,10 @@ public static void register(LocalWebServerRegistry registry) {
}

private static void reloadInternalServer() {
var mc = Minecraft.getInstance();
var server = ServerLifecycleHooks.getCurrentServer();

if (mc.player != null) {
mc.player.kjs$runCommand("/reload");
if (server != null) {
server.kjs$runCommand("/reload");
}
}

Expand Down

0 comments on commit 94895bc

Please sign in to comment.