redo like literally all of networking
This commit is contained in:
parent
ff55cbf1b2
commit
3c141d9e1b
|
|
@ -33,25 +33,21 @@ import net.minecraftforge.event.level.LevelEvent;
|
|||
import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.montoyo.wd.client.ClientProxy;
|
||||
import net.montoyo.wd.config.ModConfig;
|
||||
import net.montoyo.wd.core.*;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.init.ItemInit;
|
||||
import net.montoyo.wd.init.TileInit;
|
||||
import net.montoyo.wd.miniserv.server.Server;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageServerInfo;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageServerInfo;
|
||||
import net.montoyo.wd.utilities.DistSafety;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
|
|
@ -160,7 +156,7 @@ public class WebDisplays {
|
|||
padResX = padResY * PAD_RATIO;
|
||||
|
||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
bus.addListener(Messages::registryNetworkPackets);
|
||||
WDNetworkRegistry.init();
|
||||
SOUNDS.register(bus);
|
||||
onRegisterSounds();
|
||||
BlockInit.init(bus);
|
||||
|
|
@ -319,8 +315,7 @@ public class WebDisplays {
|
|||
@SubscribeEvent
|
||||
public void onLogIn(PlayerEvent.PlayerLoggedInEvent ev) {
|
||||
if(!ev.getEntity().getLevel().isClientSide && ev.getEntity() instanceof ServerPlayer) {
|
||||
IWDDCapability cap =
|
||||
ev.getEntity().getCapability(WDDCapability.Provider.cap, null).orElseThrow(RuntimeException::new);
|
||||
IWDDCapability cap = ev.getEntity().getCapability(WDDCapability.Provider.cap, null).orElseThrow(RuntimeException::new);
|
||||
|
||||
if(cap.isFirstRun()) {
|
||||
Util.toast(ev.getEntity(), ChatFormatting.LIGHT_PURPLE, "welcome1");
|
||||
|
|
@ -330,14 +325,13 @@ public class WebDisplays {
|
|||
cap.clearFirstRun();
|
||||
}
|
||||
|
||||
PacketDistributor.PacketTarget packetDistrutor = PacketDistributor.PLAYER
|
||||
.with(
|
||||
() ->
|
||||
(ServerPlayer) ev.getEntity());
|
||||
PacketDistributor.PacketTarget packetDistrutor = PacketDistributor.PLAYER.with(
|
||||
() -> (ServerPlayer) ev.getEntity()
|
||||
);
|
||||
|
||||
CMessageServerInfo message = new CMessageServerInfo(miniservPort);
|
||||
S2CMessageServerInfo message = new S2CMessageServerInfo(miniservPort);
|
||||
|
||||
Messages.INSTANCE.send(packetDistrutor, message);
|
||||
WDNetworkRegistry.INSTANCE.send(packetDistrutor, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,18 +6,12 @@ package net.montoyo.wd.block;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
|
|
@ -34,16 +28,11 @@ import net.minecraft.world.phys.shapes.Shapes;
|
|||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.core.DefaultPeripheral;
|
||||
import net.montoyo.wd.entity.TileEntityInterfaceBase;
|
||||
import net.montoyo.wd.entity.TileEntityKeyboard;
|
||||
import net.montoyo.wd.entity.TileEntityPeripheralBase;
|
||||
import net.montoyo.wd.entity.TileEntityServer;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.item.ItemLinker;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageCloseGui;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockKeyboardLeft extends BlockPeripheral {
|
||||
|
||||
|
|
@ -146,7 +135,7 @@ public class BlockKeyboardLeft extends BlockPeripheral {
|
|||
}
|
||||
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||
}
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ import net.minecraftforge.network.PacketDistributor;
|
|||
import net.montoyo.wd.core.IPeripheral;
|
||||
import net.montoyo.wd.entity.TileEntityKeyboard;
|
||||
import net.montoyo.wd.item.ItemLinker;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageCloseGui;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -60,7 +60,7 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
|
|||
}
|
||||
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||
}
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> BlockKeyboardLeft.point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> BlockKeyboardLeft.point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ package net.montoyo.wd.block;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
|
@ -40,10 +39,9 @@ import net.montoyo.wd.entity.TileEntityInterfaceBase;
|
|||
import net.montoyo.wd.entity.TileEntityKeyboard;
|
||||
import net.montoyo.wd.entity.TileEntityPeripheralBase;
|
||||
import net.montoyo.wd.entity.TileEntityServer;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.item.ItemLinker;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageCloseGui;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockPeripheral extends WDBlockContainer {
|
||||
|
|
@ -220,7 +218,7 @@ public class BlockPeripheral extends WDBlockContainer {
|
|||
removeRightPiece(world, pos);
|
||||
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||
// dropBlockAsItem(world, pos, state, 0); //TODO Loottable
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +228,7 @@ public class BlockPeripheral extends WDBlockContainer {
|
|||
if(state.getBlock() == this && state.getValue(type) == DefaultPeripheral.KEYBOARD)
|
||||
removeRightPiece(world, pos);
|
||||
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,21 +6,18 @@ package net.montoyo.wd.block;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
|
|
@ -30,17 +27,12 @@ import net.minecraft.world.level.block.state.properties.Property;
|
|||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.material.PushReaction;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.mcef.utilities.Log;
|
||||
import net.montoyo.wd.core.DefaultPeripheral;
|
||||
import net.montoyo.wd.entity.*;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.item.ItemLinker;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageCloseGui;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockRCTRL extends WDBlockContainer {
|
||||
|
|
@ -188,14 +180,14 @@ public class BlockRCTRL extends WDBlockContainer {
|
|||
if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) {
|
||||
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||
// dropBlockAsItem(world, pos, state, 0); //TODO Loottable
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {
|
||||
if(!world.isClientSide) {
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,21 +6,18 @@ package net.montoyo.wd.block;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
|
|
@ -30,17 +27,12 @@ import net.minecraft.world.level.block.state.properties.Property;
|
|||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.material.PushReaction;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.mcef.utilities.Log;
|
||||
import net.montoyo.wd.core.DefaultPeripheral;
|
||||
import net.montoyo.wd.entity.*;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.item.ItemLinker;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageCloseGui;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockRedCTRL extends WDBlockContainer {
|
||||
|
|
@ -188,14 +180,14 @@ public class BlockRedCTRL extends WDBlockContainer {
|
|||
if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) {
|
||||
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||
// dropBlockAsItem(world, pos, state, 0); //TODO Loottable
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {
|
||||
if(!world.isClientSide) {
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,7 @@
|
|||
|
||||
package net.montoyo.wd.block;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.Input;
|
||||
import net.minecraft.client.player.KeyboardInput;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
|
@ -35,25 +31,19 @@ import net.minecraft.world.level.block.state.properties.Property;
|
|||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.PushReaction;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.client.renderers.ScreenRenderer;
|
||||
import net.montoyo.wd.config.ModConfig;
|
||||
import net.montoyo.wd.core.DefaultUpgrade;
|
||||
import net.montoyo.wd.core.IUpgrade;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.data.SetURLData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.init.ItemInit;
|
||||
import net.montoyo.wd.item.WDItem;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockScreen extends BaseEntityBlock {
|
||||
|
||||
|
|
@ -247,7 +237,7 @@ public class BlockScreen extends BaseEntityBlock {
|
|||
created = true;
|
||||
}
|
||||
|
||||
te.addScreen(side, size, null, player, !created);
|
||||
te.addScreen(side, size, null, player, true);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,21 +6,18 @@ package net.montoyo.wd.block;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
|
|
@ -30,20 +27,15 @@ import net.minecraft.world.level.block.state.properties.Property;
|
|||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.material.PushReaction;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.mcef.utilities.Log;
|
||||
import net.montoyo.wd.core.DefaultPeripheral;
|
||||
import net.montoyo.wd.entity.TileEntityInterfaceBase;
|
||||
import net.montoyo.wd.entity.TileEntityKeyboard;
|
||||
import net.montoyo.wd.entity.TileEntityPeripheralBase;
|
||||
import net.montoyo.wd.entity.TileEntityServer;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.item.ItemLinker;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageCloseGui;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockServer extends WDBlockContainer{
|
||||
|
|
@ -189,14 +181,14 @@ public class BlockServer extends WDBlockContainer{
|
|||
if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) {
|
||||
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||
// dropBlockAsItem(world, pos, state, 0); //TODO Loottable
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {
|
||||
if(!world.isClientSide) {
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new CMessageCloseGui(pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,9 +65,8 @@ import net.montoyo.wd.init.ItemInit;
|
|||
import net.montoyo.wd.init.TileInit;
|
||||
import net.montoyo.wd.item.WDItem;
|
||||
import net.montoyo.wd.miniserv.client.Client;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.server.SMessagePadCtrl;
|
||||
import net.montoyo.wd.net.server.SMessageScreenCtrl;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageScreenCtrl;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
|
|
@ -179,8 +178,6 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
|
|||
mcef.registerDisplayHandler(this);
|
||||
//mcef.registerJSQueryHandler(this); //TODO why crashing on this method!
|
||||
findAdvancementToProgressField();
|
||||
String url = "https://www.google.com";
|
||||
new ScreenRenderer(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -428,7 +425,7 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
|
|||
pd.view.loadURL(WebDisplays.BLACKLIST_URL);
|
||||
else {
|
||||
pd.lastURLSent = t; //Avoid spamming the server with porn URLs
|
||||
Messages.INSTANCE.sendToServer(new SMessagePadCtrl(pd.id, url));
|
||||
// WDNetworkRegistry.INSTANCE.sendToServer(new SMessagePadCtrl(pd.id, url));
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -697,19 +694,19 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
|
|||
|
||||
if(t - lastPointPacket >= 100) {
|
||||
lastPointPacket = t;
|
||||
Messages.INSTANCE.sendToServer(SMessageScreenCtrl.vec2(tes, side, SMessageScreenCtrl.CTRL_LASER_MOVE, hit));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.vec2(tes, side, C2SMessageScreenCtrl.CTRL_LASER_MOVE, hit));
|
||||
}
|
||||
} else {
|
||||
deselectScreen();
|
||||
pointedScreen = tes;
|
||||
pointedScreenSide = side;
|
||||
Messages.INSTANCE.sendToServer(SMessageScreenCtrl.vec2(tes, side, SMessageScreenCtrl.CTRL_LASER_DOWN, hit));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.vec2(tes, side, C2SMessageScreenCtrl.CTRL_LASER_DOWN, hit));
|
||||
}
|
||||
}
|
||||
|
||||
private void deselectScreen() {
|
||||
if(pointedScreen != null && pointedScreenSide != null) {
|
||||
Messages.INSTANCE.sendToServer(SMessageScreenCtrl.laserUp(pointedScreen, pointedScreenSide));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserUp(pointedScreen, pointedScreenSide));
|
||||
pointedScreen = null;
|
||||
pointedScreenSide = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,15 +12,14 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.montoyo.mcef.api.IBrowser;
|
||||
import net.montoyo.mcef.api.IJSQueryCallback;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.block.BlockScreen;
|
||||
import net.montoyo.wd.core.DefaultUpgrade;
|
||||
import net.montoyo.wd.core.IScreenQueryHandler;
|
||||
import net.montoyo.wd.core.IUpgrade;
|
||||
import net.montoyo.wd.core.JSServerRequest;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.server.SMessageScreenCtrl;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageScreenCtrl;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -215,7 +214,7 @@ public final class JSQueryDispatcher {
|
|||
ServerQuery ret = new ServerQuery(tes, side, cb);
|
||||
serverQueries.add(ret);
|
||||
|
||||
Messages.INSTANCE.sendToServer(SMessageScreenCtrl.jsRequest(tes, side, ret.id, type, data));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.jsRequest(tes, side, ret.id, type, data));
|
||||
}
|
||||
|
||||
private void registerDefaults() {
|
||||
|
|
|
|||
|
|
@ -18,21 +18,19 @@ import net.montoyo.wd.client.gui.controls.Control;
|
|||
import net.montoyo.wd.client.gui.controls.Label;
|
||||
import net.montoyo.wd.client.gui.loading.FillControl;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.server.SMessageScreenCtrl;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageScreenCtrl;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.TypeData;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.cef.browser.CefBrowserOsr;
|
||||
import org.vivecraft.gameplay.VRPlayer;
|
||||
import org.vivecraft.gameplay.screenhandlers.KeyboardHandler;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
@ -181,7 +179,7 @@ public class GuiKeyboard extends WDScreen {
|
|||
@Override
|
||||
protected void sync() {
|
||||
if(!evStack.isEmpty()) {
|
||||
Messages.INSTANCE.sendToServer(SMessageScreenCtrl.type(tes, side, WebDisplays.GSON.toJson(evStack), kbPos));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.type(tes, side, WebDisplays.GSON.toJson(evStack), kbPos));
|
||||
evStack.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import net.montoyo.wd.client.ClientProxy;
|
|||
import net.montoyo.wd.client.gui.controls.Button;
|
||||
import net.montoyo.wd.client.gui.controls.TextField;
|
||||
import net.montoyo.wd.client.gui.loading.FillControl;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.server.SMessageRedstoneCtrl;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageRedstoneCtrl;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
|
@ -60,7 +60,7 @@ public class GuiRedstoneCtrl extends WDScreen {
|
|||
|
||||
String rising = mcef.punycode(Util.addProtocol(tfRisingEdge.getText()));
|
||||
String falling = mcef.punycode(Util.addProtocol(tfFallingEdge.getText()));
|
||||
Messages.INSTANCE.sendToServer(new SMessageRedstoneCtrl(dimension, pos, rising, falling));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(new C2SMessageRedstoneCtrl(pos, rising, falling));
|
||||
}
|
||||
|
||||
minecraft.setScreen(null);
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ import net.montoyo.wd.client.gui.loading.FillControl;
|
|||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.item.WDItem;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.server.SMessageScreenCtrl;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageScreenCtrl;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
@ -201,7 +201,7 @@ public class GuiScreenConfig extends WDScreen {
|
|||
throw new NumberFormatException(); //I'm lazy
|
||||
|
||||
if(x != scr.resolution.x || y != scr.resolution.y)
|
||||
Messages.INSTANCE.sendToServer(SMessageScreenCtrl.vec2(tes, side, SMessageScreenCtrl.CTRL_SET_RESOLUTION, new Vector2i(x, y)));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.vec2(tes, side, C2SMessageScreenCtrl.CTRL_SET_RESOLUTION, new Vector2i(x, y)));
|
||||
} catch(NumberFormatException ex) {
|
||||
//Roll back
|
||||
tfResX.setText("" + scr.resolution.x);
|
||||
|
|
@ -219,7 +219,7 @@ public class GuiScreenConfig extends WDScreen {
|
|||
clickSetRes();
|
||||
else if(ev.getSource() == btnChangeRot) {
|
||||
Rotation[] rots = Rotation.values();
|
||||
Messages.INSTANCE.sendToServer(new SMessageScreenCtrl(tes, side, rots[(rotation.ordinal() + 1) % rots.length]));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(new C2SMessageScreenCtrl(tes, side, rots[(rotation.ordinal() + 1) % rots.length]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -282,7 +282,7 @@ public class GuiScreenConfig extends WDScreen {
|
|||
@GuiSubscribe
|
||||
public void onRemovePlayer(List.EntryClick ev) {
|
||||
if(ev.getSource() == lstFriends)
|
||||
Messages.INSTANCE.sendToServer(new SMessageScreenCtrl(tes, side, (NameUUIDPair) ev.getUserdata(), true));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(new C2SMessageScreenCtrl(tes, side, (NameUUIDPair) ev.getUserdata(), true));
|
||||
}
|
||||
|
||||
@GuiSubscribe
|
||||
|
|
@ -312,13 +312,12 @@ public class GuiScreenConfig extends WDScreen {
|
|||
} catch(NumberFormatException ex) {
|
||||
cbLockRatio.setChecked(false);
|
||||
}
|
||||
} else if(ev.getSource() == cbAutoVolume)
|
||||
Messages.INSTANCE.sendToServer(SMessageScreenCtrl.autoVol(tes, side, ev.isChecked()));
|
||||
} else if(ev.getSource() == cbAutoVolume) WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.autoVol(tes, side, ev.isChecked()));
|
||||
}
|
||||
|
||||
@GuiSubscribe
|
||||
public void onRemoveUpgrade(UpgradeGroup.ClickEvent ev) {
|
||||
Messages.INSTANCE.sendToServer(new SMessageScreenCtrl(tes, side, ev.getMouseOverStack()));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(new C2SMessageScreenCtrl(tes, side, ev.getMouseOverStack()));
|
||||
}
|
||||
|
||||
public boolean isFriendCheckbox(CheckBox cb) {
|
||||
|
|
@ -339,7 +338,7 @@ public class GuiScreenConfig extends WDScreen {
|
|||
|
||||
if(adding) {
|
||||
if(!hasFriend(pairs[0]))
|
||||
Messages.INSTANCE.sendToServer(new SMessageScreenCtrl(tes, side, pairs[0], false));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(new C2SMessageScreenCtrl(tes, side, pairs[0], false));
|
||||
|
||||
tfFriend.setDisabled(false);
|
||||
tfFriend.clear();
|
||||
|
|
@ -428,7 +427,7 @@ public class GuiScreenConfig extends WDScreen {
|
|||
|
||||
@Override
|
||||
protected void sync() {
|
||||
Messages.INSTANCE.sendToServer(new SMessageScreenCtrl(tes, side, friendRights, otherRights));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(new C2SMessageScreenCtrl(tes, side, friendRights, otherRights));
|
||||
Log.info("Sent sync packet");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import net.minecraft.util.RandomSource;
|
|||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.miniserv.Constants;
|
||||
import net.montoyo.wd.miniserv.client.*;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
|
|
@ -689,7 +689,7 @@ public class GuiServer extends WDScreen {
|
|||
@CommandHandler("reconnect")
|
||||
public void commandReconnect() {
|
||||
Client.getInstance().stop();
|
||||
Messages.INSTANCE.sendToServer(Client.getInstance().beginConnection());
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(Client.getInstance().beginConnection());
|
||||
}
|
||||
|
||||
private void startFileUpload(File f, boolean quit) {
|
||||
|
|
|
|||
|
|
@ -16,13 +16,10 @@ import net.montoyo.wd.client.ClientProxy;
|
|||
import net.montoyo.wd.client.gui.controls.Button;
|
||||
import net.montoyo.wd.client.gui.controls.TextField;
|
||||
import net.montoyo.wd.client.gui.loading.FillControl;
|
||||
import net.montoyo.wd.client.renderers.ScreenRenderer;
|
||||
import net.montoyo.wd.entity.ServerEventHandler;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.ItemInit;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.server.SMessagePadCtrl;
|
||||
import net.montoyo.wd.net.server.SMessageScreenCtrl;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageScreenCtrl;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
|
@ -90,8 +87,8 @@ public class GuiSetURL2 extends WDScreen {
|
|||
else if(ev.getSource() == btnOk)
|
||||
validate(tfURL.getText());
|
||||
else if(ev.getSource() == btnShutDown) {
|
||||
if(isPad)
|
||||
Messages.INSTANCE.sendToServer(new SMessagePadCtrl(""));
|
||||
// if(isPad)
|
||||
// WDNetworkRegistry.INSTANCE.sendToServer(new SMessagePadCtrl(""));
|
||||
|
||||
minecraft.setScreen(null);
|
||||
}
|
||||
|
|
@ -115,7 +112,7 @@ public class GuiSetURL2 extends WDScreen {
|
|||
url = ((ClientProxy) WebDisplays.PROXY).getMCEF().punycode(url);
|
||||
|
||||
if(isPad) {
|
||||
Messages.INSTANCE.sendToServer(new SMessagePadCtrl(url));
|
||||
// WDNetworkRegistry.INSTANCE.sendToServer(new SMessagePadCtrl(url));
|
||||
ItemStack held = minecraft.player.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
|
||||
if(held.getItem().equals(ItemInit.itemMinePad.get()) && held.getTag() != null && held.getTag().contains("PadID")) {
|
||||
|
|
@ -125,8 +122,7 @@ public class GuiSetURL2 extends WDScreen {
|
|||
pd.view.loadURL(WebDisplays.applyBlacklist(url));
|
||||
}
|
||||
}
|
||||
} else
|
||||
Messages.INSTANCE.sendToServer(SMessageScreenCtrl.setURL(tileEntity, screenSide, url, remoteLocation));
|
||||
} else WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.setURL(tileEntity, screenSide, url, remoteLocation));
|
||||
}
|
||||
|
||||
minecraft.setScreen(null);
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ import net.montoyo.wd.client.gui.controls.Event;
|
|||
import net.montoyo.wd.client.gui.loading.FillControl;
|
||||
import net.montoyo.wd.client.gui.loading.GuiLoader;
|
||||
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.server.SMessageACQuery;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageACQuery;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
@ -328,7 +328,7 @@ public abstract class WDScreen extends Screen {
|
|||
}
|
||||
|
||||
protected void requestAutocomplete(String beginning, boolean matchExact) {
|
||||
Messages.INSTANCE.sendToServer(new SMessageACQuery(beginning, matchExact));
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(new C2SMessageACQuery(beginning, matchExact));
|
||||
}
|
||||
|
||||
public void onAutocompleteResult(NameUUIDPair pairs[]) {
|
||||
|
|
|
|||
|
|
@ -4,41 +4,20 @@
|
|||
|
||||
package net.montoyo.wd.client.renderers;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.montoyo.mcef.api.IStringVisitor;
|
||||
import net.montoyo.wd.SharedProxy;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.client.ClientProxy;
|
||||
import net.montoyo.wd.entity.ServerEventHandler;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.miniserv.SyncPlugin;
|
||||
import net.montoyo.wd.utilities.Vector3f;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.mojang.math.Vector3f.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class ScreenRenderer implements BlockEntityRenderer<TileEntityScreen> {
|
||||
|
||||
private String url;
|
||||
|
||||
public ScreenRenderer(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public ScreenRenderer() {}
|
||||
|
||||
public static class ScreenRendererProvider implements BlockEntityRendererProvider<TileEntityScreen> {
|
||||
|
|
@ -59,25 +38,17 @@ public class ScreenRenderer implements BlockEntityRenderer<TileEntityScreen> {
|
|||
|
||||
//Disable lighting
|
||||
RenderSystem.enableTexture();
|
||||
RenderSystem.disableCull();
|
||||
// RenderSystem.disableCull();
|
||||
RenderSystem.disableBlend();
|
||||
|
||||
for(int i = 0; i < te.screenCount(); i++) {
|
||||
TileEntityScreen.Screen scr = te.getScreen(i);
|
||||
if(scr.browser == null) {
|
||||
if(WebDisplays.PROXY instanceof ClientProxy clientProxy) {
|
||||
scr.browser = clientProxy.getMCEF().createBrowser(WebDisplays.applyBlacklist(this.url != null ? this.url : "https://www.google.com"));
|
||||
|
||||
if (scr.rotation.isVertical)
|
||||
scr.browser.resize(scr.resolution.y, scr.resolution.x);
|
||||
else
|
||||
scr.browser.resize(scr.resolution.x, scr.resolution.y);
|
||||
|
||||
scr.doTurnOnAnim = true;
|
||||
scr.turnOnTime = System.currentTimeMillis();
|
||||
}
|
||||
scr.createBrowser(true);
|
||||
}
|
||||
|
||||
|
||||
// TODO: manually backface cull the screens
|
||||
|
||||
tmpi.set(scr.side.right);
|
||||
tmpi.mul(scr.size.x);
|
||||
tmpi.addMul(scr.side.up, scr.size.y);
|
||||
|
|
@ -143,7 +114,7 @@ public class ScreenRenderer implements BlockEntityRenderer<TileEntityScreen> {
|
|||
|
||||
Tesselator tesselator = Tesselator.getInstance();
|
||||
BufferBuilder builder = tesselator.getBuilder();
|
||||
//TODO: Use tesselator
|
||||
//TODO: don't use tesselator
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||
RenderSystem._setShaderTexture(0, scr.browser.getTextureID());
|
||||
|
|
@ -159,16 +130,16 @@ public class ScreenRenderer implements BlockEntityRenderer<TileEntityScreen> {
|
|||
}
|
||||
|
||||
|
||||
//Bounding box debugging
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(-te.getBlockPos().getX(), -te.getBlockPos().getY(), -te.getBlockPos().getZ());
|
||||
LevelRenderer.renderLineBox(
|
||||
poseStack, bufferSource.getBuffer(RenderType.LINES),
|
||||
te.getRenderBoundingBox(), 1, 1, 1, 1f
|
||||
);
|
||||
poseStack.popPose();
|
||||
// //Bounding box debugging
|
||||
// poseStack.pushPose();
|
||||
// poseStack.translate(-te.getBlockPos().getX(), -te.getBlockPos().getY(), -te.getBlockPos().getZ());
|
||||
// LevelRenderer.renderLineBox(
|
||||
// poseStack, bufferSource.getBuffer(RenderType.LINES),
|
||||
// te.getRenderBoundingBox(), 1, 1, 1, 1f
|
||||
// );
|
||||
// poseStack.popPose();
|
||||
|
||||
//Re-enable lighting
|
||||
RenderSystem.enableCull();
|
||||
// RenderSystem.enableCull();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import me.shedaniel.autoconfig.ConfigData;
|
|||
import me.shedaniel.autoconfig.annotation.Config;
|
||||
import me.shedaniel.autoconfig.annotation.ConfigEntry;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.montoyo.mcef.easy_forge_compat.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package net.montoyo.wd.core;
|
|||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.capabilities.CapabilityToken;
|
||||
|
|
@ -42,11 +43,16 @@ public class WDDCapability implements IWDDCapability {
|
|||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
return new CompoundTag();
|
||||
CompoundTag tag = new CompoundTag();
|
||||
if (wddCap != null) tag.putBoolean("firstRun", wddCap.firstRun);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag tag) {}
|
||||
public void deserializeNBT(CompoundTag tag) {
|
||||
if (wddCap != null && tag.contains("firstRun", Tag.TAG_BYTE))
|
||||
wddCap.firstRun = tag.getBoolean("firstRun");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private IWDDCapability createWDDCapability() {
|
||||
|
|
|
|||
|
|
@ -6,55 +6,65 @@ package net.montoyo.wd.data;
|
|||
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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 net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageOpenGui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class GuiData {
|
||||
public static GuiData read(String name, FriendlyByteBuf buf) {
|
||||
GuiType type = dataTable.get(name);
|
||||
GuiData data = type.create();
|
||||
data.deserialize(buf);
|
||||
return data;
|
||||
}
|
||||
|
||||
protected static class GuiType {
|
||||
Class<? extends GuiData> clazz;
|
||||
Supplier<GuiData> constructor;
|
||||
|
||||
public GuiType(Class<? extends GuiData> clazz, Supplier<GuiData> constructor) {
|
||||
this.clazz = clazz;
|
||||
this.constructor = constructor;
|
||||
}
|
||||
|
||||
public GuiData create() {
|
||||
return constructor.get();
|
||||
}
|
||||
}
|
||||
|
||||
private static final HashMap<String, GuiType> dataTable = new HashMap<>();
|
||||
|
||||
static {
|
||||
dataTable.put("SetURL", new GuiType(SetURLData.class, SetURLData::new));
|
||||
dataTable.put("ScreenConfig", new GuiType(ScreenConfigData.class, ScreenConfigData::new));
|
||||
dataTable.put("Keyboard", new GuiType(KeyboardData.class, KeyboardData::new));
|
||||
dataTable.put("RedstoneCtrl", new GuiType(RedstoneCtrlData.class, RedstoneCtrlData::new));
|
||||
dataTable.put("Server", new GuiType(ServerData.class, ServerData::new));
|
||||
}
|
||||
|
||||
public static Class<? extends GuiData> classOf(String name) {
|
||||
return dataTable.get(name).clazz;
|
||||
}
|
||||
|
||||
public GuiData() {
|
||||
}
|
||||
|
||||
protected static class GuiType {
|
||||
Class<?> clazz;
|
||||
ResourceLocation id;
|
||||
}
|
||||
|
||||
private static final HashMap<String, Class<? extends GuiData>> dataTable = new HashMap<>();
|
||||
static {
|
||||
dataTable.put("SetURL", SetURLData.class);
|
||||
dataTable.put("ScreenConfig", ScreenConfigData.class);
|
||||
dataTable.put("Keyboard", KeyboardData.class);
|
||||
dataTable.put("RedstoneCtrl", RedstoneCtrlData.class);
|
||||
dataTable.put("Server", ServerData.class);
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public abstract Screen createGui(Screen old, Level world);
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public void sendTo(ServerPlayer player) {
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new S2CMessageOpenGui(this));
|
||||
}
|
||||
|
||||
public static Class<? extends GuiData> classOf(String name) {
|
||||
return dataTable.get(name);
|
||||
}
|
||||
|
||||
public GuiData() {
|
||||
}
|
||||
|
||||
// public GuiData(FriendlyByteBuf buf) {
|
||||
// this.deserialize(buf);
|
||||
// }
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public abstract Screen createGui(Screen old, Level world);
|
||||
public abstract String getName();
|
||||
|
||||
public void sendTo(ServerPlayer player) {
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new CMessageOpenGui(this));
|
||||
}
|
||||
|
||||
// public abstract void serialize(FriendlyByteBuf buf);
|
||||
// public abstract void deserialize(FriendlyByteBuf buf);
|
||||
|
||||
public abstract void serialize(FriendlyByteBuf buf);
|
||||
public abstract void deserialize(FriendlyByteBuf buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,6 @@ public class KeyboardData extends GuiData {
|
|||
public KeyboardData() {
|
||||
}
|
||||
|
||||
// public KeyboardData(FriendlyByteBuf buf) {
|
||||
// super(buf);
|
||||
// }
|
||||
|
||||
public KeyboardData(TileEntityScreen tes, BlockSide side, BlockPos kbPos) {
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
|
|
@ -57,23 +53,23 @@ public class KeyboardData extends GuiData {
|
|||
return "Keyboard";
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void serialize(FriendlyByteBuf buf) {
|
||||
// buf.writeInt(pos.x);
|
||||
// buf.writeInt(pos.y);
|
||||
// buf.writeInt(pos.z);
|
||||
// buf.writeByte(side.ordinal());
|
||||
// buf.writeInt(kbX);
|
||||
// buf.writeInt(kbY);
|
||||
// buf.writeInt(kbZ);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void deserialize(FriendlyByteBuf buf) {
|
||||
// this.pos = new Vector3i(buf.readInt(), buf.readInt(), buf.readInt());
|
||||
// this.side = BlockSide.values()[buf.readByte()];
|
||||
// this.kbX = buf.readInt();
|
||||
// this.kbY = buf.readInt();
|
||||
// this.kbZ = buf.readInt();
|
||||
// }
|
||||
@Override
|
||||
public void serialize(FriendlyByteBuf buf) {
|
||||
buf.writeInt(pos.x);
|
||||
buf.writeInt(pos.y);
|
||||
buf.writeInt(pos.z);
|
||||
buf.writeByte(side.ordinal());
|
||||
buf.writeInt(kbX);
|
||||
buf.writeInt(kbY);
|
||||
buf.writeInt(kbZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(FriendlyByteBuf buf) {
|
||||
this.pos = new Vector3i(buf.readInt(), buf.readInt(), buf.readInt());
|
||||
this.side = BlockSide.values()[buf.readByte()];
|
||||
this.kbX = buf.readInt();
|
||||
this.kbY = buf.readInt();
|
||||
this.kbZ = buf.readInt();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,16 +4,15 @@
|
|||
|
||||
package net.montoyo.wd.data;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.montoyo.wd.client.gui.GuiRedstoneCtrl;
|
||||
import net.montoyo.wd.net.BufferUtils;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
public class RedstoneCtrlData extends GuiData {
|
||||
|
|
@ -27,10 +26,6 @@ public class RedstoneCtrlData extends GuiData {
|
|||
super();
|
||||
}
|
||||
|
||||
// public RedstoneCtrlData(FriendlyByteBuf buf) {
|
||||
// super(buf);
|
||||
// }
|
||||
|
||||
public RedstoneCtrlData(ResourceLocation d, BlockPos p, String r, String f) {
|
||||
dimension = d;
|
||||
pos = new Vector3i(p);
|
||||
|
|
@ -48,5 +43,20 @@ public class RedstoneCtrlData extends GuiData {
|
|||
public String getName() {
|
||||
return "RedstoneCtrl";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(dimension.toString());
|
||||
BufferUtils.writeVec3i(buf, pos);
|
||||
buf.writeUtf(risingEdgeURL);
|
||||
buf.writeUtf(fallingEdgeURL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(FriendlyByteBuf buf) {
|
||||
dimension = new ResourceLocation(buf.readUtf());
|
||||
pos = BufferUtils.readVec3i(buf);
|
||||
risingEdgeURL = buf.readUtf();
|
||||
fallingEdgeURL = buf.readUtf();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,83 +11,97 @@ import net.minecraft.world.level.Level;
|
|||
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.net.BufferUtils;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageOpenGui;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.NameUUIDPair;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
public class ScreenConfigData extends GuiData {
|
||||
|
||||
public boolean onlyUpdate;
|
||||
public Vector3i pos;
|
||||
public BlockSide side;
|
||||
public NameUUIDPair[] friends;
|
||||
public int friendRights;
|
||||
public int otherRights;
|
||||
|
||||
public ScreenConfigData() {
|
||||
}
|
||||
|
||||
public boolean onlyUpdate;
|
||||
public Vector3i pos;
|
||||
public BlockSide side;
|
||||
public NameUUIDPair[] friends;
|
||||
public int friendRights;
|
||||
public int otherRights;
|
||||
|
||||
public ScreenConfigData() {
|
||||
}
|
||||
|
||||
// public ScreenConfigData(FriendlyByteBuf buf) {
|
||||
// super(buf);
|
||||
// }
|
||||
|
||||
public ScreenConfigData(Vector3i pos, BlockSide side, TileEntityScreen.Screen scr) {
|
||||
this.pos = pos;
|
||||
this.side = side;
|
||||
friends = scr.friends.toArray(new NameUUIDPair[0]);
|
||||
friendRights = scr.friendRights;
|
||||
otherRights = scr.otherRights;
|
||||
onlyUpdate = false;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public Screen createGui(Screen old, Level world) {
|
||||
if(old != null && old instanceof GuiScreenConfig) {
|
||||
GuiScreenConfig gsc = (GuiScreenConfig) old;
|
||||
|
||||
if(gsc.isForBlock(pos.toBlock(), side)) {
|
||||
gsc.updateFriends(friends);
|
||||
gsc.updateFriendRights(friendRights);
|
||||
gsc.updateOtherRights(otherRights);
|
||||
gsc.updateMyRights();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if(onlyUpdate)
|
||||
return null;
|
||||
|
||||
BlockEntity te = world.getBlockEntity(pos.toBlock());
|
||||
if(te == null || !(te instanceof TileEntityScreen)) {
|
||||
Log.error("TileEntity at %s is not a screen; can't open gui!", pos.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
return new GuiScreenConfig(Component.nullToEmpty(""), (TileEntityScreen) te, side, friends, friendRights, otherRights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ScreenConfig";
|
||||
}
|
||||
|
||||
public ScreenConfigData updateOnly() {
|
||||
onlyUpdate = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void sendTo(PacketDistributor.TargetPoint tp) {
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> tp), new CMessageOpenGui(this));
|
||||
}
|
||||
|
||||
public ScreenConfigData(Vector3i pos, BlockSide side, TileEntityScreen.Screen scr) {
|
||||
this.pos = pos;
|
||||
this.side = side;
|
||||
friends = scr.friends.toArray(new NameUUIDPair[0]);
|
||||
friendRights = scr.friendRights;
|
||||
otherRights = scr.otherRights;
|
||||
onlyUpdate = false;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public Screen createGui(Screen old, Level world) {
|
||||
if (old != null && old instanceof GuiScreenConfig) {
|
||||
GuiScreenConfig gsc = (GuiScreenConfig) old;
|
||||
|
||||
if (gsc.isForBlock(pos.toBlock(), side)) {
|
||||
gsc.updateFriends(friends);
|
||||
gsc.updateFriendRights(friendRights);
|
||||
gsc.updateOtherRights(otherRights);
|
||||
gsc.updateMyRights();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (onlyUpdate)
|
||||
return null;
|
||||
|
||||
BlockEntity te = world.getBlockEntity(pos.toBlock());
|
||||
if (te == null || !(te instanceof TileEntityScreen)) {
|
||||
Log.error("TileEntity at %s is not a screen; can't open gui!", pos.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
return new GuiScreenConfig(Component.nullToEmpty(""), (TileEntityScreen) te, side, friends, friendRights, otherRights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ScreenConfig";
|
||||
}
|
||||
|
||||
public ScreenConfigData updateOnly() {
|
||||
onlyUpdate = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void sendTo(PacketDistributor.TargetPoint tp) {
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> tp), new S2CMessageOpenGui(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(FriendlyByteBuf buf) {
|
||||
buf.writeBoolean(onlyUpdate);
|
||||
BufferUtils.writeVec3i(buf, pos);
|
||||
BufferUtils.writeEnum(buf, side, (byte) 1);
|
||||
BufferUtils.writeArray(buf, friends, (nameUUIDPair) -> nameUUIDPair.writeTo(buf));
|
||||
buf.writeInt(friendRights);
|
||||
buf.writeInt(otherRights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(FriendlyByteBuf buf) {
|
||||
onlyUpdate = buf.readBoolean();
|
||||
pos = BufferUtils.readVec3i(buf);
|
||||
side = (BlockSide) BufferUtils.readEnum(buf, (v) -> BlockSide.values()[v], (byte) 1);
|
||||
friends = BufferUtils.readArray(buf, () -> new NameUUIDPair(buf));
|
||||
friendRights = buf.readInt();
|
||||
otherRights = buf.readInt();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import net.minecraft.world.level.Level;
|
|||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.montoyo.wd.client.gui.GuiServer;
|
||||
import net.montoyo.wd.net.BufferUtils;
|
||||
import net.montoyo.wd.utilities.NameUUIDPair;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
|
|
@ -22,10 +23,6 @@ public class ServerData extends GuiData {
|
|||
public ServerData() {
|
||||
}
|
||||
|
||||
// public ServerData(FriendlyByteBuf buf) {
|
||||
// super(buf);
|
||||
// }
|
||||
|
||||
public ServerData(BlockPos bp, NameUUIDPair owner) {
|
||||
pos = new Vector3i(bp);
|
||||
this.owner = owner;
|
||||
|
|
@ -41,5 +38,16 @@ public class ServerData extends GuiData {
|
|||
public String getName() {
|
||||
return "Server";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(FriendlyByteBuf buf) {
|
||||
BufferUtils.writeVec3i(buf, pos);
|
||||
owner.writeTo(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(FriendlyByteBuf buf) {
|
||||
pos = BufferUtils.readVec3i(buf);
|
||||
owner = new NameUUIDPair(buf);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,13 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.montoyo.wd.client.gui.GuiSetURL2;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.BufferUtils;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
public class SetURLData extends GuiData {
|
||||
|
||||
|
||||
public Vector3i pos;
|
||||
public BlockSide side;
|
||||
public String url;
|
||||
|
|
@ -28,10 +29,6 @@ public class SetURLData extends GuiData {
|
|||
public SetURLData() {
|
||||
}
|
||||
|
||||
// public SetURLData(FriendlyByteBuf buf) {
|
||||
// super(buf);
|
||||
// }
|
||||
|
||||
public SetURLData(Vector3i pos, BlockSide side, String url) {
|
||||
this.pos = pos;
|
||||
this.side = side;
|
||||
|
|
@ -65,5 +62,23 @@ public class SetURLData extends GuiData {
|
|||
public String getName() {
|
||||
return "SetURL";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(FriendlyByteBuf buf) {
|
||||
BufferUtils.writeVec3i(buf, pos);
|
||||
BufferUtils.writeEnum(buf, side, (byte) 1);
|
||||
buf.writeUtf(url);
|
||||
buf.writeBoolean(isRemote);
|
||||
if (isRemote) BufferUtils.writeVec3i(buf, remoteLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(FriendlyByteBuf buf) {
|
||||
pos = BufferUtils.readVec3i(buf);
|
||||
side = (BlockSide) BufferUtils.readEnum(buf, (v) -> BlockSide.values()[v], (byte) 1);
|
||||
url = buf.readUtf();
|
||||
isRemote = buf.readBoolean();
|
||||
if (isRemote) remoteLocation = BufferUtils.readVec3i(buf);
|
||||
else remoteLocation = new Vector3i();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
package net.montoyo.wd.entity;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.montoyo.wd.client.renderers.ScreenRenderer;
|
||||
import net.montoyo.wd.miniserv.SyncPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class ServerEventHandler {
|
||||
public static final Map<ServerPlayer, ScreenRenderer> playerScreens = new HashMap<>();
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerConnect(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
// create a new instance of the ScreenRenderer class for the player
|
||||
ServerPlayer player = (ServerPlayer) event.getEntity();
|
||||
String url = SyncPlugin.getPlayerString(player);
|
||||
if(event.getEntity().getLevel().isClientSide) {
|
||||
ScreenRenderer screen = new ScreenRenderer(url);
|
||||
// store the ScreenRenderer instance in the playerScreens map
|
||||
playerScreens.put(player, screen);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerDisconnect(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
// remove the ScreenRenderer instance for the player
|
||||
ServerPlayer player = (ServerPlayer) event.getEntity();
|
||||
playerScreens.remove(player);
|
||||
}
|
||||
}
|
||||
|
|
@ -13,10 +13,8 @@ import net.montoyo.wd.WebDisplays;
|
|||
import net.montoyo.wd.core.IComputerArgs;
|
||||
import net.montoyo.wd.core.IUpgrade;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.net.client.CMessageScreenUpdate;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
|
|
@ -38,21 +36,19 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase {
|
|||
private NameUUIDPair owner;
|
||||
private static final Object[] TRUE = new Object[] { true };
|
||||
private static final Object[] FALSE = new Object[] { false };
|
||||
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag tag) {
|
||||
super.deserializeNBT(tag);
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
owner = Util.readOwnerFromNBT(tag);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
super.serializeNBT();
|
||||
return Util.writeOwnerToNBT(tag, owner);
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
super.saveAdditional(tag);
|
||||
Util.writeOwnerToNBT(tag, owner);
|
||||
}
|
||||
|
||||
|
||||
public void setOwner(Player ep) {
|
||||
owner = new NameUUIDPair(ep.getGameProfile());
|
||||
setChanged();
|
||||
|
|
@ -186,29 +182,29 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase {
|
|||
if(args.count() > 2)
|
||||
action = args.checkString(2).toLowerCase();
|
||||
|
||||
int actionId;
|
||||
switch(action) {
|
||||
case "click":
|
||||
actionId = CMessageScreenUpdate.MOUSE_CLICK;
|
||||
break;
|
||||
|
||||
case "up":
|
||||
case "release":
|
||||
actionId = CMessageScreenUpdate.MOUSE_UP;
|
||||
break;
|
||||
|
||||
case "down":
|
||||
case "press":
|
||||
actionId = CMessageScreenUpdate.MOUSE_DOWN;
|
||||
break;
|
||||
|
||||
case "move":
|
||||
actionId = CMessageScreenUpdate.MOUSE_MOVE;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("bad action name");
|
||||
}
|
||||
// int actionId;
|
||||
// switch(action) {
|
||||
// case "click":
|
||||
// actionId = CMessageScreenUpdate.MOUSE_CLICK;
|
||||
// break;
|
||||
//
|
||||
// case "up":
|
||||
// case "release":
|
||||
// actionId = CMessageScreenUpdate.MOUSE_UP;
|
||||
// break;
|
||||
//
|
||||
// case "down":
|
||||
// case "press":
|
||||
// actionId = CMessageScreenUpdate.MOUSE_DOWN;
|
||||
// break;
|
||||
//
|
||||
// case "move":
|
||||
// actionId = CMessageScreenUpdate.MOUSE_MOVE;
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// throw new IllegalArgumentException("bad action name");
|
||||
// }
|
||||
|
||||
TileEntityScreen scr = getConnectedScreenEx();
|
||||
|
||||
|
|
@ -238,10 +234,10 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase {
|
|||
break;
|
||||
}
|
||||
|
||||
if(scrscr.rotation.isVertical)
|
||||
scr.clickUnsafe(screenSide, actionId, y, x);
|
||||
else
|
||||
scr.clickUnsafe(screenSide, actionId, x, y);
|
||||
// if(scrscr.rotation.isVertical)
|
||||
// scr.clickUnsafe(screenSide, actionId, y, x);
|
||||
// else
|
||||
// scr.clickUnsafe(screenSide, actionId, x, y);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,20 +5,16 @@
|
|||
package net.montoyo.wd.entity;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.montoyo.wd.block.BlockKeyboardRight;
|
||||
import net.montoyo.wd.core.IPeripheral;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
|
|
@ -36,11 +32,12 @@ public abstract class TileEntityPeripheralBase extends BlockEntity implements IP
|
|||
public TileEntityPeripheralBase(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) {
|
||||
super(arg, arg2, arg3);
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag tag) {
|
||||
super.deserializeNBT(tag);
|
||||
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
|
||||
if(tag.contains("WDScreen", 10)) {
|
||||
CompoundTag scr = tag.getCompound("WDScreen");
|
||||
screenPos = new Vector3i(scr.getInt("X"), scr.getInt("Y"), scr.getInt("Z"));
|
||||
|
|
@ -50,24 +47,33 @@ public abstract class TileEntityPeripheralBase extends BlockEntity implements IP
|
|||
screenSide = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
super.serializeNBT();
|
||||
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
super.saveAdditional(tag);
|
||||
|
||||
if(screenPos != null && screenSide != null) {
|
||||
CompoundTag scr = new CompoundTag();
|
||||
scr.putInt("X", screenPos.x);
|
||||
scr.putInt("Y", screenPos.y);
|
||||
scr.putInt("Z", screenPos.z);
|
||||
scr.putByte("Side", (byte) screenSide.ordinal());
|
||||
|
||||
|
||||
tag.put("WDScreen", scr);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
// this is not used for loading from disk, so I'm marking it final
|
||||
@Override
|
||||
public final void deserializeNBT(CompoundTag tag) {
|
||||
super.deserializeNBT(tag);
|
||||
}
|
||||
|
||||
// this is not used for writing to disk, so I'm marking it final
|
||||
@Override
|
||||
@Nonnull
|
||||
public final CompoundTag serializeNBT() {
|
||||
return super.serializeNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -11,17 +11,13 @@ import net.minecraft.world.InteractionHand;
|
|||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.montoyo.wd.block.BlockPeripheral;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.data.RedstoneCtrlData;
|
||||
import net.montoyo.wd.init.TileInit;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TileEntityRedCtrl extends TileEntityPeripheralBase {
|
||||
|
|
@ -41,28 +37,24 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
|
|||
public static Block getBlockFromTE() {
|
||||
return new BlockPeripheral().defaultBlockState().getBlock();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag tag) {
|
||||
super.deserializeNBT(tag);
|
||||
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
|
||||
risingEdgeURL = tag.getString("RisingEdgeURL");
|
||||
fallingEdgeURL = tag.getString("FallingEdgeURL");
|
||||
state = tag.getBoolean("Powered");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
super.serializeNBT();
|
||||
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
super.saveAdditional(tag);
|
||||
tag.putString("RisingEdgeURL", risingEdgeURL);
|
||||
tag.putString("FallingEdgeURL", fallingEdgeURL);
|
||||
tag.putBoolean("Powered", state);
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InteractionResult onRightClick(Player player, InteractionHand hand) {
|
||||
if(level.isClientSide)
|
||||
|
|
|
|||
|
|
@ -4,18 +4,13 @@
|
|||
|
||||
package net.montoyo.wd.entity;
|
||||
|
||||
import com.mojang.authlib.minecraft.client.MinecraftClient;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.resolver.ServerAddress;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
|
|
@ -43,17 +38,21 @@ import net.montoyo.wd.init.BlockInit;
|
|||
import net.montoyo.wd.init.ItemInit;
|
||||
import net.montoyo.wd.init.TileInit;
|
||||
import net.montoyo.wd.miniserv.SyncPlugin;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.*;
|
||||
import net.montoyo.wd.net.server.SMessageRequestTEData;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageAddScreen;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageJSResponse;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageScreenUpdate;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.montoyo.wd.block.BlockPeripheral.point;
|
||||
|
|
@ -220,7 +219,20 @@ public class TileEntityScreen extends BlockEntity {
|
|||
resolution.y = WebDisplays.INSTANCE.maxResY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createBrowser(boolean doAnim) {
|
||||
if (WebDisplays.PROXY instanceof ClientProxy clientProxy) {
|
||||
browser = clientProxy.getMCEF().createBrowser(WebDisplays.applyBlacklist(url != null ? url : "https://www.google.com"));
|
||||
|
||||
if (rotation.isVertical)
|
||||
browser.resize(resolution.y, resolution.x);
|
||||
else
|
||||
browser.resize(resolution.x, resolution.y);
|
||||
|
||||
doTurnOnAnim = doAnim;
|
||||
turnOnTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void forEachScreenBlocks(BlockSide side, Consumer<BlockPos> func) {
|
||||
|
|
@ -259,32 +271,29 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag tag) {
|
||||
super.deserializeNBT(tag);
|
||||
|
||||
ListTag list = tag.getList("WDScreens", 10);
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
|
||||
ListTag list = tag.getList("WDScreens", Tag.TAG_COMPOUND);
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
|
||||
screens.clear();
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
screens.add(Screen.deserialize(list.getCompound(i)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
super.serializeNBT();
|
||||
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
super.saveAdditional(tag);
|
||||
|
||||
ListTag list = new ListTag();
|
||||
for (Screen scr : screens)
|
||||
list.add(scr.serialize());
|
||||
|
||||
|
||||
tag.put("WDScreens", list);
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
public Screen addScreen(BlockSide side, Vector2i size, @Nullable Vector2i resolution, @Nullable Player owner, boolean sendUpdate) {
|
||||
for (Screen scr : screens) {
|
||||
if (scr.side == side)
|
||||
|
|
@ -333,7 +342,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
ret.setupRedstoneStatus(level, getBlockPos());
|
||||
|
||||
if (sendUpdate)
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), new CMessageAddScreen(this, ret));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), new S2CMessageAddScreen(this, ret));
|
||||
}
|
||||
|
||||
screens.add(ret);
|
||||
|
|
@ -343,6 +352,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
else
|
||||
setChanged();
|
||||
|
||||
// level.blockEntityChanged(worldPosition);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -372,7 +383,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
|
||||
public void requestData(ServerPlayer ep) {
|
||||
if (!level.isClientSide)
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> ep), new CMessageAddScreen(this));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> ep), new S2CMessageAddScreen(this));
|
||||
}
|
||||
|
||||
public static String url(String url) throws IOException {
|
||||
|
|
@ -385,7 +396,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
return url;
|
||||
} else {
|
||||
return null;
|
||||
return url; // TODO: ?
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -406,7 +417,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (scr.browser != null)
|
||||
scr.browser.loadURL(weburl);
|
||||
} else {
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.setURL(this, side, weburl));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.setURL(this, side, weburl));
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
|
@ -430,8 +441,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
screens.get(idx).browser.close();
|
||||
screens.get(idx).browser = null;
|
||||
}
|
||||
} else
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), new CMessageScreenUpdate(this, side)); //Delete the screen
|
||||
} else WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), new S2CMessageScreenUpdate(this, side)); //Delete the screen
|
||||
|
||||
screens.remove(idx);
|
||||
|
||||
|
|
@ -466,7 +476,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
scr.browser = null; //Will be re-created by renderer
|
||||
}
|
||||
} else {
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.setResolution(this, side, res));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.setResolution(this, side, res));
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
|
@ -502,13 +512,13 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (level.isClientSide)
|
||||
Log.warning("TileEntityScreen.click() from client side is useless...");
|
||||
else if (getLaserUser(scr) == null)
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_CLICK, vec));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_CLICK, vec));
|
||||
}
|
||||
|
||||
void clickUnsafe(BlockSide side, int action, int x, int y) {
|
||||
if (level.isClientSide) {
|
||||
Vector2i vec = (action == CMessageScreenUpdate.MOUSE_UP) ? null : new Vector2i(x, y);
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.click(this, side, action, vec));
|
||||
Vector2i vec = (action == S2CMessageScreenUpdate.MOUSE_UP) ? null : new Vector2i(x, y);
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, action, vec));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -520,7 +530,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
if (scr.browser != null) {
|
||||
if (event == CMessageScreenUpdate.MOUSE_CLICK) {
|
||||
if (event == S2CMessageScreenUpdate.MOUSE_CLICK) {
|
||||
if(InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_ALT)
|
||||
|| InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_RIGHT_ALT)) {
|
||||
scr.browser.injectMouseMove(vec.x, vec.y, 0, false); //Move to target
|
||||
|
|
@ -531,12 +541,12 @@ public class TileEntityScreen extends BlockEntity {
|
|||
scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, true, 1); //Press
|
||||
scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, false, 1); //Release
|
||||
}
|
||||
} else if (event == CMessageScreenUpdate.MOUSE_DOWN) {
|
||||
} else if (event == S2CMessageScreenUpdate.MOUSE_DOWN) {
|
||||
scr.browser.injectMouseMove(vec.x, vec.y, 0, false); //Move to target
|
||||
scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, true, 1); //Press
|
||||
} else if (event == CMessageScreenUpdate.MOUSE_MOVE)
|
||||
} else if (event == S2CMessageScreenUpdate.MOUSE_MOVE)
|
||||
scr.browser.injectMouseMove(vec.x, vec.y, 0, false); //Move
|
||||
else if (event == CMessageScreenUpdate.MOUSE_UP)
|
||||
else if (event == S2CMessageScreenUpdate.MOUSE_UP)
|
||||
scr.browser.injectMouseButton(scr.lastMousePos.x, scr.lastMousePos.y, 0, 1, false, 1); //Release
|
||||
if (vec != null) {
|
||||
scr.lastMousePos.x = vec.x;
|
||||
|
|
@ -571,11 +581,12 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
if (sendMsg)
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.jsRedstone(this, side, vec, redstoneLevel));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.jsRedstone(this, side, vec, redstoneLevel));
|
||||
}
|
||||
}
|
||||
|
||||
public void handleJSRequest(ServerPlayer src, BlockSide side, int reqId, JSServerRequest req, Object[] data) {
|
||||
// TODO:
|
||||
if (level.isClientSide) {
|
||||
Log.error("Called handleJSRequest client-side");
|
||||
return;
|
||||
|
|
@ -584,18 +595,18 @@ public class TileEntityScreen extends BlockEntity {
|
|||
Screen scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Called handleJSRequest on non-existing side %s", side.toString());
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new CMessageJSResponse(reqId, req, 403, "Invalid side"));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new S2CMessageJSResponse(reqId, req, 403, "Invalid side"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!scr.owner.uuid.equals(src.getGameProfile().getId())) {
|
||||
Log.warning("Player %s (UUID %s) tries to use the redstone output API on a screen he doesn't own!", src.getName(), src.getGameProfile().getId().toString());
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new CMessageJSResponse(reqId, req, 403, "Only the owner can do that"));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new S2CMessageJSResponse(reqId, req, 403, "Only the owner can do that"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (scr.upgrades.stream().noneMatch(DefaultUpgrade.REDOUTPUT::matchesRedInput)) {
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new CMessageJSResponse(reqId, req, 403, "Missing upgrade"));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new S2CMessageJSResponse(reqId, req, 403, "Missing upgrade"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -620,14 +631,14 @@ public class TileEntityScreen extends BlockEntity {
|
|||
vec1.add(side.up.x, side.up.y, side.up.z);
|
||||
}
|
||||
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new CMessageJSResponse(reqId, req, new byte[0]));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new S2CMessageJSResponse(reqId, req, new byte[0]));
|
||||
} else if (req == JSServerRequest.SET_REDSTONE_AT) {
|
||||
int x = (Integer) data[0];
|
||||
int y = (Integer) data[1];
|
||||
boolean state = (Boolean) data[2];
|
||||
|
||||
if (x < 0 || x >= scr.size.x || y < 0 || y >= scr.size.y)
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new CMessageJSResponse(reqId, req, 403, "Out of range"));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new S2CMessageJSResponse(reqId, req, 403, "Out of range"));
|
||||
else {
|
||||
BlockPos bp = (new Vector3i(getBlockPos())).addMul(side.right, x).addMul(side.up, y).toBlock();
|
||||
BlockState bs = level.getBlockState(bp);
|
||||
|
|
@ -635,20 +646,36 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (!bs.getValue(BlockScreen.emitting).equals(state))
|
||||
level.setBlockAndUpdate(bp, bs.setValue(BlockScreen.emitting, state));
|
||||
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new CMessageJSResponse(reqId, req, new byte[0]));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new S2CMessageJSResponse(reqId, req, new byte[0]));
|
||||
}
|
||||
} else
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new CMessageJSResponse(reqId, req, 400, "Invalid request"));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new S2CMessageJSResponse(reqId, req, 400, "Invalid request"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
if (level.isClientSide) {
|
||||
Messages.INSTANCE.sendToServer(new SMessageRequestTEData(this));
|
||||
WebDisplays.PROXY.trackScreen(this, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompoundTag getUpdateTag() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
saveAdditional(tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag(CompoundTag tag) {
|
||||
load(tag);
|
||||
for (Screen screen : screens) {
|
||||
if (screen.browser == null) screen.createBrowser(false);
|
||||
if (screen.browser != null) screen.browser.loadURL(screen.url);
|
||||
}
|
||||
updateAABB();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnloaded() {
|
||||
if (level.isClientSide) {
|
||||
|
|
@ -705,7 +732,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
}
|
||||
|
||||
renderBB = box.toMc();
|
||||
if (box == null) renderBB = new AABB(worldPosition);
|
||||
else renderBB = box.toMc();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -864,7 +892,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.type(this, side, text));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.type(this, side, text));
|
||||
|
||||
if (soundPos != null)
|
||||
playSoundAt(WebDisplays.INSTANCE.soundTyping, soundPos, 0.25f, 1.f);
|
||||
|
|
@ -931,7 +959,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
isCopy.setCount(1);
|
||||
|
||||
scr.upgrades.add(isCopy);
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.upgrade(this, side));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.upgrade(this, side));
|
||||
itemAsUpgrade.onInstall(this, side, player, isCopy);
|
||||
playSoundAt(WebDisplays.INSTANCE.soundUpgradeAdd, getBlockPos(), 1.0f, 1.0f);
|
||||
setChanged();
|
||||
|
|
@ -993,7 +1021,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (idxToRemove >= 0) {
|
||||
dropUpgrade(scr.upgrades.get(idxToRemove), side, player);
|
||||
scr.upgrades.remove(idxToRemove);
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.upgrade(this, side));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.upgrade(this, side));
|
||||
playSoundAt(WebDisplays.INSTANCE.soundUpgradeDel, getBlockPos(), 1.0f, 1.0f);
|
||||
setChanged();
|
||||
} else
|
||||
|
|
@ -1049,10 +1077,10 @@ public class TileEntityScreen extends BlockEntity {
|
|||
//Try to acquire laser lock
|
||||
if (getLaserUser(scr) == null) {
|
||||
scr.laserUser = ply;
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_DOWN, pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_DOWN, pos));
|
||||
}
|
||||
} else if (getLaserUser(scr) == ply)
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_MOVE, pos));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_MOVE, pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1062,7 +1090,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (scr != null) {
|
||||
if (getLaserUser(scr) == ply) {
|
||||
scr.laserUser = null;
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_UP, null));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_UP, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1073,7 +1101,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
scr.upgrades.clear();
|
||||
}
|
||||
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), new CMessageCloseGui(getBlockPos()));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), new S2CMessageCloseGui(getBlockPos()));
|
||||
}
|
||||
|
||||
public void setOwner(BlockSide side, Player newOwner) {
|
||||
|
|
@ -1094,7 +1122,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
scr.owner = new NameUUIDPair(newOwner.getGameProfile());
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.owner(this, side, scr.owner));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.owner(this, side, scr.owner));
|
||||
checkLaserUserRights(scr);
|
||||
setChanged();
|
||||
}
|
||||
|
|
@ -1118,7 +1146,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
} else {
|
||||
scr.rotation = rot;
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.rotation(this, side, rot));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.rotation(this, side, rot));
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
|
@ -1133,8 +1161,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (level.isClientSide) {
|
||||
if (scr.browser != null)
|
||||
scr.browser.runJS(code, "");
|
||||
} else
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.js(this, side, code));
|
||||
}
|
||||
else WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.js(this, side, code));
|
||||
}
|
||||
|
||||
public void setAutoVolume(BlockSide side, boolean av) {
|
||||
|
|
@ -1149,7 +1177,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (level.isClientSide)
|
||||
WebDisplays.PROXY.screenUpdateAutoVolumeInGui(new Vector3i(getBlockPos()), side, av);
|
||||
else {
|
||||
Messages.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), CMessageScreenUpdate.autoVolume(this, side, av));
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.autoVolume(this, side, av));
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
package net.montoyo.wd.miniserv;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.server.SMessageGetUrl;
|
||||
import net.montoyo.wd.net.server.URLMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -23,9 +20,8 @@ public class SyncPlugin {
|
|||
}
|
||||
|
||||
public static String getPlayerString(ServerPlayer player) {
|
||||
if(URL.get(player) == null) {
|
||||
setPlayerString(player, new URLMessage().getURL());
|
||||
}
|
||||
// if(URL.get(player) == null)
|
||||
// setPlayerString(player, new URLMessage().getURL());
|
||||
return URL.get(player);
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +31,7 @@ public class SyncPlugin {
|
|||
if (syncedPlayersList != null) {
|
||||
for (ServerPlayer syncedPlayer : syncedPlayersList) {
|
||||
if(!syncedPlayer.hasDisconnected()) {
|
||||
Messages.INSTANCE.sendToServer(new SMessageGetUrl(URL.get(syncedPlayer)));
|
||||
// WDNetworkRegistry.INSTANCE.sendToServer(new SMessageGetUrl(URL.get(syncedPlayer)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@
|
|||
package net.montoyo.wd.miniserv.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.montoyo.wd.miniserv.*;
|
||||
import net.montoyo.wd.net.server.SMessageMiniservConnect;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageMiniservConnect;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
|
||||
|
|
@ -43,13 +44,13 @@ public class Client extends AbstractClient implements Runnable {
|
|||
private volatile boolean connected;
|
||||
private final ByteBuffer readBuffer = ByteBuffer.allocateDirect(8192);
|
||||
private volatile Thread thread;
|
||||
private final UUID clientUUID = Minecraft.getInstance().player.getGameProfile().getId();
|
||||
private UUID clientUUID;
|
||||
private final ArrayDeque<ClientTask> tasks = new ArrayDeque<>();
|
||||
private ClientTask currentTask;
|
||||
private volatile boolean authenticated;
|
||||
private long lastPingTime;
|
||||
|
||||
public SMessageMiniservConnect beginConnection() {
|
||||
public C2SMessageMiniservConnect beginConnection() {
|
||||
if(keyPair == null) {
|
||||
try {
|
||||
KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
|
||||
|
|
@ -62,7 +63,7 @@ public class Client extends AbstractClient implements Runnable {
|
|||
}
|
||||
|
||||
RSAPublicKey pubKey = (RSAPublicKey) keyPair.getPublic();
|
||||
return new SMessageMiniservConnect(pubKey.getModulus().toByteArray(), pubKey.getPublicExponent().toByteArray());
|
||||
return new C2SMessageMiniservConnect(pubKey.getModulus().toByteArray(), pubKey.getPublicExponent().toByteArray());
|
||||
}
|
||||
|
||||
public boolean decryptKey(byte[] encKey) {
|
||||
|
|
@ -146,6 +147,13 @@ public class Client extends AbstractClient implements Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
if (clientUUID == null) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player != null)
|
||||
clientUUID = player.getGameProfile().getId();
|
||||
else return; // can't tick yet; player does not exist
|
||||
}
|
||||
|
||||
try {
|
||||
selector = Selector.open();
|
||||
socket = SocketChannel.open();
|
||||
|
|
|
|||
|
|
@ -141,26 +141,30 @@ public class Server implements Runnable {
|
|||
selector.select(1000); //Allow the server to kick timed-out clients
|
||||
|
||||
for(SelectionKey key: selector.selectedKeys()) {
|
||||
if(key.isAcceptable()) {
|
||||
SocketChannel chan;
|
||||
|
||||
try {
|
||||
chan = server.accept();
|
||||
} catch(Throwable t) {
|
||||
Log.warningEx("Could not accept client", t);
|
||||
chan = null;
|
||||
}
|
||||
|
||||
if(chan != null) {
|
||||
chan.configureBlocking(false);
|
||||
ServerClient toAdd = new ServerClient(chan, selector);
|
||||
|
||||
clientMap.put(chan, toAdd);
|
||||
clientList.add(toAdd);
|
||||
}
|
||||
}
|
||||
|
||||
if (key == null) continue;
|
||||
|
||||
try {
|
||||
// this can throw an exception
|
||||
// there is no getting around this fact other than try/catch
|
||||
if(key.isAcceptable()) {
|
||||
SocketChannel chan;
|
||||
|
||||
try {
|
||||
chan = server.accept();
|
||||
} catch(Throwable t) {
|
||||
Log.warningEx("Could not accept client", t);
|
||||
chan = null;
|
||||
}
|
||||
|
||||
if(chan != null) {
|
||||
chan.configureBlocking(false);
|
||||
ServerClient toAdd = new ServerClient(chan, selector);
|
||||
|
||||
clientMap.put(chan, toAdd);
|
||||
clientList.add(toAdd);
|
||||
}
|
||||
}
|
||||
|
||||
if (key.isReadable()) {
|
||||
ServerClient cli = clientMap.get(key.channel());
|
||||
|
||||
|
|
|
|||
75
src/main/java/net/montoyo/wd/net/BufferUtils.java
Normal file
75
src/main/java/net/montoyo/wd/net/BufferUtils.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package net.montoyo.wd.net;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BufferUtils {
|
||||
public static void writeUShort(FriendlyByteBuf buf, int v) {
|
||||
// TODO: write a pair of bytes manually
|
||||
buf.writeInt(v);
|
||||
}
|
||||
|
||||
public static int readUShort(FriendlyByteBuf buf) {
|
||||
return buf.readInt();
|
||||
}
|
||||
|
||||
public static void writeBytes(FriendlyByteBuf buf, byte[] data) {
|
||||
writeUShort(buf, data.length);
|
||||
for (byte datum : data) buf.writeByte(datum);
|
||||
}
|
||||
|
||||
public static byte[] readBytes(FriendlyByteBuf buf) {
|
||||
byte[] data = new byte[readUShort(buf)];
|
||||
for (int i = 0; i < data.length; i++) data[i] = buf.readByte();
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void writeVec3i(FriendlyByteBuf buf, Vector3i pos) {
|
||||
buf.writeInt(pos.x);
|
||||
buf.writeInt(pos.y);
|
||||
buf.writeInt(pos.z);
|
||||
}
|
||||
|
||||
public static Vector3i readVec3i(FriendlyByteBuf buf) {
|
||||
return new Vector3i(buf.readInt(), buf.readInt(), buf.readInt());
|
||||
}
|
||||
|
||||
public static void writeEnum(FriendlyByteBuf buf, Enum<?> value, byte byteCount) {
|
||||
int ord = 0;
|
||||
if (value != null) ord = value.ordinal() + 1;
|
||||
switch (byteCount) {
|
||||
case 1 -> buf.writeByte(ord);
|
||||
case 2 -> buf.writeShort(ord);
|
||||
case 4 -> buf.writeInt(ord);
|
||||
default -> throw new RuntimeException("Invalid byte count " + byteCount + ". Must be 1, 2... and 4");
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void writeArray(FriendlyByteBuf buf, T[] elements, Consumer<T> writer) {
|
||||
writeUShort(buf, elements.length);
|
||||
for (T element : elements) writer.accept(element);
|
||||
}
|
||||
|
||||
public static <T> T[] readArray(FriendlyByteBuf buf, Supplier<T> reader) {
|
||||
//noinspection unchecked
|
||||
T[] ts = (T[]) new Object[readUShort(buf)];
|
||||
for (int i = 0; i < ts.length; i++) ts[i] = reader.get();
|
||||
return ts;
|
||||
}
|
||||
|
||||
public static Enum<?> readEnum(FriendlyByteBuf buf, Function<Integer, Enum<?>> mapper, byte byteCount) {
|
||||
int ord = switch (byteCount) {
|
||||
case 1 -> buf.readByte();
|
||||
case 2 -> buf.readShort();
|
||||
case 4 -> buf.readInt();
|
||||
default -> throw new RuntimeException("Invalid byte count " + byteCount + ". Must be 1, 2, or 4");
|
||||
};
|
||||
if (ord == 0) return null;
|
||||
|
||||
return mapper.apply(ord - 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
import net.montoyo.wd.net.client.*;
|
||||
import net.montoyo.wd.net.server.*;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class Messages {
|
||||
|
||||
private static final String PROTOCOL_VERSION = "1";
|
||||
private static int index = 0;
|
||||
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
|
||||
new ResourceLocation("webdisplays", "packetsystem"),
|
||||
() -> PROTOCOL_VERSION,
|
||||
PROTOCOL_VERSION::equals,
|
||||
PROTOCOL_VERSION::equals
|
||||
);
|
||||
|
||||
@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);
|
||||
INSTANCE.registerMessage(index++, SMessagePadCtrl.class, SMessagePadCtrl::encode, SMessagePadCtrl::decode, SMessagePadCtrl::handle);
|
||||
INSTANCE.registerMessage(index++, CMessageOpenGui.class, CMessageOpenGui::encode, CMessageOpenGui::decode, CMessageOpenGui::handle);
|
||||
INSTANCE.registerMessage(index++, SMessageGetUrl.class, SMessageGetUrl::encode, SMessageGetUrl::decode, SMessageGetUrl::handle);
|
||||
INSTANCE.registerMessage(index++, URLMessage.class, URLMessage::encode, URLMessage::decode, URLMessage::handle);
|
||||
}
|
||||
}
|
||||
25
src/main/java/net/montoyo/wd/net/NetworkEntry.java
Normal file
25
src/main/java/net/montoyo/wd/net/NetworkEntry.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package net.montoyo.wd.net;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class NetworkEntry<T extends Packet> {
|
||||
Class<T> clazz;
|
||||
Function<FriendlyByteBuf, T> fabricator;
|
||||
|
||||
public NetworkEntry(Class<T> clazz, Function<FriendlyByteBuf, T> fabricator) {
|
||||
this.clazz = clazz;
|
||||
this.fabricator = fabricator;
|
||||
}
|
||||
|
||||
public void register(int indx, SimpleChannel channel) {
|
||||
channel.registerMessage(
|
||||
indx, clazz,
|
||||
Packet::write,
|
||||
fabricator,
|
||||
(pkt, ctx) -> pkt.handle(ctx.get())
|
||||
);
|
||||
}
|
||||
}
|
||||
76
src/main/java/net/montoyo/wd/net/Packet.java
Normal file
76
src/main/java/net/montoyo/wd/net/Packet.java
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package net.montoyo.wd.net;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.PacketListener;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.utilities.DistSafety;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Packet implements net.minecraft.network.protocol.Packet {
|
||||
public Packet() {
|
||||
}
|
||||
|
||||
public Packet(FriendlyByteBuf buf) {
|
||||
|
||||
}
|
||||
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
}
|
||||
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
}
|
||||
|
||||
public final void handle(PacketListener pHandler) {
|
||||
}
|
||||
|
||||
public boolean isSkippable() {
|
||||
return net.minecraft.network.protocol.Packet.super.isSkippable();
|
||||
}
|
||||
|
||||
public boolean checkClient(NetworkEvent.Context ctx) {
|
||||
return ctx.getDirection().getReceptionSide().isClient();
|
||||
}
|
||||
|
||||
public boolean checkServer(NetworkEvent.Context ctx) {
|
||||
return ctx.getDirection().getReceptionSide().isServer();
|
||||
}
|
||||
|
||||
public void respond(NetworkEvent.Context ctx, Packet packet) {
|
||||
ctx.enqueueWork(() -> WDNetworkRegistry.INSTANCE.reply(packet, ctx));
|
||||
}
|
||||
|
||||
private static final ArrayList<Runnable> runLater = new ArrayList<>();
|
||||
|
||||
public void respondLater(NetworkEvent.Context ctx, Packet packet) {
|
||||
ctx.enqueueWork(() -> runLater.add(() -> {
|
||||
if (checkClient(ctx))
|
||||
WDNetworkRegistry.INSTANCE.sendToServer(packet);
|
||||
else if (ctx.getSender() != null)
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(ctx::getSender), packet);
|
||||
else WDNetworkRegistry.INSTANCE.reply(packet, ctx);
|
||||
}));
|
||||
}
|
||||
|
||||
public static void onTick(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase.equals(TickEvent.Phase.END)) {
|
||||
if (!runLater.isEmpty()) {
|
||||
if (DistSafety.isConnected()) {
|
||||
for (Runnable runnable : runLater) runnable.run();
|
||||
runLater.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
MinecraftForge.EVENT_BUS.addListener(Packet::onTick);
|
||||
}
|
||||
|
||||
public final void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
}
|
||||
}
|
||||
62
src/main/java/net/montoyo/wd/net/WDNetworkRegistry.java
Normal file
62
src/main/java/net/montoyo/wd/net/WDNetworkRegistry.java
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package net.montoyo.wd.net;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
import net.montoyo.wd.net.client_bound.*;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageACQuery;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageMiniservConnect;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageRedstoneCtrl;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageScreenCtrl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class WDNetworkRegistry {
|
||||
public static final String networkingVersion = "2";
|
||||
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
|
||||
new ResourceLocation("webdisplays", "packetsystem"),
|
||||
() -> networkingVersion,
|
||||
(s) -> s.equals(networkingVersion),
|
||||
(s) -> s.equals(networkingVersion)
|
||||
);
|
||||
|
||||
// if an old packet needs to be ported, refer to the following link
|
||||
// https://github.com/Mysticpasta1/webdisplays/tree/ff55cbf1b27773c15f44f17ad3364da3a16b6ed9/src/main/java/net/montoyo/wd/net
|
||||
// however, I think I got all the essentials
|
||||
// only thing I skipped on, is the minepad
|
||||
static {
|
||||
ArrayList<NetworkEntry<?>> entries = new ArrayList<>();
|
||||
|
||||
// login handshake
|
||||
entries.add(new NetworkEntry<>(S2CMessageServerInfo.class, S2CMessageServerInfo::new));
|
||||
entries.add(new NetworkEntry<>(C2SMessageMiniservConnect.class, C2SMessageMiniservConnect::new));
|
||||
entries.add(new NetworkEntry<>(S2CMessageMiniservKey.class, S2CMessageMiniservKey::new));
|
||||
|
||||
// guis
|
||||
entries.add(new NetworkEntry<>(S2CMessageCloseGui.class, S2CMessageCloseGui::new));
|
||||
entries.add(new NetworkEntry<>(S2CMessageOpenGui.class, S2CMessageOpenGui::new));
|
||||
|
||||
// screen creation
|
||||
entries.add(new NetworkEntry<>(S2CMessageAddScreen.class, S2CMessageAddScreen::new));
|
||||
|
||||
// screen modifications
|
||||
entries.add(new NetworkEntry<>(C2SMessageScreenCtrl.class, C2SMessageScreenCtrl::new));
|
||||
entries.add(new NetworkEntry<>(S2CMessageScreenUpdate.class, S2CMessageScreenUpdate::new));
|
||||
|
||||
// redstone control
|
||||
entries.add(new NetworkEntry<>(C2SMessageRedstoneCtrl.class, C2SMessageRedstoneCtrl::new));
|
||||
|
||||
// autocomplete
|
||||
entries.add(new NetworkEntry<>(C2SMessageACQuery.class, C2SMessageACQuery::new));
|
||||
entries.add(new NetworkEntry<>(S2CMessageACResult.class, S2CMessageACResult::new));
|
||||
|
||||
// jsquery
|
||||
entries.add(new NetworkEntry<>(S2CMessageJSResponse.class, S2CMessageJSResponse::new));
|
||||
|
||||
for (int i = 0; i < entries.size(); i++) entries.get(i).register(i, INSTANCE);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageAddScreen {
|
||||
|
||||
private boolean clear;
|
||||
private Vector3i pos;
|
||||
private TileEntityScreen.Screen[] screens;
|
||||
|
||||
public CMessageAddScreen(TileEntityScreen tes) {
|
||||
clear = true;
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
screens = new TileEntityScreen.Screen[tes.screenCount()];
|
||||
|
||||
for (int i = 0; i < tes.screenCount(); i++)
|
||||
screens[i] = tes.getScreen(i);
|
||||
}
|
||||
|
||||
public CMessageAddScreen(TileEntityScreen tes, TileEntityScreen.Screen... toSend) {
|
||||
clear = false;
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
screens = toSend;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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()];
|
||||
screens[i].size = new Vector2i(buf);
|
||||
screens[i].url = buf.readUtf();
|
||||
screens[i].resolution = new Vector2i(buf);
|
||||
screens[i].rotation = Rotation.values()[buf.readByte() & 3];
|
||||
screens[i].owner = new NameUUIDPair(buf);
|
||||
screens[i].upgrades = new ArrayList<>();
|
||||
|
||||
int numUpgrades = buf.readByte();
|
||||
for (int j = 0; j < numUpgrades; j++)
|
||||
screens[i].upgrades.add(buf.readItem());
|
||||
}
|
||||
|
||||
return new CMessageAddScreen(clear, pos, screens);
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeBoolean(clear);
|
||||
pos.writeTo(buf);
|
||||
buf.writeByte(screens.length);
|
||||
|
||||
for (TileEntityScreen.Screen scr : screens) {
|
||||
buf.writeByte(scr.side.ordinal());
|
||||
scr.size.writeTo(buf);
|
||||
buf.writeUtf(scr.url);
|
||||
scr.resolution.writeTo(buf);
|
||||
buf.writeByte(scr.rotation.ordinal());
|
||||
scr.owner.writeTo(buf);
|
||||
buf.writeByte(scr.upgrades.size());
|
||||
|
||||
for (ItemStack is : scr.upgrades)
|
||||
buf.writeItem(is);
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
BlockEntity te = WebDisplays.PROXY.getWorld(contextSupplier.get()).getBlockEntity(pos.toBlock());
|
||||
if (!(te instanceof TileEntityScreen)) {
|
||||
if (clear)
|
||||
Log.error("CMessageAddScreen: Can't add screen to invalid tile entity at %s", pos.toString());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntityScreen tes = (TileEntityScreen) te;
|
||||
if (clear)
|
||||
tes.clear();
|
||||
|
||||
for (TileEntityScreen.Screen entry : screens) {
|
||||
TileEntityScreen.Screen scr = tes.addScreen(entry.side, entry.size, entry.resolution, null, false);
|
||||
scr.rotation = entry.rotation;
|
||||
String webUrl;
|
||||
|
||||
try {
|
||||
webUrl = TileEntityScreen.url(entry.url);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
scr.url = webUrl;
|
||||
scr.owner = entry.owner;
|
||||
scr.upgrades = entry.upgrades;
|
||||
|
||||
if (scr.browser != null)
|
||||
scr.browser.loadURL(webUrl);
|
||||
}
|
||||
|
||||
});
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageCloseGui {
|
||||
|
||||
private BlockPos blockPos;
|
||||
private BlockSide blockSide;
|
||||
|
||||
public CMessageCloseGui(BlockPos bp) {
|
||||
blockPos = bp;
|
||||
blockSide = null;
|
||||
}
|
||||
|
||||
public CMessageCloseGui(BlockPos bp, BlockSide side) {
|
||||
blockPos = bp;
|
||||
blockSide = side;
|
||||
}
|
||||
|
||||
public static CMessageCloseGui decode(FriendlyByteBuf buf) {
|
||||
int x, y, z, side;
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
side = buf.readByte();
|
||||
|
||||
BlockPos blockPos = new BlockPos(x, y, z);
|
||||
BlockSide blockSide = side <= 0 ? null : BlockSide.values()[side - 1];
|
||||
|
||||
return new CMessageCloseGui(blockPos, blockSide);
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeInt(blockPos.getX());
|
||||
buf.writeInt(blockPos.getY());
|
||||
buf.writeInt(blockPos.getZ());
|
||||
|
||||
if(blockSide == null) {
|
||||
buf.writeByte(0);
|
||||
} else {
|
||||
buf.writeByte(blockSide.ordinal() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
if (blockSide == null)
|
||||
Arrays.stream(BlockSide.values()).forEach(s -> WebDisplays.PROXY.closeGui(blockPos, s));
|
||||
else
|
||||
WebDisplays.PROXY.closeGui(blockPos, blockSide);
|
||||
});
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.client.ClientProxy;
|
||||
import net.montoyo.wd.miniserv.client.Client;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageMiniservKey {
|
||||
|
||||
private byte[] encryptedKey;
|
||||
|
||||
public CMessageMiniservKey(byte[] key) {
|
||||
encryptedKey = key;
|
||||
}
|
||||
|
||||
public static CMessageMiniservKey decode(FriendlyByteBuf buf) {
|
||||
byte[] encryptedKey = new byte[buf.readShort() & 0xFFFF];
|
||||
buf.readBytes(encryptedKey);
|
||||
return new CMessageMiniservKey(encryptedKey);
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeShort(encryptedKey.length);
|
||||
buf.writeBytes(encryptedKey);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
if (Client.getInstance().decryptKey(encryptedKey)) {
|
||||
Log.info("Successfully received and decrypted key, starting miniserv client...");
|
||||
if(WebDisplays.PROXY instanceof ClientProxy proxy) {
|
||||
proxy.startMiniservClient();
|
||||
}
|
||||
}
|
||||
});
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageOpenGui implements Runnable {
|
||||
|
||||
private GuiData data;
|
||||
|
||||
public CMessageOpenGui(GuiData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static CMessageOpenGui decode(FriendlyByteBuf buf) {
|
||||
String name = buf.readUtf();
|
||||
Class<? extends GuiData> cls = GuiData.classOf(name);
|
||||
|
||||
if(cls == null) {
|
||||
Log.error("Could not create GuiData of type %s because it doesn't exist!", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CMessageOpenGui((GuiData) Util.unserialize(buf, cls));
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(data.getName());
|
||||
Util.serialize(buf, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
WebDisplays.PROXY.displayGui(data);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.miniserv.client.Client;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageServerInfo {
|
||||
|
||||
private int miniservPort;
|
||||
|
||||
public CMessageServerInfo(int msPort) {
|
||||
miniservPort = msPort;
|
||||
}
|
||||
|
||||
public static CMessageServerInfo decode(FriendlyByteBuf buf) {
|
||||
return new CMessageServerInfo(buf.readShort() & 0xFFFF);
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeShort(miniservPort);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
WebDisplays.PROXY.setMiniservClientPort(miniservPort);
|
||||
if (miniservPort > 0)
|
||||
Messages.INSTANCE.sendToServer(Client.getInstance().beginConnection());
|
||||
});
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,45 +2,44 @@
|
|||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client;
|
||||
package net.montoyo.wd.net.client_bound;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.NameUUIDPair;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageACResult {
|
||||
|
||||
public class S2CMessageACResult extends Packet {
|
||||
private static NameUUIDPair[] result;
|
||||
|
||||
public CMessageACResult(NameUUIDPair[] pairs) {
|
||||
public S2CMessageACResult(NameUUIDPair[] pairs) {
|
||||
result = pairs;
|
||||
}
|
||||
|
||||
public static CMessageACResult decode(FriendlyByteBuf buf) {
|
||||
|
||||
public S2CMessageACResult(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
|
||||
int cnt = buf.readByte();
|
||||
result = new NameUUIDPair[cnt];
|
||||
|
||||
for(int i = 0; i < cnt; i++)
|
||||
result[i] = new NameUUIDPair(buf);
|
||||
|
||||
return new CMessageACResult(result);
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeByte(result.length);
|
||||
|
||||
for(NameUUIDPair pair : result)
|
||||
pair.writeTo(buf);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
ctx.enqueueWork(() -> {
|
||||
WebDisplays.PROXY.onAutocompleteResult(result);
|
||||
});
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client_bound;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static net.montoyo.wd.block.BlockScreen.hasTE;
|
||||
|
||||
public class S2CMessageAddScreen extends Packet {
|
||||
private boolean clear;
|
||||
private Vector3i pos;
|
||||
private TileEntityScreen.Screen[] screens;
|
||||
|
||||
public S2CMessageAddScreen(TileEntityScreen tes) {
|
||||
clear = true;
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
screens = new TileEntityScreen.Screen[tes.screenCount()];
|
||||
|
||||
for (int i = 0; i < tes.screenCount(); i++)
|
||||
screens[i] = tes.getScreen(i);
|
||||
}
|
||||
|
||||
public S2CMessageAddScreen(TileEntityScreen tes, TileEntityScreen.Screen... toSend) {
|
||||
clear = false;
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
screens = toSend;
|
||||
}
|
||||
|
||||
public S2CMessageAddScreen(boolean clear, Vector3i pos, TileEntityScreen.Screen[] screens) {
|
||||
this.clear = clear;
|
||||
this.pos = pos;
|
||||
this.screens = screens;
|
||||
}
|
||||
|
||||
public S2CMessageAddScreen(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
|
||||
clear = buf.readBoolean();
|
||||
pos = new Vector3i(buf);
|
||||
|
||||
int cnt = buf.readByte() & 7;
|
||||
|
||||
screens = new TileEntityScreen.Screen[cnt];
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
screens[i] = new TileEntityScreen.Screen();
|
||||
screens[i].side = BlockSide.values()[buf.readByte()];
|
||||
screens[i].size = new Vector2i(buf);
|
||||
screens[i].url = buf.readUtf();
|
||||
screens[i].resolution = new Vector2i(buf);
|
||||
screens[i].rotation = Rotation.values()[buf.readByte() & 3];
|
||||
screens[i].owner = new NameUUIDPair(buf);
|
||||
screens[i].upgrades = new ArrayList<>();
|
||||
|
||||
int numUpgrades = buf.readByte();
|
||||
for (int j = 0; j < numUpgrades; j++)
|
||||
screens[i].upgrades.add(buf.readItem());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeBoolean(clear);
|
||||
pos.writeTo(buf);
|
||||
buf.writeByte(screens.length);
|
||||
|
||||
for (TileEntityScreen.Screen scr : screens) {
|
||||
buf.writeByte(scr.side.ordinal());
|
||||
scr.size.writeTo(buf);
|
||||
buf.writeUtf(scr.url);
|
||||
scr.resolution.writeTo(buf);
|
||||
buf.writeByte(scr.rotation.ordinal());
|
||||
scr.owner.writeTo(buf);
|
||||
buf.writeByte(scr.upgrades.size());
|
||||
|
||||
for (ItemStack is : scr.upgrades)
|
||||
buf.writeItem(is);
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
ctx.enqueueWork(() -> {
|
||||
Level lvl = (Level) WebDisplays.PROXY.getWorld(ctx);
|
||||
BlockEntity te = lvl.getBlockEntity(pos.toBlock());
|
||||
if (!(te instanceof TileEntityScreen)) {
|
||||
lvl.setBlockAndUpdate(pos.toBlock(), lvl.getBlockState(pos.toBlock()).setValue(hasTE, true));
|
||||
te = lvl.getBlockEntity(pos.toBlock());
|
||||
|
||||
if (!(te instanceof TileEntityScreen)) {
|
||||
if (clear)
|
||||
Log.error("CMessageAddScreen: Can't add screen to invalid tile entity at %s", pos.toString());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TileEntityScreen tes = (TileEntityScreen) te;
|
||||
if (clear)
|
||||
tes.clear();
|
||||
|
||||
for (TileEntityScreen.Screen entry : screens) {
|
||||
TileEntityScreen.Screen scr = tes.addScreen(entry.side, entry.size, entry.resolution, null, false);
|
||||
scr.rotation = entry.rotation;
|
||||
String webUrl;
|
||||
|
||||
try {
|
||||
webUrl = TileEntityScreen.url(entry.url);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
scr.url = webUrl;
|
||||
scr.owner = entry.owner;
|
||||
scr.upgrades = entry.upgrades;
|
||||
|
||||
if (scr.browser != null)
|
||||
scr.browser.loadURL(webUrl);
|
||||
}
|
||||
});
|
||||
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client_bound;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class S2CMessageCloseGui extends Packet {
|
||||
private BlockPos blockPos;
|
||||
private BlockSide blockSide;
|
||||
|
||||
public S2CMessageCloseGui(BlockPos bp) {
|
||||
blockPos = bp;
|
||||
blockSide = null;
|
||||
}
|
||||
|
||||
public S2CMessageCloseGui(BlockPos bp, BlockSide side) {
|
||||
blockPos = bp;
|
||||
blockSide = side;
|
||||
}
|
||||
|
||||
public S2CMessageCloseGui(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
blockPos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
|
||||
byte b = buf.readByte();
|
||||
if (b <= 0) blockSide = null;
|
||||
else blockSide = BlockSide.values()[b - 1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeInt(blockPos.getX());
|
||||
buf.writeInt(blockPos.getY());
|
||||
buf.writeInt(blockPos.getZ());
|
||||
|
||||
if (blockSide == null) buf.writeByte(0);
|
||||
else buf.writeByte(blockSide.ordinal() + 1);
|
||||
}
|
||||
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
ctx.enqueueWork(() -> {
|
||||
if (blockSide == null)
|
||||
Arrays.stream(BlockSide.values()).forEach(s -> WebDisplays.PROXY.closeGui(blockPos, s));
|
||||
else
|
||||
WebDisplays.PROXY.closeGui(blockPos, blockSide);
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,17 +2,16 @@
|
|||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client;
|
||||
package net.montoyo.wd.net.client_bound;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.core.JSServerRequest;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageJSResponse {
|
||||
public class S2CMessageJSResponse extends Packet {
|
||||
|
||||
private int id;
|
||||
private JSServerRequest type;
|
||||
|
|
@ -21,22 +20,24 @@ public class CMessageJSResponse {
|
|||
private int errCode;
|
||||
private String errString;
|
||||
|
||||
public CMessageJSResponse(int id, JSServerRequest t, byte[] d) {
|
||||
public S2CMessageJSResponse(int id, JSServerRequest t, byte[] d) {
|
||||
this.id = id;
|
||||
type = t;
|
||||
success = true;
|
||||
data = d;
|
||||
}
|
||||
|
||||
public CMessageJSResponse(int id, JSServerRequest t, int code, String err) {
|
||||
public S2CMessageJSResponse(int id, JSServerRequest t, int code, String err) {
|
||||
this.id = id;
|
||||
type = t;
|
||||
success = false;
|
||||
errCode = code;
|
||||
errString = err;
|
||||
}
|
||||
|
||||
public static CMessageJSResponse decode(FriendlyByteBuf buf) {
|
||||
|
||||
public S2CMessageJSResponse(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
|
||||
int id = buf.readInt();
|
||||
JSServerRequest type = JSServerRequest.fromID(buf.readByte());
|
||||
boolean success = buf.readBoolean();
|
||||
|
|
@ -50,15 +51,21 @@ public class CMessageJSResponse {
|
|||
data = new byte[buf.readByte()];
|
||||
buf.readBytes(data);
|
||||
|
||||
return new CMessageJSResponse(id, type, data);
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.data = data;
|
||||
} else {
|
||||
errCode = buf.readInt();
|
||||
errString = buf.readUtf();
|
||||
return new CMessageJSResponse(id, type, errCode, errString);
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.errCode = errCode;
|
||||
this.errString = errString;
|
||||
}
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeInt(id);
|
||||
buf.writeByte(type.ordinal());
|
||||
buf.writeBoolean(success);
|
||||
|
|
@ -72,8 +79,8 @@ public class CMessageJSResponse {
|
|||
}
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
ctx.enqueueWork(() -> {
|
||||
try {
|
||||
if (success)
|
||||
WebDisplays.PROXY.handleJSResponseSuccess(id, type, data);
|
||||
|
|
@ -83,6 +90,6 @@ public class CMessageJSResponse {
|
|||
Log.warningEx("Could not handle JS response", t);
|
||||
}
|
||||
});
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client_bound;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.client.ClientProxy;
|
||||
import net.montoyo.wd.miniserv.client.Client;
|
||||
import net.montoyo.wd.net.BufferUtils;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
|
||||
public class S2CMessageMiniservKey extends Packet {
|
||||
private byte[] encryptedKey;
|
||||
|
||||
public S2CMessageMiniservKey(byte[] key) {
|
||||
encryptedKey = key;
|
||||
}
|
||||
|
||||
public S2CMessageMiniservKey(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
encryptedKey = BufferUtils.readBytes(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
BufferUtils.writeBytes(buf, encryptedKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
if (checkClient(ctx)) {
|
||||
if (Client.getInstance().decryptKey(encryptedKey)) {
|
||||
Log.info("Successfully received and decrypted key, starting miniserv client...");
|
||||
if (WebDisplays.PROXY instanceof ClientProxy proxy) {
|
||||
proxy.startMiniservClient();
|
||||
}
|
||||
}
|
||||
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2019 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client_bound;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.data.GuiData;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
|
||||
public class S2CMessageOpenGui extends Packet {
|
||||
private GuiData data;
|
||||
|
||||
public S2CMessageOpenGui(GuiData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public S2CMessageOpenGui(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
|
||||
String name = buf.readUtf();
|
||||
data = GuiData.read(name, buf);
|
||||
Class<? extends GuiData> cls = GuiData.classOf(name);
|
||||
|
||||
if (cls == null) {
|
||||
Log.error("Could not create GuiData of type %s because it doesn't exist!", name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(data.getName());
|
||||
data.serialize(buf);
|
||||
}
|
||||
|
||||
public void handle(NetworkEvent.Context context) {
|
||||
context.enqueueWork(() -> WebDisplays.PROXY.displayGui(data));
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client;
|
||||
package net.montoyo.wd.net.client_bound;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
|
@ -13,16 +13,15 @@ import net.minecraftforge.network.NetworkEvent;
|
|||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.block.BlockScreen;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageScreenUpdate {
|
||||
|
||||
// TODO: use registry based approach
|
||||
public class S2CMessageScreenUpdate extends Packet {
|
||||
public static final int UPDATE_URL = 0;
|
||||
public static final int UPDATE_RESOLUTION = 1;
|
||||
public static final int UPDATE_DELETE = 2;
|
||||
|
|
@ -51,12 +50,12 @@ public class CMessageScreenUpdate {
|
|||
private NameUUIDPair owner;
|
||||
private Rotation rotation;
|
||||
private boolean autoVolume;
|
||||
|
||||
public CMessageScreenUpdate() {
|
||||
|
||||
public S2CMessageScreenUpdate() {
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate setURL(TileEntityScreen tes, BlockSide side, String url) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate setURL(TileEntityScreen tes, BlockSide side, String url) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_URL;
|
||||
|
|
@ -65,8 +64,8 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate setResolution(TileEntityScreen tes, BlockSide side, Vector2i res) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate setResolution(TileEntityScreen tes, BlockSide side, Vector2i res) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_RESOLUTION;
|
||||
|
|
@ -75,8 +74,8 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate click(TileEntityScreen tes, BlockSide side, int mouseEvent, @Nullable Vector2i pos) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate click(TileEntityScreen tes, BlockSide side, int mouseEvent, @Nullable Vector2i pos) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_MOUSE;
|
||||
|
|
@ -86,14 +85,14 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public CMessageScreenUpdate(TileEntityScreen tes, BlockSide side) {
|
||||
public S2CMessageScreenUpdate(TileEntityScreen tes, BlockSide side) {
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
action = UPDATE_DELETE;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate type(TileEntityScreen tes, BlockSide side, String text) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate type(TileEntityScreen tes, BlockSide side, String text) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.string = text;
|
||||
|
|
@ -102,8 +101,8 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate js(TileEntityScreen tes, BlockSide side, String code) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate js(TileEntityScreen tes, BlockSide side, String code) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.string = code;
|
||||
|
|
@ -112,8 +111,8 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate upgrade(TileEntityScreen tes, BlockSide side) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate upgrade(TileEntityScreen tes, BlockSide side) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_UPGRADES;
|
||||
|
|
@ -127,8 +126,8 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate jsRedstone(TileEntityScreen tes, BlockSide side, Vector2i vec, int level) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate jsRedstone(TileEntityScreen tes, BlockSide side, Vector2i vec, int level) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_JS_REDSTONE;
|
||||
|
|
@ -138,8 +137,8 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate owner(TileEntityScreen tes, BlockSide side, NameUUIDPair owner) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate owner(TileEntityScreen tes, BlockSide side, NameUUIDPair owner) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_OWNER;
|
||||
|
|
@ -148,8 +147,8 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate rotation(TileEntityScreen tes, BlockSide side, Rotation rot) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate rotation(TileEntityScreen tes, BlockSide side, Rotation rot) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_ROTATION;
|
||||
|
|
@ -158,8 +157,8 @@ public class CMessageScreenUpdate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate autoVolume(TileEntityScreen tes, BlockSide side, boolean av) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
public static S2CMessageScreenUpdate autoVolume(TileEntityScreen tes, BlockSide side, boolean av) {
|
||||
S2CMessageScreenUpdate ret = new S2CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_AUTO_VOL;
|
||||
|
|
@ -167,13 +166,15 @@ public class CMessageScreenUpdate {
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate decode(FriendlyByteBuf buf) {
|
||||
|
||||
public S2CMessageScreenUpdate(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
|
||||
Vector3i pos = new Vector3i(buf);
|
||||
BlockSide side = BlockSide.values()[buf.readByte()];
|
||||
byte action = buf.readByte();
|
||||
|
||||
CMessageScreenUpdate message = new CMessageScreenUpdate();
|
||||
S2CMessageScreenUpdate message = this;
|
||||
message.pos = pos;
|
||||
message.side = side;
|
||||
message.action = action;
|
||||
|
|
@ -199,12 +200,10 @@ public class CMessageScreenUpdate {
|
|||
case UPDATE_ROTATION -> message.rotation = Rotation.values()[buf.readByte() & 3];
|
||||
case UPDATE_AUTO_VOL -> message.autoVolume = buf.readBoolean();
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
public CMessageScreenUpdate encode(FriendlyByteBuf buf) {
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
pos.writeTo(buf);
|
||||
buf.writeByte(side.ordinal());
|
||||
buf.writeByte(action);
|
||||
|
|
@ -232,12 +231,11 @@ public class CMessageScreenUpdate {
|
|||
buf.writeByte(rotation.ordinal());
|
||||
else if(action == UPDATE_AUTO_VOL)
|
||||
buf.writeBoolean(autoVolume);
|
||||
return new CMessageScreenUpdate();
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
BlockGetter level = WebDisplays.PROXY.getWorld(contextSupplier.get());
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
ctx.enqueueWork(() -> {
|
||||
BlockGetter level = WebDisplays.PROXY.getWorld(ctx);
|
||||
if (level instanceof Level level1)
|
||||
// ensure that the TE exists
|
||||
level1.setBlock(
|
||||
|
|
@ -278,6 +276,6 @@ public class CMessageScreenUpdate {
|
|||
}
|
||||
});
|
||||
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.client_bound;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.miniserv.client.Client;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.net.server_bound.C2SMessageMiniservConnect;
|
||||
|
||||
public class S2CMessageServerInfo extends Packet {
|
||||
|
||||
private int miniservPort;
|
||||
|
||||
public S2CMessageServerInfo(int msPort) {
|
||||
miniservPort = msPort;
|
||||
}
|
||||
|
||||
public S2CMessageServerInfo(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
miniservPort = buf.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeShort(miniservPort);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
if (checkClient(ctx)) {
|
||||
try {
|
||||
WebDisplays.PROXY.setMiniservClientPort(miniservPort);
|
||||
C2SMessageMiniservConnect message = Client.getInstance().beginConnection();
|
||||
respondLater(ctx, message);
|
||||
ctx.setPacketHandled(true);
|
||||
} catch (Throwable err) {
|
||||
err.printStackTrace();
|
||||
throw new RuntimeException(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.server;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
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 implements Runnable {
|
||||
|
||||
private ServerPlayer player;
|
||||
private String beginning;
|
||||
private boolean matchExact;
|
||||
|
||||
public SMessageACQuery(String beg, boolean exact) {
|
||||
beginning = beg;
|
||||
matchExact = exact;
|
||||
}
|
||||
|
||||
public static SMessageACQuery decode(FriendlyByteBuf buf) {
|
||||
return new SMessageACQuery(buf.readUtf(), buf.readBoolean());
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(beginning);
|
||||
buf.writeBoolean(matchExact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
GameProfile[] profiles = WebDisplays.PROXY.getOnlineGameProfiles();
|
||||
NameUUIDPair[] result;
|
||||
|
||||
if(matchExact)
|
||||
result = Arrays.stream(profiles).filter(gp -> gp.getName().equalsIgnoreCase(beginning)).map(NameUUIDPair::new).toArray(NameUUIDPair[]::new);
|
||||
else {
|
||||
final String lBeg = beginning.toLowerCase();
|
||||
result = Arrays.stream(profiles).filter(gp -> gp.getName().toLowerCase().startsWith(lBeg)).map(NameUUIDPair::new).toArray(NameUUIDPair[]::new);
|
||||
}
|
||||
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new CMessageACResult(result));
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
player = contextSupplier.get().getSender();
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
package net.montoyo.wd.net.server;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SMessageGetUrl {
|
||||
String url;
|
||||
|
||||
public SMessageGetUrl() {
|
||||
}
|
||||
|
||||
public SMessageGetUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public static SMessageGetUrl decode(FriendlyByteBuf buf) {
|
||||
SMessageGetUrl message = new SMessageGetUrl();
|
||||
message.url = buf.readUtf();
|
||||
return message;
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(url);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
if(Objects.requireNonNull(contextSupplier.get().getSender()).connection.getConnection().isConnected()) {
|
||||
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> contextSupplier.get().getSender()), new URLMessage(url));
|
||||
}
|
||||
Messages.INSTANCE.send(PacketDistributor.ALL.noArg(), new URLMessage(url));
|
||||
});
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.server;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraftforge.network.NetworkDirection;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.miniserv.server.ClientManager;
|
||||
import net.montoyo.wd.miniserv.server.Server;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageMiniservKey;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SMessageMiniservConnect {
|
||||
|
||||
private byte[] modulus;
|
||||
private byte[] exponent;
|
||||
|
||||
public SMessageMiniservConnect() {
|
||||
}
|
||||
|
||||
public SMessageMiniservConnect(byte[] mod, byte[] exp) {
|
||||
modulus = mod;
|
||||
exponent = exp;
|
||||
}
|
||||
|
||||
public static SMessageMiniservConnect decode(FriendlyByteBuf buf) {
|
||||
int sz = buf.readShort() & 0xFFFF;
|
||||
byte[] modulus = new byte[sz];
|
||||
buf.readBytes(modulus);
|
||||
|
||||
sz = buf.readShort() & 0xFFFF;
|
||||
byte[] exponent = new byte[sz];
|
||||
buf.readBytes(exponent);
|
||||
|
||||
return new SMessageMiniservConnect(modulus, exponent);
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeShort(modulus.length);
|
||||
buf.writeBytes(modulus);
|
||||
buf.writeShort(exponent.length);
|
||||
buf.writeBytes(exponent);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
ClientManager cliMgr = Server.getInstance().getClientManager();
|
||||
byte[] encKey = cliMgr.encryptClientKey(Objects.requireNonNull(contextSupplier.get().getSender()).getGameProfile().getId(), modulus, exponent);
|
||||
|
||||
if (encKey != null) {
|
||||
Messages.INSTANCE.sendTo(new CMessageMiniservKey(encKey), new Connection(PacketFlow.SERVERBOUND), NetworkDirection.LOGIN_TO_SERVER);
|
||||
}
|
||||
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.server;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.ItemInit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SMessagePadCtrl implements Runnable {
|
||||
|
||||
private int id;
|
||||
private String url;
|
||||
private ServerPlayer player;
|
||||
|
||||
public SMessagePadCtrl() {
|
||||
}
|
||||
|
||||
public SMessagePadCtrl(String url) {
|
||||
id = -1;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public SMessagePadCtrl(int id, String url) {
|
||||
this.id = id;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
private boolean matchesMinePadID(ItemStack is) {
|
||||
return is.getItem() == ItemInit.itemMinePad.get() && is.getTag() != null && is.getTag().contains("PadID") && is.getTag().getInt("PadID") == id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(id < 0) {
|
||||
ItemStack is = player.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
|
||||
if(is.getItem() == ItemInit.itemMinePad.get()) {
|
||||
if(url.isEmpty())
|
||||
is.setTag(null); //Shutdown
|
||||
else {
|
||||
if(is.getTag() == null)
|
||||
is.setTag(new CompoundTag());
|
||||
|
||||
if(!is.getTag().contains("PadID"))
|
||||
is.getTag().putInt("PadID", WebDisplays.getNextAvailablePadID());
|
||||
|
||||
String webUrl;
|
||||
try {
|
||||
webUrl = TileEntityScreen.url(url);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
is.getTag().putString("PadURL", WebDisplays.applyBlacklist(webUrl));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NonNullList<ItemStack> inv = player.getInventory().items;
|
||||
ItemStack target = null;
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
if(matchesMinePadID(inv.get(i))) {
|
||||
target = inv.get(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(target == null && matchesMinePadID(player.getInventory().offhand.get(0)))
|
||||
target = player.getInventory().offhand.get(0);
|
||||
|
||||
if(target != null) {
|
||||
String webUrl;
|
||||
try {
|
||||
webUrl = TileEntityScreen.url(url);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
target.getTag().putString("PadURL", WebDisplays.applyBlacklist(webUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static SMessagePadCtrl decode(FriendlyByteBuf buf) {
|
||||
SMessagePadCtrl message = new SMessagePadCtrl();
|
||||
message.id = buf.readInt();
|
||||
message.url = buf.readUtf();
|
||||
return message;
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeInt(id);
|
||||
buf.writeUtf(url);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
player = contextSupplier.get().getSender();
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.server;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SMessageRequestTEData implements Runnable {
|
||||
|
||||
private ResourceLocation dim;
|
||||
private Vector3i pos;
|
||||
private ServerPlayer player;
|
||||
|
||||
public SMessageRequestTEData() {
|
||||
}
|
||||
|
||||
public SMessageRequestTEData(BlockEntity te) {
|
||||
dim = te.getLevel().dimension().location();
|
||||
pos = new Vector3i(te.getBlockPos());
|
||||
}
|
||||
|
||||
public SMessageRequestTEData(ResourceLocation dim, Vector3i pos) {
|
||||
this.dim = dim;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
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.level.dimension().location().equals(dim))
|
||||
return;
|
||||
|
||||
BlockPos bp = pos.toBlock();
|
||||
if(player.distanceToSqr(bp.getX(), bp.getY(), bp.getZ()) > 512.0 * 512.0)
|
||||
return;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(te instanceof TileEntityScreen)
|
||||
((TileEntityScreen) te).requestData(player);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
player = contextSupplier.get().getSender();
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,372 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.server;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
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.network.NetworkEvent;
|
||||
import net.montoyo.wd.block.BlockPeripheral;
|
||||
import net.montoyo.wd.core.DefaultPeripheral;
|
||||
import net.montoyo.wd.core.JSServerRequest;
|
||||
import net.montoyo.wd.core.MissingPermissionException;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.init.ItemInit;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SMessageScreenCtrl implements Runnable {
|
||||
|
||||
public static final int CTRL_SET_URL = 0;
|
||||
public static final int CTRL_SHUT_DOWN = 1;
|
||||
public static final int CTRL_ADD_FRIEND = 2;
|
||||
public static final int CTRL_REMOVE_FRIEND = 3;
|
||||
public static final int CTRL_SET_RIGHTS = 4;
|
||||
public static final int CTRL_SET_RESOLUTION = 5;
|
||||
public static final int CTRL_TYPE = 6;
|
||||
public static final int CTRL_REMOVE_UPGRADE = 7;
|
||||
public static final int CTRL_LASER_DOWN = 8;
|
||||
public static final int CTRL_LASER_MOVE = 9;
|
||||
public static final int CTRL_LASER_UP = 10;
|
||||
public static final int CTRL_JS_REQUEST = 11;
|
||||
public static final int CTRL_SET_ROTATION = 12;
|
||||
public static final int CTRL_SET_URL_REMOTE = 13;
|
||||
public static final int CTRL_SET_AUTO_VOL = 14;
|
||||
|
||||
private int ctrl;
|
||||
private ResourceLocation dim;
|
||||
private Vector3i pos;
|
||||
private BlockSide side;
|
||||
private String url;
|
||||
private NameUUIDPair friend;
|
||||
private ServerPlayer player;
|
||||
private int friendRights;
|
||||
private int otherRights;
|
||||
private Vector2i vec2i;
|
||||
private String text;
|
||||
private BlockPos soundPos;
|
||||
private ItemStack toRemove;
|
||||
private int jsReqID;
|
||||
private JSServerRequest jsReqType;
|
||||
private Object[] jsReqData;
|
||||
private Rotation rotation;
|
||||
private Vector3i remoteLoc;
|
||||
private boolean autoVol;
|
||||
|
||||
public SMessageScreenCtrl() {
|
||||
}
|
||||
|
||||
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.getLevel().dimension().location();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.url = url;
|
||||
|
||||
if(remoteLocation != null)
|
||||
ret.remoteLoc = remoteLocation;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, NameUUIDPair friend, boolean del) {
|
||||
ctrl = del ? CTRL_REMOVE_FRIEND : CTRL_ADD_FRIEND;
|
||||
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.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
friendRights = fr;
|
||||
otherRights = or;
|
||||
}
|
||||
|
||||
public SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, ItemStack toRem) {
|
||||
ctrl = CTRL_REMOVE_UPGRADE;
|
||||
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.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
rotation = rot;
|
||||
}
|
||||
|
||||
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.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.text = text;
|
||||
ret.soundPos = soundPos;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static SMessageScreenCtrl vec2(TileEntityScreen tes, BlockSide side, int ctrl, Vector2i vec) {
|
||||
if(!isVec2Ctrl(ctrl))
|
||||
throw new RuntimeException("Called SMessageScreenCtrl.vec2() with non-vec2 control message " + ctrl);
|
||||
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = ctrl;
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.vec2i = vec;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static SMessageScreenCtrl laserUp(TileEntityScreen tes, BlockSide side) {
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_LASER_UP;
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.jsReqID = reqId;
|
||||
ret.jsReqType = reqType;
|
||||
ret.jsReqData = data;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.autoVol = av;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static boolean isVec2Ctrl(int msg) {
|
||||
return msg == CTRL_SET_RESOLUTION || msg == CTRL_LASER_DOWN || msg == CTRL_LASER_MOVE;
|
||||
}
|
||||
|
||||
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(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();
|
||||
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(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;
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeByte(ctrl);
|
||||
buf.writeResourceLocation(dim);
|
||||
pos.writeTo(buf);
|
||||
buf.writeByte(side.ordinal());
|
||||
|
||||
if(ctrl == CTRL_SET_URL)
|
||||
buf.writeUtf(url);
|
||||
else if(ctrl == CTRL_ADD_FRIEND || ctrl == CTRL_REMOVE_FRIEND)
|
||||
friend.writeTo(buf);
|
||||
else if(ctrl == CTRL_SET_RIGHTS) {
|
||||
buf.writeByte(friendRights);
|
||||
buf.writeByte(otherRights);
|
||||
} else if(isVec2Ctrl(ctrl))
|
||||
vec2i.writeTo(buf);
|
||||
else if(ctrl == CTRL_TYPE) {
|
||||
buf.writeUtf(text);
|
||||
buf.writeInt(soundPos.getX());
|
||||
buf.writeInt(soundPos.getY());
|
||||
buf.writeInt(soundPos.getZ());
|
||||
} else if(ctrl == CTRL_REMOVE_UPGRADE)
|
||||
buf.writeItem(toRemove);
|
||||
else if(ctrl == CTRL_JS_REQUEST) {
|
||||
buf.writeInt(jsReqID);
|
||||
buf.writeByte(jsReqType.ordinal());
|
||||
|
||||
if(!jsReqType.serialize(buf, jsReqData))
|
||||
throw new RuntimeException("Could not serialize CTRL_JS_REQUEST " + jsReqType);
|
||||
} else if(ctrl == CTRL_SET_ROTATION)
|
||||
buf.writeByte(rotation.ordinal());
|
||||
else if(ctrl == CTRL_SET_URL_REMOTE) {
|
||||
buf.writeUtf(url);
|
||||
remoteLoc.writeTo(buf);
|
||||
} else if(ctrl == CTRL_SET_AUTO_VOL)
|
||||
buf.writeBoolean(autoVol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(side == null) {
|
||||
Log.warning("Caught invalid packet from %s (UUID %s) referencing an invalid block side", player.getName(), player.getGameProfile().getId().toString());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
runUnsafe();
|
||||
} catch(MissingPermissionException e) {
|
||||
Log.errorEx("I have reasons to believe %s (UUID %s) is a hacker, but don't take my word for it...", e, e.getPlayer().getName(), e.getPlayer().getGameProfile().getId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPermission(TileEntityScreen scr, int right) throws MissingPermissionException {
|
||||
int prights = scr.getScreen(side).rightsFor(player);
|
||||
if((prights & right) == 0)
|
||||
throw new MissingPermissionException(right, player);
|
||||
}
|
||||
|
||||
private void runUnsafe() throws MissingPermissionException {
|
||||
Level world = player.level;
|
||||
BlockPos bp = pos.toBlock();
|
||||
|
||||
if(!world.dimension().location().equals(dim))
|
||||
return; //Out of range (dimension mismatch)
|
||||
|
||||
if(ctrl == CTRL_SET_URL_REMOTE) {
|
||||
double reachDist = player.getAttributeValue(ForgeMod.REACH_DISTANCE.get());
|
||||
BlockPos blockPos = remoteLoc.toBlock();
|
||||
|
||||
if(player.distanceToSqr(blockPos.getX(), blockPos.getY(), blockPos.getZ()) > reachDist * reachDist)
|
||||
return; //Out of range (player reach distance)
|
||||
|
||||
BlockState bs = world.getBlockState(blockPos);
|
||||
if(bs.getBlock() != BlockInit.blockServer.get() && bs.getBlock() != BlockInit.blockRControl.get() &&
|
||||
bs.getBlock() != BlockInit.blockKeyBoard.get() && bs.getBlock() != BlockInit.blockRedControl.get()
|
||||
&& bs.getValue(BlockPeripheral.type) != DefaultPeripheral.REMOTE_CONTROLLER)
|
||||
return; //I call it hax...
|
||||
} else if(player.distanceToSqr(bp.getX(), bp.getY(), bp.getZ()) > (128 * 128))
|
||||
return; //Out of range (range problem)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
TileEntityScreen tes = (TileEntityScreen) te;
|
||||
|
||||
if(ctrl == CTRL_SET_URL || ctrl == CTRL_SET_URL_REMOTE) {
|
||||
checkPermission(tes, ScreenRights.CHANGE_URL);
|
||||
try {
|
||||
tes.setScreenURL(side, url);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else if(ctrl == CTRL_SHUT_DOWN) {
|
||||
//TODO
|
||||
//checkPermission(tes, ScreenRights.CHANGE_URL);
|
||||
//tes.removeScreen(side);
|
||||
} else if(ctrl == CTRL_ADD_FRIEND) {
|
||||
checkPermission(tes, ScreenRights.MANAGE_FRIEND_LIST);
|
||||
tes.addFriend(player, side, friend);
|
||||
} else if(ctrl == CTRL_REMOVE_FRIEND) {
|
||||
checkPermission(tes, ScreenRights.MANAGE_FRIEND_LIST);
|
||||
tes.removeFriend(player, side, friend);
|
||||
} else if(ctrl == CTRL_SET_RIGHTS) {
|
||||
TileEntityScreen.Screen scr = tes.getScreen(side);
|
||||
|
||||
if(scr != null) {
|
||||
int fr = scr.owner.uuid.equals(player.getGameProfile().getId()) ? friendRights : scr.friendRights;
|
||||
int or = (scr.rightsFor(player) & ScreenRights.MANAGE_OTHER_RIGHTS) == 0 ? scr.otherRights : otherRights;
|
||||
|
||||
if(scr.friendRights != fr || scr.otherRights != or)
|
||||
tes.setRights(player, side, fr, or);
|
||||
}
|
||||
} else if(ctrl == CTRL_SET_RESOLUTION) {
|
||||
checkPermission(tes, ScreenRights.CHANGE_RESOLUTION);
|
||||
tes.setResolution(side, vec2i);
|
||||
} else if(ctrl == CTRL_TYPE) {
|
||||
checkPermission(tes, ScreenRights.CLICK);
|
||||
tes.type(side, text, soundPos);
|
||||
} else if(ctrl == CTRL_REMOVE_UPGRADE) {
|
||||
checkPermission(tes, ScreenRights.MANAGE_UPGRADES);
|
||||
tes.removeUpgrade(side, toRemove, player);
|
||||
} else if(ctrl == CTRL_LASER_DOWN || ctrl == CTRL_LASER_MOVE)
|
||||
tes.laserDownMove(side, player, vec2i, ctrl == CTRL_LASER_DOWN);
|
||||
else if(ctrl == CTRL_LASER_UP)
|
||||
tes.laserUp(side, player);
|
||||
else if(ctrl == CTRL_JS_REQUEST) {
|
||||
if(jsReqType == null || jsReqData == null)
|
||||
Log.warning("Caught invalid JS request from player %s (UUID %s)", player.getName(), player.getGameProfile().getId().toString());
|
||||
else
|
||||
tes.handleJSRequest(player, side, jsReqID, jsReqType, jsReqData);
|
||||
} else if(ctrl == CTRL_SET_ROTATION) {
|
||||
checkPermission(tes, ScreenRights.CHANGE_RESOLUTION);
|
||||
tes.setRotation(side, rotation);
|
||||
} else if(ctrl == CTRL_SET_AUTO_VOL) {
|
||||
checkPermission(tes, ScreenRights.MANAGE_UPGRADES); //because why not
|
||||
tes.setAutoVolume(side, autoVol);
|
||||
} else
|
||||
Log.warning("Caught SMessageScreenCtrl with invalid control ID %d from player %s (UUID %s)", ctrl, player.getName(), player.getGameProfile().getId().toString());
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
player = contextSupplier.get().getSender();
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package net.montoyo.wd.net.server;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class URLMessage {
|
||||
|
||||
private String url;
|
||||
|
||||
public URLMessage() {}
|
||||
|
||||
public URLMessage(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getURL() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public static URLMessage decode(FriendlyByteBuf buf) {
|
||||
URLMessage message = new URLMessage();
|
||||
message.url = buf.readUtf();
|
||||
return message;
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(url);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.server_bound;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageACResult;
|
||||
import net.montoyo.wd.utilities.NameUUIDPair;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class C2SMessageACQuery extends Packet implements Runnable {
|
||||
|
||||
private ServerPlayer player;
|
||||
private String beginning;
|
||||
private boolean matchExact;
|
||||
|
||||
public C2SMessageACQuery(String beg, boolean exact) {
|
||||
beginning = beg;
|
||||
matchExact = exact;
|
||||
}
|
||||
|
||||
public C2SMessageACQuery(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
beginning = buf.readUtf();
|
||||
matchExact = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(beginning);
|
||||
buf.writeBoolean(matchExact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
GameProfile[] profiles = WebDisplays.PROXY.getOnlineGameProfiles();
|
||||
NameUUIDPair[] result;
|
||||
|
||||
if (matchExact)
|
||||
result = Arrays.stream(profiles).filter(gp -> gp.getName().equalsIgnoreCase(beginning)).map(NameUUIDPair::new).toArray(NameUUIDPair[]::new);
|
||||
else {
|
||||
final String lBeg = beginning.toLowerCase();
|
||||
result = Arrays.stream(profiles).filter(gp -> gp.getName().toLowerCase().startsWith(lBeg)).map(NameUUIDPair::new).toArray(NameUUIDPair[]::new);
|
||||
}
|
||||
|
||||
WDNetworkRegistry.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new S2CMessageACResult(result));
|
||||
}
|
||||
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
player = ctx.getSender();
|
||||
ctx.enqueueWork(this);
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.server_bound;
|
||||
|
||||
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.BufferUtils;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageMiniservKey;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class C2SMessageMiniservConnect extends Packet {
|
||||
private byte[] modulus;
|
||||
private byte[] exponent;
|
||||
|
||||
public C2SMessageMiniservConnect(byte[] mod, byte[] exp) {
|
||||
modulus = mod;
|
||||
exponent = exp;
|
||||
}
|
||||
|
||||
public C2SMessageMiniservConnect(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
|
||||
modulus = BufferUtils.readBytes(buf);
|
||||
exponent = BufferUtils.readBytes(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
BufferUtils.writeBytes(buf, modulus);
|
||||
BufferUtils.writeBytes(buf, exponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
if (checkServer(ctx)) {
|
||||
try {
|
||||
ClientManager cliMgr = Server.getInstance().getClientManager();
|
||||
byte[] encKey = cliMgr.encryptClientKey(Objects.requireNonNull(ctx.getSender()).getGameProfile().getId(), modulus, exponent);
|
||||
|
||||
if (encKey != null) {
|
||||
respond(ctx, new S2CMessageMiniservKey(encKey));
|
||||
}
|
||||
|
||||
ctx.setPacketHandled(true);
|
||||
} catch (Throwable err) {
|
||||
err.printStackTrace();
|
||||
throw new RuntimeException(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,11 +2,10 @@
|
|||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.server;
|
||||
package net.montoyo.wd.net.server_bound;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
|
@ -15,36 +14,39 @@ import net.minecraftforge.network.NetworkEvent;
|
|||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.entity.TileEntityRedCtrl;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SMessageRedstoneCtrl implements Runnable {
|
||||
|
||||
public class C2SMessageRedstoneCtrl extends Packet implements Runnable {
|
||||
private Player player;
|
||||
private ResourceLocation dimension;
|
||||
private Vector3i pos;
|
||||
private String risingEdgeURL;
|
||||
private String fallingEdgeURL;
|
||||
|
||||
public SMessageRedstoneCtrl() {
|
||||
public C2SMessageRedstoneCtrl() {
|
||||
}
|
||||
|
||||
public SMessageRedstoneCtrl(ResourceLocation d, Vector3i p, String r, String f) {
|
||||
dimension = d;
|
||||
public C2SMessageRedstoneCtrl(Vector3i p, String r, String f) {
|
||||
pos = p;
|
||||
risingEdgeURL = r;
|
||||
fallingEdgeURL = f;
|
||||
}
|
||||
|
||||
|
||||
public C2SMessageRedstoneCtrl(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
pos = new Vector3i(buf);
|
||||
risingEdgeURL = buf.readUtf();
|
||||
fallingEdgeURL = buf.readUtf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Level world = player.level;
|
||||
BlockPos blockPos = pos.toBlock();
|
||||
final double maxRange = player.getAttribute(ForgeMod.REACH_DISTANCE.get()).getValue();
|
||||
|
||||
if(!world.dimension().location().equals(dimension) || player.distanceToSqr(blockPos.getX(), blockPos.getY(), blockPos.getZ()) > maxRange * maxRange)
|
||||
if(player.distanceToSqr(blockPos.getX(), blockPos.getY(), blockPos.getZ()) > maxRange * maxRange)
|
||||
return;
|
||||
|
||||
BlockEntity te = world.getBlockEntity(blockPos);
|
||||
|
|
@ -67,20 +69,16 @@ public class SMessageRedstoneCtrl implements Runnable {
|
|||
redCtrl.setURLs(risingEdgeURL, fallingEdgeURL);
|
||||
}
|
||||
|
||||
public static SMessageRedstoneCtrl decode(FriendlyByteBuf buf) {
|
||||
return new SMessageRedstoneCtrl(buf.readResourceLocation(), new Vector3i(buf), buf.readUtf(), buf.readUtf());
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeResourceLocation(dimension);
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
pos.writeTo(buf);
|
||||
buf.writeUtf(risingEdgeURL);
|
||||
buf.writeUtf(fallingEdgeURL);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
player = contextSupplier.get().getSender();
|
||||
contextSupplier.get().enqueueWork(this);
|
||||
contextSupplier.get().setPacketHandled(true);
|
||||
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
player = ctx.getSender();
|
||||
ctx.enqueueWork(this);
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,374 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net.server_bound;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
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.network.NetworkEvent;
|
||||
import net.montoyo.wd.block.BlockPeripheral;
|
||||
import net.montoyo.wd.core.DefaultPeripheral;
|
||||
import net.montoyo.wd.core.JSServerRequest;
|
||||
import net.montoyo.wd.core.MissingPermissionException;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
// TODO: this is a mess; a registry based approach would likely be more readable
|
||||
public class C2SMessageScreenCtrl extends Packet implements Runnable {
|
||||
public static final int CTRL_SET_URL = 0;
|
||||
public static final int CTRL_SHUT_DOWN = 1;
|
||||
public static final int CTRL_ADD_FRIEND = 2;
|
||||
public static final int CTRL_REMOVE_FRIEND = 3;
|
||||
public static final int CTRL_SET_RIGHTS = 4;
|
||||
public static final int CTRL_SET_RESOLUTION = 5;
|
||||
public static final int CTRL_TYPE = 6;
|
||||
public static final int CTRL_REMOVE_UPGRADE = 7;
|
||||
public static final int CTRL_LASER_DOWN = 8;
|
||||
public static final int CTRL_LASER_MOVE = 9;
|
||||
public static final int CTRL_LASER_UP = 10;
|
||||
public static final int CTRL_JS_REQUEST = 11;
|
||||
public static final int CTRL_SET_ROTATION = 12;
|
||||
public static final int CTRL_SET_URL_REMOTE = 13;
|
||||
public static final int CTRL_SET_AUTO_VOL = 14;
|
||||
|
||||
private int ctrl;
|
||||
private ResourceLocation dim;
|
||||
private Vector3i pos;
|
||||
private BlockSide side;
|
||||
private String url;
|
||||
private NameUUIDPair friend;
|
||||
private ServerPlayer player;
|
||||
private int friendRights;
|
||||
private int otherRights;
|
||||
private Vector2i vec2i;
|
||||
private String text;
|
||||
private BlockPos soundPos;
|
||||
private ItemStack toRemove;
|
||||
private int jsReqID;
|
||||
private JSServerRequest jsReqType;
|
||||
private Object[] jsReqData;
|
||||
private Rotation rotation;
|
||||
private Vector3i remoteLoc;
|
||||
private boolean autoVol;
|
||||
|
||||
public C2SMessageScreenCtrl() {
|
||||
}
|
||||
|
||||
public static C2SMessageScreenCtrl setURL(TileEntityScreen tes, BlockSide side, String url, Vector3i remoteLocation) {
|
||||
C2SMessageScreenCtrl ret = new C2SMessageScreenCtrl();
|
||||
ret.ctrl = (remoteLocation == null) ? CTRL_SET_URL : CTRL_SET_URL_REMOTE;
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.url = url;
|
||||
|
||||
if (remoteLocation != null)
|
||||
ret.remoteLoc = remoteLocation;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public C2SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, NameUUIDPair friend, boolean del) {
|
||||
ctrl = del ? CTRL_REMOVE_FRIEND : CTRL_ADD_FRIEND;
|
||||
dim = tes.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
this.friend = friend;
|
||||
}
|
||||
|
||||
public C2SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, int fr, int or) {
|
||||
ctrl = CTRL_SET_RIGHTS;
|
||||
dim = tes.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
friendRights = fr;
|
||||
otherRights = or;
|
||||
}
|
||||
|
||||
public C2SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, ItemStack toRem) {
|
||||
ctrl = CTRL_REMOVE_UPGRADE;
|
||||
dim = tes.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
toRemove = toRem;
|
||||
}
|
||||
|
||||
public C2SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, Rotation rot) {
|
||||
ctrl = CTRL_SET_ROTATION;
|
||||
dim = tes.getLevel().dimension().location();
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
this.side = side;
|
||||
rotation = rot;
|
||||
}
|
||||
|
||||
public static C2SMessageScreenCtrl type(TileEntityScreen tes, BlockSide side, String text, BlockPos soundPos) {
|
||||
C2SMessageScreenCtrl ret = new C2SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_TYPE;
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.text = text;
|
||||
ret.soundPos = soundPos;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static C2SMessageScreenCtrl vec2(TileEntityScreen tes, BlockSide side, int ctrl, Vector2i vec) {
|
||||
if (!isVec2Ctrl(ctrl))
|
||||
throw new RuntimeException("Called SMessageScreenCtrl.vec2() with non-vec2 control message " + ctrl);
|
||||
|
||||
C2SMessageScreenCtrl ret = new C2SMessageScreenCtrl();
|
||||
ret.ctrl = ctrl;
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.vec2i = vec;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static C2SMessageScreenCtrl laserUp(TileEntityScreen tes, BlockSide side) {
|
||||
C2SMessageScreenCtrl ret = new C2SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_LASER_UP;
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static C2SMessageScreenCtrl jsRequest(TileEntityScreen tes, BlockSide side, int reqId, JSServerRequest reqType, Object... data) {
|
||||
C2SMessageScreenCtrl ret = new C2SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_JS_REQUEST;
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.jsReqID = reqId;
|
||||
ret.jsReqType = reqType;
|
||||
ret.jsReqData = data;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static C2SMessageScreenCtrl autoVol(TileEntityScreen tes, BlockSide side, boolean av) {
|
||||
C2SMessageScreenCtrl ret = new C2SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_SET_AUTO_VOL;
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.dim = tes.getLevel().dimension().location();
|
||||
ret.side = side;
|
||||
ret.autoVol = av;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static boolean isVec2Ctrl(int msg) {
|
||||
return msg == CTRL_SET_RESOLUTION || msg == CTRL_LASER_DOWN || msg == CTRL_LASER_MOVE;
|
||||
}
|
||||
|
||||
public C2SMessageScreenCtrl(FriendlyByteBuf buf) {
|
||||
super(buf);
|
||||
decode(buf);
|
||||
}
|
||||
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
C2SMessageScreenCtrl message = this;
|
||||
message.ctrl = buf.readByte();
|
||||
message.dim = buf.readResourceLocation();
|
||||
message.pos = new Vector3i(buf);
|
||||
message.side = BlockSide.fromInt(buf.readByte());
|
||||
|
||||
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();
|
||||
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 (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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeByte(ctrl);
|
||||
buf.writeResourceLocation(dim);
|
||||
pos.writeTo(buf);
|
||||
buf.writeByte(side.ordinal());
|
||||
|
||||
if (ctrl == CTRL_SET_URL)
|
||||
buf.writeUtf(url);
|
||||
else if (ctrl == CTRL_ADD_FRIEND || ctrl == CTRL_REMOVE_FRIEND)
|
||||
friend.writeTo(buf);
|
||||
else if (ctrl == CTRL_SET_RIGHTS) {
|
||||
buf.writeByte(friendRights);
|
||||
buf.writeByte(otherRights);
|
||||
} else if (isVec2Ctrl(ctrl))
|
||||
vec2i.writeTo(buf);
|
||||
else if (ctrl == CTRL_TYPE) {
|
||||
buf.writeUtf(text);
|
||||
buf.writeInt(soundPos.getX());
|
||||
buf.writeInt(soundPos.getY());
|
||||
buf.writeInt(soundPos.getZ());
|
||||
} else if (ctrl == CTRL_REMOVE_UPGRADE)
|
||||
buf.writeItem(toRemove);
|
||||
else if (ctrl == CTRL_JS_REQUEST) {
|
||||
buf.writeInt(jsReqID);
|
||||
buf.writeByte(jsReqType.ordinal());
|
||||
|
||||
if (!jsReqType.serialize(buf, jsReqData))
|
||||
throw new RuntimeException("Could not serialize CTRL_JS_REQUEST " + jsReqType);
|
||||
} else if (ctrl == CTRL_SET_ROTATION)
|
||||
buf.writeByte(rotation.ordinal());
|
||||
else if (ctrl == CTRL_SET_URL_REMOTE) {
|
||||
buf.writeUtf(url);
|
||||
remoteLoc.writeTo(buf);
|
||||
} else if (ctrl == CTRL_SET_AUTO_VOL)
|
||||
buf.writeBoolean(autoVol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (side == null) {
|
||||
Log.warning("Caught invalid packet from %s (UUID %s) referencing an invalid block side", player.getName(), player.getGameProfile().getId().toString());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
runUnsafe();
|
||||
} catch (MissingPermissionException e) {
|
||||
Log.errorEx("I have reasons to believe %s (UUID %s) is a hacker, but don't take my word for it...", e, e.getPlayer().getName(), e.getPlayer().getGameProfile().getId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPermission(TileEntityScreen scr, int right) throws MissingPermissionException {
|
||||
int prights = scr.getScreen(side).rightsFor(player);
|
||||
if ((prights & right) == 0)
|
||||
throw new MissingPermissionException(right, player);
|
||||
}
|
||||
|
||||
private void runUnsafe() throws MissingPermissionException {
|
||||
Level world = player.level;
|
||||
BlockPos bp = pos.toBlock();
|
||||
|
||||
if (!world.dimension().location().equals(dim))
|
||||
return; //Out of range (dimension mismatch)
|
||||
|
||||
if (ctrl == CTRL_SET_URL_REMOTE) {
|
||||
double reachDist = player.getAttributeValue(ForgeMod.REACH_DISTANCE.get());
|
||||
BlockPos blockPos = remoteLoc.toBlock();
|
||||
|
||||
if (player.distanceToSqr(blockPos.getX(), blockPos.getY(), blockPos.getZ()) > reachDist * reachDist)
|
||||
return; //Out of range (player reach distance)
|
||||
|
||||
BlockState bs = world.getBlockState(blockPos);
|
||||
if (bs.getBlock() != BlockInit.blockServer.get() && bs.getBlock() != BlockInit.blockRControl.get() &&
|
||||
bs.getBlock() != BlockInit.blockKeyBoard.get() && bs.getBlock() != BlockInit.blockRedControl.get()
|
||||
&& bs.getValue(BlockPeripheral.type) != DefaultPeripheral.REMOTE_CONTROLLER)
|
||||
return; //I call it hax...
|
||||
} else if (player.distanceToSqr(bp.getX(), bp.getY(), bp.getZ()) > (128 * 128))
|
||||
return; //Out of range (range problem)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
TileEntityScreen tes = (TileEntityScreen) te;
|
||||
|
||||
if (ctrl == CTRL_SET_URL || ctrl == CTRL_SET_URL_REMOTE) {
|
||||
checkPermission(tes, ScreenRights.CHANGE_URL);
|
||||
try {
|
||||
tes.setScreenURL(side, url);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else if (ctrl == CTRL_SHUT_DOWN) {
|
||||
//TODO
|
||||
//checkPermission(tes, ScreenRights.CHANGE_URL);
|
||||
//tes.removeScreen(side);
|
||||
} else if (ctrl == CTRL_ADD_FRIEND) {
|
||||
checkPermission(tes, ScreenRights.MANAGE_FRIEND_LIST);
|
||||
tes.addFriend(player, side, friend);
|
||||
} else if (ctrl == CTRL_REMOVE_FRIEND) {
|
||||
checkPermission(tes, ScreenRights.MANAGE_FRIEND_LIST);
|
||||
tes.removeFriend(player, side, friend);
|
||||
} else if (ctrl == CTRL_SET_RIGHTS) {
|
||||
TileEntityScreen.Screen scr = tes.getScreen(side);
|
||||
|
||||
if (scr != null) {
|
||||
int fr = scr.owner.uuid.equals(player.getGameProfile().getId()) ? friendRights : scr.friendRights;
|
||||
int or = (scr.rightsFor(player) & ScreenRights.MANAGE_OTHER_RIGHTS) == 0 ? scr.otherRights : otherRights;
|
||||
|
||||
if (scr.friendRights != fr || scr.otherRights != or)
|
||||
tes.setRights(player, side, fr, or);
|
||||
}
|
||||
} else if (ctrl == CTRL_SET_RESOLUTION) {
|
||||
checkPermission(tes, ScreenRights.CHANGE_RESOLUTION);
|
||||
tes.setResolution(side, vec2i);
|
||||
} else if (ctrl == CTRL_TYPE) {
|
||||
checkPermission(tes, ScreenRights.CLICK);
|
||||
tes.type(side, text, soundPos);
|
||||
} else if (ctrl == CTRL_REMOVE_UPGRADE) {
|
||||
checkPermission(tes, ScreenRights.MANAGE_UPGRADES);
|
||||
tes.removeUpgrade(side, toRemove, player);
|
||||
} else if (ctrl == CTRL_LASER_DOWN || ctrl == CTRL_LASER_MOVE)
|
||||
tes.laserDownMove(side, player, vec2i, ctrl == CTRL_LASER_DOWN);
|
||||
else if (ctrl == CTRL_LASER_UP)
|
||||
tes.laserUp(side, player);
|
||||
else if (ctrl == CTRL_JS_REQUEST) {
|
||||
if (jsReqType == null || jsReqData == null)
|
||||
Log.warning("Caught invalid JS request from player %s (UUID %s)", player.getName(), player.getGameProfile().getId().toString());
|
||||
else
|
||||
tes.handleJSRequest(player, side, jsReqID, jsReqType, jsReqData);
|
||||
} else if (ctrl == CTRL_SET_ROTATION) {
|
||||
checkPermission(tes, ScreenRights.CHANGE_RESOLUTION);
|
||||
tes.setRotation(side, rotation);
|
||||
} else if (ctrl == CTRL_SET_AUTO_VOL) {
|
||||
checkPermission(tes, ScreenRights.MANAGE_UPGRADES); //because why not
|
||||
tes.setAutoVolume(side, autoVol);
|
||||
} else
|
||||
Log.warning("Caught SMessageScreenCtrl with invalid control ID %d from player %s (UUID %s)", ctrl, player.getName(), player.getGameProfile().getId().toString());
|
||||
}
|
||||
|
||||
public void handle(NetworkEvent.Context ctx) {
|
||||
player = ctx.getSender();
|
||||
ctx.enqueueWork(this);
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,16 @@
|
|||
package net.montoyo.wd.utilities;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.montoyo.wd.client.ClientProxy;
|
||||
|
||||
public class DistSafety {
|
||||
public static ClientProxy createProxy() {
|
||||
return new ClientProxy();
|
||||
}
|
||||
|
||||
public static boolean isConnected() {
|
||||
if (Minecraft.getInstance().getConnection() == null) return false;
|
||||
if (Minecraft.getInstance().getConnection().getConnection().isConnecting()) return false;
|
||||
return Minecraft.getInstance().getConnection().getConnection().isConnected();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user