fixed more stuff
This commit is contained in:
parent
75734fa631
commit
ca41720a9c
|
|
@ -6,8 +6,11 @@ package net.montoyo.wd;
|
|||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.core.HasAdvancement;
|
||||
|
|
@ -20,10 +23,7 @@ import javax.annotation.Nonnull;
|
|||
|
||||
import static net.minecraftforge.api.distmarker.Dist.CLIENT;
|
||||
|
||||
public class SharedProxy {
|
||||
|
||||
public static final int CURRENT_DIMENSION = Integer.MAX_VALUE;
|
||||
|
||||
public abstract class SharedProxy {
|
||||
public void preInit() {
|
||||
}
|
||||
|
||||
|
|
@ -33,11 +33,8 @@ public class SharedProxy {
|
|||
public void postInit() {
|
||||
}
|
||||
|
||||
public World getWorld(int dim) {
|
||||
if(dim == CURRENT_DIMENSION)
|
||||
throw new RuntimeException("Current dimension not available server side...");
|
||||
|
||||
return DimensionManager.getWorld(dim);
|
||||
public Level getWorld(ResourceKey<Level> dim) {
|
||||
return getServer().getLevel(dim);
|
||||
}
|
||||
|
||||
public void enqueue(Runnable r) {
|
||||
|
|
@ -54,9 +51,7 @@ public class SharedProxy {
|
|||
public void onAutocompleteResult(NameUUIDPair pairs[]) {
|
||||
}
|
||||
|
||||
public GameProfile[] getOnlineGameProfiles() {
|
||||
return FMLServerHandler.instance().getServer().getOnlinePlayerProfiles();
|
||||
}
|
||||
public abstract GameProfile[] getOnlineGameProfiles();
|
||||
|
||||
public void screenUpdateResolutionInGui(Vector3i pos, BlockSide side, Vector2i res) {
|
||||
}
|
||||
|
|
@ -89,7 +84,7 @@ public class SharedProxy {
|
|||
}
|
||||
|
||||
public MinecraftServer getServer() {
|
||||
return ServerLifecycleHooks.getCurrentServer();CLIENT
|
||||
return ServerLifecycleHooks.getCurrentServer();
|
||||
}
|
||||
|
||||
public void setMiniservClientPort(int port) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
|
|||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
|
@ -20,10 +22,11 @@ import net.minecraft.sounds.SoundSource;
|
|||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.client.event.ClientChatEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
|
|
@ -53,8 +56,8 @@ import net.montoyo.wd.utilities.Util;
|
|||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mod("webdisplays")
|
||||
|
|
@ -66,7 +69,6 @@ public class WebDisplays {
|
|||
|
||||
public static SharedProxy PROXY = DistExecutor.<SharedProxy>runForDist(() -> ClientProxy::new, () -> SharedProxy::new);
|
||||
|
||||
public static SimpleNetworkWrapper NET_HANDLER;
|
||||
public static WDCreativeTab CREATIVE_TAB;
|
||||
public static final ResourceLocation ADV_PAD_BREAK = new ResourceLocation("webdisplays", "webdisplays/pad_break");
|
||||
public static final String BLACKLIST_URL = "mod://webdisplays/blacklisted.html";
|
||||
|
|
@ -129,65 +131,6 @@ public class WebDisplays {
|
|||
public WebDisplays() {
|
||||
AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new);
|
||||
ConfigHolder<ModConfig> configHolder = AutoConfig.getConfigHolder(ModConfig.class);
|
||||
// Configuration cfg = new Configuration();
|
||||
// cfg.load();
|
||||
//
|
||||
// //CAT: Main
|
||||
// Property blacklist = cfg.get("main", "blacklist", new String[0]);
|
||||
// Property padHeight = cfg.get("main", "padHeight", 480);
|
||||
// Property hardRecipe = cfg.get("main", "hardRecipes", true);
|
||||
// Property homePage = cfg.get("main", "homepage", "mod://webdisplays/main.html");
|
||||
// Property disableOT = cfg.get("main", "disableOwnershipThief", false);
|
||||
// Property maxResX = cfg.get("main", "maxResolutionX", 1920);
|
||||
// Property maxResY = cfg.get("main", "maxResolutionY", 1080);
|
||||
// Property miniservPort = cfg.get("main", "miniservPort", 25566);
|
||||
// Property miniservQuota = cfg.get("main", "miniservQuota", 1024); //It's stored as a string anyway
|
||||
// Property maxScreenX = cfg.get("main", "maxScreenSizeX", 16);
|
||||
// Property maxScreenY = cfg.get("main", "maxScreenSizeY", 16);
|
||||
//
|
||||
// //CAT: Client options
|
||||
// Property loadDistance = cfg.get("client", "loadDistance", 30.0);
|
||||
// Property unloadDistance = cfg.get("client", "unloadDistance", 32.0);
|
||||
//
|
||||
// //CAT: Auto volume config (client-side)
|
||||
// Property enableAutoVol = cfg.get("clientAutoVolume", "enableAutoVolume", true);
|
||||
// Property ytVolume = cfg.get("clientAutoVolume", "ytVolume", 100.0);
|
||||
// Property dist100 = cfg.get("clientAutoVolume", "dist100", 10.0);
|
||||
// Property dist0 = cfg.get("clientAutoVolume", "dist0", 30.0);
|
||||
//
|
||||
//
|
||||
// //Comments & shit
|
||||
// blacklist.setComment("An array of domain names you don't want to load.");
|
||||
// padHeight.setComment("The minePad Y resolution in pixels. padWidth = padHeight * " + PAD_RATIO);
|
||||
// hardRecipe.setComment("If true, breaking the minePad is required to craft upgrades.");
|
||||
// homePage.setComment("The URL that will be loaded each time you create a screen");
|
||||
// disableOT.setComment("If true, the ownership thief item will be disabled");
|
||||
// loadDistance.setComment("All screens outside this range will be unloaded");
|
||||
// unloadDistance.setComment("All unloaded screens inside this range will be loaded");
|
||||
// maxResX.setComment("Maximum horizontal screen resolution, in pixels");
|
||||
// maxResY.setComment("Maximum vertical screen resolution, in pixels");
|
||||
// miniservPort.setComment("The port used by miniserv. 0 to disable.");
|
||||
// miniservPort.setMaxValue(Short.MAX_VALUE);
|
||||
// miniservQuota.setComment("The amount of data that can be uploaded to miniserv, in KiB (so 1024 = 1 MiO)");
|
||||
// maxScreenX.setComment("Maximum screen width, in blocks. Resolution will be clamped by maxResolutionX.");
|
||||
// maxScreenY.setComment("Maximum screen height, in blocks. Resolution will be clamped by maxResolutionY.");
|
||||
// enableAutoVol.setComment("If true, the volume of YouTube videos will change depending on how far you are");
|
||||
// ytVolume.setComment("Volume for YouTube videos. This will have no effect if enableSoundDistance is set to false");
|
||||
// ytVolume.setMinValue(0.0);
|
||||
// ytVolume.setMaxValue(100.0);
|
||||
// dist100.setComment("Distance after which the sound starts dropping (in blocks)");
|
||||
// dist100.setMinValue(0.0);
|
||||
// dist0.setComment("Distance after which you can't hear anything (in blocks)");
|
||||
// dist0.setMinValue(0.0);
|
||||
//
|
||||
// if(unloadDistance.getDouble() < loadDistance.getDouble() + 2.0)
|
||||
// unloadDistance.set(loadDistance.getDouble() + 2.0);
|
||||
//
|
||||
// if(dist0.getDouble() < dist100.getDouble() + 0.1)
|
||||
// dist0.set(dist100.getDouble() + 0.1);
|
||||
//
|
||||
// cfg.save();
|
||||
|
||||
ModConfig config = configHolder.getConfig();
|
||||
configHolder.save();
|
||||
|
||||
|
|
@ -246,23 +189,20 @@ public class WebDisplays {
|
|||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
//Register tile entities
|
||||
GameRegistry.registerTileEntity(TileEntityScreen.class, new ResourceLocation("webdisplays", "screen"));
|
||||
Registry.register(Registry.BLOCK_ENTITY_TYPE, TileEntityScreen.class, new ResourceLocation("webdisplays", "screen"));
|
||||
for(DefaultPeripheral dp: DefaultPeripheral.values()) {
|
||||
if(dp.getTEClass() != null)
|
||||
GameRegistry.registerTileEntity(dp.getTEClass(), new ResourceLocation("webdisplays", dp.getName()));
|
||||
}
|
||||
|
||||
//Other things
|
||||
CapabilityManager.INSTANCE.register(IWDDCapability.class, new WDDCapability.Storage(), new WDDCapability.Factory());
|
||||
PROXY.init();
|
||||
NET_HANDLER = NetworkRegistry.INSTANCE.newSimpleChannel("webdisplays");
|
||||
Messages.registerAll(NET_HANDLER);
|
||||
|
||||
PROXY.postInit();
|
||||
hasOC = ModList.get().isLoaded("opencomputers");
|
||||
hasCC = ModList.get().isLoaded("computercraft");
|
||||
|
||||
if(hasCC) {
|
||||
/* if(hasCC) {
|
||||
try {
|
||||
//We have to do this because the "register" method might be stripped out if CC isn't loaded
|
||||
CCPeripheralProvider.class.getMethod("register").invoke(null);
|
||||
|
|
@ -270,6 +210,13 @@ public class WebDisplays {
|
|||
Log.error("ComputerCraft was found, but WebDisplays wasn't able to register its CC Interface Peripheral");
|
||||
t.printStackTrace();
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onAttachPlayerCap(AttachCapabilitiesEvent<Entity> event) {
|
||||
if (event.getObject() instanceof Player && !event.getObject().getCapability(WDDCapability.Provider.cap).isPresent()) {
|
||||
event.addCapability(new ResourceLocation("webdisplays", "wddcapability"), new WDDCapability.Provider());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -296,84 +243,87 @@ public class WebDisplays {
|
|||
|
||||
@SubscribeEvent
|
||||
public void onWorldLoad(WorldEvent.Load ev) {
|
||||
if(ev.getWorld().isClientSide() || ev.getWorld().provider.getDimension() != 0)
|
||||
return;
|
||||
if (ev.getWorld() instanceof Level level) {
|
||||
if (ev.getWorld().isClientSide() || level.dimension() != Level.OVERWORLD)
|
||||
return;
|
||||
|
||||
File worldDir = ev.getWorld().getSaveHandler().getWorldDirectory();
|
||||
File f = new File(worldDir, "wd_next.txt");
|
||||
File worldDir = Objects.requireNonNull(ev.getWorld().getServer()).getServerDirectory();
|
||||
File f = new File(worldDir, "wd_next.txt");
|
||||
|
||||
if(f.exists()) {
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader(f));
|
||||
String idx = br.readLine();
|
||||
Util.silentClose(br);
|
||||
if (f.exists()) {
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader(f));
|
||||
String idx = br.readLine();
|
||||
Util.silentClose(br);
|
||||
|
||||
if(idx == null)
|
||||
throw new RuntimeException("Seems like the file is empty (1)");
|
||||
if (idx == null)
|
||||
throw new RuntimeException("Seems like the file is empty (1)");
|
||||
|
||||
idx = idx.trim();
|
||||
if(idx.isEmpty())
|
||||
throw new RuntimeException("Seems like the file is empty (2)");
|
||||
idx = idx.trim();
|
||||
if (idx.isEmpty())
|
||||
throw new RuntimeException("Seems like the file is empty (2)");
|
||||
|
||||
lastPadId = Integer.parseInt(idx); //This will throw NumberFormatException if it goes wrong
|
||||
} catch(Throwable t) {
|
||||
Log.warningEx("Could not read last minePad ID from %s. I'm afraid this might break all minePads.", t, f.getAbsolutePath());
|
||||
lastPadId = Integer.parseInt(idx); //This will throw NumberFormatException if it goes wrong
|
||||
} catch (Throwable t) {
|
||||
Log.warningEx("Could not read last minePad ID from %s. I'm afraid this might break all minePads.", t, f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(miniservPort != 0) {
|
||||
Server sv = Server.getInstance();
|
||||
sv.setPort(miniservPort);
|
||||
sv.setDirectory(new File(worldDir, "wd_filehost"));
|
||||
sv.start();
|
||||
if (miniservPort != 0) {
|
||||
Server sv = Server.getInstance();
|
||||
sv.setPort(miniservPort);
|
||||
sv.setDirectory(new File(worldDir, "wd_filehost"));
|
||||
sv.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldSave(WorldEvent.Save ev) {
|
||||
if(ev.getWorld().isClientSide() || ev.getWorld().provider.getDimension() != 0)
|
||||
return;
|
||||
if(ev.getWorld() instanceof Level level) {
|
||||
if (ev.getWorld().isClientSide() || level.dimension() != Level.OVERWORLD)
|
||||
return;
|
||||
File f = new File(Objects.requireNonNull(ev.getWorld().getServer()).getServerDirectory(), "wd_next.txt");
|
||||
|
||||
File f = new File(ev.getWorld().getSaveHandler().getWorldDirectory(), "wd_next.txt");
|
||||
|
||||
try {
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
|
||||
bw.write("" + lastPadId + "\n");
|
||||
Util.silentClose(bw);
|
||||
} catch(Throwable t) {
|
||||
Log.warningEx("Could not save last minePad ID (%d) to %s. I'm afraid this might break all minePads.", t, lastPadId, f.getAbsolutePath());
|
||||
try {
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
|
||||
bw.write("" + lastPadId + "\n");
|
||||
Util.silentClose(bw);
|
||||
} catch (Throwable t) {
|
||||
Log.warningEx("Could not save last minePad ID (%d) to %s. I'm afraid this might break all minePads.", t, lastPadId, f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onToss(ItemTossEvent ev) {
|
||||
if(!ev.getEntityItem().world.isRemote) {
|
||||
if(!ev.getEntityItem().getLevel().isClientSide) {
|
||||
ItemStack is = ev.getEntityItem().getItem();
|
||||
|
||||
if(is.getItem() == itemMinePad) {
|
||||
NBTTagCompound tag = is.getTagCompound();
|
||||
CompoundTag tag = is.getTag();
|
||||
|
||||
if(tag == null) {
|
||||
tag = new NBTTagCompound();
|
||||
is.setTagCompound(tag);
|
||||
tag = new CompoundTag();
|
||||
is.setTag(tag);
|
||||
}
|
||||
|
||||
UUID thrower = ev.getPlayer().getGameProfile().getId();
|
||||
tag.setLong("ThrowerMSB", thrower.getMostSignificantBits());
|
||||
tag.setLong("ThrowerLSB", thrower.getLeastSignificantBits());
|
||||
tag.setDouble("ThrowHeight", ev.getPlayer().getY() + ev.getPlayer().getEyeHeight());
|
||||
tag.putLong("ThrowerMSB", thrower.getMostSignificantBits());
|
||||
tag.putLong("ThrowerLSB", thrower.getLeastSignificantBits());
|
||||
tag.putDouble("ThrowHeight", ev.getPlayer().getY() + ev.getPlayer().getEyeHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerCraft(PlayerEvent.ItemCraftedEvent ev) {
|
||||
if(doHardRecipe && ev.getCrafting().getItem() == itemCraftComp && ev.getCrafting().is(CraftComponent.EXTENSION_CARD.makeItemStack()) {
|
||||
if((ev.getCrafting() instanceof ServerPlayer && !hasPlayerAdvancement((ServerPlayer) ev.getPlayer(), ADV_PAD_BREAK)) || PROXY.hasClientPlayerAdvancement(ADV_PAD_BREAK) != HasAdvancement.YES) {
|
||||
if(doHardRecipe && ev.getCrafting().getItem() == itemCraftComp && (CraftComponent.EXTENSION_CARD.makeItemStack().is(ev.getCrafting().getItem()))) {
|
||||
if((ev.getPlayer() instanceof ServerPlayer && !hasPlayerAdvancement((ServerPlayer) ev.getPlayer(), ADV_PAD_BREAK)) || PROXY.hasClientPlayerAdvancement(ADV_PAD_BREAK) != HasAdvancement.YES) {
|
||||
ev.getCrafting().setDamageValue(CraftComponent.BAD_EXTENSION_CARD.ordinal());
|
||||
|
||||
if(!ev.getPlayer().getLevel().isClientSide)
|
||||
ev.getPlayer().getLevel().playSound(null, ev.getPlayer().getX(), ev.getPlayer().getY(), ev.getPlayer().getZ(), SoundEvents.ENTITY_ITEM_BREAK, SoundSource.MASTER, 1.0f, 1.0f);
|
||||
ev.getPlayer().getLevel().playSound(null, ev.getPlayer().getX(), ev.getPlayer().getY(), ev.getPlayer().getZ(), SoundEvents.ITEM_BREAK, SoundSource.MASTER, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -387,7 +337,7 @@ public class WebDisplays {
|
|||
public void onLogIn(PlayerEvent.PlayerLoggedInEvent ev) {
|
||||
if(!ev.getPlayer().getLevel().isClientSide && ev.getPlayer() instanceof ServerPlayer) {
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageServerInfo(miniservPort), (ServerPlayer) ev.getPlayer());
|
||||
IWDDCapability cap = ev.getPlayer().getCapability(WDDCapability.INSTANCE, null);
|
||||
IWDDCapability cap = (IWDDCapability) ev.getPlayer().getCapability(WDDCapability.Provider.cap, null);
|
||||
|
||||
if(cap == null)
|
||||
Log.warning("Player %s (%s) has null IWDDCapability!", ev.getPlayer().getName(), ev.getPlayer().getGameProfile().getId().toString());
|
||||
|
|
@ -415,8 +365,8 @@ public class WebDisplays {
|
|||
|
||||
@SubscribeEvent
|
||||
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone ev) {
|
||||
IWDDCapability src = ev.getOriginal().getCapability(WDDCapability.INSTANCE, null);
|
||||
IWDDCapability dst = ev.getPlayer().getCapability(WDDCapability.INSTANCE, null);
|
||||
IWDDCapability src = (IWDDCapability) ev.getOriginal().getCapability(WDDCapability.Provider.cap, null);
|
||||
IWDDCapability dst = (IWDDCapability) ev.getPlayer().getCapability(WDDCapability.Provider.cap, null);
|
||||
|
||||
if(src == null) {
|
||||
Log.error("src is null");
|
||||
|
|
@ -492,7 +442,7 @@ public class WebDisplays {
|
|||
public static boolean isSiteBlacklisted(String url) {
|
||||
try {
|
||||
URL url2 = new URL(Util.addProtocol(url));
|
||||
return Arrays.stream(INSTANCE.blacklist).anyMatch(str -> str.equalsIgnoreCase(url2.getHost()));
|
||||
return INSTANCE.blacklist.stream().anyMatch(str -> str.equalsIgnoreCase(url2.getHost()));
|
||||
} catch(MalformedURLException ex) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,16 +13,21 @@ import net.minecraft.client.gui.GuiScreen;
|
|||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.multiplayer.ClientAdvancementManager;
|
||||
import net.minecraft.client.multiplayer.ClientAdvancements;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.SimpleReloadableResourceManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.EnumHandSide;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
|
@ -31,15 +36,16 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.*;
|
||||
import net.minecraftforge.client.ClientRegistry;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.resource.IResourceType;
|
||||
import net.minecraftforge.client.resource.ISelectiveResourceReloadListener;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.montoyo.mcef.api.*;
|
||||
import net.montoyo.wd.SharedProxy;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
|
|
@ -55,11 +61,10 @@ import net.montoyo.wd.entity.TileEntityScreen;
|
|||
import net.montoyo.wd.item.ItemMulti;
|
||||
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.utilities.*;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import paulscode.sound.SoundSystemConfig;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Field;
|
||||
|
|
@ -68,7 +73,7 @@ import java.net.SocketAddress;
|
|||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ClientProxy extends SharedProxy implements ISelectiveResourceReloadListener, IDisplayHandler, IJSQueryHandler {
|
||||
public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQueryHandler {
|
||||
|
||||
public class PadData {
|
||||
|
||||
|
|
@ -101,7 +106,7 @@ public class ClientProxy extends SharedProxy implements ISelectiveResourceReload
|
|||
|
||||
//Client-side advancement hack
|
||||
private final Field advancementToProgressField = findAdvancementToProgressField();
|
||||
private ClientAdvancementManager lastAdvMgr;
|
||||
private ClientAdvancements lastAdvMgr;
|
||||
private Map advancementToProgress;
|
||||
|
||||
//Laser pointer
|
||||
|
|
@ -122,7 +127,7 @@ public class ClientProxy extends SharedProxy implements ISelectiveResourceReload
|
|||
|
||||
@Override
|
||||
public void preInit() {
|
||||
mc = Minecraft.getMinecraft();
|
||||
mc = Minecraft.getInstance();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
registerCustomBlockBaker(new ScreenBaker(), WebDisplays.INSTANCE.blockScreen);
|
||||
|
||||
|
|
@ -293,7 +298,7 @@ public class ClientProxy extends SharedProxy implements ISelectiveResourceReload
|
|||
|
||||
@Override
|
||||
public MinecraftServer getServer() {
|
||||
return mc.getIntegratedServer();
|
||||
return mc.getSingleplayerServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -337,7 +342,7 @@ public class ClientProxy extends SharedProxy implements ISelectiveResourceReload
|
|||
return;
|
||||
}
|
||||
|
||||
SocketAddress saddr = mc.player.connection.getNetworkManager().channel().remoteAddress();
|
||||
SocketAddress saddr = mc.player.connection.getConnection().channel().remoteAddress();
|
||||
if(saddr == null || !(saddr instanceof InetSocketAddress)) {
|
||||
Log.warning("Miniserv client: remote address is not inet, assuming local address");
|
||||
saddr = new InetSocketAddress("127.0.0.1", 1234);
|
||||
|
|
@ -355,11 +360,11 @@ public class ClientProxy extends SharedProxy implements ISelectiveResourceReload
|
|||
|
||||
@Override
|
||||
public void closeGui(BlockPos bp, BlockSide bs) {
|
||||
if(mc.currentScreen instanceof WDScreen) {
|
||||
WDScreen scr = (WDScreen) mc.currentScreen;
|
||||
if(mc.screen instanceof WDScreen) {
|
||||
WDScreen scr = (WDScreen) mc.screen;
|
||||
|
||||
if(scr.isForBlock(bp, bs))
|
||||
mc.displayGuiScreen(null);
|
||||
mc.setScreen(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -376,7 +381,7 @@ public class ClientProxy extends SharedProxy implements ISelectiveResourceReload
|
|||
/**************************************** RESOURCE MANAGER METHODS ****************************************/
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager, Predicate<IResourceType> resourcePredicate) {
|
||||
public void onResourceManagerReload(ResourceManager resourceManager, Predicate<ExistingFileHelper.ResourceType> resourcePredicate) {
|
||||
Log.info("Resource manager reload: clearing GUI cache...");
|
||||
GuiLoader.clearCache();
|
||||
}
|
||||
|
|
@ -394,7 +399,7 @@ public class ClientProxy extends SharedProxy implements ISelectiveResourceReload
|
|||
pd.view.loadURL(WebDisplays.BLACKLIST_URL);
|
||||
else {
|
||||
pd.lastURLSent = t; //Avoid spamming the server with porn URLs
|
||||
WebDisplays.NET_HANDLER.sendToServer(new SMessagePadCtrl(pd.id, url));
|
||||
Messages.INSTANCE.sendToServer(new SMessagePadCtrl(pd.id, url));
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -462,9 +467,9 @@ public class ClientProxy extends SharedProxy implements ISelectiveResourceReload
|
|||
|
||||
@SubscribeEvent
|
||||
public void onStitchTextures(TextureStitchEvent.Pre ev) {
|
||||
TextureMap texMap = ev.getMap();
|
||||
TextureAtlas texMap = ev.getAtlas();
|
||||
|
||||
if(texMap == mc.getTextureMapBlocks()) {
|
||||
if(texMap == mc.getTextureAtlas()) {
|
||||
for(ResourceModelPair pair : modelBakers)
|
||||
pair.getModel().loadTextures(texMap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@ import net.minecraft.item.crafting.CraftingManager;
|
|||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
|
|
|
|||
|
|
@ -9,20 +9,15 @@ import com.google.gson.JsonElement;
|
|||
import com.google.gson.JsonObject;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.client.gui.controls.Container;
|
||||
import net.montoyo.wd.client.gui.controls.Control;
|
||||
import net.montoyo.wd.client.gui.controls.Event;
|
||||
import net.montoyo.wd.client.gui.controls.List;
|
||||
import net.montoyo.wd.client.gui.loading.FillControl;
|
||||
import net.montoyo.wd.client.gui.loading.GuiLoader;
|
||||
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
|
||||
|
|
@ -31,10 +26,8 @@ import net.montoyo.wd.utilities.BlockSide;
|
|||
import net.montoyo.wd.utilities.Bounds;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.NameUUIDPair;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
|
@ -86,7 +79,7 @@ public abstract class WDScreen extends Screen {
|
|||
}
|
||||
|
||||
public int screen2DisplayY(int y) {
|
||||
double ret = ((double) y) / ((double) height) * ((double) minecraft.getWindow().getHeight();
|
||||
double ret = ((double) y) / ((double) height) * ((double) minecraft.getWindow().getHeight());
|
||||
return (int) ret;
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +124,7 @@ public abstract class WDScreen extends Screen {
|
|||
|
||||
@Override
|
||||
public boolean charTyped(char codePoint, int modifiers) {
|
||||
if(quitOnEscape && codePoint == Keyboard.KEY_ESCAPE) {
|
||||
if(quitOnEscape && codePoint == GLFW.GLFW_KEY_ESCAPE) {
|
||||
minecraft.setScreen(null);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package net.montoyo.wd.client.renderers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public interface IItemRenderer {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
package net.montoyo.wd.client.renderers;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
|
||||
public interface IModelBaker extends IBakedModel {
|
||||
public interface IModelBaker extends BakedModel {
|
||||
|
||||
void loadTextures(TextureMap texMap);
|
||||
void loadTextures(TextureAtlas texMap);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,24 +4,25 @@
|
|||
|
||||
package net.montoyo.wd.client.renderers;
|
||||
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public final class LaserPointerRenderer implements IItemRenderer {
|
||||
|
||||
private static final float PI = (float) Math.PI;
|
||||
private final Tessellator t = Tessellator.getInstance();
|
||||
private final BufferBuilder bb = t.getBuffer();
|
||||
private final Tesselator t = Tesselator.getInstance();
|
||||
private final BufferBuilder bb = t.getBuilder();
|
||||
private final VertexBuffer vb = new VertexBuffer();
|
||||
private final FloatBuffer matrix1 = BufferUtils.createFloatBuffer(16);
|
||||
private final FloatBuffer renderBuffer = BufferUtils.createFloatBuffer(8);
|
||||
|
||||
|
|
@ -37,18 +38,17 @@ public final class LaserPointerRenderer implements IItemRenderer {
|
|||
@Override
|
||||
public final void render(ItemStack is, float handSideSign, float swingProgress, float equipProgress) {
|
||||
//This whole method is a fucking hack
|
||||
float sqrtSwingProg = (float) Math.sqrt((double) swingProgress);
|
||||
float sinSqrtSwingProg1 = MathHelper.sin(sqrtSwingProg * PI);
|
||||
float sqrtSwingProg = (float) Math.sqrt(swingProgress);
|
||||
float sinSqrtSwingProg1 = (float) Math.sin(sqrtSwingProg * PI);
|
||||
|
||||
GlStateManager.disableCull();
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
RenderSystem.disableCull();
|
||||
RenderSystem.disableTexture();
|
||||
|
||||
//Laser pointer
|
||||
glPushMatrix();
|
||||
glTranslatef(handSideSign * -0.4f * sinSqrtSwingProg1, 0.2f * MathHelper.sin(sqrtSwingProg * PI * 2.0f), -0.2f * MathHelper.sin(swingProgress * PI));
|
||||
glTranslatef(handSideSign * -0.4f * sinSqrtSwingProg1, (float) (0.2f * Math.sin(sqrtSwingProg * PI * 2.0f)), (float) (-0.2f * Math.sin(swingProgress * PI)));
|
||||
glTranslatef(handSideSign * 0.56f, -0.52f - equipProgress * 0.6f, -0.72f);
|
||||
glRotatef(handSideSign * (45.0f - MathHelper.sin(swingProgress * swingProgress * PI) * 20.0f), 0.0f, 1.0f, 0.0f);
|
||||
glRotatef((float) (handSideSign * (45.0f - Math.sin(swingProgress * swingProgress * PI) * 20.0f)), 0.0f, 1.0f, 0.0f);
|
||||
glRotatef(handSideSign * sinSqrtSwingProg1 * -20.0f, 0.0f, 0.0f, 1.0f);
|
||||
glRotatef(sinSqrtSwingProg1 * -80.0f, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(handSideSign * -30.0f, 0.0f, 1.0f, 0.0f);
|
||||
|
|
@ -57,49 +57,44 @@ public final class LaserPointerRenderer implements IItemRenderer {
|
|||
glScalef(1.0f / 16.0f, 1.0f / 16.0f, 1.0f / 16.0f);
|
||||
|
||||
glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
bb.begin(GL_QUADS, DefaultVertexFormats.POSITION_NORMAL);
|
||||
bb.pos(0.0, 0.0, 0.0).normal(0.0f, 1.0f, 0.0f).endVertex();
|
||||
bb.pos(1.0, 0.0, 0.0).normal(0.0f, 1.0f, 0.0f).endVertex();
|
||||
bb.pos(1.0, 0.0, 4.0).normal(0.0f, 1.0f, 0.0f).endVertex();
|
||||
bb.pos(0.0, 0.0, 4.0).normal(0.0f, 1.0f, 0.0f).endVertex();
|
||||
bb.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
|
||||
bb.vertex(0.0, 0.0, 0.0).endVertex();
|
||||
bb.vertex(1.0, 0.0, 0.0).endVertex();
|
||||
bb.vertex(1.0, 0.0, 4.0).endVertex();
|
||||
bb.vertex(0.0, 0.0, 4.0).endVertex();
|
||||
|
||||
bb.pos(0.0, 0.0, 0.0).normal(-1.0f, 0.0f, 0.0f).endVertex();
|
||||
bb.pos(0.0, -1.0, 0.0).normal(-1.0f, 0.0f, 0.0f).endVertex();
|
||||
bb.pos(0.0, -1.0, 4.0).normal(-1.0f, 0.0f, 0.0f).endVertex();
|
||||
bb.pos(0.0, 0.0, 4.0).normal(-1.0f, 0.0f, 0.0f).endVertex();
|
||||
bb.vertex(0.0, 0.0, 0.0).endVertex();
|
||||
bb.vertex(0.0, -1.0, 0.0).endVertex();
|
||||
bb.vertex(0.0, -1.0, 4.0).endVertex();
|
||||
bb.vertex(0.0, 0.0, 4.0).endVertex();
|
||||
|
||||
bb.pos(1.0, 0.0, 0.0).normal(1.0f, 0.0f, 0.0f).endVertex();
|
||||
bb.pos(1.0, -1.0, 0.0).normal(1.0f, 0.0f, 0.0f).endVertex();
|
||||
bb.pos(1.0, -1.0, 4.0).normal(1.0f, 0.0f, 0.0f).endVertex();
|
||||
bb.pos(1.0, 0.0, 4.0).normal(1.0f, 0.0f, 0.0f).endVertex();
|
||||
bb.vertex(1.0, 0.0, 0.0).endVertex();
|
||||
bb.vertex(1.0, -1.0, 0.0).endVertex();
|
||||
bb.vertex(1.0, -1.0, 4.0).endVertex();
|
||||
bb.vertex(1.0, 0.0, 4.0).endVertex();
|
||||
|
||||
bb.pos(0.0, -1.0, 4.0).normal(0.0f, 0.0f, 1.0f).endVertex();
|
||||
bb.pos(1.0, -1.0, 4.0).normal(0.0f, 0.0f, 1.0f).endVertex();
|
||||
bb.pos(1.0, 0.0, 4.0).normal(0.0f, 0.0f, 1.0f).endVertex();
|
||||
bb.pos(0.0, 0.0, 4.0).normal(0.0f, 0.0f, 1.0f).endVertex();
|
||||
t.draw();
|
||||
bb.vertex(0.0, -1.0, 4.0).endVertex();
|
||||
bb.vertex(1.0, -1.0, 4.0).endVertex();
|
||||
bb.vertex(1.0, 0.0, 4.0).endVertex();
|
||||
bb.vertex(0.0, 0.0, 4.0).endVertex();
|
||||
vb.draw();
|
||||
|
||||
if(isOn) {
|
||||
glTranslatef(0.5f, -0.5f, 0.0f);
|
||||
matrix1.position(0);
|
||||
glGetFloat(GL_MODELVIEW_MATRIX, matrix1); //Hax to get that damn position
|
||||
glGetFloat(GL_MODELVIEW_MATRIX); //Hax to get that damn position
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
if(isOn) {
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
|
||||
//Actual laser
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.DST_ALPHA);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.DST_ALPHA);
|
||||
glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
|
||||
GlStateManager.glLineWidth(3.0f);
|
||||
RenderSystem.lineWidth(3.0f);
|
||||
|
||||
matrix1.position(12);
|
||||
renderBuffer.put(matrix1.get());
|
||||
|
|
@ -107,14 +102,14 @@ public final class LaserPointerRenderer implements IItemRenderer {
|
|||
renderBuffer.put(matrix1.get() - 0.02f); //I know this is stupid, but it's the only thing that worked...
|
||||
renderBuffer.put(matrix1.get());
|
||||
renderBuffer.position(0);
|
||||
glVertexPointer(4, 0, renderBuffer);
|
||||
glVertexPointer(4, 0, 0 , renderBuffer);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glDrawArrays(GL_LINES, 0, 2);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
GlStateManager.enableTexture2D(); //Fix for shitty minecraft fire
|
||||
RenderSystem.enableTexture(); //Fix for shitty minecraft fire
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,26 +5,21 @@
|
|||
package net.montoyo.wd.client.renderers;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.client.ClientProxy;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL12.GL_RESCALE_NORMAL;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public final class MinePadRenderer implements IItemRenderer {
|
||||
|
||||
private static final float PI = (float) Math.PI;
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
private final Minecraft mc = Minecraft.getInstance();
|
||||
private final ResourceLocation tex = new ResourceLocation("webdisplays", "textures/models/minepad.png");
|
||||
private final ModelMinePad model = new ModelMinePad();
|
||||
private final ClientProxy clientProxy = (ClientProxy) WebDisplays.PROXY;
|
||||
|
|
@ -50,11 +45,11 @@ public final class MinePadRenderer implements IItemRenderer {
|
|||
@Override
|
||||
public final void render(ItemStack is, float handSideSign, float swingProgress, float equipProgress) {
|
||||
//Pre-compute values
|
||||
float sqrtSwingProg = (float) Math.sqrt((double) swingProgress);
|
||||
sinSqrtSwingProg1 = MathHelper.sin(sqrtSwingProg * PI);
|
||||
sinSqrtSwingProg2 = MathHelper.sin(sqrtSwingProg * PI * 2.0f);
|
||||
sinSwingProg1 = MathHelper.sin(swingProgress * PI);
|
||||
sinSwingProg2 = MathHelper.sin(swingProgress * swingProgress * PI);
|
||||
float sqrtSwingProg = (float) Math.sqrt(swingProgress);
|
||||
sinSqrtSwingProg1 = (float) Math.sin(sqrtSwingProg * PI);
|
||||
sinSqrtSwingProg2 = (float) Math.sin(sqrtSwingProg * PI * 2.0f);
|
||||
sinSwingProg1 = (float) Math.sin(swingProgress * PI);
|
||||
sinSwingProg2 = (float) Math.sin(swingProgress * swingProgress * PI);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_RESCALE_NORMAL);
|
||||
|
|
@ -86,20 +81,17 @@ public final class MinePadRenderer implements IItemRenderer {
|
|||
glPushMatrix();
|
||||
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
mc.renderEngine.bindTexture(tex);
|
||||
//TODO mc.renderEngine.bindTexture(tex);
|
||||
model.render(1.f / 16.f);
|
||||
glPopMatrix();
|
||||
|
||||
//Render web view
|
||||
if(is.getTagCompound() != null && is.getTagCompound().hasKey("PadID")) {
|
||||
ClientProxy.PadData pd = clientProxy.getPadByID(is.getTagCompound().getInteger("PadID"));
|
||||
if(is.getTag() != null && is.getTag().contains("PadID")) {
|
||||
ClientProxy.PadData pd = clientProxy.getPadByID(is.getTag().getInt("PadID"));
|
||||
|
||||
if(pd != null) {
|
||||
glTranslatef(0.063f, 0.28f, 0.001f);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
pd.view.draw(0.0, 0.0, 27.65 / 32.0 + 0.01, 14.0 / 32.0 + 0.002);
|
||||
}
|
||||
}
|
||||
|
|
@ -124,13 +116,13 @@ public final class MinePadRenderer implements IItemRenderer {
|
|||
glRotatef(handSideSign * -135.0f, 0.0f, 1.0f, 0.0f);
|
||||
glTranslatef(handSideSign * 5.6f, 0.0f, 0.0f);
|
||||
|
||||
RenderPlayer playerRenderer = (RenderPlayer) mc.getRenderManager().<AbstractClientPlayer>getEntityRenderObject(mc.player);
|
||||
/*RenderPlayer playerRenderer = (RenderPlayer) mc.getRenderManager().<AbstractClientPlayer>getEntityRenderObject(mc.player);
|
||||
mc.getTextureManager().bindTexture(mc.player.getLocationSkin());
|
||||
|
||||
if(handSideSign >= 0.0f)
|
||||
playerRenderer.renderRightArm(mc.player);
|
||||
else
|
||||
playerRenderer.renderLeftArm(mc.player);
|
||||
playerRenderer.renderLeftArm(mc.player);*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,24 +4,26 @@
|
|||
|
||||
package net.montoyo.wd.client.renderers;
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.minecraft.client.model.Model;
|
||||
import net.minecraft.client.model.geom.ModelPart;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public final class ModelMinePad extends ModelBase {
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public final class ModelMinePad extends Model {
|
||||
|
||||
// fields
|
||||
private final ModelRenderer base;
|
||||
private final ModelRenderer left;
|
||||
private final ModelRenderer right;
|
||||
private final ModelPart base;
|
||||
private final ModelPart left;
|
||||
private final ModelPart right;
|
||||
|
||||
public ModelMinePad() {
|
||||
textureWidth = 64;
|
||||
textureHeight = 32;
|
||||
|
||||
base = new ModelRenderer(this, 0, 0);
|
||||
base = new ModelPart(this, 0, 0);
|
||||
base.addBox(0F, 0F, 0F, 14, 1, 9);
|
||||
base.setRotationPoint(1F, 0F, 3.5F);
|
||||
base.setTextureSize(64, 32);
|
||||
|
|
@ -47,10 +49,14 @@ public final class ModelMinePad extends ModelBase {
|
|||
right.render(f5);
|
||||
}
|
||||
|
||||
private void clearRotation(ModelRenderer model) {
|
||||
private void clearRotation(ModelPart model) {
|
||||
model.rotateAngleX = 0.0f;
|
||||
model.rotateAngleY = 0.0f;
|
||||
model.rotateAngleZ = 0.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderToBuffer(PoseStack poseStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,20 @@
|
|||
package net.montoyo.wd.client.renderers;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.montoyo.wd.block.BlockScreen;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
|
|
@ -30,12 +35,12 @@ public class ScreenBaker implements IModelBaker {
|
|||
private static final List<BakedQuad> noQuads = ImmutableList.of();
|
||||
private final TextureAtlasSprite[] texs = new TextureAtlasSprite[16];
|
||||
private final BlockSide[] blockSides = BlockSide.values();
|
||||
private final EnumFacing[] blockFacings = EnumFacing.values();
|
||||
private final Direction[] blockFacings = Direction.values();
|
||||
|
||||
@Override
|
||||
public void loadTextures(TextureMap texMap) {
|
||||
public void loadTextures(TextureAtlas texMap) {
|
||||
for(int i = 0; i < texs.length; i++)
|
||||
texs[i] = texMap.registerSprite(new ResourceLocation("webdisplays", "blocks/screen" + i));
|
||||
texs[i] = texMap.getSprite(new ResourceLocation("webdisplays", "blocks/screen" + i));
|
||||
}
|
||||
|
||||
private void putVertex(int[] buf, int pos, Vector3f vpos, TextureAtlasSprite tex, Vector3f uv, Vector3i normal) {
|
||||
|
|
@ -43,8 +48,8 @@ public class ScreenBaker implements IModelBaker {
|
|||
buf[pos * 7 + 1] = Float.floatToRawIntBits(vpos.y);
|
||||
buf[pos * 7 + 2] = Float.floatToRawIntBits(vpos.z);
|
||||
buf[pos * 7 + 3] = 0xFFFFFFFF; //Color, let this white...
|
||||
buf[pos * 7 + 4] = Float.floatToRawIntBits(tex.getInterpolatedU(uv.x));
|
||||
buf[pos * 7 + 5] = Float.floatToRawIntBits(tex.getInterpolatedV(uv.y));
|
||||
buf[pos * 7 + 4] = Float.floatToRawIntBits(tex.getU(uv.x));
|
||||
buf[pos * 7 + 5] = Float.floatToRawIntBits(tex.getV(uv.y));
|
||||
|
||||
int nx = (normal.x * 127) & 0xFF;
|
||||
int ny = (normal.y * 127) & 0xFF;
|
||||
|
|
@ -86,16 +91,14 @@ public class ScreenBaker implements IModelBaker {
|
|||
putVertex(data, 1, rotateVec(new Vector3f(1.0f, 0.0f, 1.0f), side), tex, rotateTex(side, 16.0f, 16.0f), side.backward);
|
||||
putVertex(data, 0, rotateVec(new Vector3f(1.0f, 0.0f, 0.0f), side), tex, rotateTex(side, 16.0f, 0.0f ), side.backward);
|
||||
|
||||
return new BakedQuad(data, 0xFFFFFFFF, blockFacings[side.ordinal()], tex, true, DefaultVertexFormats.ITEM);
|
||||
return new BakedQuad(data, 0xFFFFFFFF, blockFacings[side.ordinal()], tex, true, DefaultVertexFormat.ITEM);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, long rand) {
|
||||
if(side == null)
|
||||
return noQuads;
|
||||
|
||||
IExtendedBlockState bs = (IExtendedBlockState) state;
|
||||
BlockState bs = state;
|
||||
List<BakedQuad> ret = new ArrayList<>();
|
||||
|
||||
int sid = BlockSide.reverse(side.ordinal());
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ package net.montoyo.wd.core;
|
|||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
|
||||
|
|
@ -34,8 +36,8 @@ public enum CraftComponent {
|
|||
return name;
|
||||
}
|
||||
|
||||
public ItemStack makeItemStack(CompoundTag compoundTag) {
|
||||
return new ItemStack(WebDisplays.INSTANCE.itemCraftComp, 1, compoundTag);
|
||||
public ItemStack makeItemStack() {
|
||||
return new ItemStack(WebDisplays.INSTANCE.itemCraftComp, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,78 +4,61 @@
|
|||
|
||||
package net.montoyo.wd.core;
|
||||
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.capabilities.CapabilityToken;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class WDDCapability implements IWDDCapability {
|
||||
|
||||
@CapabilityInject(IWDDCapability.class)
|
||||
public static final Capability<IWDDCapability> INSTANCE = null;
|
||||
|
||||
public static class Storage implements Capability.IStorage<IWDDCapability> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NBTBase writeNBT(Capability<IWDDCapability> cap, IWDDCapability inst, EnumFacing side) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setBoolean("FirstRun", inst.isFirstRun());
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<IWDDCapability> cap, IWDDCapability inst, EnumFacing side, NBTBase nbt) {
|
||||
if(nbt instanceof NBTTagCompound) {
|
||||
NBTTagCompound tag = (NBTTagCompound) nbt;
|
||||
|
||||
if(tag.hasKey("FirstRun") && tag.getTag("FirstRun") instanceof NBTTagByte && !tag.getBoolean("FirstRun"))
|
||||
inst.clearFirstRun();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Factory implements Callable<IWDDCapability> {
|
||||
|
||||
@Override
|
||||
public IWDDCapability call() throws Exception {
|
||||
public IWDDCapability call() {
|
||||
return new WDDCapability();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Provider implements ICapabilitySerializable<NBTBase> {
|
||||
public static class Provider implements ICapabilitySerializable<CompoundTag> {
|
||||
|
||||
private IWDDCapability cap = INSTANCE.getDefaultInstance();
|
||||
public static Capability<IWDDCapability> cap = CapabilityManager.get(new CapabilityToken<>(){});
|
||||
private final LazyOptional<IWDDCapability> INSTANCE = LazyOptional.of(this::createWDDCapability);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> cap, @Nullable EnumFacing f) {
|
||||
return cap == INSTANCE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> cap, @Nullable EnumFacing f) {
|
||||
return cap == INSTANCE ? INSTANCE.cast(this.cap) : null;
|
||||
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> capability, @org.jetbrains.annotations.Nullable Direction arg) {
|
||||
return cap == capability ? INSTANCE.cast() : LazyOptional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase serializeNBT() {
|
||||
return INSTANCE.getStorage().writeNBT(INSTANCE, cap, null);
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
if (INSTANCE.isPresent()) {
|
||||
INSTANCE.ifPresent(cap -> tag.put("Tag", tag));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(NBTBase nbt) {
|
||||
INSTANCE.getStorage().readNBT(INSTANCE, cap, null, nbt);
|
||||
public void deserializeNBT(CompoundTag tag) {
|
||||
if (INSTANCE.isPresent()) {
|
||||
INSTANCE.ifPresent(cap -> {
|
||||
tag.get("Tag");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private IWDDCapability createWDDCapability() {
|
||||
return cap == null ? new WDDCapability() : (IWDDCapability) cap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,21 +4,25 @@
|
|||
|
||||
package net.montoyo.wd.entity;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.montoyo.mcef.api.IBrowser;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.block.BlockScreen;
|
||||
|
|
@ -27,20 +31,26 @@ import net.montoyo.wd.core.IUpgrade;
|
|||
import net.montoyo.wd.core.JSServerRequest;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.data.ScreenConfigData;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageAddScreen;
|
||||
import net.montoyo.wd.net.client.CMessageCloseGui;
|
||||
import net.montoyo.wd.net.client.CMessageJSResponse;
|
||||
import net.montoyo.wd.net.client.CMessageScreenUpdate;
|
||||
import net.montoyo.wd.net.server.SMessageRequestTEData;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import net.montoyo.wd.utilities.Rotation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TileEntityScreen extends BlockEntity {
|
||||
public class TileEntityScreen extends BlockEntity{
|
||||
|
||||
public TileEntityScreen(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) {
|
||||
super(arg, arg2, arg3);
|
||||
}
|
||||
|
||||
public static class Screen {
|
||||
|
||||
|
|
@ -58,16 +68,16 @@ public class TileEntityScreen extends BlockEntity {
|
|||
public ArrayList<ItemStack> upgrades;
|
||||
public boolean doTurnOnAnim;
|
||||
public long turnOnTime;
|
||||
public EntityPlayer laserUser;
|
||||
public Player laserUser;
|
||||
public final Vector2i lastMousePos = new Vector2i();
|
||||
public NibbleArray redstoneStatus; //null on client
|
||||
public boolean autoVolume = true;
|
||||
|
||||
public static Screen deserialize(NBTTagCompound tag) {
|
||||
public static Screen deserialize(CompoundTag tag) {
|
||||
Screen ret = new Screen();
|
||||
ret.side = BlockSide.values()[tag.getByte("Side")];
|
||||
ret.size = new Vector2i(tag.getInteger("Width"), tag.getInteger("Height"));
|
||||
ret.resolution = new Vector2i(tag.getInteger("ResolutionX"), tag.getInteger("ResolutionY"));
|
||||
ret.size = new Vector2i(tag.getInt("Width"), tag.getInt("Height"));
|
||||
ret.resolution = new Vector2i(tag.getInt("ResolutionX"), tag.getInt("ResolutionY"));
|
||||
ret.rotation = Rotation.values()[tag.getByte("Rotation")];
|
||||
ret.url = tag.getString("URL");
|
||||
ret.videoType = VideoType.getTypeFromURL(ret.url);
|
||||
|
|
@ -82,76 +92,76 @@ public class TileEntityScreen extends BlockEntity {
|
|||
ret.resolution.y = (int) psy;
|
||||
}
|
||||
|
||||
if(tag.hasKey("OwnerName")) {
|
||||
if(tag.contains("OwnerName")) {
|
||||
String name = tag.getString("OwnerName");
|
||||
UUID uuid = tag.getUniqueId("OwnerUUID");
|
||||
UUID uuid = tag.getUUID("OwnerUUID");
|
||||
ret.owner = new NameUUIDPair(name, uuid);
|
||||
}
|
||||
|
||||
NBTTagList friends = tag.getTagList("Friends", 10);
|
||||
ret.friends = new ArrayList<>(friends.tagCount());
|
||||
ListTag friends = tag.getList("Friends", 10);
|
||||
ret.friends = new ArrayList<>(friends.size());
|
||||
|
||||
for(int i = 0; i < friends.tagCount(); i++) {
|
||||
NBTTagCompound nf = friends.getCompoundTagAt(i);
|
||||
NameUUIDPair pair = new NameUUIDPair(nf.getString("Name"), nf.getUniqueId("UUID"));
|
||||
for(int i = 0; i < friends.size(); i++) {
|
||||
CompoundTag nf = friends.getCompound(i);
|
||||
NameUUIDPair pair = new NameUUIDPair(nf.getString("Name"), nf.getUUID("UUID"));
|
||||
ret.friends.add(pair);
|
||||
}
|
||||
|
||||
ret.friendRights = tag.getByte("FriendRights");
|
||||
ret.otherRights = tag.getByte("OtherRights");
|
||||
|
||||
NBTTagList upgrades = tag.getTagList("Upgrades", 10);
|
||||
ListTag upgrades = tag.getList("Upgrades", 10);
|
||||
ret.upgrades = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < upgrades.tagCount(); i++)
|
||||
ret.upgrades.add(new ItemStack(upgrades.getCompoundTagAt(i)));
|
||||
for(int i = 0; i < upgrades.size(); i++)
|
||||
ret.upgrades.add(new ItemStack((ItemLike) upgrades.getCompound(i)));
|
||||
|
||||
if(tag.hasKey("AutoVolume"))
|
||||
if(tag.contains("AutoVolume"))
|
||||
ret.autoVolume = tag.getBoolean("AutoVolume");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public NBTTagCompound serialize() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setByte("Side", (byte) side.ordinal());
|
||||
tag.setInteger("Width", size.x);
|
||||
tag.setInteger("Height", size.y);
|
||||
tag.setInteger("ResolutionX", resolution.x);
|
||||
tag.setInteger("ResolutionY", resolution.y);
|
||||
tag.setByte("Rotation", (byte) rotation.ordinal());
|
||||
tag.setString("URL", url);
|
||||
public CompoundTag serialize() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putByte("Side", (byte) side.ordinal());
|
||||
tag.putInt("Width", size.x);
|
||||
tag.putInt("Height", size.y);
|
||||
tag.putInt("ResolutionX", resolution.x);
|
||||
tag.putInt("ResolutionY", resolution.y);
|
||||
tag.putByte("Rotation", (byte) rotation.ordinal());
|
||||
tag.putString("URL", url);
|
||||
|
||||
if(owner == null)
|
||||
Log.warning("Found TES with NO OWNER!!");
|
||||
else {
|
||||
tag.setString("OwnerName", owner.name);
|
||||
tag.setUniqueId("OwnerUUID", owner.uuid);
|
||||
tag.putString("OwnerName", owner.name);
|
||||
tag.putUUID("OwnerUUID", owner.uuid);
|
||||
}
|
||||
|
||||
NBTTagList list = new NBTTagList();
|
||||
ListTag list = new ListTag();
|
||||
for(NameUUIDPair f: friends) {
|
||||
NBTTagCompound nf = new NBTTagCompound();
|
||||
nf.setString("Name", f.name);
|
||||
nf.setUniqueId("UUID", f.uuid);
|
||||
CompoundTag nf = new CompoundTag();
|
||||
nf.putString("Name", f.name);
|
||||
nf.putUUID("UUID", f.uuid);
|
||||
|
||||
list.appendTag(nf);
|
||||
list.add(nf);
|
||||
}
|
||||
|
||||
tag.setTag("Friends", list);
|
||||
tag.setByte("FriendRights", (byte) friendRights);
|
||||
tag.setByte("OtherRights", (byte) otherRights);
|
||||
tag.put("Friends", list);
|
||||
tag.putByte("FriendRights", (byte) friendRights);
|
||||
tag.putByte("OtherRights", (byte) otherRights);
|
||||
|
||||
list = new NBTTagList();
|
||||
list = new ListTag();
|
||||
for(ItemStack is: upgrades)
|
||||
list.appendTag(is.writeToNBT(new NBTTagCompound()));
|
||||
list.add(is.save(new CompoundTag()));
|
||||
|
||||
tag.setTag("Upgrades", list);
|
||||
tag.setBoolean("AutoVolume", autoVolume);
|
||||
tag.put("Upgrades", list);
|
||||
tag.putBoolean("AutoVolume", autoVolume);
|
||||
return tag;
|
||||
}
|
||||
|
||||
public int rightsFor(EntityPlayer ply) {
|
||||
public int rightsFor(Player ply) {
|
||||
return rightsFor(ply.getGameProfile().getId());
|
||||
}
|
||||
|
||||
|
|
@ -162,8 +172,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return friends.stream().anyMatch(f -> f.uuid.equals(uuid)) ? friendRights : otherRights;
|
||||
}
|
||||
|
||||
public void setupRedstoneStatus(World world, BlockPos start) {
|
||||
if(world.isRemote) {
|
||||
public void setupRedstoneStatus(Level world, BlockPos start) {
|
||||
if(world.isClientSide()) {
|
||||
Log.warning("Called Screen.setupRedstoneStatus() on client.");
|
||||
return;
|
||||
}
|
||||
|
|
@ -173,16 +183,19 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
Direction[] VALUES = Direction.values();
|
||||
redstoneStatus = new NibbleArray(size.x * size.y);
|
||||
final EnumFacing facing = EnumFacing.VALUES[side.reverse().ordinal()];
|
||||
final Direction facing = VALUES[side.reverse().ordinal()];
|
||||
final ScreenIterator it = new ScreenIterator(start, side, size);
|
||||
|
||||
while(it.hasNext()) {
|
||||
int idx = it.getIndex();
|
||||
redstoneStatus.set(idx, world.getRedstonePower(it.next(), facing));
|
||||
redstoneStatus.set(idx, world.getSignal(it.next(), facing));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void clampResolution() {
|
||||
if(resolution.x > WebDisplays.INSTANCE.maxResX) {
|
||||
float newY = ((float) resolution.y) * ((float) WebDisplays.INSTANCE.maxResX) / ((float) resolution.x);
|
||||
|
|
@ -203,7 +216,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
Screen scr = getScreen(side);
|
||||
|
||||
if(scr != null) {
|
||||
ScreenIterator it = new ScreenIterator(pos, side, scr.size);
|
||||
ScreenIterator it = new ScreenIterator(getBlockPos(), side, scr.size);
|
||||
|
||||
while(it.hasNext())
|
||||
func.accept(it.next());
|
||||
|
|
@ -211,7 +224,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
private final ArrayList<Screen> screens = new ArrayList<>();
|
||||
private AxisAlignedBB renderBB = new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
|
||||
private net.minecraft.world.phys.AABB renderBB = new net.minecraft.world.phys.AABB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
|
||||
private boolean loaded = true;
|
||||
public float ytVolume = Float.POSITIVE_INFINITY;
|
||||
|
||||
|
|
@ -235,36 +248,33 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
public void deserializeNBT(CompoundTag tag) {
|
||||
super.deserializeNBT(tag);
|
||||
|
||||
NBTTagList list = tag.getTagList("WDScreens", 10);
|
||||
if(list.hasNoTags())
|
||||
ListTag list = tag.getList("WDScreens", 10);
|
||||
if(list.isEmpty())
|
||||
return;
|
||||
|
||||
screens.clear();
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
screens.add(Screen.deserialize(list.getCompoundTagAt(i)));
|
||||
for(int i = 0; i < list.size(); i++)
|
||||
screens.add(Screen.deserialize(list.getCompound(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
super.serializeNBT();
|
||||
|
||||
NBTTagList list = new NBTTagList();
|
||||
ListTag list = new ListTag();
|
||||
for(Screen scr: screens)
|
||||
list.appendTag(scr.serialize());
|
||||
list.add(scr.serialize());
|
||||
|
||||
tag.setTag("WDScreens", list);
|
||||
tag.put("WDScreens", list);
|
||||
return tag;
|
||||
}
|
||||
|
||||
private NetworkRegistry.TargetPoint point() {
|
||||
return new NetworkRegistry.TargetPoint(world.provider.getDimension(), (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 64.0);
|
||||
}
|
||||
|
||||
public Screen addScreen(BlockSide side, Vector2i size, @Nullable Vector2i resolution, @Nullable EntityPlayer owner, boolean sendUpdate) {
|
||||
public Screen addScreen(BlockSide side, Vector2i size, @Nullable Vector2i resolution, @Nullable Player owner, boolean sendUpdate) {
|
||||
for(Screen scr: screens) {
|
||||
if(scr.side == side)
|
||||
return scr;
|
||||
|
|
@ -283,7 +293,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
ret.owner = new NameUUIDPair(owner.getGameProfile());
|
||||
|
||||
if(side == BlockSide.TOP || side == BlockSide.BOTTOM) {
|
||||
int rot = MathHelper.floor(((double) (owner.rotationYaw * 4.0f / 360.0f)) + 2.5) & 3;
|
||||
int rot = (int) Math.floor(((double) (owner.getYRot() * 4.0f / 360.0f)) + 2.5) & 3;
|
||||
|
||||
if(side == BlockSide.TOP) {
|
||||
if(rot == 1)
|
||||
|
|
@ -308,16 +318,16 @@ public class TileEntityScreen extends BlockEntity {
|
|||
|
||||
ret.clampResolution();
|
||||
|
||||
if(!world.isRemote) {
|
||||
ret.setupRedstoneStatus(world, pos);
|
||||
if(!level.isClientSide) {
|
||||
ret.setupRedstoneStatus(level, getBlockPos());
|
||||
|
||||
if(sendUpdate)
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(new CMessageAddScreen(this, ret), point());
|
||||
Messages.INSTANCE.sendTo(new CMessageAddScreen(this, ret), point());
|
||||
}
|
||||
|
||||
screens.add(ret);
|
||||
|
||||
if(world.isRemote)
|
||||
if(level.isClientSide)
|
||||
updateAABB();
|
||||
else
|
||||
markDirty();
|
||||
|
|
@ -345,13 +355,13 @@ public class TileEntityScreen extends BlockEntity {
|
|||
public void clear() {
|
||||
screens.clear();
|
||||
|
||||
if(!world.isRemote)
|
||||
if(!level.isClientSide)
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void requestData(EntityPlayerMP ep) {
|
||||
if(!world.isRemote)
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageAddScreen(this), ep);
|
||||
public void requestData(ServerPlayer ep) {
|
||||
if(!level.isClientSide)
|
||||
Messages.INSTANCE.sendTo(new CMessageAddScreen(this), ep);
|
||||
}
|
||||
|
||||
public void setScreenURL(BlockSide side, String url) {
|
||||
|
|
@ -365,11 +375,11 @@ public class TileEntityScreen extends BlockEntity {
|
|||
scr.url = url;
|
||||
scr.videoType = VideoType.getTypeFromURL(url);
|
||||
|
||||
if(world.isRemote) {
|
||||
if(level.isClientSide) {
|
||||
if(scr.browser != null)
|
||||
scr.browser.loadURL(url);
|
||||
} else {
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.setURL(this, side, url), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.setURL(this, side, url), point());
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
|
@ -388,19 +398,19 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
if(world.isRemote) {
|
||||
if(level.isClientSide) {
|
||||
if(screens.get(idx).browser != null) {
|
||||
screens.get(idx).browser.close();
|
||||
screens.get(idx).browser = null;
|
||||
}
|
||||
} else
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(new CMessageScreenUpdate(this, side), point()); //Delete the screen
|
||||
Messages.INSTANCE(new CMessageScreenUpdate(this, side), point()); //Delete the screen
|
||||
|
||||
screens.remove(idx);
|
||||
|
||||
if(!world.isRemote) {
|
||||
if(!level.isClientSide) {
|
||||
if(screens.isEmpty()) //No more screens: remove tile entity
|
||||
world.setBlockState(pos, WebDisplays.INSTANCE.blockScreen.getDefaultState().withProperty(BlockScreen.hasTE, false));
|
||||
level.setBlock(getBlockPos(), WebDisplays.INSTANCE.blockScreen.getDefaultInstance().withProperty(BlockScreen.hasTE, false));
|
||||
else
|
||||
markDirty();
|
||||
}
|
||||
|
|
@ -421,22 +431,22 @@ public class TileEntityScreen extends BlockEntity {
|
|||
scr.resolution = res;
|
||||
scr.clampResolution();
|
||||
|
||||
if(world.isRemote) {
|
||||
WebDisplays.PROXY.screenUpdateResolutionInGui(new Vector3i(pos), side, res);
|
||||
if(level.isClientSide) {
|
||||
WebDisplays.PROXY.screenUpdateResolutionInGui(new Vector3i(getBlockPos()), side, res);
|
||||
|
||||
if(scr.browser != null) {
|
||||
scr.browser.close();
|
||||
scr.browser = null; //Will be re-created by renderer
|
||||
}
|
||||
} else {
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.setResolution(this, side, res), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.setResolution(this, side, res), point());
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
private static EntityPlayer getLaserUser(Screen scr) {
|
||||
private static Player getLaserUser(Screen scr) {
|
||||
if(scr.laserUser != null) {
|
||||
if(scr.laserUser.isDead || scr.laserUser.getHeldItem(EnumHand.MAIN_HAND).getItem() != WebDisplays.INSTANCE.itemLaserPointer)
|
||||
if(scr.laserUser.isRemoved() || scr.laserUser.getItemInHand(InteractionHand.MAIN_HAND).getItem() != WebDisplays.INSTANCE.itemLaserPointer)
|
||||
scr.laserUser = null;
|
||||
}
|
||||
|
||||
|
|
@ -462,16 +472,16 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
if(world.isRemote)
|
||||
if(level.isClientSide)
|
||||
Log.warning("TileEntityScreen.click() from client side is useless...");
|
||||
else if(getLaserUser(scr) == null)
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_CLICK, vec), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_CLICK, vec), point());
|
||||
}
|
||||
|
||||
void clickUnsafe(BlockSide side, int action, int x, int y) {
|
||||
if(world.isRemote) {
|
||||
if(level.isClientSide) {
|
||||
Vector2i vec = (action == CMessageScreenUpdate.MOUSE_UP) ? null : new Vector2i(x, y);
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.click(this, side, action, vec), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.click(this, side, action, vec), point());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -509,14 +519,14 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
if(world.isRemote) {
|
||||
if(level.isClientSide) {
|
||||
if(scr.browser != null)
|
||||
scr.browser.runJS("if(typeof webdisplaysRedstoneCallback == \"function\") webdisplaysRedstoneCallback(" + vec.x + ", " + vec.y + ", " + redstoneLevel + ");", "");
|
||||
} else {
|
||||
boolean sendMsg = false;
|
||||
|
||||
if(scr.redstoneStatus == null) {
|
||||
scr.setupRedstoneStatus(world, pos);
|
||||
scr.setupRedstoneStatus(level, getBlockPos());
|
||||
sendMsg = true;
|
||||
} else {
|
||||
int idx = vec.y * scr.size.x + vec.x;
|
||||
|
|
@ -528,12 +538,12 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
if(sendMsg)
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.jsRedstone(this, side, vec, redstoneLevel), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.jsRedstone(this, side, vec, redstoneLevel), point());
|
||||
}
|
||||
}
|
||||
|
||||
public void handleJSRequest(EntityPlayerMP src, BlockSide side, int reqId, JSServerRequest req, Object[] data) {
|
||||
if(world.isRemote) {
|
||||
public void handleJSRequest(ServerPlayer src, BlockSide side, int reqId, JSServerRequest req, Object[] data) {
|
||||
if(level.isClientSide) {
|
||||
Log.error("Called handleJSRequest client-side");
|
||||
return;
|
||||
}
|
||||
|
|
@ -541,24 +551,24 @@ public class TileEntityScreen extends BlockEntity {
|
|||
Screen scr = getScreen(side);
|
||||
if(scr == null) {
|
||||
Log.error("Called handleJSRequest on non-existing side %s", side.toString());
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageJSResponse(reqId, req, 403, "Invalid side"), src);
|
||||
Messages.INSTANCE.sendTo(new CMessageJSResponse(reqId, req, 403, "Invalid side"), src);
|
||||
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());
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageJSResponse(reqId, req, 403, "Only the owner can do that"), src);
|
||||
Messages.INSTANCE.sendTo(new CMessageJSResponse(reqId, req, 403, "Only the owner can do that"), src);
|
||||
return;
|
||||
}
|
||||
|
||||
if(scr.upgrades.stream().noneMatch(DefaultUpgrade.REDSTONE_OUTPUT::matches)) {
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageJSResponse(reqId, req, 403, "Missing upgrade"), src);
|
||||
Messages.INSTANCE.sendTo(new CMessageJSResponse(reqId, req, 403, "Missing upgrade"), src);
|
||||
return;
|
||||
}
|
||||
|
||||
if(req == JSServerRequest.CLEAR_REDSTONE) {
|
||||
final BlockPos.MutableBlockPos mbp = new BlockPos.MutableBlockPos();
|
||||
final Vector3i vec1 = new Vector3i(pos);
|
||||
final Vector3i vec1 = new Vector3i(getBlockPos());
|
||||
final Vector3i vec2 = new Vector3i();
|
||||
|
||||
for(int y = 0; y < scr.size.y; y++) {
|
||||
|
|
@ -567,9 +577,9 @@ public class TileEntityScreen extends BlockEntity {
|
|||
for(int x = 0; x < scr.size.x; x++) {
|
||||
vec2.toBlock(mbp);
|
||||
|
||||
IBlockState bs = world.getBlockState(mbp);
|
||||
BlockState bs = level.getBlockState(mbp);
|
||||
if(bs.getValue(BlockScreen.emitting))
|
||||
world.setBlockState(mbp, bs.withProperty(BlockScreen.emitting, false));
|
||||
level.setBlock(mbp, bs.setValue(BlockScreen.emitting, false), Block.UPDATE_ALL_IMMEDIATE);
|
||||
|
||||
vec2.add(side.right.x, side.right.y, side.right.z);
|
||||
}
|
||||
|
|
@ -577,38 +587,38 @@ public class TileEntityScreen extends BlockEntity {
|
|||
vec1.add(side.up.x, side.up.y, side.up.z);
|
||||
}
|
||||
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageJSResponse(reqId, req, new byte[0]), src);
|
||||
Messages.INSTANCE.sendTo(new CMessageJSResponse(reqId, req, new byte[0]), src);
|
||||
} 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)
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageJSResponse(reqId, req, 403, "Out of range"), src);
|
||||
Messages.INSTANCE.sendTo(new CMessageJSResponse(reqId, req, 403, "Out of range"), src);
|
||||
else {
|
||||
BlockPos bp = (new Vector3i(pos)).addMul(side.right, x).addMul(side.up, y).toBlock();
|
||||
IBlockState bs = world.getBlockState(bp);
|
||||
BlockPos bp = (new Vector3i(getBlockPos())).addMul(side.right, x).addMul(side.up, y).toBlock();
|
||||
BlockState bs = level.getBlockState(bp);
|
||||
|
||||
if(bs.getValue(BlockScreen.emitting) != state)
|
||||
world.setBlockState(bp, bs.withProperty(BlockScreen.emitting, state));
|
||||
if(!bs.getValue(BlockScreen.emitting).equals(state))
|
||||
level.setBlock(bp, bs.setValue(BlockScreen.emitting, state));
|
||||
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageJSResponse(reqId, req, new byte[0]), src);
|
||||
Messages.INSTANCE.sendTo(new CMessageJSResponse(reqId, req, new byte[0]), src);
|
||||
}
|
||||
} else
|
||||
WebDisplays.NET_HANDLER.sendTo(new CMessageJSResponse(reqId, req, 400, "Invalid request"), src);
|
||||
Messages.INSTANCE.sendTo(new CMessageJSResponse(reqId, req, 400, "Invalid request"), src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
if(world.isRemote) {
|
||||
WebDisplays.NET_HANDLER.sendToServer(new SMessageRequestTEData(this));
|
||||
if(level.isClientSide) {
|
||||
Messages.INSTANCE.sendToServer(new SMessageRequestTEData(this));
|
||||
WebDisplays.PROXY.trackScreen(this, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
if(world.isRemote) {
|
||||
public void onChunkUnloaded() {
|
||||
if(level.isClientSide) {
|
||||
WebDisplays.PROXY.trackScreen(this, false);
|
||||
|
||||
for(Screen scr: screens) {
|
||||
|
|
@ -621,7 +631,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
private void updateAABB() {
|
||||
Vector3i origin = new Vector3i(pos);
|
||||
Vector3i origin = new Vector3i(getBlockPos());
|
||||
Vector3i tmp = new Vector3i();
|
||||
AABB aabb = new AABB(origin);
|
||||
|
||||
|
|
@ -634,12 +644,12 @@ public class TileEntityScreen extends BlockEntity {
|
|||
aabb.expand(tmp);
|
||||
}
|
||||
|
||||
renderBB = aabb.toMc().expand(0.1, 0.1, 0.1);
|
||||
renderBB = aabb.toMc().expandTowards(0.1, 0.1, 0.1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
public net.minecraft.world.phys.AABB getRenderBoundingBox() {
|
||||
return renderBB;
|
||||
}
|
||||
|
||||
|
|
@ -694,15 +704,15 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
public void invalidateCaps() {
|
||||
super.invalidateCaps();
|
||||
|
||||
if(world.isRemote)
|
||||
onChunkUnload();
|
||||
if(level.isClientSide)
|
||||
onChunkUnloaded();
|
||||
}
|
||||
|
||||
public void addFriend(EntityPlayerMP ply, BlockSide side, NameUUIDPair pair) {
|
||||
if(!world.isRemote) {
|
||||
public void addFriend(ServerPlayer ply, BlockSide side, NameUUIDPair pair) {
|
||||
if(!level.isClientSide) {
|
||||
Screen scr = getScreen(side);
|
||||
if(scr == null) {
|
||||
Log.error("Tried to add friend to invalid screen side %s", side.toString());
|
||||
|
|
@ -711,14 +721,14 @@ public class TileEntityScreen extends BlockEntity {
|
|||
|
||||
if(!scr.friends.contains(pair)) {
|
||||
scr.friends.add(pair);
|
||||
(new ScreenConfigData(new Vector3i(pos), side, scr)).updateOnly().sendTo(point());
|
||||
(new ScreenConfigData(new Vector3i(getBlockPos()), side, scr)).updateOnly().sendTo(point());
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFriend(EntityPlayerMP ply, BlockSide side, NameUUIDPair pair) {
|
||||
if(!world.isRemote) {
|
||||
public void removeFriend(ServerPlayer ply, BlockSide side, NameUUIDPair pair) {
|
||||
if(!level.isClientSide) {
|
||||
Screen scr = getScreen(side);
|
||||
if(scr == null) {
|
||||
Log.error("Tried to remove friend from invalid screen side %s", side.toString());
|
||||
|
|
@ -727,14 +737,14 @@ public class TileEntityScreen extends BlockEntity {
|
|||
|
||||
if(scr.friends.remove(pair)) {
|
||||
checkLaserUserRights(scr);
|
||||
(new ScreenConfigData(new Vector3i(pos), side, scr)).updateOnly().sendTo(point());
|
||||
(new ScreenConfigData(new Vector3i(getBlockPos()), side, scr)).updateOnly().sendTo(point());
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRights(EntityPlayerMP ply, BlockSide side, int fr, int or) {
|
||||
if(!world.isRemote) {
|
||||
public void setRights(ServerPlayer ply, BlockSide side, int fr, int or) {
|
||||
if(!level.isClientSide) {
|
||||
Screen scr = getScreen(side);
|
||||
if(scr == null) {
|
||||
Log.error("Tried to change rights of invalid screen on side %s", side.toString());
|
||||
|
|
@ -745,7 +755,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
scr.otherRights = or;
|
||||
|
||||
checkLaserUserRights(scr);
|
||||
(new ScreenConfigData(new Vector3i(pos), side, scr)).updateOnly().sendTo(point());
|
||||
(new ScreenConfigData(new Vector3i(getBlockPos()), side, scr)).updateOnly().sendTo(point());
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
|
@ -757,7 +767,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
if(world.isRemote) {
|
||||
if(level.isClientSide) {
|
||||
if(scr.browser != null) {
|
||||
try {
|
||||
if(text.startsWith("t")) {
|
||||
|
|
@ -795,7 +805,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.type(this, side, text), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.type(this, side, text), point());
|
||||
|
||||
if(soundPos != null)
|
||||
playSoundAt(WebDisplays.INSTANCE.soundTyping, soundPos, 0.25f, 1.f);
|
||||
|
|
@ -803,11 +813,11 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
private void playSoundAt(SoundEvent snd, BlockPos at, float vol, float pitch) {
|
||||
double x = (double) at.getX();
|
||||
double y = (double) at.getY();
|
||||
double z = (double) at.getZ();
|
||||
double x = at.getX();
|
||||
double y = at.getY();
|
||||
double z = at.getZ();
|
||||
|
||||
world.playSound(null, x + 0.5, y + 0.5, z + 0.5, snd, SoundCategory.BLOCKS, vol, pitch);
|
||||
level.playSound(null, x + 0.5, y + 0.5, z + 0.5, snd, SoundSource.BLOCKS, vol, pitch);
|
||||
}
|
||||
|
||||
public void updateUpgrades(BlockSide side, ItemStack[] upgrades) {
|
||||
|
|
@ -835,8 +845,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
//If equal is null, no duplicate check is preformed
|
||||
public boolean addUpgrade(BlockSide side, ItemStack is, @Nullable EntityPlayer player, boolean abortIfExisting) {
|
||||
if(world.isRemote)
|
||||
public boolean addUpgrade(BlockSide side, ItemStack is, @Nullable Player player, boolean abortIfExisting) {
|
||||
if(level.isClientSide)
|
||||
return false;
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
|
|
@ -863,9 +873,9 @@ public class TileEntityScreen extends BlockEntity {
|
|||
isCopy.setCount(1);
|
||||
|
||||
scr.upgrades.add(isCopy);
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.upgrade(this, side), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.upgrade(this, side), point());
|
||||
itemAsUpgrade.onInstall(this, side, player, isCopy);
|
||||
playSoundAt(WebDisplays.INSTANCE.soundUpgradeAdd, pos, 1.0f, 1.0f);
|
||||
playSoundAt(WebDisplays.INSTANCE.soundUpgradeAdd, getBlockPos(), 1.0f, 1.0f);
|
||||
markDirty();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -887,8 +897,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return scr != null && scr.upgrades.stream().anyMatch(du::matches);
|
||||
}
|
||||
|
||||
public void removeUpgrade(BlockSide side, ItemStack is, @Nullable EntityPlayer player) {
|
||||
if(world.isRemote)
|
||||
public void removeUpgrade(BlockSide side, ItemStack is, @Nullable Player player) {
|
||||
if(level.isClientSide)
|
||||
return;
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
|
|
@ -915,33 +925,35 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if(idxToRemove >= 0) {
|
||||
dropUpgrade(scr.upgrades.get(idxToRemove), side, player);
|
||||
scr.upgrades.remove(idxToRemove);
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.upgrade(this, side), point());
|
||||
playSoundAt(WebDisplays.INSTANCE.soundUpgradeDel, pos, 1.0f, 1.0f);
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.upgrade(this, side), point());
|
||||
playSoundAt(WebDisplays.INSTANCE.soundUpgradeDel, getBlockPos(), 1.0f, 1.0f);
|
||||
markDirty();
|
||||
} else
|
||||
Log.warning("Tried to remove non-existing upgrade %s to screen %s at %s", safeName(is), side.toString(), pos.toString());
|
||||
}
|
||||
|
||||
private void dropUpgrade(ItemStack is, BlockSide side, @Nullable EntityPlayer ply) {
|
||||
private void dropUpgrade(ItemStack is, BlockSide side, @Nullable Player ply) {
|
||||
if(!((IUpgrade) is.getItem()).onRemove(this, side, ply, is)) { //Drop upgrade item
|
||||
boolean spawnDrop = true;
|
||||
|
||||
if(ply != null) {
|
||||
if(ply.isCreative() || ply.addItemStackToInventory(is))
|
||||
if(ply.isCreative() || ply.addItem(is))
|
||||
spawnDrop = false; //If in creative or if the item was added to the player's inventory, don't spawn drop entity
|
||||
}
|
||||
|
||||
if(spawnDrop) {
|
||||
Vector3f pos = new Vector3f((float) this.pos.getX(), (float) this.pos.getY(), (float) this.pos.getZ());
|
||||
Vector3f pos = new Vector3f((float) this.getBlockPos().getX(), (float) this.getBlockPos().getY(), (float) this.getBlockPos().getZ());
|
||||
pos.addMul(side.backward.toFloat(), 1.5f);
|
||||
|
||||
world.spawnEntity(new EntityItem(world, (double) pos.x, (double) pos.y, (double) pos.z, is));
|
||||
if(level != null) {
|
||||
level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, is));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Screen getScreenForLaserOp(BlockSide side, EntityPlayer ply) {
|
||||
if(world.isRemote)
|
||||
private Screen getScreenForLaserOp(BlockSide side, Player ply) {
|
||||
if(level.isClientSide)
|
||||
return null;
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
|
|
@ -961,7 +973,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return scr; //Okay, go for it...
|
||||
}
|
||||
|
||||
public void laserDownMove(BlockSide side, EntityPlayer ply, Vector2i pos, boolean down) {
|
||||
public void laserDownMove(BlockSide side, Player ply, Vector2i pos, boolean down) {
|
||||
Screen scr = getScreenForLaserOp(side, ply);
|
||||
|
||||
if(scr != null) {
|
||||
|
|
@ -969,35 +981,35 @@ public class TileEntityScreen extends BlockEntity {
|
|||
//Try to acquire laser lock
|
||||
if(getLaserUser(scr) == null) {
|
||||
scr.laserUser = ply;
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_DOWN, pos), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_DOWN, pos), point());
|
||||
}
|
||||
} else if(getLaserUser(scr) == ply)
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_MOVE, pos), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_MOVE, pos), point());
|
||||
}
|
||||
}
|
||||
|
||||
public void laserUp(BlockSide side, EntityPlayer ply) {
|
||||
public void laserUp(BlockSide side, Player ply) {
|
||||
Screen scr = getScreenForLaserOp(side, ply);
|
||||
|
||||
if(scr != null) {
|
||||
if(getLaserUser(scr) == ply) {
|
||||
scr.laserUser = null;
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_UP, null), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_UP, null), point());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroy(@Nullable EntityPlayer ply) {
|
||||
public void onDestroy(@Nullable Player ply) {
|
||||
for(Screen scr: screens) {
|
||||
scr.upgrades.forEach(is -> dropUpgrade(is, scr.side, ply));
|
||||
scr.upgrades.clear();
|
||||
}
|
||||
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(new CMessageCloseGui(pos), point());
|
||||
Messages.INSTANCE.sendTo(new CMessageCloseGui(getBlockPos()), point());
|
||||
}
|
||||
|
||||
public void setOwner(BlockSide side, EntityPlayer newOwner) {
|
||||
if(world.isRemote) {
|
||||
public void setOwner(BlockSide side, Player newOwner) {
|
||||
if(level.isClientSide) {
|
||||
Log.error("Called TileEntityScreen.setOwner() on client...");
|
||||
return;
|
||||
}
|
||||
|
|
@ -1014,7 +1026,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
scr.owner = new NameUUIDPair(newOwner.getGameProfile());
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.owner(this, side, scr.owner), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.owner(this, side, scr.owner), point());
|
||||
checkLaserUserRights(scr);
|
||||
markDirty();
|
||||
}
|
||||
|
|
@ -1026,11 +1038,11 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
if(world.isRemote) {
|
||||
if(level.isClientSide) {
|
||||
boolean oldWasVertical = scr.rotation.isVertical;
|
||||
scr.rotation = rot;
|
||||
|
||||
WebDisplays.PROXY.screenUpdateRotationInGui(new Vector3i(pos), side, rot);
|
||||
WebDisplays.PROXY.screenUpdateRotationInGui(new Vector3i(getBlockPos()), side, rot);
|
||||
|
||||
if(scr.browser != null && oldWasVertical != rot.isVertical) {
|
||||
scr.browser.close();
|
||||
|
|
@ -1038,7 +1050,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
} else {
|
||||
scr.rotation = rot;
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.rotation(this, side, rot), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.rotation(this, side, rot), point());
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1050,11 +1062,11 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
if(world.isRemote) {
|
||||
if(level.isClientSide) {
|
||||
if(scr.browser != null)
|
||||
scr.browser.runJS(code, "");
|
||||
} else
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.js(this, side, code), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.js(this, side, code), point());
|
||||
}
|
||||
|
||||
public void setAutoVolume(BlockSide side, boolean av) {
|
||||
|
|
@ -1066,16 +1078,17 @@ public class TileEntityScreen extends BlockEntity {
|
|||
|
||||
scr.autoVolume = av;
|
||||
|
||||
if(world.isRemote)
|
||||
WebDisplays.PROXY.screenUpdateAutoVolumeInGui(new Vector3i(pos), side, av);
|
||||
if(level.isClientSide)
|
||||
WebDisplays.PROXY.screenUpdateAutoVolumeInGui(new Vector3i(getBlockPos()), side, av);
|
||||
else {
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.autoVolume(this, side, av), point());
|
||||
Messages.INSTANCE.sendTo(CMessageScreenUpdate.autoVolume(this, side, av), point());
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, @Nonnull IBlockState oldState, @Nonnull IBlockState newState) {
|
||||
public boolean shouldRefresh(Level world, BlockPos pos, @Nonnull BlockState oldState, @Nonnull BlockState newState) {
|
||||
if(oldState.getBlock() != WebDisplays.INSTANCE.blockScreen || newState.getBlock() != WebDisplays.INSTANCE.blockScreen)
|
||||
return true;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net;
|
||||
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
|
||||
public class DefaultHandler implements IMessageHandler<IMessage, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(IMessage message, MessageContext ctx) {
|
||||
WebDisplays.PROXY.enqueue((Runnable) message);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 BARBOTIN Nicolas
|
||||
*/
|
||||
|
||||
package net.montoyo.wd.net;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Message {
|
||||
|
||||
int messageId();
|
||||
Side side();
|
||||
|
||||
}
|
||||
|
|
@ -4,71 +4,36 @@
|
|||
|
||||
package net.montoyo.wd.net;
|
||||
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.montoyo.wd.net.client.*;
|
||||
import net.montoyo.wd.net.server.*;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
import net.montoyo.wd.net.client.CMessageACResult;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
public class Messages {
|
||||
|
||||
public abstract 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
|
||||
);
|
||||
|
||||
private static final DefaultHandler DEFAULT_HANDLER = new DefaultHandler();
|
||||
private static final Class<? extends IMessage>[] MESSAGES;
|
||||
static {
|
||||
ArrayList<Class<? extends IMessage>> l = new ArrayList<>();
|
||||
l.add(CMessageAddScreen.class);
|
||||
l.add(SMessageRequestTEData.class);
|
||||
l.add(SMessageScreenCtrl.class);
|
||||
l.add(CMessageOpenGui.class);
|
||||
l.add(CMessageScreenUpdate.class);
|
||||
l.add(SMessageACQuery.class);
|
||||
l.add(CMessageACResult.class);
|
||||
l.add(SMessagePadCtrl.class);
|
||||
l.add(SMessageRedstoneCtrl.class);
|
||||
l.add(CMessageJSResponse.class);
|
||||
l.add(SMessageMiniservConnect.class);
|
||||
l.add(CMessageMiniservKey.class);
|
||||
l.add(CMessageServerInfo.class);
|
||||
l.add(CMessageCloseGui.class);
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@SubscribeEvent
|
||||
public static void registryNetworkPackets (FMLClientSetupEvent event) {
|
||||
INSTANCE.registerMessage(index++, CMessageACResult.class, CMessageACResult::encode, CMessageACResult::decode, CMessageACResult::handle);
|
||||
|
||||
MESSAGES = l.toArray(new Class[0]);
|
||||
}
|
||||
|
||||
public static void registerAll(SimpleNetworkWrapper wrapper) {
|
||||
for(Class<? extends IMessage> md: MESSAGES) {
|
||||
Message data = md.getAnnotation(Message.class);
|
||||
if(data == null)
|
||||
throw new RuntimeException("Missing @Message annotation for message class " + md.getSimpleName());
|
||||
@SubscribeEvent
|
||||
public static void registryNetworkPackets (FMLCommonSetupEvent event) {
|
||||
|
||||
Class<?>[] classes = md.getClasses();
|
||||
Class<? extends IMessageHandler> handler = null;
|
||||
|
||||
for(Class<?> cls: classes) {
|
||||
if(cls.getSimpleName().equals("Handler") && Modifier.isStatic(cls.getModifiers()) && IMessageHandler.class.isAssignableFrom(cls)) {
|
||||
handler = (Class<? extends IMessageHandler>) cls;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
IMessageHandler handlerInst;
|
||||
if(handler == null) {
|
||||
if(Runnable.class.isAssignableFrom(md))
|
||||
handlerInst = DEFAULT_HANDLER;
|
||||
else
|
||||
throw new RuntimeException("Could not find message handler for message " + md.getSimpleName());
|
||||
} else {
|
||||
try {
|
||||
handlerInst = handler.newInstance();
|
||||
} catch(Throwable t) {
|
||||
throw new RuntimeException("Could not instantiate message handler for message " + md.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.registerMessage(handlerInst, md, data.messageId(), data.side());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,45 +4,42 @@
|
|||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.net.Message;
|
||||
import net.montoyo.wd.utilities.NameUUIDPair;
|
||||
|
||||
@Message(messageId = 6, side = Side.CLIENT)
|
||||
public class CMessageACResult implements IMessage, Runnable {
|
||||
import java.util.function.Supplier;
|
||||
|
||||
private NameUUIDPair[] result;
|
||||
public class CMessageACResult {
|
||||
|
||||
public CMessageACResult() {
|
||||
}
|
||||
private static NameUUIDPair[] result;
|
||||
|
||||
public CMessageACResult(NameUUIDPair[] pairs) {
|
||||
result = pairs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public static CMessageACResult decode(FriendlyByteBuf 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeByte(result.length);
|
||||
|
||||
for(NameUUIDPair pair : result)
|
||||
pair.writeTo(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
WebDisplays.PROXY.onAutocompleteResult(result);
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
WebDisplays.PROXY.onAutocompleteResult(result);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,112 +4,106 @@
|
|||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.montoyo.wd.SharedProxy;
|
||||
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.Message;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Message(messageId = 0, side = Side.CLIENT)
|
||||
public class CMessageAddScreen implements IMessage, Runnable {
|
||||
public class CMessageAddScreen {
|
||||
|
||||
private boolean clear;
|
||||
private Vector3i pos;
|
||||
private TileEntityScreen.Screen[] screens;
|
||||
|
||||
public CMessageAddScreen() {
|
||||
}
|
||||
|
||||
public CMessageAddScreen(TileEntityScreen tes) {
|
||||
clear = true;
|
||||
pos = new Vector3i(tes.getPos());
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
screens = new TileEntityScreen.Screen[tes.screenCount()];
|
||||
|
||||
for(int i = 0; i < tes.screenCount(); i++)
|
||||
for (int i = 0; i < tes.screenCount(); i++)
|
||||
screens[i] = tes.getScreen(i);
|
||||
}
|
||||
|
||||
public CMessageAddScreen(TileEntityScreen tes, TileEntityScreen.Screen ... toSend) {
|
||||
public CMessageAddScreen(TileEntityScreen tes, TileEntityScreen.Screen... toSend) {
|
||||
clear = false;
|
||||
pos = new Vector3i(tes.getPos());
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
screens = toSend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void decode(FriendlyByteBuf 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++) {
|
||||
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 = ByteBufUtils.readUTF8String(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(ByteBufUtils.readItemStack(buf));
|
||||
for (int j = 0; j < numUpgrades; j++)
|
||||
screens[i].upgrades.add(buf.readItem());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public CMessageAddScreen encode(FriendlyByteBuf buf) {
|
||||
buf.writeBoolean(clear);
|
||||
pos.writeTo(buf);
|
||||
buf.writeByte(screens.length);
|
||||
|
||||
for(TileEntityScreen.Screen scr: screens) {
|
||||
for (TileEntityScreen.Screen scr : screens) {
|
||||
buf.writeByte(scr.side.ordinal());
|
||||
scr.size.writeTo(buf);
|
||||
ByteBufUtils.writeUTF8String(buf, scr.url);
|
||||
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)
|
||||
ByteBufUtils.writeItemStack(buf, is);
|
||||
for (ItemStack is : scr.upgrades)
|
||||
buf.writeItem(is);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
TileEntity te = WebDisplays.PROXY.getWorld(SharedProxy.CURRENT_DIMENSION).getTileEntity(pos.toBlock());
|
||||
if(te == null || !(te instanceof TileEntityScreen)) {
|
||||
if(clear)
|
||||
Log.error("CMessageAddScreen: Can't add screen to invalid tile entity at %s", pos.toString());
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
BlockEntity te = WebDisplays.PROXY.getWorld(Level.OVERWORLD).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;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntityScreen tes = (TileEntityScreen) te;
|
||||
if(clear)
|
||||
tes.clear();
|
||||
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;
|
||||
scr.url = entry.url;
|
||||
scr.owner = entry.owner;
|
||||
scr.upgrades = entry.upgrades;
|
||||
for (TileEntityScreen.Screen entry : screens) {
|
||||
TileEntityScreen.Screen scr = tes.addScreen(entry.side, entry.size, entry.resolution, null, false);
|
||||
scr.rotation = entry.rotation;
|
||||
scr.url = entry.url;
|
||||
scr.owner = entry.owner;
|
||||
scr.upgrades = entry.upgrades;
|
||||
|
||||
if(scr.browser != null)
|
||||
scr.browser.loadURL(entry.url);
|
||||
}
|
||||
if (scr.browser != null)
|
||||
scr.browser.loadURL(entry.url);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,25 +4,20 @@
|
|||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
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.Message;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Message(messageId = 13, side = Side.CLIENT)
|
||||
public class CMessageCloseGui implements IMessage, Runnable {
|
||||
public class CMessageCloseGui {
|
||||
|
||||
private BlockPos blockPos;
|
||||
private BlockSide blockSide;
|
||||
|
||||
public CMessageCloseGui() {
|
||||
}
|
||||
|
||||
public CMessageCloseGui(BlockPos bp) {
|
||||
blockPos = bp;
|
||||
blockSide = null;
|
||||
|
|
@ -33,8 +28,7 @@ public class CMessageCloseGui implements IMessage, Runnable {
|
|||
blockSide = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
int x, y, z, side;
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
|
|
@ -48,24 +42,26 @@ public class CMessageCloseGui implements IMessage, Runnable {
|
|||
blockSide = BlockSide.values()[side - 1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public CMessageCloseGui encode(FriendlyByteBuf buf) {
|
||||
buf.writeInt(blockPos.getX());
|
||||
buf.writeInt(blockPos.getY());
|
||||
buf.writeInt(blockPos.getZ());
|
||||
|
||||
if(blockSide == null)
|
||||
if(blockSide == null) {
|
||||
buf.writeByte(0);
|
||||
else
|
||||
} else {
|
||||
buf.writeByte(blockSide.ordinal() + 1);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(blockSide == null)
|
||||
Arrays.stream(BlockSide.values()).forEach(s -> WebDisplays.PROXY.closeGui(blockPos, s));
|
||||
else
|
||||
WebDisplays.PROXY.closeGui(blockPos, blockSide);
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,15 @@
|
|||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
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.Message;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
|
||||
@Message(messageId = 9, side = Side.CLIENT)
|
||||
public class CMessageJSResponse implements IMessage, Runnable {
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageJSResponse {
|
||||
|
||||
private int id;
|
||||
private JSServerRequest type;
|
||||
|
|
@ -23,9 +21,6 @@ public class CMessageJSResponse implements IMessage, Runnable {
|
|||
private int errCode;
|
||||
private String errString;
|
||||
|
||||
public CMessageJSResponse() {
|
||||
}
|
||||
|
||||
public CMessageJSResponse(int id, JSServerRequest t, byte[] d) {
|
||||
this.id = id;
|
||||
type = t;
|
||||
|
|
@ -41,8 +36,7 @@ public class CMessageJSResponse implements IMessage, Runnable {
|
|||
errString = err;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
id = buf.readInt();
|
||||
type = JSServerRequest.fromID(buf.readByte());
|
||||
success = buf.readBoolean();
|
||||
|
|
@ -52,12 +46,11 @@ public class CMessageJSResponse implements IMessage, Runnable {
|
|||
buf.readBytes(data);
|
||||
} else {
|
||||
errCode = buf.readInt();
|
||||
errString = ByteBufUtils.readUTF8String(buf);
|
||||
errString = buf.readUtf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public CMessageJSResponse encode(FriendlyByteBuf buf) {
|
||||
buf.writeInt(id);
|
||||
buf.writeByte(type.ordinal());
|
||||
buf.writeBoolean(success);
|
||||
|
|
@ -67,20 +60,21 @@ public class CMessageJSResponse implements IMessage, Runnable {
|
|||
buf.writeBytes(data); //TODO: Eventually compress this data
|
||||
} else {
|
||||
buf.writeInt(errCode);
|
||||
ByteBufUtils.writeUTF8String(buf, errString);
|
||||
buf.writeUtf(errString);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if(success)
|
||||
WebDisplays.PROXY.handleJSResponseSuccess(id, type, data);
|
||||
else
|
||||
WebDisplays.PROXY.handleJSResponseError(id, type, errCode, errString);
|
||||
} catch(Throwable t) {
|
||||
Log.warningEx("Could not handle JS response", t);
|
||||
}
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
try {
|
||||
if (success)
|
||||
WebDisplays.PROXY.handleJSResponseSuccess(id, type, data);
|
||||
else
|
||||
WebDisplays.PROXY.handleJSResponseError(id, type, errCode, errString);
|
||||
} catch (Throwable t) {
|
||||
Log.warningEx("Could not handle JS response", t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,43 +5,39 @@
|
|||
package net.montoyo.wd.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
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.Message;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
|
||||
@Message(messageId = 11, side = Side.CLIENT)
|
||||
public class CMessageMiniservKey implements IMessage, Runnable {
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageMiniservKey {
|
||||
|
||||
private byte[] encryptedKey;
|
||||
|
||||
public CMessageMiniservKey() {
|
||||
}
|
||||
|
||||
public CMessageMiniservKey(byte[] key) {
|
||||
encryptedKey = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
encryptedKey = new byte[buf.readShort() & 0xFFFF];
|
||||
buf.readBytes(encryptedKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public CMessageMiniservKey encode(FriendlyByteBuf buf) {
|
||||
buf.writeShort(encryptedKey.length);
|
||||
buf.writeBytes(encryptedKey);
|
||||
return new CMessageMiniservKey(encryptedKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(Client.getInstance().decryptKey(encryptedKey)) {
|
||||
Log.info("Successfully received and decrypted key, starting miniserv client...");
|
||||
WebDisplays.PROXY.startMiniservClient();
|
||||
}
|
||||
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...");
|
||||
WebDisplays.PROXY.startMiniservClient();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,31 +4,22 @@
|
|||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.data.GuiData;
|
||||
import net.montoyo.wd.net.Message;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
|
||||
@Message(messageId = 3, side = Side.CLIENT)
|
||||
public class CMessageOpenGui implements IMessage, Runnable {
|
||||
public class CMessageOpenGui {
|
||||
|
||||
private GuiData data;
|
||||
|
||||
public CMessageOpenGui() {
|
||||
}
|
||||
|
||||
public CMessageOpenGui(GuiData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
String name = ByteBufUtils.readUTF8String(buf);
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
String name = buf.readUtf();
|
||||
Class<? extends GuiData> cls = GuiData.classOf(name);
|
||||
|
||||
if(cls == null) {
|
||||
|
|
@ -40,7 +31,7 @@ public class CMessageOpenGui implements IMessage, Runnable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public CMessageOpenGui encode(FriendlyByteBuf buf) {
|
||||
ByteBufUtils.writeUTF8String(buf, data.getName());
|
||||
Util.serialize(buf, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,23 +4,20 @@
|
|||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.montoyo.wd.SharedProxy;
|
||||
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.Message;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Message(messageId = 4, side = Side.CLIENT)
|
||||
public class CMessageScreenUpdate implements IMessage, Runnable {
|
||||
public class CMessageScreenUpdate {
|
||||
|
||||
public static final int UPDATE_URL = 0;
|
||||
public static final int UPDATE_RESOLUTION = 1;
|
||||
|
|
@ -56,7 +53,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
public static CMessageScreenUpdate setURL(TileEntityScreen tes, BlockSide side, String url) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_URL;
|
||||
ret.string = url;
|
||||
|
|
@ -66,7 +63,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
public static CMessageScreenUpdate setResolution(TileEntityScreen tes, BlockSide side, Vector2i res) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_RESOLUTION;
|
||||
ret.vec2i = res;
|
||||
|
|
@ -76,7 +73,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
public static CMessageScreenUpdate click(TileEntityScreen tes, BlockSide side, int mouseEvent, @Nullable Vector2i pos) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_MOUSE;
|
||||
ret.mouseEvent = mouseEvent;
|
||||
|
|
@ -86,14 +83,14 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
}
|
||||
|
||||
public CMessageScreenUpdate(TileEntityScreen tes, BlockSide side) {
|
||||
pos = new Vector3i(tes.getPos());
|
||||
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();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.string = text;
|
||||
ret.action = UPDATE_TYPE;
|
||||
|
|
@ -103,7 +100,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
public static CMessageScreenUpdate js(TileEntityScreen tes, BlockSide side, String code) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.string = code;
|
||||
ret.action = UPDATE_RUN_JS;
|
||||
|
|
@ -113,7 +110,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
public static CMessageScreenUpdate upgrade(TileEntityScreen tes, BlockSide side) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_UPGRADES;
|
||||
|
||||
|
|
@ -128,7 +125,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
public static CMessageScreenUpdate jsRedstone(TileEntityScreen tes, BlockSide side, Vector2i vec, int level) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_JS_REDSTONE;
|
||||
ret.vec2i = vec;
|
||||
|
|
@ -139,7 +136,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
public static CMessageScreenUpdate owner(TileEntityScreen tes, BlockSide side, NameUUIDPair owner) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_OWNER;
|
||||
ret.owner = owner;
|
||||
|
|
@ -149,7 +146,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
public static CMessageScreenUpdate rotation(TileEntityScreen tes, BlockSide side, Rotation rot) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_ROTATION;
|
||||
ret.rotation = rot;
|
||||
|
|
@ -159,7 +156,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
public static CMessageScreenUpdate autoVolume(TileEntityScreen tes, BlockSide side, boolean av) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.pos = new Vector3i(tes.getBlockPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_AUTO_VOL;
|
||||
ret.autoVolume = av;
|
||||
|
|
@ -167,14 +164,13 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
pos = new Vector3i(buf);
|
||||
side = BlockSide.values()[buf.readByte()];
|
||||
action = buf.readByte();
|
||||
|
||||
if(action == UPDATE_URL || action == UPDATE_TYPE || action == UPDATE_RUN_JS)
|
||||
string = ByteBufUtils.readUTF8String(buf);
|
||||
string = buf.readUtf();
|
||||
else if(action == UPDATE_MOUSE) {
|
||||
mouseEvent = buf.readByte();
|
||||
|
||||
|
|
@ -186,7 +182,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
upgrades = new ItemStack[buf.readByte()];
|
||||
|
||||
for(int i = 0; i < upgrades.length; i++)
|
||||
upgrades[i] = ByteBufUtils.readItemStack(buf);
|
||||
upgrades[i] = buf.readItem();
|
||||
} else if(action == UPDATE_JS_REDSTONE) {
|
||||
vec2i = new Vector2i(buf);
|
||||
redstoneLevel = buf.readByte();
|
||||
|
|
@ -198,14 +194,14 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
autoVolume = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
|
||||
public CMessageScreenUpdate encode(FriendlyByteBuf buf) {
|
||||
pos.writeTo(buf);
|
||||
buf.writeByte(side.ordinal());
|
||||
buf.writeByte(action);
|
||||
|
||||
if(action == UPDATE_URL || action == UPDATE_TYPE || action == UPDATE_RUN_JS)
|
||||
ByteBufUtils.writeUTF8String(buf, string);
|
||||
buf.writeUtf(string);
|
||||
else if(action == UPDATE_MOUSE) {
|
||||
buf.writeByte(mouseEvent);
|
||||
|
||||
|
|
@ -217,7 +213,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
buf.writeByte(upgrades.length);
|
||||
|
||||
for(ItemStack is: upgrades)
|
||||
ByteBufUtils.writeItemStack(buf, is);
|
||||
buf.writeItem(is);
|
||||
} else if(action == UPDATE_JS_REDSTONE) {
|
||||
vec2i.writeTo(buf);
|
||||
buf.writeByte(redstoneLevel);
|
||||
|
|
@ -227,22 +223,18 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
buf.writeByte(rotation.ordinal());
|
||||
else if(action == UPDATE_AUTO_VOL)
|
||||
buf.writeBoolean(autoVolume);
|
||||
return new CMessageScreenUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
TileEntity te = WebDisplays.PROXY.getWorld(SharedProxy.CURRENT_DIMENSION).getTileEntity(pos.toBlock());
|
||||
if(te == null || !(te instanceof TileEntityScreen)) {
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
BlockEntity te = WebDisplays.PROXY.getWorld(Level.OVERWORLD).getBlockEntity(pos.toBlock());
|
||||
if(!(te instanceof TileEntityScreen)) {
|
||||
Log.error("CMessageScreenUpdate: TileEntity at %s is not a screen!", pos.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntityScreen tes = (TileEntityScreen) te;
|
||||
/*TileEntityScreen.Screen scr = tes.getScreen(side);
|
||||
if(scr == null) {
|
||||
Log.error("CMessageScreenUpdate: No screen on side %s at %s", side.toString(), pos.toString());
|
||||
return;
|
||||
}*/
|
||||
|
||||
if(action == UPDATE_URL)
|
||||
tes.setScreenURL(side, string);
|
||||
|
|
@ -271,6 +263,6 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
tes.setAutoVolume(side, autoVolume);
|
||||
else
|
||||
Log.warning("Caught invalid CMessageScreenUpdate with action ID %d", action);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,41 +4,37 @@
|
|||
|
||||
package net.montoyo.wd.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
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.Message;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
|
||||
@Message(messageId = 12, side = Side.CLIENT)
|
||||
public class CMessageServerInfo implements IMessage, Runnable {
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CMessageServerInfo {
|
||||
|
||||
private int miniservPort;
|
||||
|
||||
public CMessageServerInfo() {
|
||||
}
|
||||
|
||||
public CMessageServerInfo(int msPort) {
|
||||
miniservPort = msPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
miniservPort = buf.readShort() & 0xFFFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public CMessageServerInfo encode(FriendlyByteBuf buf) {
|
||||
buf.writeShort(miniservPort);
|
||||
return new CMessageServerInfo(miniservPort);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
WebDisplays.PROXY.setMiniservClientPort(miniservPort);
|
||||
public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
contextSupplier.get().enqueueWork(() -> {
|
||||
WebDisplays.PROXY.setMiniservClientPort(miniservPort);
|
||||
|
||||
if(miniservPort > 0)
|
||||
WebDisplays.NET_HANDLER.sendToServer(Client.getInstance().beginConnection());
|
||||
if (miniservPort > 0)
|
||||
Messages.INSTANCE.sendToServer(Client.getInstance().beginConnection());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ package net.montoyo.wd.net.server;
|
|||
import com.mojang.authlib.GameProfile;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
|
@ -20,36 +23,31 @@ import net.montoyo.wd.utilities.NameUUIDPair;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Message(messageId = 5, side = Side.SERVER)
|
||||
public class SMessageACQuery implements IMessage, Runnable {
|
||||
public class SMessageACQuery {
|
||||
|
||||
private EntityPlayerMP player;
|
||||
private ServerPlayer player;
|
||||
private String beginning;
|
||||
private boolean matchExact;
|
||||
|
||||
public SMessageACQuery() {
|
||||
}
|
||||
|
||||
public SMessageACQuery(String beg, boolean exact) {
|
||||
beginning = beg;
|
||||
matchExact = exact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
beginning = ByteBufUtils.readUTF8String(buf);
|
||||
public void decode(FriendlyByteBuf buf) {
|
||||
beginning = buf.readUtf();
|
||||
matchExact = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeUTF8String(buf, beginning);
|
||||
public SMessageACQuery encode(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(beginning);
|
||||
buf.writeBoolean(matchExact);
|
||||
return new SMessageACQuery(beginning, matchExact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
GameProfile[] profiles = WebDisplays.PROXY.getOnlineGameProfiles();
|
||||
GameProfile[] profiles = ;
|
||||
NameUUIDPair[] result;
|
||||
|
||||
if(matchExact)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user