split "Screen" class out of TileEntityScreen
This commit is contained in:
parent
aa8c545089
commit
3d2f786049
|
|
@ -34,6 +34,7 @@ import net.montoyo.wd.core.DefaultUpgrade;
|
|||
import net.montoyo.wd.core.IUpgrade;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.data.SetURLData;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.item.ItemLaserPointer;
|
||||
|
|
@ -76,17 +77,6 @@ public class BlockScreen extends BaseEntityBlock {
|
|||
return super.updateShape(state, direction, neighborState, level, currentPos, neighborPos);
|
||||
}
|
||||
|
||||
public int getMetaFromState(BlockState state) {
|
||||
int ret = 0;
|
||||
if (state.getValue(hasTE))
|
||||
ret |= 1;
|
||||
|
||||
if (state.getValue(emitting))
|
||||
ret |= 2;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState p_60515_, Level p_60516_, BlockPos p_60517_, BlockState p_60518_, boolean p_60519_) {
|
||||
// TODO: make this also get called on client?
|
||||
|
|
@ -135,7 +125,7 @@ public class BlockScreen extends BaseEntityBlock {
|
|||
TileEntityScreen te = (TileEntityScreen) world.getBlockEntity(pos.toBlock());
|
||||
|
||||
if (te != null && te.getScreen(side) != null) {
|
||||
TileEntityScreen.Screen scr = te.getScreen(side);
|
||||
ScreenData scr = te.getScreen(side);
|
||||
|
||||
if (sneaking) { //Right Click
|
||||
if((scr.rightsFor(player) & ScreenRights.CHANGE_URL) == 0)
|
||||
|
|
@ -234,7 +224,7 @@ public class BlockScreen extends BaseEntityBlock {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean hit2pixels(BlockSide side, BlockPos bpos, Vector3i pos, TileEntityScreen.Screen scr, float hitX, float hitY, float hitZ, Vector2i dst) {
|
||||
public static boolean hit2pixels(BlockSide side, BlockPos bpos, Vector3i pos, ScreenData scr, float hitX, float hitY, float hitZ, Vector2i dst) {
|
||||
if(side.right.x < 0)
|
||||
hitX -= 1.f;
|
||||
|
||||
|
|
@ -295,12 +285,9 @@ public class BlockScreen extends BaseEntityBlock {
|
|||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity (BlockPos pos, BlockState state){
|
||||
int meta = getMetaFromState(state);
|
||||
|
||||
if ((meta & 1) == 0)
|
||||
if (!state.getValue(hasTE))
|
||||
return null;
|
||||
|
||||
return ((meta & 1) == 0) ? null : new TileEntityScreen(pos, state);
|
||||
return new TileEntityScreen(pos, state);
|
||||
}
|
||||
|
||||
/************************************************* DESTRUCTION HANDLING *************************************************/
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ import net.montoyo.wd.config.ClientConfig;
|
|||
import net.montoyo.wd.core.HasAdvancement;
|
||||
import net.montoyo.wd.core.JSServerRequest;
|
||||
import net.montoyo.wd.data.GuiData;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.init.ItemInit;
|
||||
|
|
@ -165,8 +166,8 @@ public class ClientProxy extends SharedProxy implements CefDisplayHandler/*, IJS
|
|||
|
||||
Multiblock.findOrigin(mc.level, pos, side, null);
|
||||
TileEntityScreen te = (TileEntityScreen) mc.level.getBlockEntity(pos.toBlock());
|
||||
|
||||
TileEntityScreen.Screen sc = te.getScreen(side);
|
||||
|
||||
ScreenData sc = te.getScreen(side);
|
||||
|
||||
if (sc == null) return;
|
||||
|
||||
|
|
@ -665,7 +666,7 @@ public class ClientProxy extends SharedProxy implements CefDisplayHandler/*, IJS
|
|||
} else {
|
||||
double dist = Double.POSITIVE_INFINITY;
|
||||
for (int i = 0; i < tes.screenCount(); i++) {
|
||||
TileEntityScreen.Screen scrn = tes.getScreen(i);
|
||||
ScreenData scrn = tes.getScreen(i);
|
||||
|
||||
Vector3d pos = new Vector3d(
|
||||
scrn.side.right.x * scrn.size.x + scrn.size.y * scrn.side.up.x,
|
||||
|
|
@ -864,7 +865,7 @@ public class ClientProxy extends SharedProxy implements CefDisplayHandler/*, IJS
|
|||
public boolean findScreenFromBrowser(CefBrowser browser, ScreenSidePair pair) {
|
||||
for (TileEntityScreen tes : screenTracking) {
|
||||
for (int i = 0; i < tes.screenCount(); i++) {
|
||||
TileEntityScreen.Screen scr = tes.getScreen(i);
|
||||
ScreenData scr = tes.getScreen(i);
|
||||
|
||||
if (scr.browser == browser) {
|
||||
pair.tes = tes;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import net.montoyo.wd.WebDisplays;
|
|||
import net.montoyo.wd.client.gui.controls.*;
|
||||
import net.montoyo.wd.client.gui.loading.FillControl;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.item.WDItem;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
|
|
@ -147,7 +148,7 @@ public class GuiScreenConfig extends WDScreen {
|
|||
boxOClick.setUserdata(ScreenRights.INTERACT);
|
||||
boxOSetUrl.setUserdata(ScreenRights.CHANGE_URL);
|
||||
|
||||
TileEntityScreen.Screen scr = tes.getScreen(side);
|
||||
ScreenData scr = tes.getScreen(side);
|
||||
if(scr != null) {
|
||||
owner = scr.owner;
|
||||
rotation = scr.rotation;
|
||||
|
|
@ -191,7 +192,7 @@ public class GuiScreenConfig extends WDScreen {
|
|||
}
|
||||
|
||||
private void clickSetRes() {
|
||||
TileEntityScreen.Screen scr = tes.getScreen(side);
|
||||
ScreenData scr = tes.getScreen(side);
|
||||
if(scr == null)
|
||||
return; //WHATDAFUQ?
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import net.minecraft.client.renderer.GameRenderer;
|
|||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.utilities.Vector3f;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
|
@ -45,7 +46,7 @@ public class ScreenRenderer implements BlockEntityRenderer<TileEntityScreen> {
|
|||
RenderSystem.disableBlend();
|
||||
|
||||
for (int i = 0; i < te.screenCount(); i++) {
|
||||
TileEntityScreen.Screen scr = te.getScreen(i);
|
||||
ScreenData scr = te.getScreen(i);
|
||||
if (scr.browser == null) {
|
||||
scr.createBrowser(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import net.minecraftforge.network.NetworkEvent;
|
|||
import net.montoyo.wd.controls.ScreenControl;
|
||||
import net.montoyo.wd.core.MissingPermissionException;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
|
||||
|
|
@ -89,7 +90,7 @@ public class ManageRightsAndUpdgradesControl extends ScreenControl {
|
|||
else tes.removeUpgrade(side, toRemove, player);
|
||||
}
|
||||
case RIGHTS -> {
|
||||
TileEntityScreen.Screen scr = tes.getScreen(side);
|
||||
ScreenData scr = tes.getScreen(side);
|
||||
|
||||
int fr = scr.owner.uuid.equals(player.getGameProfile().getId()) ? friendRights : scr.friendRights;
|
||||
int or = (scr.rightsFor(player) & ScreenRights.MANAGE_OTHER_RIGHTS) == 0 ? scr.otherRights : otherRights;
|
||||
|
|
@ -111,7 +112,7 @@ public class ManageRightsAndUpdgradesControl extends ScreenControl {
|
|||
else tes.removeUpgrade(side, toRemove, player);
|
||||
}
|
||||
case RIGHTS -> {
|
||||
TileEntityScreen.Screen scr = tes.getScreen(side);
|
||||
ScreenData scr = tes.getScreen(side);
|
||||
|
||||
int fr = friendRights;
|
||||
int or = otherRights;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.client.gui.GuiScreenConfig;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.BufferUtils;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
|
|
@ -34,7 +35,7 @@ public class ScreenConfigData extends GuiData {
|
|||
public ScreenConfigData() {
|
||||
}
|
||||
|
||||
public ScreenConfigData(Vector3i pos, BlockSide side, TileEntityScreen.Screen scr) {
|
||||
public ScreenConfigData(Vector3i pos, BlockSide side, ScreenData scr) {
|
||||
this.pos = pos;
|
||||
this.side = side;
|
||||
friends = scr.friends.toArray(new NameUUIDPair[0]);
|
||||
|
|
|
|||
203
src/main/java/net/montoyo/wd/entity/ScreenData.java
Normal file
203
src/main/java/net/montoyo/wd/entity/ScreenData.java
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
package net.montoyo.wd.entity;
|
||||
|
||||
import com.cinemamod.mcef.MCEF;
|
||||
import com.cinemamod.mcef.MCEFBrowser;
|
||||
import com.cinemamod.mcef.listeners.MCEFCursorChangeListener;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.client.ClientProxy;
|
||||
import net.montoyo.wd.config.CommonConfig;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.cef.browser.CefBrowser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ScreenData {
|
||||
|
||||
public BlockSide side;
|
||||
public Vector2i size;
|
||||
public Vector2i resolution;
|
||||
public Rotation rotation = Rotation.ROT_0;
|
||||
public String url;
|
||||
protected VideoType videoType;
|
||||
public NameUUIDPair owner;
|
||||
public ArrayList<NameUUIDPair> friends;
|
||||
public int friendRights;
|
||||
public int otherRights;
|
||||
public CefBrowser browser;
|
||||
public ArrayList<ItemStack> upgrades;
|
||||
public boolean doTurnOnAnim;
|
||||
public long turnOnTime;
|
||||
public Player laserUser;
|
||||
public final Vector2i lastMousePos = new Vector2i();
|
||||
public NibbleArray redstoneStatus; //null on client
|
||||
public boolean autoVolume = true;
|
||||
|
||||
public int mouseType;
|
||||
|
||||
public static ScreenData deserialize(CompoundTag tag) {
|
||||
ScreenData ret = new ScreenData();
|
||||
ret.side = BlockSide.values()[tag.getByte("Side")];
|
||||
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);
|
||||
|
||||
if (ret.resolution.x <= 0 || ret.resolution.y <= 0) {
|
||||
float psx = ((float) ret.size.x) * 16.f - 4.f;
|
||||
float psy = ((float) ret.size.y) * 16.f - 4.f;
|
||||
psx *= 8.f; //TODO: Use ratio in config file
|
||||
psy *= 8.f;
|
||||
|
||||
ret.resolution.x = (int) psx;
|
||||
ret.resolution.y = (int) psy;
|
||||
}
|
||||
|
||||
if (tag.contains("OwnerName")) {
|
||||
String name = tag.getString("OwnerName");
|
||||
UUID uuid = tag.getUUID("OwnerUUID");
|
||||
ret.owner = new NameUUIDPair(name, uuid);
|
||||
}
|
||||
|
||||
ListTag friends = tag.getList("Friends", 10);
|
||||
ret.friends = new ArrayList<>(friends.size());
|
||||
|
||||
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");
|
||||
|
||||
ListTag upgrades = tag.getList("Upgrades", 10);
|
||||
ret.upgrades = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < upgrades.size(); i++)
|
||||
ret.upgrades.add(ItemStack.of(upgrades.getCompound(i)));
|
||||
|
||||
if (tag.contains("AutoVolume"))
|
||||
ret.autoVolume = tag.getBoolean("AutoVolume");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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.putString("OwnerName", owner.name);
|
||||
tag.putUUID("OwnerUUID", owner.uuid);
|
||||
}
|
||||
|
||||
ListTag list = new ListTag();
|
||||
for (NameUUIDPair f : friends) {
|
||||
CompoundTag nf = new CompoundTag();
|
||||
nf.putString("Name", f.name);
|
||||
nf.putUUID("UUID", f.uuid);
|
||||
|
||||
list.add(nf);
|
||||
}
|
||||
|
||||
tag.put("Friends", list);
|
||||
tag.putByte("FriendRights", (byte) friendRights);
|
||||
tag.putByte("OtherRights", (byte) otherRights);
|
||||
|
||||
list = new ListTag();
|
||||
for (ItemStack is : upgrades)
|
||||
list.add(is.save(new CompoundTag()));
|
||||
|
||||
tag.put("Upgrades", list);
|
||||
tag.putBoolean("AutoVolume", autoVolume);
|
||||
return tag;
|
||||
}
|
||||
|
||||
public int rightsFor(Player ply) {
|
||||
return rightsFor(ply.getGameProfile().getId());
|
||||
}
|
||||
|
||||
public int rightsFor(UUID uuid) {
|
||||
if (owner.uuid.equals(uuid))
|
||||
return ScreenRights.ALL;
|
||||
|
||||
return friends.stream().anyMatch(f -> f.uuid.equals(uuid)) ? friendRights : otherRights;
|
||||
}
|
||||
|
||||
public void setupRedstoneStatus(Level world, BlockPos start) {
|
||||
if (world.isClientSide()) {
|
||||
Log.warning("Called Screen.setupRedstoneStatus() on client.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (redstoneStatus != null) {
|
||||
Log.warning("Called Screen.setupRedstoneStatus() on server, but redstone status is non-null");
|
||||
return;
|
||||
}
|
||||
|
||||
Direction[] VALUES = Direction.values();
|
||||
redstoneStatus = new NibbleArray(size.x * size.y);
|
||||
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.getSignal(it.next(), facing));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void clampResolution() {
|
||||
if (resolution.x > CommonConfig.Screen.maxResolutionX) {
|
||||
float newY = ((float) resolution.y) * ((float) CommonConfig.Screen.maxResolutionX) / ((float) resolution.x);
|
||||
resolution.x = CommonConfig.Screen.maxResolutionX;
|
||||
resolution.y = (int) newY;
|
||||
}
|
||||
|
||||
if (resolution.y > CommonConfig.Screen.maxResolutionY) {
|
||||
float newX = ((float) resolution.x) * ((float) CommonConfig.Screen.maxResolutionY) / ((float) resolution.y);
|
||||
resolution.x = (int) newX;
|
||||
resolution.y = CommonConfig.Screen.maxResolutionY;
|
||||
}
|
||||
}
|
||||
|
||||
public void createBrowser(boolean doAnim) {
|
||||
if (WebDisplays.PROXY instanceof ClientProxy clientProxy) {
|
||||
browser = MCEF.createBrowser(WebDisplays.applyBlacklist(url != null ? url : "https://www.google.com"), false);
|
||||
|
||||
if (browser instanceof MCEFBrowser mcefBrowser) {
|
||||
if (rotation.isVertical)
|
||||
mcefBrowser.resize(resolution.y, resolution.x);
|
||||
else
|
||||
mcefBrowser.resize(resolution.x, resolution.y);
|
||||
|
||||
// uh yes this is intentional
|
||||
// basically: on my laptop, this line caused an error inexplicably
|
||||
// reason: the compiler didn't update this file, so it stayed as a Consumer<Integer> in the bytecode
|
||||
//noinspection RedundantCast
|
||||
mcefBrowser.setCursorChangeListener((MCEFCursorChangeListener) (type) -> mouseType = type);
|
||||
}
|
||||
|
||||
doTurnOnAnim = doAnim;
|
||||
turnOnTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase {
|
|||
if(owner == null || scr == null)
|
||||
return err("notlinked");
|
||||
else {
|
||||
TileEntityScreen.Screen scrscr = scr.getScreen(screenSide);
|
||||
ScreenData scrscr = scr.getScreen(screenSide);
|
||||
|
||||
if((scrscr.rightsFor(owner.uuid) & ScreenRights.INTERACT) == 0)
|
||||
return err("restrictions");
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class TileEntityKeyboard extends TileEntityPeripheralBase {
|
|||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
TileEntityScreen.Screen scr = tes.getScreen(screenSide);
|
||||
ScreenData scr = tes.getScreen(screenSide);
|
||||
if((scr.rightsFor(player) & ScreenRights.INTERACT) == 0) {
|
||||
Util.toast(player, "restrictions");
|
||||
return InteractionResult.SUCCESS;
|
||||
|
|
@ -59,7 +59,7 @@ public class TileEntityKeyboard extends TileEntityPeripheralBase {
|
|||
TileEntityScreen tes = getConnectedScreen();
|
||||
|
||||
if(tes != null) {
|
||||
TileEntityScreen.Screen scr = tes.getScreen(screenSide);
|
||||
ScreenData scr = tes.getScreen(screenSide);
|
||||
boolean ok;
|
||||
|
||||
if(ent instanceof Player)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class TileEntityRCtrl extends TileEntityPeripheralBase {
|
|||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
TileEntityScreen.Screen scr = tes.getScreen(screenSide);
|
||||
ScreenData scr = tes.getScreen(screenSide);
|
||||
if((scr.rightsFor(player) & ScreenRights.CHANGE_URL) == 0) {
|
||||
Util.toast(player, "restrictions");
|
||||
return InteractionResult.SUCCESS;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
|
|||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
TileEntityScreen.Screen scr = tes.getScreen(screenSide);
|
||||
ScreenData scr = tes.getScreen(screenSide);
|
||||
if((scr.rightsFor(player) & ScreenRights.CHANGE_URL) == 0) {
|
||||
Util.toast(player, "restrictions");
|
||||
return InteractionResult.SUCCESS;
|
||||
|
|
|
|||
|
|
@ -64,190 +64,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
super(TileInit.SCREEN_BLOCK_ENTITY.get(), arg2, arg3);
|
||||
}
|
||||
|
||||
public static class Screen {
|
||||
|
||||
public BlockSide side;
|
||||
public Vector2i size;
|
||||
public Vector2i resolution;
|
||||
public Rotation rotation = Rotation.ROT_0;
|
||||
public String url;
|
||||
private VideoType videoType;
|
||||
public NameUUIDPair owner;
|
||||
public ArrayList<NameUUIDPair> friends;
|
||||
public int friendRights;
|
||||
public int otherRights;
|
||||
public CefBrowser browser;
|
||||
public ArrayList<ItemStack> upgrades;
|
||||
public boolean doTurnOnAnim;
|
||||
public long turnOnTime;
|
||||
public Player laserUser;
|
||||
public final Vector2i lastMousePos = new Vector2i();
|
||||
public NibbleArray redstoneStatus; //null on client
|
||||
public boolean autoVolume = true;
|
||||
|
||||
public int mouseType;
|
||||
|
||||
public static Screen deserialize(CompoundTag tag) {
|
||||
Screen ret = new Screen();
|
||||
ret.side = BlockSide.values()[tag.getByte("Side")];
|
||||
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);
|
||||
|
||||
if (ret.resolution.x <= 0 || ret.resolution.y <= 0) {
|
||||
float psx = ((float) ret.size.x) * 16.f - 4.f;
|
||||
float psy = ((float) ret.size.y) * 16.f - 4.f;
|
||||
psx *= 8.f; //TODO: Use ratio in config file
|
||||
psy *= 8.f;
|
||||
|
||||
ret.resolution.x = (int) psx;
|
||||
ret.resolution.y = (int) psy;
|
||||
}
|
||||
|
||||
if (tag.contains("OwnerName")) {
|
||||
String name = tag.getString("OwnerName");
|
||||
UUID uuid = tag.getUUID("OwnerUUID");
|
||||
ret.owner = new NameUUIDPair(name, uuid);
|
||||
}
|
||||
|
||||
ListTag friends = tag.getList("Friends", 10);
|
||||
ret.friends = new ArrayList<>(friends.size());
|
||||
|
||||
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");
|
||||
|
||||
ListTag upgrades = tag.getList("Upgrades", 10);
|
||||
ret.upgrades = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < upgrades.size(); i++)
|
||||
ret.upgrades.add(ItemStack.of(upgrades.getCompound(i)));
|
||||
|
||||
if (tag.contains("AutoVolume"))
|
||||
ret.autoVolume = tag.getBoolean("AutoVolume");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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.putString("OwnerName", owner.name);
|
||||
tag.putUUID("OwnerUUID", owner.uuid);
|
||||
}
|
||||
|
||||
ListTag list = new ListTag();
|
||||
for (NameUUIDPair f : friends) {
|
||||
CompoundTag nf = new CompoundTag();
|
||||
nf.putString("Name", f.name);
|
||||
nf.putUUID("UUID", f.uuid);
|
||||
|
||||
list.add(nf);
|
||||
}
|
||||
|
||||
tag.put("Friends", list);
|
||||
tag.putByte("FriendRights", (byte) friendRights);
|
||||
tag.putByte("OtherRights", (byte) otherRights);
|
||||
|
||||
list = new ListTag();
|
||||
for (ItemStack is : upgrades)
|
||||
list.add(is.save(new CompoundTag()));
|
||||
|
||||
tag.put("Upgrades", list);
|
||||
tag.putBoolean("AutoVolume", autoVolume);
|
||||
return tag;
|
||||
}
|
||||
|
||||
public int rightsFor(Player ply) {
|
||||
return rightsFor(ply.getGameProfile().getId());
|
||||
}
|
||||
|
||||
public int rightsFor(UUID uuid) {
|
||||
if (owner.uuid.equals(uuid))
|
||||
return ScreenRights.ALL;
|
||||
|
||||
return friends.stream().anyMatch(f -> f.uuid.equals(uuid)) ? friendRights : otherRights;
|
||||
}
|
||||
|
||||
public void setupRedstoneStatus(Level world, BlockPos start) {
|
||||
if (world.isClientSide()) {
|
||||
Log.warning("Called Screen.setupRedstoneStatus() on client.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (redstoneStatus != null) {
|
||||
Log.warning("Called Screen.setupRedstoneStatus() on server, but redstone status is non-null");
|
||||
return;
|
||||
}
|
||||
|
||||
Direction[] VALUES = Direction.values();
|
||||
redstoneStatus = new NibbleArray(size.x * size.y);
|
||||
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.getSignal(it.next(), facing));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void clampResolution() {
|
||||
if (resolution.x > CommonConfig.Screen.maxResolutionX) {
|
||||
float newY = ((float) resolution.y) * ((float) CommonConfig.Screen.maxResolutionX) / ((float) resolution.x);
|
||||
resolution.x = CommonConfig.Screen.maxResolutionX;
|
||||
resolution.y = (int) newY;
|
||||
}
|
||||
|
||||
if (resolution.y > CommonConfig.Screen.maxResolutionY) {
|
||||
float newX = ((float) resolution.x) * ((float) CommonConfig.Screen.maxResolutionY) / ((float) resolution.y);
|
||||
resolution.x = (int) newX;
|
||||
resolution.y = CommonConfig.Screen.maxResolutionY;
|
||||
}
|
||||
}
|
||||
|
||||
public void createBrowser(boolean doAnim) {
|
||||
if (WebDisplays.PROXY instanceof ClientProxy clientProxy) {
|
||||
browser = MCEF.createBrowser(WebDisplays.applyBlacklist(url != null ? url : "https://www.google.com"), false);
|
||||
|
||||
if (browser instanceof MCEFBrowser mcefBrowser) {
|
||||
if (rotation.isVertical)
|
||||
mcefBrowser.resize(resolution.y, resolution.x);
|
||||
else
|
||||
mcefBrowser.resize(resolution.x, resolution.y);
|
||||
|
||||
// uh yes this is intentional
|
||||
// basically: on my laptop, this line caused an error inexplicably
|
||||
// reason: the compiler didn't update this file, so it stayed as a Consumer<Integer> in the bytecode
|
||||
//noinspection RedundantCast
|
||||
mcefBrowser.setCursorChangeListener((MCEFCursorChangeListener) (type) -> mouseType = type);
|
||||
}
|
||||
|
||||
doTurnOnAnim = doAnim;
|
||||
turnOnTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void forEachScreenBlocks(BlockSide side, Consumer<BlockPos> func) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
|
||||
if (scr != null) {
|
||||
ScreenIterator it = new ScreenIterator(getBlockPos(), side, scr.size);
|
||||
|
|
@ -257,7 +75,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
}
|
||||
|
||||
private final ArrayList<Screen> screens = new ArrayList<>();
|
||||
private final ArrayList<ScreenData> screens = new ArrayList<>();
|
||||
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;
|
||||
|
|
@ -271,7 +89,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public void unload() {
|
||||
for (Screen scr : screens) {
|
||||
for (ScreenData scr : screens) {
|
||||
if (scr.browser != null) {
|
||||
scr.browser.close(true);
|
||||
scr.browser = null;
|
||||
|
|
@ -291,7 +109,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
|
||||
screens.clear();
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
screens.add(Screen.deserialize(list.getCompound(i)));
|
||||
screens.add(ScreenData.deserialize(list.getCompound(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -304,7 +122,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
@Override
|
||||
public void handleUpdateTag(CompoundTag tag) {
|
||||
load(tag);
|
||||
for (Screen screen : screens) {
|
||||
for (ScreenData screen : screens) {
|
||||
if (screen.browser == null) screen.createBrowser(false);
|
||||
if (screen.browser != null) screen.browser.loadURL(screen.url);
|
||||
}
|
||||
|
|
@ -316,19 +134,19 @@ public class TileEntityScreen extends BlockEntity {
|
|||
super.saveAdditional(tag);
|
||||
|
||||
ListTag list = new ListTag();
|
||||
for (Screen scr : screens)
|
||||
for (ScreenData scr : screens)
|
||||
list.add(scr.serialize());
|
||||
|
||||
tag.put("WDScreens", list);
|
||||
}
|
||||
|
||||
public Screen addScreen(BlockSide side, Vector2i size, @Nullable Vector2i resolution, @Nullable Player owner, boolean sendUpdate) {
|
||||
for (Screen scr : screens) {
|
||||
public ScreenData addScreen(BlockSide side, Vector2i size, @Nullable Vector2i resolution, @Nullable Player owner, boolean sendUpdate) {
|
||||
for (ScreenData scr : screens) {
|
||||
if (scr.side == side)
|
||||
return scr;
|
||||
}
|
||||
|
||||
Screen ret = new Screen();
|
||||
ScreenData ret = new ScreenData();
|
||||
ret.side = side;
|
||||
ret.size = size;
|
||||
ret.url = CommonConfig.Browser.homepage;
|
||||
|
|
@ -385,8 +203,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public Screen getScreen(BlockSide side) {
|
||||
for (Screen scr : screens) {
|
||||
public ScreenData getScreen(BlockSide side) {
|
||||
for (ScreenData scr : screens) {
|
||||
if (scr.side == side)
|
||||
return scr;
|
||||
}
|
||||
|
|
@ -398,7 +216,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return screens.size();
|
||||
}
|
||||
|
||||
public Screen getScreen(int idx) {
|
||||
public ScreenData getScreen(int idx) {
|
||||
return screens.get(idx);
|
||||
}
|
||||
|
||||
|
|
@ -429,7 +247,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public void setScreenURL(BlockSide side, String url) throws IOException {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Attempt to change URL of non-existing screen on side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -488,7 +306,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Tried to change resolution of non-existing screen on side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -510,7 +328,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
}
|
||||
|
||||
private static Player getLaserUser(Screen scr) {
|
||||
private static Player getLaserUser(ScreenData scr) {
|
||||
if (scr.laserUser != null) {
|
||||
if (scr.laserUser.isRemoved() || !scr.laserUser.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.LASER_POINTER.get()))
|
||||
scr.laserUser = null;
|
||||
|
|
@ -519,20 +337,20 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return scr.laserUser;
|
||||
}
|
||||
|
||||
private static void checkLaserUserRights(Screen scr) {
|
||||
private static void checkLaserUserRights(ScreenData scr) {
|
||||
if (scr.laserUser != null && (scr.rightsFor(scr.laserUser) & ScreenRights.INTERACT) == 0)
|
||||
scr.laserUser = null;
|
||||
}
|
||||
|
||||
public void clearLaserUser(BlockSide side) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
|
||||
if (scr != null)
|
||||
scr.laserUser = null;
|
||||
}
|
||||
|
||||
public void click(BlockSide side, Vector2i vec) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Attempt click non-existing screen of side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -554,7 +372,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
public void handleMouseEvent(BlockSide side, ClickControl.ControlType event, @Nullable Vector2i vec, int button) {
|
||||
if (button > 1) return; // buttons above 1 crash the game
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Attempt inject mouse events on non-existing screen of side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -693,7 +511,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (level.isClientSide) {
|
||||
WebDisplays.PROXY.trackScreen(this, false);
|
||||
|
||||
for (Screen scr : screens) {
|
||||
for (ScreenData scr : screens) {
|
||||
if (scr.browser != null) {
|
||||
scr.browser.close(true);
|
||||
scr.browser = null;
|
||||
|
|
@ -706,7 +524,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
Vector3i origin = new Vector3i(getBlockPos());
|
||||
MutableAABB box = null;
|
||||
|
||||
for (Screen scr : screens) {
|
||||
for (ScreenData scr : screens) {
|
||||
Vector3i f = scr.side.forward;
|
||||
|
||||
int fx = Math.max(f.x, 0);
|
||||
|
|
@ -789,7 +607,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
// }
|
||||
|
||||
public void updateClientSideURL(CefBrowser target, String url) {
|
||||
for (Screen scr : screens) {
|
||||
for (ScreenData scr : screens) {
|
||||
if (scr.browser == target) {
|
||||
String webUrl;
|
||||
try {
|
||||
|
|
@ -820,7 +638,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
|
||||
public void addFriend(ServerPlayer ply, BlockSide side, NameUUIDPair pair) {
|
||||
if (!level.isClientSide) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Tried to add friend to invalid screen side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -836,7 +654,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
|
||||
public void removeFriend(ServerPlayer ply, BlockSide side, NameUUIDPair pair) {
|
||||
if (!level.isClientSide) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Tried to remove friend from invalid screen side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -852,7 +670,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
|
||||
public void setRights(ServerPlayer ply, BlockSide side, int fr, int or) {
|
||||
if (!level.isClientSide) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Tried to change rights of invalid screen on side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -872,7 +690,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public void type(BlockSide side, String text, BlockPos soundPos, @Nullable ServerPlayer sender) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Tried to type on invalid screen on side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -967,7 +785,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
public boolean addUpgrade(BlockSide side, ItemStack is, @Nullable Player player, boolean abortIfExisting) {
|
||||
if (level.isClientSide) {
|
||||
IUpgrade itemAsUpgrade = (IUpgrade) is.getItem();
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
// if (abortIfExisting && scr.upgrades.stream().anyMatch(otherStack -> itemAsUpgrade.isSameUpgrade(is, otherStack)))
|
||||
// return false; //Upgrade already exists
|
||||
ItemStack isCopy = is.copy(); //FIXME: Duct tape fix, because the original stack will be shrinked
|
||||
|
|
@ -976,7 +794,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return false;
|
||||
}
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Tried to add an upgrade on invalid screen on side %s", side.toString());
|
||||
return false;
|
||||
|
|
@ -1010,7 +828,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public boolean hasUpgrade(BlockSide side, ItemStack is) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null)
|
||||
return false;
|
||||
|
||||
|
|
@ -1022,7 +840,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public boolean hasUpgrade(BlockSide side, DefaultUpgrade du) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (du == DefaultUpgrade.LASERMOUSE) {
|
||||
return scr != null && scr.upgrades.stream().anyMatch(du::matchesLaserMouse);
|
||||
} else if (du == DefaultUpgrade.REDINPUT) {
|
||||
|
|
@ -1040,7 +858,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (level.isClientSide)
|
||||
return;
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Tried to remove an upgrade on invalid screen on side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -1093,11 +911,11 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
}
|
||||
|
||||
private Screen getScreenForLaserOp(BlockSide side, Player ply) {
|
||||
private ScreenData getScreenForLaserOp(BlockSide side, Player ply) {
|
||||
if (level.isClientSide)
|
||||
return null;
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Called laser operation on invalid screen on side %s", side.toString());
|
||||
return null;
|
||||
|
|
@ -1115,7 +933,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public void laserDownMove(BlockSide side, Player ply, Vector2i pos, boolean down, int button) {
|
||||
Screen scr = getScreenForLaserOp(side, ply);
|
||||
ScreenData scr = getScreenForLaserOp(side, ply);
|
||||
|
||||
if (scr != null) {
|
||||
if (button == -1)
|
||||
|
|
@ -1128,7 +946,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public void laserUp(BlockSide side, Player ply, int button) {
|
||||
Screen scr = getScreenForLaserOp(side, ply);
|
||||
ScreenData scr = getScreenForLaserOp(side, ply);
|
||||
|
||||
if (scr != null) {
|
||||
if (getLaserUser(scr) == ply) {
|
||||
|
|
@ -1139,7 +957,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public void onDestroy(@Nullable Player ply) {
|
||||
for (Screen scr : screens) {
|
||||
for (ScreenData scr : screens) {
|
||||
scr.upgrades.forEach(is -> dropUpgrade(is, scr.side, ply));
|
||||
scr.upgrades.clear();
|
||||
}
|
||||
|
|
@ -1148,8 +966,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public void disableScreen(BlockSide side) {
|
||||
Screen remove = null;
|
||||
for (Screen screen : screens) {
|
||||
ScreenData remove = null;
|
||||
for (ScreenData screen : screens) {
|
||||
if (screen.side == side) {
|
||||
remove = screen;
|
||||
break;
|
||||
|
|
@ -1159,7 +977,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
if (remove == null) return;
|
||||
|
||||
if (level != null && !level.isClientSide) {
|
||||
final Screen scrn = remove;
|
||||
final ScreenData scrn = remove;
|
||||
remove.upgrades.forEach(is -> dropUpgrade(is, scrn.side, null));
|
||||
}
|
||||
|
||||
|
|
@ -1180,7 +998,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Called TileEntityScreen.setOwner() on invalid screen on side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -1193,7 +1011,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
}
|
||||
|
||||
public void setRotation(BlockSide side, Rotation rot) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Trying to change rotation of invalid screen on side %s", side.toString());
|
||||
return;
|
||||
|
|
@ -1231,7 +1049,7 @@ public class TileEntityScreen extends BlockEntity {
|
|||
// }
|
||||
|
||||
public void setAutoVolume(BlockSide side, boolean av) {
|
||||
Screen scr = getScreen(side);
|
||||
ScreenData scr = getScreen(side);
|
||||
if (scr == null) {
|
||||
Log.error("Trying to toggle auto-volume on invalid screen (side %s)", side.toString());
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import net.montoyo.wd.client.ClientProxy;
|
|||
import net.montoyo.wd.config.ClientConfig;
|
||||
import net.montoyo.wd.controls.builtin.ClickControl;
|
||||
import net.montoyo.wd.core.DefaultUpgrade;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
|
|
@ -62,7 +63,7 @@ public class ItemLaserPointer extends Item implements WDItem {
|
|||
|
||||
if (te != null && te.hasUpgrade(side, DefaultUpgrade.LASERMOUSE)) { //hasUpgrade returns false is there's no screen on side 'side'
|
||||
//Since rights aren't synchronized, let the server check them for us...
|
||||
TileEntityScreen.Screen scr = te.getScreen(side);
|
||||
ScreenData scr = te.getScreen(side);
|
||||
|
||||
if (scr.browser != null) {
|
||||
float hitX = ((float) result.getLocation().x) - (float) pos.x;
|
||||
|
|
@ -82,7 +83,7 @@ public class ItemLaserPointer extends Item implements WDItem {
|
|||
deselectScreen();
|
||||
}
|
||||
|
||||
private static void laserClick(TileEntityScreen tes, BlockSide side, TileEntityScreen.Screen scr, Vector2i hit) {
|
||||
private static void laserClick(TileEntityScreen tes, BlockSide side, ScreenData scr, Vector2i hit) {
|
||||
tes.handleMouseEvent(side, ClickControl.ControlType.MOVE, hit, -1);
|
||||
if (pointedScreen == tes && pointedScreenSide == side) {
|
||||
long t = System.currentTimeMillis();
|
||||
|
|
@ -133,7 +134,7 @@ public class ItemLaserPointer extends Item implements WDItem {
|
|||
|
||||
if (te.hasUpgrade(side, DefaultUpgrade.LASERMOUSE)) { //hasUpgrade returns false is there's no screen on side 'side'
|
||||
//Since rights aren't synchronized, let the server check them for us...
|
||||
TileEntityScreen.Screen scr = te.getScreen(side);
|
||||
ScreenData scr = te.getScreen(side);
|
||||
|
||||
if (scr.browser != null) {
|
||||
if (BlockScreen.hit2pixels(side, result.getBlockPos(), new Vector3i(result.getBlockPos()), scr, hitX, hitY, hitZ, tmp)) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import net.montoyo.wd.WebDisplays;
|
|||
import net.montoyo.wd.block.BlockScreen;
|
||||
import net.montoyo.wd.core.IPeripheral;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Multiblock;
|
||||
|
|
@ -96,7 +97,7 @@ public class ItemLinker extends Item implements WDItem {
|
|||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
TileEntityScreen.Screen scr = ((TileEntityScreen) te).getScreen(side);
|
||||
ScreenData scr = ((TileEntityScreen) te).getScreen(side);
|
||||
if(scr == null)
|
||||
Util.toast(context.getPlayer(), "turnOn");
|
||||
else if((scr.rightsFor(context.getPlayer()) & ScreenRights.MANAGE_UPGRADES) == 0)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.block.BlockScreen;
|
||||
import net.montoyo.wd.config.CommonConfig;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -60,7 +61,7 @@ public class ItemOwnershipThief extends Item implements WDItem {
|
|||
return InteractionResult.SUCCESS;
|
||||
|
||||
TileEntityScreen tes = (TileEntityScreen) te;
|
||||
TileEntityScreen.Screen scr = tes.getScreen(side);
|
||||
ScreenData scr = tes.getScreen(side);
|
||||
if(scr == null)
|
||||
return InteractionResult.SUCCESS;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.block.BlockScreen;
|
||||
import net.montoyo.wd.data.ScreenConfigData;
|
||||
import net.montoyo.wd.entity.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.utilities.BlockSide;
|
||||
import net.montoyo.wd.utilities.Multiblock;
|
||||
|
|
@ -48,7 +49,7 @@ public class ItemScreenConfigurator extends Item implements WDItem {
|
|||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
TileEntityScreen.Screen scr = ((TileEntityScreen) te).getScreen(side);
|
||||
ScreenData scr = ((TileEntityScreen) te).getScreen(side);
|
||||
if(scr == null)
|
||||
Util.toast(context.getPlayer(), "turnOn");
|
||||
else
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ 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.ScreenData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.Packet;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
|
@ -22,24 +23,24 @@ import static net.montoyo.wd.block.BlockScreen.hasTE;
|
|||
public class S2CMessageAddScreen extends Packet {
|
||||
private boolean clear;
|
||||
private Vector3i pos;
|
||||
private TileEntityScreen.Screen[] screens;
|
||||
private ScreenData[] screens;
|
||||
|
||||
public S2CMessageAddScreen(TileEntityScreen tes) {
|
||||
clear = true;
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
screens = new TileEntityScreen.Screen[tes.screenCount()];
|
||||
screens = new ScreenData[tes.screenCount()];
|
||||
|
||||
for (int i = 0; i < tes.screenCount(); i++)
|
||||
screens[i] = tes.getScreen(i);
|
||||
}
|
||||
|
||||
public S2CMessageAddScreen(TileEntityScreen tes, TileEntityScreen.Screen... toSend) {
|
||||
public S2CMessageAddScreen(TileEntityScreen tes, ScreenData... toSend) {
|
||||
clear = false;
|
||||
pos = new Vector3i(tes.getBlockPos());
|
||||
screens = toSend;
|
||||
}
|
||||
|
||||
public S2CMessageAddScreen(boolean clear, Vector3i pos, TileEntityScreen.Screen[] screens) {
|
||||
public S2CMessageAddScreen(boolean clear, Vector3i pos, ScreenData[] screens) {
|
||||
this.clear = clear;
|
||||
this.pos = pos;
|
||||
this.screens = screens;
|
||||
|
|
@ -53,9 +54,9 @@ public class S2CMessageAddScreen extends Packet {
|
|||
|
||||
int cnt = buf.readByte() & 7;
|
||||
|
||||
screens = new TileEntityScreen.Screen[cnt];
|
||||
screens = new ScreenData[cnt];
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
screens[i] = new TileEntityScreen.Screen();
|
||||
screens[i] = new ScreenData();
|
||||
screens[i].side = BlockSide.values()[buf.readByte()];
|
||||
screens[i].size = new Vector2i(buf);
|
||||
screens[i].url = buf.readUtf();
|
||||
|
|
@ -76,7 +77,7 @@ public class S2CMessageAddScreen extends Packet {
|
|||
pos.writeTo(buf);
|
||||
buf.writeByte(screens.length);
|
||||
|
||||
for (TileEntityScreen.Screen scr : screens) {
|
||||
for (ScreenData scr : screens) {
|
||||
buf.writeByte(scr.side.ordinal());
|
||||
scr.size.writeTo(buf);
|
||||
buf.writeUtf(scr.url);
|
||||
|
|
@ -111,8 +112,8 @@ public class S2CMessageAddScreen extends Packet {
|
|||
if (clear)
|
||||
tes.clear();
|
||||
|
||||
for (TileEntityScreen.Screen entry : screens) {
|
||||
TileEntityScreen.Screen scr = tes.addScreen(entry.side, entry.size, entry.resolution, null, false);
|
||||
for (ScreenData entry : screens) {
|
||||
ScreenData scr = tes.addScreen(entry.side, entry.size, entry.resolution, null, false);
|
||||
scr.rotation = entry.rotation;
|
||||
String webUrl;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user