Network
This commit is contained in:
parent
ca41720a9c
commit
74192a7f8b
|
|
@ -208,7 +208,7 @@ public abstract class WDScreen extends Screen {
|
|||
else if(Mouse.getEventButton() == -1)
|
||||
onMouseMove(x, y);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleKeyboardInput() throws IOException {
|
||||
super.handleKeyboardInput();
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ import net.minecraft.server.level.ServerPlayer;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageOpenGui;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -34,7 +36,7 @@ public abstract class GuiData {
|
|||
public abstract String getName();
|
||||
|
||||
public void sendTo(ServerPlayer player) {
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageOpenGui(this), player);
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new CMessageOpenGui(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.client.gui.GuiScreenConfig;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageOpenGui;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
|
|
@ -78,8 +80,8 @@ public class ScreenConfigData extends GuiData {
|
|||
return this;
|
||||
}
|
||||
|
||||
public void sendTo(NetworkRegistry.TargetPoint tp) {
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(new CMessageOpenGui(this), tp);
|
||||
public void sendTo(PacketDistributor.TargetPoint tp) {
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> tp), new CMessageOpenGui(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import net.minecraft.util.EnumActionResult;
|
|||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.core.CraftComponent;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
import net.montoyo.wd.net.client.CMessageACResult;
|
||||
import net.montoyo.wd.net.client.*;
|
||||
import net.montoyo.wd.net.server.*;
|
||||
|
||||
public class Messages {
|
||||
|
||||
|
|
@ -28,12 +29,21 @@ public class Messages {
|
|||
@OnlyIn(Dist.CLIENT)
|
||||
@SubscribeEvent
|
||||
public static void registryNetworkPackets (FMLClientSetupEvent event) {
|
||||
INSTANCE.registerMessage(index++, CMessageACResult.class, CMessageACResult::encode, CMessageACResult::decode, CMessageACResult::handle);
|
||||
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registryNetworkPackets (FMLCommonSetupEvent event) {
|
||||
|
||||
INSTANCE.registerMessage(index++, CMessageACResult.class, CMessageACResult::encode, CMessageACResult::decode, CMessageACResult::handle);
|
||||
INSTANCE.registerMessage(index++, CMessageAddScreen.class, CMessageAddScreen::encode, CMessageAddScreen::decode, CMessageAddScreen::handle);
|
||||
INSTANCE.registerMessage(index++, CMessageCloseGui.class, CMessageCloseGui::encode, CMessageCloseGui::decode, CMessageCloseGui::handle);
|
||||
INSTANCE.registerMessage(index++, CMessageJSResponse.class, CMessageJSResponse::encode, CMessageJSResponse::decode, CMessageJSResponse::handle);
|
||||
INSTANCE.registerMessage(index++, CMessageMiniservKey.class, CMessageMiniservKey::encode, CMessageMiniservKey::decode, CMessageMiniservKey::handle);
|
||||
INSTANCE.registerMessage(index++, CMessageScreenUpdate.class, CMessageScreenUpdate::encode, CMessageScreenUpdate::decode, CMessageScreenUpdate::handle);
|
||||
INSTANCE.registerMessage(index++, CMessageServerInfo.class, CMessageServerInfo::encode, CMessageServerInfo::decode, CMessageServerInfo::handle);
|
||||
INSTANCE.registerMessage(index++, SMessageACQuery.class, SMessageACQuery::encode, SMessageACQuery::decode, SMessageACQuery::handle);
|
||||
INSTANCE.registerMessage(index++, SMessageMiniservConnect.class, SMessageMiniservConnect::encode, SMessageMiniservConnect::decode, SMessageMiniservConnect::handle);
|
||||
INSTANCE.registerMessage(index++, SMessageRedstoneCtrl.class, SMessageRedstoneCtrl::encode, SMessageRedstoneCtrl::decode, SMessageRedstoneCtrl::handle);
|
||||
INSTANCE.registerMessage(index++, SMessageRequestTEData.class, SMessageRequestTEData::encode, SMessageRequestTEData::decode, SMessageRequestTEData::handle);
|
||||
INSTANCE.registerMessage(index++, SMessageScreenCtrl.class, SMessageScreenCtrl::encode, SMessageScreenCtrl::decode, SMessageScreenCtrl::handle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,12 +37,19 @@ public class CMessageAddScreen {
|
|||
screens = toSend;
|
||||
}
|
||||
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
clear = buf.readBoolean();
|
||||
pos = new Vector3i(buf);
|
||||
public CMessageAddScreen(boolean clear, Vector3i pos, TileEntityScreen.Screen[] screens) {
|
||||
this.clear = clear;
|
||||
this.pos = pos;
|
||||
this.screens = screens;
|
||||
}
|
||||
|
||||
public static CMessageAddScreen decode(FriendlyByteBuf buf) {
|
||||
boolean clear = buf.readBoolean();
|
||||
Vector3i pos = new Vector3i(buf);
|
||||
|
||||
int cnt = buf.readByte() & 7;
|
||||
|
||||
screens = new TileEntityScreen.Screen[cnt];
|
||||
TileEntityScreen.Screen[] screens = new TileEntityScreen.Screen[cnt];
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
screens[i] = new TileEntityScreen.Screen();
|
||||
screens[i].side = BlockSide.values()[buf.readByte()];
|
||||
|
|
@ -57,9 +64,11 @@ public class CMessageAddScreen {
|
|||
for (int j = 0; j < numUpgrades; j++)
|
||||
screens[i].upgrades.add(buf.readItem());
|
||||
}
|
||||
|
||||
return new CMessageAddScreen(clear, pos, screens);
|
||||
}
|
||||
|
||||
public CMessageAddScreen encode(FriendlyByteBuf buf) {
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeBoolean(clear);
|
||||
pos.writeTo(buf);
|
||||
buf.writeByte(screens.length);
|
||||
|
|
@ -76,7 +85,6 @@ public class CMessageAddScreen {
|
|||
for (ItemStack is : scr.upgrades)
|
||||
buf.writeItem(is);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
|
|
|
|||
|
|
@ -28,21 +28,20 @@ public class CMessageCloseGui {
|
|||
blockSide = side;
|
||||
}
|
||||
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
public static CMessageCloseGui decode(FriendlyByteBuf buf) {
|
||||
int x, y, z, side;
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
side = buf.readByte();
|
||||
|
||||
blockPos = new BlockPos(x, y, z);
|
||||
if(side <= 0)
|
||||
blockSide = null;
|
||||
else
|
||||
blockSide = BlockSide.values()[side - 1];
|
||||
BlockPos blockPos = new BlockPos(x, y, z);
|
||||
BlockSide blockSide = side <= 0 ? null : BlockSide.values()[side - 1];
|
||||
|
||||
return new CMessageCloseGui(blockPos, blockSide);
|
||||
}
|
||||
|
||||
public CMessageCloseGui encode(FriendlyByteBuf buf) {
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeInt(blockPos.getX());
|
||||
buf.writeInt(blockPos.getY());
|
||||
buf.writeInt(blockPos.getZ());
|
||||
|
|
@ -52,8 +51,6 @@ public class CMessageCloseGui {
|
|||
} else {
|
||||
buf.writeByte(blockSide.ordinal() + 1);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
|
|
|
|||
|
|
@ -36,21 +36,29 @@ public class CMessageJSResponse {
|
|||
errString = err;
|
||||
}
|
||||
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
id = buf.readInt();
|
||||
type = JSServerRequest.fromID(buf.readByte());
|
||||
success = buf.readBoolean();
|
||||
public static CMessageJSResponse decode(FriendlyByteBuf buf) {
|
||||
int id = buf.readInt();
|
||||
JSServerRequest type = JSServerRequest.fromID(buf.readByte());
|
||||
boolean success = buf.readBoolean();
|
||||
|
||||
byte[] data = null;
|
||||
|
||||
int errCode;
|
||||
String errString;
|
||||
|
||||
if(success) {
|
||||
data = new byte[buf.readByte()];
|
||||
buf.readBytes(data);
|
||||
|
||||
return new CMessageJSResponse(id, type, data);
|
||||
} else {
|
||||
errCode = buf.readInt();
|
||||
errString = buf.readUtf();
|
||||
return new CMessageJSResponse(id, type, errCode, errString);
|
||||
}
|
||||
}
|
||||
|
||||
public CMessageJSResponse encode(FriendlyByteBuf buf) {
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeInt(id);
|
||||
buf.writeByte(type.ordinal());
|
||||
buf.writeBoolean(success);
|
||||
|
|
@ -62,7 +70,6 @@ public class CMessageJSResponse {
|
|||
buf.writeInt(errCode);
|
||||
buf.writeUtf(errString);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
|
|
|
|||
|
|
@ -21,15 +21,15 @@ public class CMessageMiniservKey {
|
|||
encryptedKey = key;
|
||||
}
|
||||
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
encryptedKey = new byte[buf.readShort() & 0xFFFF];
|
||||
public static CMessageMiniservKey decode(FriendlyByteBuf buf) {
|
||||
byte[] encryptedKey = new byte[buf.readShort() & 0xFFFF];
|
||||
buf.readBytes(encryptedKey);
|
||||
return new CMessageMiniservKey(encryptedKey);
|
||||
}
|
||||
|
||||
public CMessageMiniservKey encode(FriendlyByteBuf buf) {
|
||||
buf.writeShort(encryptedKey.length);
|
||||
buf.writeBytes(encryptedKey);
|
||||
return new CMessageMiniservKey(encryptedKey);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,15 @@
|
|||
package net.montoyo.wd.net.client;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.data.GuiData;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
|
||||
public class CMessageOpenGui {
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageOpenGui implements Runnable {
|
||||
|
||||
private GuiData data;
|
||||
|
||||
|
|
@ -30,9 +33,8 @@ public class CMessageOpenGui {
|
|||
data = (GuiData) Util.unserialize(buf, cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CMessageOpenGui encode(FriendlyByteBuf buf) {
|
||||
ByteBufUtils.writeUTF8String(buf, data.getName());
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(data.getName());
|
||||
Util.serialize(buf, data);
|
||||
}
|
||||
|
||||
|
|
@ -41,4 +43,7 @@ public class CMessageOpenGui {
|
|||
WebDisplays.PROXY.displayGui(data);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,34 +164,39 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
pos = new Vector3i(buf);
|
||||
side = BlockSide.values()[buf.readByte()];
|
||||
action = buf.readByte();
|
||||
public static CMessageScreenUpdate decode(FriendlyByteBuf buf) {
|
||||
Vector3i pos = new Vector3i(buf);
|
||||
BlockSide side = BlockSide.values()[buf.readByte()];
|
||||
byte action = buf.readByte();
|
||||
|
||||
if(action == UPDATE_URL || action == UPDATE_TYPE || action == UPDATE_RUN_JS)
|
||||
string = buf.readUtf();
|
||||
else if(action == UPDATE_MOUSE) {
|
||||
mouseEvent = buf.readByte();
|
||||
CMessageScreenUpdate message = new CMessageScreenUpdate();
|
||||
message.pos = pos;
|
||||
message.side = side;
|
||||
message.action = action;
|
||||
|
||||
if(mouseEvent != MOUSE_UP)
|
||||
vec2i = new Vector2i(buf);
|
||||
} else if(action == UPDATE_RESOLUTION)
|
||||
vec2i = new Vector2i(buf);
|
||||
else if(action == UPDATE_UPGRADES) {
|
||||
upgrades = new ItemStack[buf.readByte()];
|
||||
switch (action) {
|
||||
case UPDATE_URL, UPDATE_TYPE, UPDATE_RUN_JS -> message.string = buf.readUtf();
|
||||
case UPDATE_MOUSE -> {
|
||||
message.mouseEvent = buf.readByte();
|
||||
if (message.mouseEvent != MOUSE_UP)
|
||||
message.vec2i = new Vector2i(buf);
|
||||
}
|
||||
case UPDATE_RESOLUTION -> message.vec2i = new Vector2i(buf);
|
||||
case UPDATE_UPGRADES -> {
|
||||
message.upgrades = new ItemStack[buf.readByte()];
|
||||
for (int i = 0; i < message.upgrades.length; i++)
|
||||
message.upgrades[i] = buf.readItem();
|
||||
}
|
||||
case UPDATE_JS_REDSTONE -> {
|
||||
message.vec2i = new Vector2i(buf);
|
||||
message.redstoneLevel = buf.readByte();
|
||||
}
|
||||
case UPDATE_OWNER -> message.owner = new NameUUIDPair(buf);
|
||||
case UPDATE_ROTATION -> message.rotation = Rotation.values()[buf.readByte() & 3];
|
||||
case UPDATE_AUTO_VOL -> message.autoVolume = buf.readBoolean();
|
||||
}
|
||||
|
||||
for(int i = 0; i < upgrades.length; i++)
|
||||
upgrades[i] = buf.readItem();
|
||||
} else if(action == UPDATE_JS_REDSTONE) {
|
||||
vec2i = new Vector2i(buf);
|
||||
redstoneLevel = buf.readByte();
|
||||
} else if(action == UPDATE_OWNER)
|
||||
owner = new NameUUIDPair(buf);
|
||||
else if(action == UPDATE_ROTATION)
|
||||
rotation = Rotation.values()[buf.readByte() & 3];
|
||||
else if(action == UPDATE_AUTO_VOL)
|
||||
autoVolume = buf.readBoolean();
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ public class CMessageServerInfo {
|
|||
miniservPort = msPort;
|
||||
}
|
||||
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
miniservPort = buf.readShort() & 0xFFFF;
|
||||
public static CMessageServerInfo decode(FriendlyByteBuf buf) {
|
||||
return new CMessageServerInfo(buf.readShort() & 0xFFFF);
|
||||
}
|
||||
|
||||
public CMessageServerInfo encode(FriendlyByteBuf buf) {
|
||||
|
|
|
|||
|
|
@ -5,25 +5,19 @@
|
|||
package net.montoyo.wd.net.server;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.net.Message;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageACResult;
|
||||
import net.montoyo.wd.utilities.NameUUIDPair;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SMessageACQuery {
|
||||
public class SMessageACQuery implements Runnable {
|
||||
|
||||
private ServerPlayer player;
|
||||
private String beginning;
|
||||
|
|
@ -34,20 +28,18 @@ public class SMessageACQuery {
|
|||
matchExact = exact;
|
||||
}
|
||||
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
beginning = buf.readUtf();
|
||||
matchExact = buf.readBoolean();
|
||||
public static SMessageACQuery decode(FriendlyByteBuf buf) {
|
||||
return new SMessageACQuery(buf.readUtf(), buf.readBoolean());
|
||||
}
|
||||
|
||||
public SMessageACQuery encode(FriendlyByteBuf buf) {
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(beginning);
|
||||
buf.writeBoolean(matchExact);
|
||||
return new SMessageACQuery(beginning, matchExact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
GameProfile[] profiles = ;
|
||||
GameProfile[] profiles = WebDisplays.PROXY.getOnlineGameProfiles();
|
||||
NameUUIDPair[] result;
|
||||
|
||||
if(matchExact)
|
||||
|
|
@ -57,18 +49,12 @@ public class SMessageACQuery {
|
|||
result = Arrays.stream(profiles).filter(gp -> gp.getName().toLowerCase().startsWith(lBeg)).map(NameUUIDPair::new).toArray(NameUUIDPair[]::new);
|
||||
}
|
||||
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageACResult(result), player);
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new CMessageACResult(result));
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SMessageACQuery, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SMessageACQuery msg, MessageContext ctx) {
|
||||
msg.player = ctx.getServerHandler().player;
|
||||
((WorldServer) msg.player.world).addScheduledTask(msg);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
player = contextSupplier.get().getSender();
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,16 @@
|
|||
|
||||
package net.montoyo.wd.net.server;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.miniserv.server.ClientManager;
|
||||
import net.montoyo.wd.miniserv.server.Server;
|
||||
import net.montoyo.wd.net.Message;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageMiniservKey;
|
||||
|
||||
@Message(messageId = 10, side = Side.SERVER)
|
||||
public class SMessageMiniservConnect implements IMessage {
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SMessageMiniservConnect {
|
||||
|
||||
private byte[] modulus;
|
||||
private byte[] exponent;
|
||||
|
|
@ -28,35 +26,31 @@ public class SMessageMiniservConnect implements IMessage {
|
|||
exponent = exp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public static SMessageMiniservConnect decode(FriendlyByteBuf buf) {
|
||||
int sz = buf.readShort() & 0xFFFF;
|
||||
modulus = new byte[sz];
|
||||
byte[] modulus = new byte[sz];
|
||||
buf.readBytes(modulus);
|
||||
|
||||
sz = buf.readShort() & 0xFFFF;
|
||||
exponent = new byte[sz];
|
||||
byte[] exponent = new byte[sz];
|
||||
buf.readBytes(exponent);
|
||||
|
||||
return new SMessageMiniservConnect(modulus, exponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeShort(modulus.length);
|
||||
buf.writeBytes(modulus);
|
||||
buf.writeShort(exponent.length);
|
||||
buf.writeBytes(exponent);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SMessageMiniservConnect, IMessage> {
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
ClientManager cliMgr = Server.getInstance().getClientManager();
|
||||
byte[] encKey = cliMgr.encryptClientKey(contextSupplier.get().getSender().getGameProfile().getId(), modulus, exponent);
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SMessageMiniservConnect msg, MessageContext ctx) {
|
||||
ClientManager cliMgr = Server.getInstance().getClientManager();
|
||||
byte[] encKey = cliMgr.encryptClientKey(ctx.getServerHandler().player.getGameProfile().getId(), msg.modulus, msg.exponent);
|
||||
|
||||
return encKey == null ? null : new CMessageMiniservKey(encKey);
|
||||
if (encKey != null) {
|
||||
Messages.INSTANCE.sendToServer(new CMessageMiniservKey(encKey));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,25 @@
|
|||
package net.montoyo.wd.net.server;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.entity.TileEntityRedCtrl;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
|
|
@ -22,11 +31,12 @@ import net.montoyo.wd.net.Message;
|
|||
import net.montoyo.wd.utilities.Util;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
@Message(messageId = 8, side = Side.SERVER)
|
||||
public class SMessageRedstoneCtrl implements IMessage, Runnable {
|
||||
import java.util.function.Supplier;
|
||||
|
||||
private EntityPlayer player;
|
||||
private int dimension;
|
||||
public class SMessageRedstoneCtrl implements Runnable {
|
||||
|
||||
private Player player;
|
||||
private ResourceLocation dimension;
|
||||
private Vector3i pos;
|
||||
private String risingEdgeURL;
|
||||
private String fallingEdgeURL;
|
||||
|
|
@ -34,7 +44,7 @@ public class SMessageRedstoneCtrl implements IMessage, Runnable {
|
|||
public SMessageRedstoneCtrl() {
|
||||
}
|
||||
|
||||
public SMessageRedstoneCtrl(int d, Vector3i p, String r, String f) {
|
||||
public SMessageRedstoneCtrl(ResourceLocation d, Vector3i p, String r, String f) {
|
||||
dimension = d;
|
||||
pos = p;
|
||||
risingEdgeURL = r;
|
||||
|
|
@ -43,14 +53,14 @@ public class SMessageRedstoneCtrl implements IMessage, Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
World world = player.world;
|
||||
Level world = player.level;
|
||||
BlockPos blockPos = pos.toBlock();
|
||||
final double maxRange = player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue();
|
||||
final double maxRange = player.getAttribute(ForgeMod.REACH_DISTANCE.get()).getValue();
|
||||
|
||||
if(world.provider.getDimension() != dimension || player.getDistanceSq(blockPos) > maxRange * maxRange)
|
||||
if(!world.dimension().location().equals(dimension) || player.distanceToSqr(blockPos.getX(), blockPos.getY(), blockPos.getZ()) > maxRange * maxRange)
|
||||
return;
|
||||
|
||||
TileEntity te = player.world.getTileEntity(blockPos);
|
||||
BlockEntity te = world.getBlockEntity(blockPos);
|
||||
if(te == null || !(te instanceof TileEntityRedCtrl))
|
||||
return;
|
||||
|
||||
|
|
@ -70,30 +80,19 @@ public class SMessageRedstoneCtrl implements IMessage, Runnable {
|
|||
redCtrl.setURLs(risingEdgeURL, fallingEdgeURL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
dimension = buf.readInt();
|
||||
pos = new Vector3i(buf);
|
||||
risingEdgeURL = ByteBufUtils.readUTF8String(buf);
|
||||
fallingEdgeURL = ByteBufUtils.readUTF8String(buf);
|
||||
public static SMessageRedstoneCtrl decode(FriendlyByteBuf buf) {
|
||||
return new SMessageRedstoneCtrl(buf.readResourceLocation(), new Vector3i(buf), buf.readUtf(), buf.readUtf());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(dimension);
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeResourceLocation(dimension);
|
||||
pos.writeTo(buf);
|
||||
ByteBufUtils.writeUTF8String(buf, risingEdgeURL);
|
||||
ByteBufUtils.writeUTF8String(buf, fallingEdgeURL);
|
||||
buf.writeUtf(risingEdgeURL);
|
||||
buf.writeUtf(fallingEdgeURL);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SMessageRedstoneCtrl, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SMessageRedstoneCtrl msg, MessageContext ctx) {
|
||||
msg.player = ctx.getServerHandler().player;
|
||||
((WorldServer) msg.player.world).addScheduledTask(msg);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
player = contextSupplier.get().getSender();
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,56 +5,61 @@
|
|||
package net.montoyo.wd.net.server;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.Message;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
@Message(messageId = 1, side = Side.SERVER)
|
||||
public class SMessageRequestTEData implements IMessage, Runnable {
|
||||
import java.util.function.Supplier;
|
||||
|
||||
private int dim;
|
||||
public class SMessageRequestTEData implements Runnable {
|
||||
|
||||
private ResourceLocation dim;
|
||||
private Vector3i pos;
|
||||
private EntityPlayerMP player;
|
||||
private ServerPlayer player;
|
||||
|
||||
public SMessageRequestTEData() {
|
||||
}
|
||||
|
||||
public SMessageRequestTEData(TileEntity te) {
|
||||
dim = te.getWorld().provider.getDimension();
|
||||
pos = new Vector3i(te.getPos());
|
||||
public SMessageRequestTEData(BlockEntity te) {
|
||||
dim = te.getLevel().dimension().location();
|
||||
pos = new Vector3i(te.getBlockPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
dim = buf.readInt();
|
||||
pos = new Vector3i(buf);
|
||||
public SMessageRequestTEData(ResourceLocation dim, Vector3i pos) {
|
||||
this.dim = dim;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(dim);
|
||||
public static SMessageRequestTEData decode(FriendlyByteBuf buf) {
|
||||
return new SMessageRequestTEData(buf.readResourceLocation(), new Vector3i(buf));
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeResourceLocation(dim);
|
||||
pos.writeTo(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(player.world.provider.getDimension() != dim)
|
||||
if(!player.level.dimension().location().equals(dim))
|
||||
return;
|
||||
|
||||
BlockPos bp = pos.toBlock();
|
||||
if(player.getDistanceSq(bp) > 512.0 * 512.0)
|
||||
if(player.distanceToSqr(bp.getX(), bp.getY(), bp.getZ()) > 512.0 * 512.0)
|
||||
return;
|
||||
|
||||
TileEntity te = player.world.getTileEntity(bp);
|
||||
BlockEntity te = player.level.getBlockEntity(bp);
|
||||
if(te == null) {
|
||||
Log.error("MesageRequestTEData: Can't request data of null tile entity at %s", pos.toString());
|
||||
return;
|
||||
|
|
@ -64,15 +69,8 @@ public class SMessageRequestTEData implements IMessage, Runnable {
|
|||
((TileEntityScreen) te).requestData(player);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SMessageRequestTEData, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SMessageRequestTEData message, MessageContext ctx) {
|
||||
message.player = ctx.getServerHandler().player;
|
||||
((WorldServer) message.player.world).addScheduledTask(message);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
player = contextSupplier.get().getSender();
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,20 +4,29 @@
|
|||
|
||||
package net.montoyo.wd.net.server;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.block.BlockPeripheral;
|
||||
import net.montoyo.wd.core.DefaultPeripheral;
|
||||
|
|
@ -28,6 +37,8 @@ import net.montoyo.wd.entity.TileEntityScreen;
|
|||
import net.montoyo.wd.net.Message;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Message(messageId = 2, side = Side.SERVER)
|
||||
public class SMessageScreenCtrl implements IMessage, Runnable {
|
||||
|
||||
|
|
@ -48,12 +59,12 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
public static final int CTRL_SET_AUTO_VOL = 14;
|
||||
|
||||
private int ctrl;
|
||||
private int dim;
|
||||
private ResourceLocation dim;
|
||||
private Vector3i pos;
|
||||
private BlockSide side;
|
||||
private String url;
|
||||
private NameUUIDPair friend;
|
||||
private EntityPlayerMP player;
|
||||
private ServerPlayer player;
|
||||
private int friendRights;
|
||||
private int otherRights;
|
||||
private Vector2i vec2i;
|
||||
|
|
@ -73,8 +84,8 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
public static SMessageScreenCtrl setURL(TileEntityScreen tes, BlockSide side, String url, Vector3i remoteLocation) {
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = (remoteLocation == null) ? CTRL_SET_URL : CTRL_SET_URL_REMOTE;
|
||||
ret.dim = tes.getWorld().provider.getDimension();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.url = url;
|
||||
|
||||
|
|
@ -86,16 +97,16 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
|
||||
public SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, NameUUIDPair friend, boolean del) {
|
||||
ctrl = del ? CTRL_REMOVE_FRIEND : CTRL_ADD_FRIEND;
|
||||
dim = tes.getWorld().provider.getDimension();
|
||||
pos = new Vector3i(tes.getPos());
|
||||
dim = tes.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
this.friend = friend;
|
||||
}
|
||||
|
||||
public SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, int fr, int or) {
|
||||
ctrl = CTRL_SET_RIGHTS;
|
||||
dim = tes.getWorld().provider.getDimension();
|
||||
pos = new Vector3i(tes.getPos());
|
||||
dim = tes.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
friendRights = fr;
|
||||
otherRights = or;
|
||||
|
|
@ -103,16 +114,16 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
|
||||
public SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, ItemStack toRem) {
|
||||
ctrl = CTRL_REMOVE_UPGRADE;
|
||||
dim = tes.getWorld().provider.getDimension();
|
||||
pos = new Vector3i(tes.getPos());
|
||||
dim = tes.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
toRemove = toRem;
|
||||
}
|
||||
|
||||
public SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, Rotation rot) {
|
||||
ctrl = CTRL_SET_ROTATION;
|
||||
dim = tes.getWorld().provider.getDimension();
|
||||
pos = new Vector3i(tes.getPos());
|
||||
dim = tes.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
rotation = rot;
|
||||
}
|
||||
|
|
@ -120,8 +131,8 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
public static SMessageScreenCtrl type(TileEntityScreen tes, BlockSide side, String text, BlockPos soundPos) {
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_TYPE;
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.dim = tes.getWorld().provider.getDimension();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.text = text;
|
||||
ret.soundPos = soundPos;
|
||||
|
|
@ -135,8 +146,8 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = ctrl;
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.dim = tes.getWorld().provider.getDimension();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.vec2i = vec;
|
||||
|
||||
|
|
@ -146,8 +157,8 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
public static SMessageScreenCtrl laserUp(TileEntityScreen tes, BlockSide side) {
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_LASER_UP;
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.dim = tes.getWorld().provider.getDimension();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
|
||||
return ret;
|
||||
|
|
@ -156,8 +167,8 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
public static SMessageScreenCtrl jsRequest(TileEntityScreen tes, BlockSide side, int reqId, JSServerRequest reqType, Object ... data) {
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_JS_REQUEST;
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.dim = tes.getWorld().provider.getDimension();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.jsReqID = reqId;
|
||||
ret.jsReqType = reqType;
|
||||
|
|
@ -169,8 +180,8 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
public static SMessageScreenCtrl autoVol(TileEntityScreen tes, BlockSide side, boolean av) {
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_SET_AUTO_VOL;
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.dim = tes.getWorld().provider.getDimension();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.autoVol = av;
|
||||
|
||||
|
|
@ -181,55 +192,56 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
return msg == CTRL_SET_RESOLUTION || msg == CTRL_LASER_DOWN || msg == CTRL_LASER_MOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
ctrl = buf.readByte();
|
||||
dim = buf.readInt();
|
||||
pos = new Vector3i(buf);
|
||||
side = BlockSide.fromInt(buf.readByte());
|
||||
public static SMessageScreenCtrl decode(FriendlyByteBuf buf) {
|
||||
SMessageScreenCtrl message = new SMessageScreenCtrl();
|
||||
message.ctrl = buf.readByte();
|
||||
message.dim = buf.readResourceLocation();
|
||||
message.pos = new Vector3i(buf);
|
||||
message.side = BlockSide.fromInt(buf.readByte());
|
||||
|
||||
if(ctrl == CTRL_SET_URL)
|
||||
url = ByteBufUtils.readUTF8String(buf);
|
||||
else if(ctrl == CTRL_ADD_FRIEND || ctrl == CTRL_REMOVE_FRIEND)
|
||||
friend = new NameUUIDPair(buf);
|
||||
else if(ctrl == CTRL_SET_RIGHTS) {
|
||||
friendRights = buf.readByte();
|
||||
otherRights = buf.readByte();
|
||||
} else if(isVec2Ctrl(ctrl))
|
||||
vec2i = new Vector2i(buf);
|
||||
else if(ctrl == CTRL_TYPE) {
|
||||
text = ByteBufUtils.readUTF8String(buf);
|
||||
if(message.ctrl == CTRL_SET_URL)
|
||||
message.url = buf.readUtf();
|
||||
else if(message.ctrl == CTRL_ADD_FRIEND || message.ctrl == CTRL_REMOVE_FRIEND)
|
||||
message.friend = new NameUUIDPair(buf);
|
||||
else if(message.ctrl == CTRL_SET_RIGHTS) {
|
||||
message.friendRights = buf.readByte();
|
||||
message.otherRights = buf.readByte();
|
||||
} else if(isVec2Ctrl(message.ctrl))
|
||||
message.vec2i = new Vector2i(buf);
|
||||
else if(message.ctrl == CTRL_TYPE) {
|
||||
message.text = buf.readUtf();
|
||||
|
||||
int sx = buf.readInt();
|
||||
int sy = buf.readInt();
|
||||
int sz = buf.readInt();
|
||||
soundPos = new BlockPos(sx, sy, sz);
|
||||
} else if(ctrl == CTRL_REMOVE_UPGRADE)
|
||||
toRemove = ByteBufUtils.readItemStack(buf);
|
||||
else if(ctrl == CTRL_JS_REQUEST) {
|
||||
jsReqID = buf.readInt();
|
||||
jsReqType = JSServerRequest.fromID(buf.readByte());
|
||||
message.soundPos = new BlockPos(sx, sy, sz);
|
||||
} else if(message.ctrl == CTRL_REMOVE_UPGRADE)
|
||||
message.toRemove = buf.readItem();
|
||||
else if(message.ctrl == CTRL_JS_REQUEST) {
|
||||
message.jsReqID = buf.readInt();
|
||||
message.jsReqType = JSServerRequest.fromID(buf.readByte());
|
||||
|
||||
if(jsReqType != null)
|
||||
jsReqData = jsReqType.deserialize(buf);
|
||||
} else if(ctrl == CTRL_SET_ROTATION)
|
||||
rotation = Rotation.values()[buf.readByte() & 3];
|
||||
else if(ctrl == CTRL_SET_URL_REMOTE) {
|
||||
url = ByteBufUtils.readUTF8String(buf);
|
||||
remoteLoc = new Vector3i(buf);
|
||||
} else if(ctrl == CTRL_SET_AUTO_VOL)
|
||||
autoVol = buf.readBoolean();
|
||||
if(message.jsReqType != null)
|
||||
message.jsReqData = message.jsReqType.deserialize(buf);
|
||||
} else if(message.ctrl == CTRL_SET_ROTATION)
|
||||
message.rotation = Rotation.values()[buf.readByte() & 3];
|
||||
else if(message.ctrl == CTRL_SET_URL_REMOTE) {
|
||||
message.url = buf.readUtf();
|
||||
message.remoteLoc = new Vector3i(buf);
|
||||
} else if(message.ctrl == CTRL_SET_AUTO_VOL)
|
||||
message.autoVol = buf.readBoolean();
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeByte(ctrl);
|
||||
buf.writeInt(dim);
|
||||
buf.writeResourceLocation(dim);
|
||||
pos.writeTo(buf);
|
||||
buf.writeByte(side.ordinal());
|
||||
|
||||
if(ctrl == CTRL_SET_URL)
|
||||
ByteBufUtils.writeUTF8String(buf, url);
|
||||
buf.writeUtf(url);
|
||||
else if(ctrl == CTRL_ADD_FRIEND || ctrl == CTRL_REMOVE_FRIEND)
|
||||
friend.writeTo(buf);
|
||||
else if(ctrl == CTRL_SET_RIGHTS) {
|
||||
|
|
@ -238,12 +250,12 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
} else if(isVec2Ctrl(ctrl))
|
||||
vec2i.writeTo(buf);
|
||||
else if(ctrl == CTRL_TYPE) {
|
||||
ByteBufUtils.writeUTF8String(buf, text);
|
||||
buf.writeUtf(text);
|
||||
buf.writeInt(soundPos.getX());
|
||||
buf.writeInt(soundPos.getY());
|
||||
buf.writeInt(soundPos.getZ());
|
||||
} else if(ctrl == CTRL_REMOVE_UPGRADE)
|
||||
ByteBufUtils.writeItemStack(buf, toRemove);
|
||||
buf.writeItem(toRemove);
|
||||
else if(ctrl == CTRL_JS_REQUEST) {
|
||||
buf.writeInt(jsReqID);
|
||||
buf.writeByte(jsReqType.ordinal());
|
||||
|
|
@ -253,7 +265,7 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
} else if(ctrl == CTRL_SET_ROTATION)
|
||||
buf.writeByte(rotation.ordinal());
|
||||
else if(ctrl == CTRL_SET_URL_REMOTE) {
|
||||
ByteBufUtils.writeUTF8String(buf, url);
|
||||
buf.writeUtf(url);
|
||||
remoteLoc.writeTo(buf);
|
||||
} else if(ctrl == CTRL_SET_AUTO_VOL)
|
||||
buf.writeBoolean(autoVol);
|
||||
|
|
@ -280,26 +292,26 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
}
|
||||
|
||||
private void runUnsafe() throws MissingPermissionException {
|
||||
World world = player.world;
|
||||
Level world = player.level;
|
||||
BlockPos bp = pos.toBlock();
|
||||
|
||||
if(world.provider.getDimension() != dim)
|
||||
if(!world.dimension().location().equals(dim))
|
||||
return; //Out of range (dimension mismatch)
|
||||
|
||||
if(ctrl == CTRL_SET_URL_REMOTE) {
|
||||
double reachDist = player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue();
|
||||
double reachDist = player.getAttributeValue(ForgeMod.REACH_DISTANCE.get());
|
||||
BlockPos blockPos = remoteLoc.toBlock();
|
||||
|
||||
if(player.getDistanceSq(blockPos) > reachDist * reachDist)
|
||||
if(player.distanceToSqr(blockPos.getX(), blockPos.getY(), blockPos.getZ()) > reachDist * reachDist)
|
||||
return; //Out of range (player reach distance)
|
||||
|
||||
IBlockState bs = world.getBlockState(blockPos);
|
||||
BlockState bs = world.getBlockState(blockPos);
|
||||
if(bs.getBlock() != WebDisplays.INSTANCE.blockPeripheral || bs.getValue(BlockPeripheral.type) != DefaultPeripheral.REMOTE_CONTROLLER)
|
||||
return; //I call it hax...
|
||||
} else if(player.getDistanceSq(bp) > 128.0 * 128.0)
|
||||
} else if(player.shouldRenderAtSqrDistance(player.distanceToSqr(bp.getX(), bp.getY(), bp.getZ())))
|
||||
return; //Out of range (range problem)
|
||||
|
||||
TileEntity te = world.getTileEntity(bp);
|
||||
BlockEntity te = world.getBlockEntity(bp);
|
||||
if(te == null || !(te instanceof TileEntityScreen)) {
|
||||
Log.error("TileEntity at %s is not a screen; can't control it!", pos.toString());
|
||||
return;
|
||||
|
|
@ -358,15 +370,9 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
Log.warning("Caught SMessageScreenCtrl with invalid control ID %d from player %s (UUID %s)", ctrl, player.getName(), player.getGameProfile().getId().toString());
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SMessageScreenCtrl, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SMessageScreenCtrl message, MessageContext ctx) {
|
||||
message.player = ctx.getServerHandler().player;
|
||||
((WorldServer) message.player.world).addScheduledTask(message);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
player = contextSupplier.get().getSender();
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user