* last push for tonight...
This commit is contained in:
parent
7184286be7
commit
e40b919a49
|
|
@ -151,32 +151,9 @@ public class BlockScreen extends WDBlockContainer {
|
|||
return true;
|
||||
}
|
||||
|
||||
if(side.right.x < 0)
|
||||
hitX -= 1.f;
|
||||
|
||||
if(side.right.z < 0 || side == BlockSide.TOP || side == BlockSide.BOTTOM)
|
||||
hitZ -= 1.f;
|
||||
|
||||
Vector3f rel = new Vector3f(bpos.getX(), bpos.getY(), bpos.getZ());
|
||||
rel.sub((float) pos.x, (float) pos.y, (float) pos.z);
|
||||
rel.add(hitX, hitY, hitZ);
|
||||
|
||||
float cx = rel.dot(side.right.toFloat()) - 2.f / 16.f;
|
||||
float cy = rel.dot(side.up.toFloat()) - 2.f / 16.f;
|
||||
float sw = ((float) scr.size.x) - 4.f / 16.f;
|
||||
float sh = ((float) scr.size.y) - 4.f / 16.f;
|
||||
|
||||
cx /= sw;
|
||||
cy /= sh;
|
||||
|
||||
if(cx >= 0.f && cx <= 1.0 && cy >= 0.f && cy <= 1.f) {
|
||||
if(side != BlockSide.BOTTOM)
|
||||
cy = 1.f - cy;
|
||||
|
||||
cx *= (float) scr.resolution.x;
|
||||
cy *= (float) scr.resolution.y;
|
||||
te.click(side, new Vector2i((int) cx, (int) cy));
|
||||
}
|
||||
Vector2i tmp = new Vector2i();
|
||||
if(hit2pixels(side, bpos, pos, scr, hitX, hitY, hitZ, tmp))
|
||||
te.click(side, tmp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -211,6 +188,39 @@ public class BlockScreen extends WDBlockContainer {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean hit2pixels(BlockSide side, BlockPos bpos, Vector3i pos, TileEntityScreen.Screen scr, float hitX, float hitY, float hitZ, Vector2i dst) {
|
||||
if(side.right.x < 0)
|
||||
hitX -= 1.f;
|
||||
|
||||
if(side.right.z < 0 || side == BlockSide.TOP || side == BlockSide.BOTTOM)
|
||||
hitZ -= 1.f;
|
||||
|
||||
Vector3f rel = new Vector3f(bpos.getX(), bpos.getY(), bpos.getZ());
|
||||
rel.sub((float) pos.x, (float) pos.y, (float) pos.z);
|
||||
rel.add(hitX, hitY, hitZ);
|
||||
|
||||
float cx = rel.dot(side.right.toFloat()) - 2.f / 16.f;
|
||||
float cy = rel.dot(side.up.toFloat()) - 2.f / 16.f;
|
||||
float sw = ((float) scr.size.x) - 4.f / 16.f;
|
||||
float sh = ((float) scr.size.y) - 4.f / 16.f;
|
||||
|
||||
cx /= sw;
|
||||
cy /= sh;
|
||||
|
||||
if(cx >= 0.f && cx <= 1.0 && cy >= 0.f && cy <= 1.f) {
|
||||
if(side != BlockSide.BOTTOM)
|
||||
cy = 1.f - cy;
|
||||
|
||||
cx *= (float) scr.resolution.x;
|
||||
cy *= (float) scr.resolution.y;
|
||||
dst.x = (int) cx;
|
||||
dst.y = (int) cy;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.EnumHandSide;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
|
@ -34,6 +35,7 @@ import net.montoyo.mcef.api.IDisplayHandler;
|
|||
import net.montoyo.mcef.api.MCEFApi;
|
||||
import net.montoyo.wd.SharedProxy;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.block.BlockScreen;
|
||||
import net.montoyo.wd.client.gui.GuiMinePad;
|
||||
import net.montoyo.wd.client.gui.GuiScreenConfig;
|
||||
import net.montoyo.wd.client.gui.GuiSetURL2;
|
||||
|
|
@ -45,8 +47,7 @@ import net.montoyo.wd.data.GuiData;
|
|||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.net.SMessagePadCtrl;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import scala.tools.nsc.doc.model.Def;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -315,6 +316,34 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If laser is on, raycast
|
||||
if(laserPointerRenderer.isOn) {
|
||||
RayTraceResult result = raycast(64.0); //TODO: Make that distance configurable
|
||||
|
||||
if(result != null) {
|
||||
BlockPos bpos = result.getBlockPos();
|
||||
|
||||
if(result.typeOfHit == RayTraceResult.Type.BLOCK && mc.world.getBlockState(bpos).getBlock() == WebDisplays.INSTANCE.blockScreen) {
|
||||
Vector3i pos = new Vector3i(result.getBlockPos());
|
||||
BlockSide side = BlockSide.values()[result.sideHit.ordinal()];
|
||||
|
||||
Multiblock.findOrigin(mc.world, pos, side, null);
|
||||
TileEntityScreen te = (TileEntityScreen) mc.world.getTileEntity(pos.toBlock());
|
||||
|
||||
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();
|
||||
|
||||
if(BlockScreen.hit2pixels(side, bpos, pos, te.getScreen(side), hitX, hitY, hitZ, tmp))
|
||||
System.out.println("At " + tmp.x + ", " + tmp.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -340,16 +369,22 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi
|
|||
|
||||
@SubscribeEvent
|
||||
public void onMouseButton(MouseEvent ev) {
|
||||
if(mc.player != null && mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() == WebDisplays.INSTANCE.itemLaserPointer) {
|
||||
if(ev.getButton() == 1) {
|
||||
//Right button
|
||||
laserPointerRenderer.isOn = ev.isButtonstate();
|
||||
}
|
||||
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 RayTraceResult raycast(double dist) {
|
||||
Vec3d start = mc.player.getPositionEyes(1.0f);
|
||||
Vec3d lookVec = mc.player.getLook(1.0f);
|
||||
Vec3d end = start.addVector(lookVec.x * dist, lookVec.y * dist, lookVec.z * dist);
|
||||
|
||||
return mc.world.rayTraceBlocks(start, end, true, true, false);
|
||||
}
|
||||
|
||||
private void updateInventory(NonNullList<ItemStack> inv, ItemStack heldStack, int cnt) {
|
||||
for(int i = 0; i < cnt; i++) {
|
||||
ItemStack item = inv.get(i);
|
||||
|
|
|
|||
|
|
@ -121,12 +121,4 @@ public final class LaserPointerRenderer implements IItemRenderer {
|
|||
GlStateManager.enableTexture2D(); //Fix for shitty minecraft fire
|
||||
}
|
||||
|
||||
private void raycast(float ptt, double dist) {
|
||||
Vec3d start = mc.player.getPositionEyes(ptt);
|
||||
Vec3d lookVec = mc.player.getLook(ptt);
|
||||
Vec3d end = start.addVector(lookVec.x * dist, lookVec.y * dist, lookVec.z * dist);
|
||||
|
||||
RayTraceResult rtr = mc.world.rayTraceBlocks(start, end, true, true, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package net.montoyo.wd.entity;
|
|||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
|
@ -615,7 +616,6 @@ public class TileEntityScreen extends TileEntity {
|
|||
return true;
|
||||
}
|
||||
|
||||
//Uses the default item stack comparing (same Item & metadata)
|
||||
public boolean hasUpgrade(BlockSide side, ItemStack is) {
|
||||
Screen scr = getScreen(side);
|
||||
if(scr == null)
|
||||
|
|
@ -628,6 +628,15 @@ public class TileEntityScreen extends TileEntity {
|
|||
return scr.upgrades.stream().anyMatch((otherStack) -> itemAsUpgrade.isSameUpgrade(is, otherStack));
|
||||
}
|
||||
|
||||
//Special version of hasUpgrade(BlockSide, ItemStack) that matches only the item and the meta
|
||||
public boolean hasUpgrade(BlockSide side, Item item, int meta) {
|
||||
Screen scr = getScreen(side);
|
||||
if(scr == null)
|
||||
return false;
|
||||
|
||||
return scr.upgrades.stream().anyMatch((otherStack) -> otherStack.getItem() == item && otherStack.getMetadata() == meta);
|
||||
}
|
||||
|
||||
public void removeUpgrade(BlockSide side, ItemStack is, @Nullable EntityPlayer player) {
|
||||
if(world.isRemote)
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user