new config option, fix a clicking issues with clicking on the display

This commit is contained in:
GiantLuigi4 2023-06-02 21:50:46 -04:00
parent 246eb45d90
commit 5d3426706f
7 changed files with 42 additions and 12 deletions

View File

@ -6,6 +6,7 @@ package net.montoyo.wd.block;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
@ -181,6 +182,10 @@ public class BlockPeripheral extends WDBlockContainer {
}
}
public static PacketDistributor.TargetPoint point(Player exclude, Level world, BlockPos bp) {
return new PacketDistributor.TargetPoint((ServerPlayer) exclude, bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension());
}
public static PacketDistributor.TargetPoint point(Level world, BlockPos bp) {
return new PacketDistributor.TargetPoint(bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension());
}

View File

@ -39,6 +39,7 @@ import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.data.SetURLData;
import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.init.BlockInit;
import net.montoyo.wd.item.ItemLaserPointer;
import net.montoyo.wd.item.WDItem;
import net.montoyo.wd.utilities.*;
import org.jetbrains.annotations.NotNull;
@ -121,9 +122,16 @@ public class BlockScreen extends BaseEntityBlock {
@Override
public InteractionResult use(BlockState state, Level world, BlockPos position, Player player, InteractionHand hand, BlockHitResult hit) {
ItemStack heldItem = player.getItemInHand(hand);
boolean isUpgrade = false;
if (heldItem.isEmpty())
heldItem = null; //Easier to work with
else if (!(heldItem.getItem() instanceof IUpgrade))
else if (!(isUpgrade = heldItem.getItem() instanceof IUpgrade))
return InteractionResult.FAIL;
else if (heldItem.getItem() instanceof ItemLaserPointer)
return InteractionResult.FAIL; // laser pointer already handles stuff
// handling the off hand leads to double clicking
if (!isUpgrade && hand == InteractionHand.OFF_HAND)
return InteractionResult.FAIL;
if (world.isClientSide)
@ -151,7 +159,7 @@ public class BlockScreen extends BaseEntityBlock {
if (!te.hasUpgrade(side, heldItem)) {
if ((scr.rightsFor(player) & ScreenRights.MANAGE_UPGRADES) == 0) {
Util.toast(player, "restrictions");
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}
if (te.addUpgrade(side, heldItem, player, false)) {
@ -164,12 +172,12 @@ public class BlockScreen extends BaseEntityBlock {
} else
Util.toast(player, "upgradeError");
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}
} else {
if ((scr.rightsFor(player) & ScreenRights.INTERACT) == 0) {
Util.toast(player, "restrictions");
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}
Vector2i tmp = new Vector2i();
@ -180,7 +188,7 @@ public class BlockScreen extends BaseEntityBlock {
if (hit2pixels(side, hit.getBlockPos(), new Vector3i(hit.getBlockPos()), scr, hitX, hitY, hitZ, tmp))
te.click(side, tmp);
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}
}
// else if(sneaking) {

View File

@ -70,6 +70,7 @@ import net.montoyo.wd.init.TileInit;
import net.montoyo.wd.item.WDItem;
import net.montoyo.wd.miniserv.client.Client;
import net.montoyo.wd.net.WDNetworkRegistry;
import net.montoyo.wd.net.client_bound.S2CMessageScreenUpdate;
import net.montoyo.wd.net.server_bound.C2SMessageScreenCtrl;
import net.montoyo.wd.net.server_bound.C2SMinepadUrl;
import net.montoyo.wd.utilities.*;
@ -648,9 +649,9 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
TileEntityScreen.Screen scr = te.getScreen(side);
if(scr.browser != null) {
float hitX = ((float) result.getLocation().x) - (float) bpos.getX();
float hitY = ((float) result.getLocation().y) - (float) bpos.getY();
float hitZ = ((float) result.getLocation().z) - (float) bpos.getZ();
float hitX = ((float) result.getLocation().x) - (float) pos.x;
float hitY = ((float) result.getLocation().y) - (float) pos.y;
float hitZ = ((float) result.getLocation().z) - (float) pos.z;
Vector2i tmp = new Vector2i();
if(BlockScreen.hit2pixels(side, bpos, new Vector3i(result.getBlockPos()), scr, hitX, hitY, hitZ, tmp)) {
@ -717,8 +718,10 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
if(t - lastPointPacket >= 100) {
lastPointPacket = t;
if (Minecraft.getInstance().player.isShiftKeyDown()) {
tes.handleMouseEvent(side, S2CMessageScreenUpdate.MOUSE_CLICK, hit);
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserDown(tes, side, hit));
} else {
tes.handleMouseEvent(side, S2CMessageScreenUpdate.MOUSE_MOVE, hit);
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserMove(tes, side, hit));
}
}

View File

@ -17,6 +17,7 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.client.ClientProxy;
import net.montoyo.wd.config.ClientConfig;
import net.montoyo.wd.item.ItemMinePad2;
@OnlyIn(Dist.CLIENT)
@ -58,7 +59,7 @@ public final class MinePadRenderer implements IItemRenderer {
// by default, the player holds the device off to the side
// if they are crouching, they hold it infront of them
// however, if they are holding two at once, then it once again should just be held off to the side
boolean sideHold = !Minecraft.getInstance().player.isShiftKeyDown();
boolean sideHold = Minecraft.getInstance().player.isShiftKeyDown() != ClientConfig.sidePad;
if (
(handSideSign < 0 && Minecraft.getInstance().player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof ItemMinePad2) ||
(handSideSign > 0 && Minecraft.getInstance().player.getItemInHand(InteractionHand.OFF_HAND).getItem() instanceof ItemMinePad2)

View File

@ -46,6 +46,15 @@ public class ClientConfig {
@Default(valueI = 720)
public static int padResolution = 720;
@Name("side_pad")
@Comment({
"When this is true, the minePad is placed off to the side of the screen when held, so it's visible but doesn't take up too much of the screen",
"When this is false, the minePad is placed closer to the center of the screen, allow it to be seen better, but taking up more of your view",
})
@Translation("config.webdisplays.side_pad")
@Default(valueBoolean = true)
public static boolean sidePad = true;
@Comment({
"AutoVolume makes audio fade off based on distance",
"Currently, this seems to not work"

View File

@ -1077,11 +1077,11 @@ public class TileEntityScreen extends BlockEntity {
//Try to acquire laser lock
// if (getLaserUser(scr) == null) {
scr.laserUser = ply;
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_CLICK, pos));
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(ply, level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_CLICK, pos));
// }
} else
// if (getLaserUser(scr) == ply)
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_MOVE, pos));
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(ply, level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_MOVE, pos));
}
}
@ -1091,7 +1091,7 @@ public class TileEntityScreen extends BlockEntity {
if (scr != null) {
if (getLaserUser(scr) == ply) {
scr.laserUser = null;
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_UP, null));
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(ply, level, getBlockPos())), S2CMessageScreenUpdate.click(this, side, S2CMessageScreenUpdate.MOUSE_UP, null));
}
}
}

View File

@ -17,6 +17,10 @@ public class WDNetworkRegistry {
(s) -> s.equals(networkingVersion)
);
public static void sendToNearExcept() {
}
// if an old packet needs to be ported, refer to the following link
// https://github.com/Mysticpasta1/webdisplays/tree/ff55cbf1b27773c15f44f17ad3364da3a16b6ed9/src/main/java/net/montoyo/wd/net
// however, I think I got all the essentials