+ IMMA FIRIN MAH LAZOR
This commit is contained in:
parent
14ae656684
commit
1fd101ddbe
|
|
@ -2,7 +2,6 @@
|
|||
This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The text below is my "TODO" list.
|
||||
|
||||
### Missing features
|
||||
* Screen upgrade: "laser" mouse
|
||||
* Screen upgrade: redstone input
|
||||
* Screen upgrade: redstone output
|
||||
* ~~Peripheral: ComputerCraft interface~~ (CC not up to date)
|
||||
|
|
@ -11,6 +10,7 @@ This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The tex
|
|||
* Read config (see "Config elements" below)
|
||||
|
||||
### TODO
|
||||
* VideoType doesn't seem to be used...
|
||||
* DROP UPGRADES WHEN SCREEN IS DESTROYED
|
||||
* Achievements (minePad 2 and all that stuff)
|
||||
* Top/bottom screen orientation
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import net.minecraft.client.renderer.texture.TextureMap;
|
|||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.client.resources.SimpleReloadableResourceManager;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
|
@ -46,6 +47,7 @@ import net.montoyo.wd.core.DefaultUpgrade;
|
|||
import net.montoyo.wd.data.GuiData;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.SMessagePadCtrl;
|
||||
import net.montoyo.wd.net.SMessageScreenCtrl;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
|
|
@ -76,6 +78,11 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi
|
|||
private MinePadRenderer minePadRenderer;
|
||||
private LaserPointerRenderer laserPointerRenderer;
|
||||
|
||||
//Laser pointer
|
||||
private TileEntityScreen pointedScreen;
|
||||
private BlockSide pointedScreenSide;
|
||||
private long lastPointPacket;
|
||||
|
||||
//Tracking
|
||||
private ArrayList<TileEntityScreen> screenTracking = new ArrayList<>();
|
||||
private double unloadDistance2 = 32.0 * 32.0;
|
||||
|
|
@ -317,8 +324,13 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi
|
|||
}
|
||||
}
|
||||
|
||||
//If laser is on, raycast
|
||||
if(laserPointerRenderer.isOn) {
|
||||
//Laser pointer raycast
|
||||
boolean raycastHit = false;
|
||||
|
||||
if(mc.player != null && mc.world != null && mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() == WebDisplays.INSTANCE.itemLaserPointer
|
||||
&& mc.gameSettings.keyBindUseItem.isKeyDown()
|
||||
&& (mc.objectMouseOver == null || mc.objectMouseOver.typeOfHit != RayTraceResult.Type.BLOCK)) {
|
||||
laserPointerRenderer.isOn = true;
|
||||
RayTraceResult result = raycast(64.0); //TODO: Make that distance configurable
|
||||
|
||||
if(result != null) {
|
||||
|
|
@ -333,17 +345,27 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi
|
|||
|
||||
if(te != null && te.hasUpgrade(side, WebDisplays.INSTANCE.itemUpgrade, DefaultUpgrade.LASER_MOUSE.ordinal())) { //hasUpgrade returns false is there's no screen on side 'side'
|
||||
//Since rights aren't synchronized, let the server check them for us...
|
||||
float hitX = ((float) result.hitVec.x) - (float) bpos.getX();
|
||||
float hitY = ((float) result.hitVec.y) - (float) bpos.getY();
|
||||
float hitZ = ((float) result.hitVec.z) - (float) bpos.getZ();
|
||||
Vector2i tmp = new Vector2i();
|
||||
TileEntityScreen.Screen scr = te.getScreen(side);
|
||||
|
||||
if(BlockScreen.hit2pixels(side, bpos, pos, te.getScreen(side), hitX, hitY, hitZ, tmp))
|
||||
System.out.println("At " + tmp.x + ", " + tmp.y);
|
||||
if(scr.browser != null) {
|
||||
float hitX = ((float) result.hitVec.x) - (float) bpos.getX();
|
||||
float hitY = ((float) result.hitVec.y) - (float) bpos.getY();
|
||||
float hitZ = ((float) result.hitVec.z) - (float) bpos.getZ();
|
||||
Vector2i tmp = new Vector2i();
|
||||
|
||||
if(BlockScreen.hit2pixels(side, bpos, pos, scr, hitX, hitY, hitZ, tmp)) {
|
||||
laserClick(te, side, scr, tmp);
|
||||
raycastHit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
laserPointerRenderer.isOn = false;
|
||||
|
||||
if(!raycastHit)
|
||||
deselectScreen();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -367,15 +389,31 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi
|
|||
ev.setCanceled(true);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMouseButton(MouseEvent ev) {
|
||||
if(ev.getButton() == 1 && mc.player != null && mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() == WebDisplays.INSTANCE.itemLaserPointer) {
|
||||
laserPointerRenderer.isOn = ev.isButtonstate();
|
||||
ev.setCanceled(true); //Do I really need this?
|
||||
/**************************************** OTHER METHODS ****************************************/
|
||||
|
||||
private void laserClick(TileEntityScreen tes, BlockSide side, TileEntityScreen.Screen scr, Vector2i hit) {
|
||||
if(pointedScreen == tes && pointedScreenSide == side) {
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
if(t - lastPointPacket >= 100) {
|
||||
lastPointPacket = t;
|
||||
WebDisplays.NET_HANDLER.sendToServer(SMessageScreenCtrl.vec2(tes, side, SMessageScreenCtrl.CTRL_LASER_MOVE, hit));
|
||||
}
|
||||
} else {
|
||||
deselectScreen();
|
||||
pointedScreen = tes;
|
||||
pointedScreenSide = side;
|
||||
WebDisplays.NET_HANDLER.sendToServer(SMessageScreenCtrl.vec2(tes, side, SMessageScreenCtrl.CTRL_LASER_DOWN, hit));
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************** OTHER METHODS ****************************************/
|
||||
private void deselectScreen() {
|
||||
if(pointedScreen != null && pointedScreenSide != null) {
|
||||
WebDisplays.NET_HANDLER.sendToServer(SMessageScreenCtrl.laserUp(pointedScreen, pointedScreenSide));
|
||||
pointedScreen = null;
|
||||
pointedScreenSide = null;
|
||||
}
|
||||
}
|
||||
|
||||
private RayTraceResult raycast(double dist) {
|
||||
Vec3d start = mc.player.getPositionEyes(1.0f);
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ public class GuiScreenConfig extends WDScreen {
|
|||
throw new NumberFormatException(); //I'm lazy
|
||||
|
||||
if(x != scr.resolution.x || y != scr.resolution.y)
|
||||
WebDisplays.NET_HANDLER.sendToServer(new SMessageScreenCtrl(tes, side, new Vector2i(x, y)));
|
||||
WebDisplays.NET_HANDLER.sendToServer(SMessageScreenCtrl.vec2(tes, side, SMessageScreenCtrl.CTRL_SET_RESOLUTION, new Vector2i(x, y)));
|
||||
} catch(NumberFormatException ex) {
|
||||
//Roll back
|
||||
tfResX.setText("" + scr.resolution.x);
|
||||
|
|
|
|||
|
|
@ -4,13 +4,10 @@
|
|||
|
||||
package net.montoyo.wd.client.renderers;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
|
@ -25,7 +22,6 @@ 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 Minecraft mc = Minecraft.getMinecraft();
|
||||
private final FloatBuffer matrix1 = BufferUtils.createFloatBuffer(16);
|
||||
private final FloatBuffer renderBuffer = BufferUtils.createFloatBuffer(8);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
|
|
@ -21,13 +22,16 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
|
|||
import net.montoyo.mcef.api.IBrowser;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.block.BlockScreen;
|
||||
import net.montoyo.wd.core.DefaultUpgrade;
|
||||
import net.montoyo.wd.core.IUpgrade;
|
||||
import net.montoyo.wd.core.ScreenRights;
|
||||
import net.montoyo.wd.data.ScreenConfigData;
|
||||
import net.montoyo.wd.net.CMessageAddScreen;
|
||||
import net.montoyo.wd.net.CMessageScreenUpdate;
|
||||
import net.montoyo.wd.net.SMessageRequestTEData;
|
||||
import net.montoyo.wd.net.SMessageScreenCtrl;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
|
@ -52,6 +56,8 @@ public class TileEntityScreen extends TileEntity {
|
|||
public ArrayList<ItemStack> upgrades;
|
||||
public boolean doTurnOnAnim;
|
||||
public long turnOnTime;
|
||||
public EntityPlayer laserUser;
|
||||
public final Vector2i lastMousePos = new Vector2i();
|
||||
|
||||
public static boolean isYouTubeURL(String url) {
|
||||
return url.matches(YT_REGEX1) || url.matches(YT_REGEX2);
|
||||
|
|
@ -147,16 +153,11 @@ public class TileEntityScreen extends TileEntity {
|
|||
}
|
||||
|
||||
public int rightsFor(EntityPlayer ply) {
|
||||
UUID uuid = ply.getGameProfile().getId();
|
||||
final UUID uuid = ply.getGameProfile().getId();
|
||||
if(owner.uuid.equals(uuid))
|
||||
return ScreenRights.ALL;
|
||||
|
||||
for(NameUUIDPair f: friends) {
|
||||
if(f.uuid.equals(uuid))
|
||||
return friendRights;
|
||||
}
|
||||
|
||||
return otherRights;
|
||||
return friends.stream().anyMatch((f) -> f.uuid.equals(uuid)) ? friendRights : otherRights;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -361,6 +362,27 @@ public class TileEntityScreen extends TileEntity {
|
|||
}
|
||||
}
|
||||
|
||||
private static EntityPlayer getLaserUser(Screen scr) {
|
||||
if(scr.laserUser != null) {
|
||||
if(scr.laserUser.isDead || scr.laserUser.getHeldItem(EnumHand.MAIN_HAND).getItem() != WebDisplays.INSTANCE.itemLaserPointer)
|
||||
scr.laserUser = null;
|
||||
}
|
||||
|
||||
return scr.laserUser;
|
||||
}
|
||||
|
||||
private static void checkLaserUserRights(Screen scr) {
|
||||
if(scr.laserUser != null && (scr.rightsFor(scr.laserUser) & ScreenRights.CLICK) == 0)
|
||||
scr.laserUser = null;
|
||||
}
|
||||
|
||||
public void clearLaserUser(BlockSide side) {
|
||||
Screen scr = getScreen(side);
|
||||
|
||||
if(scr != null)
|
||||
scr.laserUser = null;
|
||||
}
|
||||
|
||||
public void click(BlockSide side, Vector2i vec) {
|
||||
Screen scr = getScreen(side);
|
||||
if(scr == null) {
|
||||
|
|
@ -368,14 +390,40 @@ public class TileEntityScreen extends TileEntity {
|
|||
return;
|
||||
}
|
||||
|
||||
if(world.isRemote) {
|
||||
if(scr.browser != null) {
|
||||
scr.browser.injectMouseMove(vec.x, vec.y, 0, false);
|
||||
scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, true, 1);
|
||||
scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, false, 1);
|
||||
if(world.isRemote)
|
||||
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());
|
||||
}
|
||||
|
||||
public void handleMouseEvent(BlockSide side, int event, @Nullable Vector2i vec) {
|
||||
Screen scr = getScreen(side);
|
||||
if(scr == null) {
|
||||
Log.error("Attempt inject mouse events on non-existing screen of side %s", side.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if(scr.browser != null) {
|
||||
if(event != CMessageScreenUpdate.MOUSE_MOVE)
|
||||
System.out.println(String.format("handleMouseEvent2 %d @ %d, %d", event, vec == null ? -1 : vec.x, vec == null ? -1 : vec.y));
|
||||
|
||||
if(event == CMessageScreenUpdate.MOUSE_CLICK) {
|
||||
scr.browser.injectMouseMove(vec.x, vec.y, 0, false); //Move to target
|
||||
scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, true, 1); //Press
|
||||
scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, false, 1); //Release
|
||||
} else if(event == CMessageScreenUpdate.MOUSE_DOWN) {
|
||||
scr.browser.injectMouseMove(vec.x, vec.y, 0, false); //Move to target
|
||||
scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, true, 1); //Press
|
||||
} else if(event == CMessageScreenUpdate.MOUSE_MOVE)
|
||||
scr.browser.injectMouseMove(vec.x, vec.y, 0, false); //Move
|
||||
else if(event == CMessageScreenUpdate.MOUSE_UP)
|
||||
scr.browser.injectMouseButton(scr.lastMousePos.x, scr.lastMousePos.y, 0, 1, false, 1); //Release
|
||||
|
||||
if(vec != null) {
|
||||
scr.lastMousePos.x = vec.x;
|
||||
scr.lastMousePos.y = vec.y;
|
||||
}
|
||||
} else
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.click(this, side, vec), point());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -424,7 +472,7 @@ public class TileEntityScreen extends TileEntity {
|
|||
|
||||
public void updateTrackDistance(double d) {
|
||||
boolean needsComputation = true;
|
||||
float vol = -1.f;
|
||||
float vol;
|
||||
String jsCode = null;
|
||||
|
||||
for(Screen scr: screens) {
|
||||
|
|
@ -499,6 +547,7 @@ public class TileEntityScreen extends TileEntity {
|
|||
}
|
||||
|
||||
if(scr.friends.remove(pair)) {
|
||||
checkLaserUserRights(scr);
|
||||
(new ScreenConfigData(new Vector3i(pos), side, scr)).updateOnly().sendTo(point());
|
||||
markDirty();
|
||||
}
|
||||
|
|
@ -515,6 +564,8 @@ public class TileEntityScreen extends TileEntity {
|
|||
|
||||
scr.friendRights = fr;
|
||||
scr.otherRights = or;
|
||||
|
||||
checkLaserUserRights(scr);
|
||||
(new ScreenConfigData(new Vector3i(pos), side, scr)).updateOnly().sendTo(point());
|
||||
markDirty();
|
||||
}
|
||||
|
|
@ -611,9 +662,12 @@ public class TileEntityScreen extends TileEntity {
|
|||
if(abortIfExisting && scr.upgrades.stream().anyMatch((otherStack) -> itemAsUpgrade.isSameUpgrade(is, otherStack)))
|
||||
return false; //Upgrade already exists
|
||||
|
||||
scr.upgrades.add(is);
|
||||
ItemStack isCopy = is.copy(); //FIXME: Duct tape fix, because the original stack will be shrinked
|
||||
isCopy.setCount(1);
|
||||
|
||||
scr.upgrades.add(isCopy);
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.upgrade(this, side), point());
|
||||
itemAsUpgrade.onInstall(this, side, player, is);
|
||||
itemAsUpgrade.onInstall(this, side, player, isCopy);
|
||||
playSoundAt(WebDisplays.INSTANCE.soundUpgradeAdd, pos, 1.0f, 1.0f);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -689,4 +743,56 @@ public class TileEntityScreen extends TileEntity {
|
|||
Log.warning("Tried to remove non-existing upgrade %s to screen %s at %s", safeName(is), side.toString(), pos.toString());
|
||||
}
|
||||
|
||||
private Screen getScreenForLaserOp(BlockSide side, EntityPlayer ply) {
|
||||
if(world.isRemote)
|
||||
return null;
|
||||
|
||||
Screen scr = getScreen(side);
|
||||
if(scr == null) {
|
||||
Log.error("Called laser operation on invalid screen on side %s", side.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
if((scr.rightsFor(ply) & ScreenRights.CLICK) == 0)
|
||||
return null; //Don't output an error, it can 'legally' happen
|
||||
|
||||
if(scr.upgrades.stream().noneMatch((is) -> is.getItem() == WebDisplays.INSTANCE.itemUpgrade && is.getMetadata() == DefaultUpgrade.LASER_MOUSE.ordinal())) {
|
||||
Log.error("Called laser operation on side %s, but it's missing the laser sensor upgrade", side.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
return scr; //Okay, go for it...
|
||||
}
|
||||
|
||||
public void laserDownMove(BlockSide side, EntityPlayer ply, Vector2i pos, boolean down) {
|
||||
//System.out.println("called laser" + (down ? "Down" : "Move"));
|
||||
if(down)
|
||||
System.out.println("called laserDown");
|
||||
|
||||
Screen scr = getScreenForLaserOp(side, ply);
|
||||
|
||||
if(scr != null) {
|
||||
if(down) {
|
||||
//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());
|
||||
}
|
||||
} else if(getLaserUser(scr) == ply)
|
||||
WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.click(this, side, CMessageScreenUpdate.MOUSE_MOVE, pos), point());
|
||||
}
|
||||
}
|
||||
|
||||
public void laserUp(BlockSide side, EntityPlayer ply) {
|
||||
System.out.println("called laserUp");
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,9 @@ public class ItemUpgrade extends Item implements IUpgrade {
|
|||
|
||||
@Override
|
||||
public boolean onRemove(@Nonnull TileEntityScreen tes, @Nonnull BlockSide screenSide, @Nullable EntityPlayer player, @Nonnull ItemStack is) {
|
||||
if(is.getMetadata() == DefaultUpgrade.LASER_MOUSE.ordinal())
|
||||
tes.clearLaserUser(screenSide);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import net.montoyo.wd.utilities.Log;
|
|||
import net.montoyo.wd.utilities.Vector2i;
|
||||
import net.montoyo.wd.utilities.Vector3i;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Message(messageId = 4, side = Side.CLIENT)
|
||||
|
|
@ -26,16 +27,22 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
public static final int UPDATE_URL = 0;
|
||||
public static final int UPDATE_RESOLUTION = 1;
|
||||
public static final int UPDATE_DELETE = 2;
|
||||
public static final int UPDATE_CLICK = 3;
|
||||
public static final int UPDATE_MOUSE = 3;
|
||||
public static final int UPDATE_TYPE = 4;
|
||||
public static final int UPDATE_UPGRADES = 5;
|
||||
|
||||
public static final int MOUSE_CLICK = 0;
|
||||
public static final int MOUSE_UP = 1;
|
||||
public static final int MOUSE_MOVE = 2;
|
||||
public static final int MOUSE_DOWN = 3;
|
||||
|
||||
private Vector3i pos;
|
||||
private BlockSide side;
|
||||
private int action;
|
||||
private String url;
|
||||
private Vector2i resolution;
|
||||
private Vector2i click;
|
||||
private int mouseEvent;
|
||||
private Vector2i mouse;
|
||||
private String text;
|
||||
private ItemStack[] upgrades;
|
||||
|
||||
|
|
@ -62,12 +69,13 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static CMessageScreenUpdate click(TileEntityScreen tes, BlockSide side, Vector2i pos) {
|
||||
public static CMessageScreenUpdate click(TileEntityScreen tes, BlockSide side, int mouseEvent, @Nullable Vector2i pos) {
|
||||
CMessageScreenUpdate ret = new CMessageScreenUpdate();
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.side = side;
|
||||
ret.action = UPDATE_CLICK;
|
||||
ret.click = pos;
|
||||
ret.action = UPDATE_MOUSE;
|
||||
ret.mouseEvent = mouseEvent;
|
||||
ret.mouse = pos;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -111,9 +119,12 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
if(action == UPDATE_URL)
|
||||
url = ByteBufUtils.readUTF8String(buf);
|
||||
else if(action == UPDATE_CLICK)
|
||||
click = new Vector2i(buf);
|
||||
else if(action == UPDATE_RESOLUTION)
|
||||
else if(action == UPDATE_MOUSE) {
|
||||
mouseEvent = buf.readByte();
|
||||
|
||||
if(mouseEvent != MOUSE_UP)
|
||||
mouse = new Vector2i(buf);
|
||||
} else if(action == UPDATE_RESOLUTION)
|
||||
resolution = new Vector2i(buf);
|
||||
else if(action == UPDATE_TYPE)
|
||||
text = ByteBufUtils.readUTF8String(buf);
|
||||
|
|
@ -133,9 +144,12 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
if(action == UPDATE_URL)
|
||||
ByteBufUtils.writeUTF8String(buf, url);
|
||||
else if(action == UPDATE_CLICK)
|
||||
click.writeTo(buf);
|
||||
else if(action == UPDATE_RESOLUTION)
|
||||
else if(action == UPDATE_MOUSE) {
|
||||
buf.writeByte(mouseEvent);
|
||||
|
||||
if(mouseEvent != MOUSE_UP)
|
||||
mouse.writeTo(buf);
|
||||
} else if(action == UPDATE_RESOLUTION)
|
||||
resolution.writeTo(buf);
|
||||
else if(action == UPDATE_TYPE)
|
||||
ByteBufUtils.writeUTF8String(buf, text);
|
||||
|
|
@ -164,8 +178,8 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
|
|||
|
||||
if(action == UPDATE_URL)
|
||||
tes.setScreenURL(side, url);
|
||||
else if(action == UPDATE_CLICK)
|
||||
tes.click(side, click);
|
||||
else if(action == UPDATE_MOUSE)
|
||||
tes.handleMouseEvent(side, mouseEvent, mouse);
|
||||
else if(action == UPDATE_DELETE)
|
||||
tes.removeScreen(side);
|
||||
else if(action == UPDATE_RESOLUTION)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
public static final int CTRL_SET_RESOLUTION = 5;
|
||||
public static final int CTRL_TYPE = 6;
|
||||
public static final int CTRL_REMOVE_UPGRADE = 7;
|
||||
public static final int CTRL_LASER_DOWN = 8;
|
||||
public static final int CTRL_LASER_MOVE = 9;
|
||||
public static final int CTRL_LASER_UP = 10;
|
||||
|
||||
private int ctrl;
|
||||
private int dim;
|
||||
|
|
@ -42,7 +45,7 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
private EntityPlayerMP player;
|
||||
private int friendRights;
|
||||
private int otherRights;
|
||||
private Vector2i resolution;
|
||||
private Vector2i vec2i;
|
||||
private String text;
|
||||
private BlockPos soundPos;
|
||||
private ItemStack toRemove;
|
||||
|
|
@ -83,14 +86,6 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
otherRights = or;
|
||||
}
|
||||
|
||||
public SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, Vector2i res) {
|
||||
ctrl = CTRL_SET_RESOLUTION;
|
||||
dim = tes.getWorld().provider.getDimension();
|
||||
pos = new Vector3i(tes.getPos());
|
||||
this.side = side;
|
||||
resolution = res;
|
||||
}
|
||||
|
||||
public SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, ItemStack toRem) {
|
||||
ctrl = CTRL_REMOVE_UPGRADE;
|
||||
dim = tes.getWorld().provider.getDimension();
|
||||
|
|
@ -111,6 +106,34 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static SMessageScreenCtrl vec2(TileEntityScreen tes, BlockSide side, int ctrl, Vector2i vec) {
|
||||
if(!isVec2Ctrl(ctrl))
|
||||
throw new RuntimeException("Called SMessageScreenCtrl.vec2() with non-vec2 control message " + ctrl);
|
||||
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = ctrl;
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.dim = tes.getWorld().provider.getDimension();
|
||||
ret.side = side;
|
||||
ret.vec2i = vec;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static SMessageScreenCtrl laserUp(TileEntityScreen tes, BlockSide side) {
|
||||
SMessageScreenCtrl ret = new SMessageScreenCtrl();
|
||||
ret.ctrl = CTRL_LASER_UP;
|
||||
ret.pos = new Vector3i(tes.getPos());
|
||||
ret.dim = tes.getWorld().provider.getDimension();
|
||||
ret.side = side;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static boolean isVec2Ctrl(int msg) {
|
||||
return msg == CTRL_SET_RESOLUTION || msg == CTRL_LASER_DOWN || msg == CTRL_LASER_MOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
ctrl = buf.readByte();
|
||||
|
|
@ -125,8 +148,8 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
else if(ctrl == CTRL_SET_RIGHTS) {
|
||||
friendRights = buf.readByte();
|
||||
otherRights = buf.readByte();
|
||||
} else if(ctrl == CTRL_SET_RESOLUTION)
|
||||
resolution = new Vector2i(buf);
|
||||
} else if(isVec2Ctrl(ctrl))
|
||||
vec2i = new Vector2i(buf);
|
||||
else if(ctrl == CTRL_TYPE) {
|
||||
text = ByteBufUtils.readUTF8String(buf);
|
||||
|
||||
|
|
@ -152,8 +175,8 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
else if(ctrl == CTRL_SET_RIGHTS) {
|
||||
buf.writeByte(friendRights);
|
||||
buf.writeByte(otherRights);
|
||||
} else if(ctrl == CTRL_SET_RESOLUTION)
|
||||
resolution.writeTo(buf);
|
||||
} else if(isVec2Ctrl(ctrl))
|
||||
vec2i.writeTo(buf);
|
||||
else if(ctrl == CTRL_TYPE) {
|
||||
ByteBufUtils.writeUTF8String(buf, text);
|
||||
buf.writeInt(soundPos.getX());
|
||||
|
|
@ -214,14 +237,18 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
|
|||
tes.setRights(player, side, fr, or);
|
||||
} else if(ctrl == CTRL_SET_RESOLUTION) {
|
||||
checkPermission(tes, ScreenRights.CHANGE_RESOLUTION);
|
||||
tes.setResolution(side, resolution);
|
||||
tes.setResolution(side, vec2i);
|
||||
} else if(ctrl == CTRL_TYPE) {
|
||||
checkPermission(tes, ScreenRights.CLICK);
|
||||
tes.type(side, text, soundPos);
|
||||
} else if(ctrl == CTRL_REMOVE_UPGRADE) {
|
||||
checkPermission(tes, ScreenRights.MANAGE_UPGRADES);
|
||||
tes.removeUpgrade(side, toRemove, player);
|
||||
} else
|
||||
} else if(ctrl == CTRL_LASER_DOWN || ctrl == CTRL_LASER_MOVE)
|
||||
tes.laserDownMove(side, player, vec2i, ctrl == CTRL_LASER_DOWN);
|
||||
else if(ctrl == CTRL_LASER_UP)
|
||||
tes.laserUp(side, player);
|
||||
else
|
||||
Log.info("SMessageScreenCtrl: TODO"); //TODO: other ctrl messages
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user