right clicking function active

This commit is contained in:
Mysticpasta1 2023-03-09 03:26:22 -06:00
parent f4dbd00f9d
commit 3b5ad2112f
10 changed files with 340 additions and 291 deletions

View File

@ -75,7 +75,7 @@ dependencies {
minecraft 'net.minecraftforge:forge:1.19.2-43.2.6'
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
implementation fg.deobf("com.github.Mysticpasta1:mcef-forge:d45957d9f6")
implementation fg.deobf("com.github.Mysticpasta1:mcef-forge:f50060a90a")
implementation fg.deobf("curse.maven:cloth_config_forge-348521:3972423")
implementation fg.deobf("curse.maven:SU-370704:4410614")
implementation fg.deobf("curse.maven:spark-361579:4381167")

View File

@ -4,7 +4,11 @@
package net.montoyo.wd.block;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.Input;
import net.minecraft.client.player.KeyboardInput;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
@ -31,7 +35,9 @@ import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.client.renderers.ScreenRenderer;
import net.montoyo.wd.config.ModConfig;
import net.montoyo.wd.core.DefaultUpgrade;
import net.montoyo.wd.core.IUpgrade;
@ -39,18 +45,21 @@ 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.init.ItemInit;
import net.montoyo.wd.item.WDItem;
import net.montoyo.wd.utilities.*;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;
public class BlockScreen extends BaseEntityBlock {
public static final BooleanProperty hasTE = BooleanProperty.create("haste");
public static final BooleanProperty emitting = BooleanProperty.create("emitting");
private static final Property<?>[] properties = new Property<?>[] { hasTE, emitting };
private static final Property<?>[] properties = new Property<?>[]{hasTE, emitting};
public static final DirectionProperty FACING = BlockStateProperties.FACING;
private static final int BAR_BOT = 1;
@ -118,15 +127,15 @@ public class BlockScreen extends BaseEntityBlock {
public int getMetaFromState(BlockState state) {
int ret = 0;
if(state.getValue(hasTE))
if (state.getValue(hasTE))
ret |= 1;
if(state.getValue(emitting))
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?
@ -142,65 +151,71 @@ public class BlockScreen extends BaseEntityBlock {
);
}
}
super.onRemove(p_60515_, p_60516_, p_60517_, p_60518_, p_60519_);
}
@Override
public InteractionResult use(BlockState state, Level world, BlockPos position, Player player, InteractionHand hand, BlockHitResult hit) {
ItemStack heldItem = player.getItemInHand(hand);
if(heldItem.isEmpty())
if (heldItem.isEmpty())
heldItem = null; //Easier to work with
else if(!(heldItem.getItem() instanceof IUpgrade))
else if (!(heldItem.getItem() instanceof IUpgrade))
return InteractionResult.FAIL;
if(world.isClientSide)
if (world.isClientSide)
return InteractionResult.FAIL;
boolean sneaking = player.isShiftKeyDown();
Vector3i pos = new Vector3i(position);
BlockSide side = BlockSide.values()[hit.getDirection().ordinal()];
Multiblock.findOrigin(world, pos, side, null);
TileEntityScreen te = (TileEntityScreen) world.getBlockEntity(pos.toBlock());
if(te != null && te.getScreen(side) != null) {
if (te != null && te.getScreen(side) != null) {
TileEntityScreen.Screen scr = te.getScreen(side);
if(sneaking) { //Set URL
if((scr.rightsFor(player) & ScreenRights.CHANGE_URL) == 0)
Util.toast(player, "restrictions");
else
(new SetURLData(pos, scr.side, scr.url)).sendTo((ServerPlayer) player);
return InteractionResult.SUCCESS;
} else if(heldItem != null && !te.hasUpgrade(side, heldItem)) { //Add upgrade
if((scr.rightsFor(player) & ScreenRights.MANAGE_UPGRADES) == 0) {
Util.toast(player, "restrictions");
return InteractionResult.SUCCESS;
}
if(te.addUpgrade(side, heldItem, player, false)) {
if(!player.isCreative())
heldItem.shrink(1);
Util.toast(player, ChatFormatting.AQUA, "upgradeOk");
if(player instanceof ServerPlayer)
WebDisplays.INSTANCE.criterionUpgradeScreen.trigger(((ServerPlayer) player).getAdvancements());
} else
Util.toast(player, "upgradeError");
return InteractionResult.SUCCESS;
} else { //Click
if((scr.rightsFor(player) & ScreenRights.CLICK) == 0) {
if (sneaking) { //Right Click
if ((scr.rightsFor(player) & ScreenRights.CLICK) == 0) {
Util.toast(player, "restrictions");
return InteractionResult.SUCCESS;
}
Vector2i tmp = new Vector2i();
if(hit2pixels(side, hit.getBlockPos(), pos, scr, (float) hit.getLocation().x, (float) hit.getLocation().y, (float) hit.getLocation().z, tmp))
if (hit2pixels(side, hit.getBlockPos(), pos, scr, (float) hit.getLocation().x, (float) hit.getLocation().y, (float) hit.getLocation().z, tmp))
te.click(side, tmp);
return InteractionResult.SUCCESS;
} else if (heldItem != null) {
if (!te.hasUpgrade(side, heldItem)) {
if ((scr.rightsFor(player) & ScreenRights.MANAGE_UPGRADES) == 0) {
Util.toast(player, "restrictions");
return InteractionResult.SUCCESS;
}
if (te.addUpgrade(side, heldItem, player, false)) {
if (!player.isCreative())
heldItem.shrink(1);
Util.toast(player, ChatFormatting.AQUA, "upgradeOk");
if (player instanceof ServerPlayer)
WebDisplays.INSTANCE.criterionUpgradeScreen.trigger(((ServerPlayer) player).getAdvancements());
} else
Util.toast(player, "upgradeError");
return InteractionResult.SUCCESS;
}
} else {
if ((scr.rightsFor(player) & ScreenRights.CLICK) == 0) {
Util.toast(player, "restrictions");
return InteractionResult.SUCCESS;
}
Vector2i tmp = new Vector2i();
if (hit2pixels(side, hit.getBlockPos(), pos, scr, (float) hit.getLocation().x, (float) hit.getLocation().y, (float) hit.getLocation().z, tmp))
te.click(side, tmp);
return InteractionResult.SUCCESS;
}
}
@ -209,209 +224,214 @@ public class BlockScreen extends BaseEntityBlock {
// return InteractionResult.SUCCESS;
// }
Vector2i size = Multiblock.measure(world, pos, side);
if(size.x < 2 || size.y < 2) {
Util.toast(player, "tooSmall");
Vector2i size = Multiblock.measure(world, pos, side);
if (size.x < 2 || size.y < 2) {
Util.toast(player, "tooSmall");
return InteractionResult.SUCCESS;
}
if (size.x > WebDisplays.INSTANCE.maxScreenX || size.y > WebDisplays.INSTANCE.maxScreenY) {
Util.toast(player, "tooBig", WebDisplays.INSTANCE.maxScreenX, WebDisplays.INSTANCE.maxScreenY);
return InteractionResult.SUCCESS;
}
Vector3i err = Multiblock.check(world, pos, size, side);
if (err != null) {
Util.toast(player, "invalid", err.toString());
return InteractionResult.SUCCESS;
}
boolean created = false;
Log.info("Player %s (UUID %s) created a screen at %s of size %dx%d", player.getName(), player.getGameProfile().getId().toString(), pos.toString(), size.x, size.y);
if (te == null) {
BlockPos bp = pos.toBlock();
world.setBlockAndUpdate(bp, world.getBlockState(bp).setValue(hasTE, true));
te = (TileEntityScreen) world.getBlockEntity(bp);
created = true;
}
te.addScreen(side, size, null, player, !created);
return InteractionResult.SUCCESS;
}
if(size.x > WebDisplays.INSTANCE.maxScreenX || size.y > WebDisplays.INSTANCE.maxScreenY) {
Util.toast(player, "tooBig", WebDisplays.INSTANCE.maxScreenX, WebDisplays.INSTANCE.maxScreenY);
return InteractionResult.SUCCESS;
}
@Override
public void neighborChanged (BlockState state, Level world, BlockPos pos, Block block, BlockPos source,
boolean isMoving){
if (block != this && !world.isClientSide && !state.getValue(emitting)) {
for (BlockSide side : BlockSide.values()) {
Vector3i vec = new Vector3i(pos);
Multiblock.findOrigin(world, vec, side, null);
Vector3i err = Multiblock.check(world, pos, size, side);
if(err != null) {
Util.toast(player, "invalid", err.toString());
return InteractionResult.SUCCESS;
}
boolean created = false;
Log.info("Player %s (UUID %s) created a screen at %s of size %dx%d", player.getName(), player.getGameProfile().getId().toString(), pos.toString(), size.x, size.y);
if(te == null) {
BlockPos bp = pos.toBlock();
world.setBlockAndUpdate(bp, world.getBlockState(bp).setValue(hasTE, true));
te = (TileEntityScreen) world.getBlockEntity(bp);
created = true;
}
te.addScreen(side, size, null, player, !created);
return InteractionResult.SUCCESS;
}
@Override
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos source, boolean isMoving) {
if(block != this && !world.isClientSide && !state.getValue(emitting)) {
for(BlockSide side: BlockSide.values()) {
Vector3i vec = new Vector3i(pos);
Multiblock.findOrigin(world, vec, side, null);
TileEntityScreen tes = (TileEntityScreen) world.getBlockEntity(vec.toBlock());
if(tes != null && tes.hasUpgrade(side, DefaultUpgrade.REDINPUT)) {
Direction facing = Direction.from2DDataValue(side.reverse().ordinal()); //Opposite face
vec.sub(pos.getX(), pos.getY(), pos.getZ()).neg();
tes.updateJSRedstone(side, new Vector2i(vec.dot(side.right), vec.dot(side.up)), world.getSignal(pos, facing));
TileEntityScreen tes = (TileEntityScreen) world.getBlockEntity(vec.toBlock());
if (tes != null && tes.hasUpgrade(side, DefaultUpgrade.REDINPUT)) {
Direction facing = Direction.from2DDataValue(side.reverse().ordinal()); //Opposite face
vec.sub(pos.getX(), pos.getY(), pos.getZ()).neg();
tes.updateJSRedstone(side, new Vector2i(vec.dot(side.right), vec.dot(side.up)), world.getSignal(pos, facing));
}
}
}
}
}
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;
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;
if (side.right.z < 0 || side == BlockSide.TOP || side == BlockSide.BOTTOM)
hitZ -= 1.f;
Vector3f rel = new Vector3f(pos.toBlock().getX(), pos.toBlock().getY(), pos.toBlock().getZ());
rel.sub(hitX, hitY, hitZ);
Vector3f rel = new Vector3f(hitX, hitY, hitZ);
rel.sub(pos.toBlock().getX(), pos.toBlock().getY(), pos.toBlock().getZ());
float cx = Math.abs(rel.dot(side.right.toFloat()) - 2.f / 16.f);
float cy = Math.abs(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;
float cx = Math.abs(rel.dot(side.right.toFloat()) - 2.f / 16.f);
float cy = Math.abs(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;
cx /= sw;
cy /= sh;
cx = cx - 0.05f;
cy = cy - 0.05f;
cx = cx - 0.05f;
cy = cy - 0.05f;
if(cx >= 0 && cx <= 1 && cy >= 0 && cy <= 1) {
if(side != BlockSide.BOTTOM)
cy = 1.f - cy;
if (cx >= 0 && cx <= 1 && cy >= 0 && cy <= 1) {
if (side != BlockSide.BOTTOM)
cy = 1.f - cy;
switch(scr.rotation) {
case ROT_90:
cy = 1.0f - cy;
break;
switch (scr.rotation) {
case ROT_90:
cy = 1.0f - cy;
break;
case ROT_180:
cx = 1.0f - cx;
cy = 1.0f - cy;
break;
case ROT_180:
cx = 1.0f - cx;
cy = 1.0f - cy;
break;
case ROT_270:
cx = 1.0f - cx;
break;
case ROT_270:
cx = 1.0f - cx;
break;
default:
break;
default:
break;
}
cx *= (float) scr.resolution.x;
cy *= (float) scr.resolution.y;
if (scr.rotation.isVertical) {
dst.x = (int) cy;
dst.y = (int) cx;
} else {
dst.x = (int) cx;
dst.y = (int) cy;
}
return true;
}
cx *= (float) scr.resolution.x;
cy *= (float) scr.resolution.y;
if(scr.rotation.isVertical) {
dst.x = (int) cy;
dst.y = (int) cx;
} else {
dst.x = (int) cx;
dst.y = (int) cy;
}
return true;
return false;
}
return false;
}
@org.jetbrains.annotations.Nullable
@Override
public BlockEntity newBlockEntity (BlockPos pos, BlockState state){
int meta = getMetaFromState(state);
@org.jetbrains.annotations.Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
int meta = getMetaFromState(state);
if ((meta & 1) == 0)
return null;
if((meta & 1) == 0)
return null;
return ((meta & 1) == 0) ? null : new TileEntityScreen(pos, state);
}
/************************************************* DESTRUCTION HANDLING *************************************************/
private void onDestroy(Level world, BlockPos pos, Player ply) {
if(!world.isClientSide) {
Vector3i bp = new Vector3i(pos);
Multiblock.BlockOverride override = new Multiblock.BlockOverride(bp, Multiblock.OverrideAction.SIMULATE);
for(BlockSide bs: BlockSide.values())
destroySide(world, bp.clone(), bs, override, ply);
return ((meta & 1) == 0) ? null : new TileEntityScreen(pos, state);
}
}
private void destroySide(Level world, Vector3i pos, BlockSide side, Multiblock.BlockOverride override, Player source) {
Multiblock.findOrigin(world, pos, side, override);
BlockPos bp = pos.toBlock();
BlockEntity te = world.getBlockEntity(bp);
/************************************************* DESTRUCTION HANDLING *************************************************/
if(te != null && te instanceof TileEntityScreen) {
((TileEntityScreen) te).onDestroy(source);
world.setBlock(bp, world.getBlockState(bp).setValue(hasTE, false), Block.UPDATE_ALL_IMMEDIATE); //Destroy tile entity.
}
}
private void onDestroy (Level world, BlockPos pos, Player ply){
if (!world.isClientSide) {
Vector3i bp = new Vector3i(pos);
Multiblock.BlockOverride override = new Multiblock.BlockOverride(bp, Multiblock.OverrideAction.SIMULATE);
@Override
public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
onDestroy(level, pos, player);
return super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid);
}
@Override
public void setPlacedBy(Level world, @NotNull BlockPos pos, @NotNull BlockState state, @org.jetbrains.annotations.Nullable LivingEntity whoDidThisShit, @NotNull ItemStack stack) {
if(world.isClientSide)
return;
Multiblock.BlockOverride override = new Multiblock.BlockOverride(new Vector3i(pos), Multiblock.OverrideAction.IGNORE);
Vector3i[] neighbors = new Vector3i[6];
neighbors[0] = new Vector3i(pos.getX() + 1, pos.getY(), pos.getZ());
neighbors[1] = new Vector3i(pos.getX() - 1, pos.getY(), pos.getZ());
neighbors[2] = new Vector3i(pos.getX(), pos.getY() + 1, pos.getZ());
neighbors[3] = new Vector3i(pos.getX(), pos.getY() - 1, pos.getZ());
neighbors[4] = new Vector3i(pos.getX(), pos.getY(), pos.getZ() + 1);
neighbors[5] = new Vector3i(pos.getX(), pos.getY(), pos.getZ() - 1);
for(Vector3i neighbor: neighbors) {
if(world.getBlockState(neighbor.toBlock()).getBlock() instanceof BlockScreen) {
for(BlockSide bs: BlockSide.values())
destroySide(world, neighbor.clone(), bs, override, (whoDidThisShit instanceof Player) ? ((Player) whoDidThisShit) : null);
for (BlockSide bs : BlockSide.values())
destroySide(world, bp.clone(), bs, override, ply);
}
}
}
@Override
public @NotNull PushReaction getPistonPushReaction(BlockState state) {
return PushReaction.IGNORE;
}
private void destroySide (Level world, Vector3i pos, BlockSide side, Multiblock.BlockOverride override, Player
source){
Multiblock.findOrigin(world, pos, side, override);
BlockPos bp = pos.toBlock();
BlockEntity te = world.getBlockEntity(bp);
@Override
public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
return state.getValue(emitting) ? 15 : 0;
}
if (te != null && te instanceof TileEntityScreen) {
((TileEntityScreen) te).onDestroy(source);
world.setBlock(bp, world.getBlockState(bp).setValue(hasTE, false), Block.UPDATE_ALL_IMMEDIATE); //Destroy tile entity.
}
}
@Override
public boolean isSignalSource(BlockState state) {
return state.getValue(emitting);
}
@Override
public boolean onDestroyedByPlayer (BlockState state, Level level, BlockPos pos, Player player,
boolean willHarvest, FluidState fluid){
onDestroy(level, pos, player);
return super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid);
}
@Override
public void setPlacedBy (Level world, @NotNull BlockPos pos, @NotNull BlockState
state, @org.jetbrains.annotations.Nullable LivingEntity whoDidThisShit, @NotNull ItemStack stack){
if (world.isClientSide)
return;
Multiblock.BlockOverride override = new Multiblock.BlockOverride(new Vector3i(pos), Multiblock.OverrideAction.IGNORE);
Vector3i[] neighbors = new Vector3i[6];
neighbors[0] = new Vector3i(pos.getX() + 1, pos.getY(), pos.getZ());
neighbors[1] = new Vector3i(pos.getX() - 1, pos.getY(), pos.getZ());
neighbors[2] = new Vector3i(pos.getX(), pos.getY() + 1, pos.getZ());
neighbors[3] = new Vector3i(pos.getX(), pos.getY() - 1, pos.getZ());
neighbors[4] = new Vector3i(pos.getX(), pos.getY(), pos.getZ() + 1);
neighbors[5] = new Vector3i(pos.getX(), pos.getY(), pos.getZ() - 1);
for (Vector3i neighbor : neighbors) {
if (world.getBlockState(neighbor.toBlock()).getBlock() instanceof BlockScreen) {
for (BlockSide bs : BlockSide.values())
destroySide(world, neighbor.clone(), bs, override, (whoDidThisShit instanceof Player) ? ((Player) whoDidThisShit) : null);
}
}
}
@Override
public @NotNull PushReaction getPistonPushReaction (BlockState state){
return PushReaction.IGNORE;
}
@Override
public int getSignal (BlockState state, BlockGetter level, BlockPos pos, Direction direction){
return state.getValue(emitting) ? 15 : 0;
}
@Override
public boolean isSignalSource (BlockState state){
return state.getValue(emitting);
}
// @Override //TODO: Add this
// protected BlockItem createItemBlock() {
// return new ItemBlockScreen(this);
// }
private static class ItemBlockScreen extends BlockItem implements WDItem {
private static class ItemBlockScreen extends BlockItem implements WDItem {
public ItemBlockScreen(BlockScreen screen) {
super(screen, new Properties());
}
public ItemBlockScreen(BlockScreen screen) {
super(screen, new Properties());
}
@Nullable
@Override
public String getWikiName(@Nonnull ItemStack is) {
return is.getItem().getName(is).getString();
}
@Nullable
@Override
public String getWikiName(@Nonnull ItemStack is) {
return is.getItem().getName(is).getString();
}
}
}

View File

@ -568,8 +568,8 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
if(tes.isLoaded()) {
if(dist2 > WebDisplays.INSTANCE.unloadDistance2)
tes.unload();
//else if(WebDisplays.INSTANCE.enableSoundDistance)
// tes.updateTrackDistance(dist2, SoundSystemConfig.getMasterGain());
else if(WebDisplays.INSTANCE.enableSoundDistance)
tes.updateTrackDistance(dist2, 80); //ToDo find master volume
} else if(dist2 <= WebDisplays.INSTANCE.loadDistance2)
tes.load();
}
@ -602,12 +602,9 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
}
//Laser pointer raycast
boolean raycastHit = false;
if(mc.player != null && mc.level != null && ItemInit.itemLaserPointer.isPresent() && mc.player.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.itemLaserPointer.get())
&& mc.options.keyUse.isDown()
&& (mc.hitResult == null || mc.hitResult.getType() != HitResult.Type.BLOCK)) {
laserPointerRenderer.isOn = true;
&& (mc.hitResult == null || mc.hitResult.getType() == HitResult.Type.BLOCK)) {
BlockHitResult result = raycast(64.0); //TODO: Make that distance configurable
BlockPos bpos = result.getBlockPos();
@ -631,24 +628,21 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
if(BlockScreen.hit2pixels(side, bpos, pos, scr, hitX, hitY, hitZ, tmp)) {
laserClick(te, side, scr, tmp);
raycastHit = true;
}
}
}
}
} else
laserPointerRenderer.isOn = false;
if(!raycastHit)
} else {
deselectScreen();
//Handle JS queries
jsDispatcher.handleQueries();
//Handle JS queries
jsDispatcher.handleQueries();
//Miniserv
if(msClientStarted && mc.player == null) {
msClientStarted = false;
Client.getInstance().stop();
//Miniserv
if (msClientStarted && mc.player == null) {
msClientStarted = false;
Client.getInstance().stop();
}
}
}
}

View File

@ -7,16 +7,13 @@ package net.montoyo.wd.client.renderers;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
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.*;
@OnlyIn(Dist.CLIENT)
public final class LaserPointerRenderer implements IItemRenderer {
@ -24,17 +21,8 @@ public final class LaserPointerRenderer implements IItemRenderer {
private static final float PI = (float) Math.PI;
private final Tesselator t = Tesselator.getInstance();
private final BufferBuilder bb = t.getBuilder();
private final FloatBuffer matrix1 = BufferUtils.createFloatBuffer(16);
private final FloatBuffer renderBuffer = BufferUtils.createFloatBuffer(8);
public boolean isOn = false;
public LaserPointerRenderer() {
for(int i = 0; i < 8; i++)
renderBuffer.put(0.0f);
renderBuffer.position(0);
}
public LaserPointerRenderer() {}
@Override
public void render(PoseStack poseStack, ItemStack is, float handSideSign, float swingProgress, float equipProgress, MultiBufferSource multiBufferSource, int packedLight) {
@ -45,7 +33,6 @@ public final class LaserPointerRenderer implements IItemRenderer {
RenderSystem.disableCull();
RenderSystem.disableTexture();
poseStack.pushPose();
//Laser pointer
poseStack.pushPose();
poseStack.translate(handSideSign * -0.4f * sinSqrtSwingProg1, (float) (0.2f * Math.sin(sqrtSwingProg * PI * 2.0f)), (float) (-0.2f * Math.sin(swingProgress * PI)));
@ -60,55 +47,45 @@ public final class LaserPointerRenderer implements IItemRenderer {
RenderSystem.setShaderColor(0.5f, 0.5f, 0.5f, 1.0f);
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();
var matrix = poseStack.last().pose();
bb.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
bb.vertex(matrix, 0.0f, 0.0f, 0.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix, 1.0f, 0.0f, 0.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix, 1.0f, 0.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix, 0.0f, 0.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.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.vertex(matrix, 0.0f, 0.0f, 0.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix, 0.0f, -1.0f, 0.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix, 0.0f, -1.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix, 0.0f, 0.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.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.vertex(matrix,1.0f, 0.0f, 0.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix,1.0f, -1.0f, 0.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix,1.0f, -1.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix,1.0f, 0.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
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();
bb.vertex(matrix, 0.0f, -1.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix, 1.0f, -1.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix, 1.0f, 0.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
bb.vertex(matrix, 0.0f, 0.0f, 4.0f).color(0.5f, 0.5f, 0.5f, 1.0f).endVertex();
t.end();
if(isOn) {
poseStack.translate(0.5f, -0.5f, 0.0f);
matrix1.position(0);
RenderSystem.getModelViewMatrix(); //Hax to get that damn position
}
poseStack.popPose();
if(isOn) {
//Actual laser
poseStack.pushPose();
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.DST_ALPHA);
RenderSystem.setShaderColor(1.0f, 0.0f, 0.0f, 0.5f);
RenderSystem.lineWidth(3.0f);
matrix1.position(12);
renderBuffer.put(matrix1.get());
renderBuffer.put(matrix1.get());
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);
RenderSystem.drawElements(GL_LINES, 0, GL_UNSIGNED_INT);
poseStack.popPose();
}
drawLine(bb, t, matrix);
RenderSystem.enableTexture(); //Fix for shitty minecraft fire
RenderSystem.enableCull();
poseStack.popPose();
}
public static void drawLine(BufferBuilder bb, Tesselator t, Matrix4f matrix) {
GlStateManager._enableBlend();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.setShaderColor(255f, 0f,0f, 127.5f);
RenderSystem.enableDepthTest();
bb.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR);
bb.vertex(matrix, 0, 0, 0).color(255f, 0f,0f, 127.5f).endVertex();
bb.vertex(matrix, 20, 0, 20).color(255f, 0f,0f, 127.5f).endVertex();
t.end();
GlStateManager._disableBlend();
}
}

View File

@ -29,7 +29,19 @@ public enum DefaultUpgrade {
return name;
}
public boolean matches(ItemStack is) {
return is.getItem() == ItemInit.itemUpgrade.get();
public boolean matchesLaserMouse(ItemStack is) {
return is.getItem() == ItemInit.laserMouse.get();
}
public boolean matchesRedInput(ItemStack is) {
return is.getItem() == ItemInit.redInput.get();
}
public boolean matchesRedOutput(ItemStack is) {
return is.getItem() == ItemInit.redOutput.get();
}
public boolean matchesGps(ItemStack is) {
return is.getItem() == ItemInit.gps.get();
}
}

View File

@ -3,12 +3,14 @@ package net.montoyo.wd.entity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.montoyo.wd.client.renderers.ScreenRenderer;
import net.montoyo.wd.miniserv.SyncPlugin;
import java.util.HashMap;
import java.util.Map;
@Mod.EventBusSubscriber
public class ServerEventHandler extends ScreenRenderer{
public static final Map<ServerPlayer, ScreenRenderer> playerScreens = new HashMap<>();

View File

@ -5,6 +5,7 @@
package net.montoyo.wd.entity;
import com.mojang.authlib.minecraft.client.MinecraftClient;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.multiplayer.PlayerInfo;
@ -50,9 +51,11 @@ import net.montoyo.wd.net.server.SMessageGetUrl;
import net.montoyo.wd.net.server.SMessageRequestTEData;
import net.montoyo.wd.net.server.URLMessage;
import net.montoyo.wd.utilities.*;
import org.lwjgl.glfw.GLFW;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.event.InputEvent;
import java.io.IOException;
import java.net.*;
import java.util.*;
@ -525,9 +528,16 @@ public class TileEntityScreen extends BlockEntity {
if (scr.browser != null) {
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
if(InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_CONTROL)
|| InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_RIGHT_CONTROL)) {
scr.browser.injectMouseMove(vec.x, vec.y,0, false); //Move to target
scr.browser.injectMouseButton(vec.x, vec.y, 0, 3, true, 1); //Press
scr.browser.injectMouseButton(vec.x, vec.y, 0, 3, false, 1); //Release
} else {
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
@ -535,7 +545,6 @@ public class TileEntityScreen extends BlockEntity {
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;
@ -592,7 +601,7 @@ public class TileEntityScreen extends BlockEntity {
return;
}
if (scr.upgrades.stream().noneMatch(DefaultUpgrade.REDOUTPUT::matches)) {
if (scr.upgrades.stream().noneMatch(DefaultUpgrade.REDOUTPUT::matchesRedInput)) {
Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> src), new CMessageJSResponse(reqId, req, 403, "Missing upgrade"));
return;
}
@ -922,7 +931,17 @@ public class TileEntityScreen extends BlockEntity {
public boolean hasUpgrade(BlockSide side, DefaultUpgrade du) {
Screen scr = getScreen(side);
return scr != null && scr.upgrades.stream().anyMatch(du::matches);
if (du == DefaultUpgrade.LASERMOUSE) {
return scr != null && scr.upgrades.stream().anyMatch(du::matchesLaserMouse);
} else if (du == DefaultUpgrade.REDINPUT) {
return scr != null && scr.upgrades.stream().anyMatch(du::matchesRedInput);
} else if (du == DefaultUpgrade.GPS) {
return scr != null && scr.upgrades.stream().anyMatch(du::matchesGps);
} else if (du == DefaultUpgrade.REDOUTPUT) {
return scr != null && scr.upgrades.stream().anyMatch(du::matchesRedOutput);
} else {
return false;
}
}
public void removeUpgrade(BlockSide side, ItemStack is, @Nullable Player player) {
@ -993,7 +1012,7 @@ public class TileEntityScreen extends BlockEntity {
if ((scr.rightsFor(ply) & ScreenRights.CLICK) == 0)
return null; //Don't output an error, it can 'legally' happen
if (scr.upgrades.stream().noneMatch(DefaultUpgrade.LASERMOUSE::matches)) {
if (scr.upgrades.stream().noneMatch(DefaultUpgrade.LASERMOUSE::matchesLaserMouse)) {
Log.error("Called laser operation on side %s, but it's missing the laser sensor upgrade", side.toString());
return null;
}

View File

@ -13,6 +13,8 @@ import net.montoyo.wd.core.CraftComponent;
import net.montoyo.wd.core.DefaultUpgrade;
import net.montoyo.wd.item.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class ItemInit{
@ -22,10 +24,13 @@ public class ItemInit{
}
public static DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "webdisplays");
public static RegistryObject<Item> itemUpgrade = null;
public static RegistryObject<Item> itemCraftComp = null;
public static RegistryObject<Item> laserMouse = null;
public static RegistryObject<Item> redInput = null;
public static RegistryObject<Item> redOutput = null;
public static RegistryObject<Item> gps = null;
public static final RegistryObject<Item> itemScreenCfg = ITEMS.register("screencfg", () -> new ItemScreenConfigurator(new Item.Properties()));
public static final RegistryObject<Item> itemOwnerThief = ITEMS.register("ownerthief", () -> new ItemOwnershipThief(new Item.Properties()));
public static final RegistryObject<Item> itemLinker = ITEMS.register("linker", () -> new ItemLinker(new Item.Properties()));
@ -33,9 +38,10 @@ public class ItemInit{
public static final RegistryObject<Item> itemLaserPointer = ITEMS.register("laserpointer", () -> new ItemLaserPointer(new Item.Properties()));
public static void registerUpgrade() {
for (DefaultUpgrade du : DefaultUpgrade.values()) {
itemUpgrade = ITEMS.register("upgrade_" + du.name().toLowerCase(Locale.ROOT), ItemUpgrade::new);
}
laserMouse = ITEMS.register("upgrade_" + DefaultUpgrade.LASERMOUSE.name().toLowerCase(Locale.ROOT), ItemUpgrade::new);
redInput = ITEMS.register("upgrade_" + DefaultUpgrade.REDINPUT.name().toLowerCase(Locale.ROOT), ItemUpgrade::new);
redOutput = ITEMS.register("upgrade_" + DefaultUpgrade.REDOUTPUT.name().toLowerCase(Locale.ROOT), ItemUpgrade::new);
gps = ITEMS.register("upgrade_" + DefaultUpgrade.GPS.name().toLowerCase(Locale.ROOT), ItemUpgrade::new);
}
public static void registerComponents() {

View File

@ -4,18 +4,37 @@
package net.montoyo.wd.item;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.block.BlockScreen;
import net.montoyo.wd.core.IPeripheral;
import net.montoyo.wd.init.BlockInit;
import net.montoyo.wd.init.ItemInit;
import net.montoyo.wd.utilities.Util;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;
public class ItemLaserPointer extends Item implements WDItem {
public ItemLaserPointer(Properties properties) {
super(properties
//setRegistryName("laserpointer")
//setRegistryName("laserpointer")
.stacksTo(1)
.tab(WebDisplays.CREATIVE_TAB));
}

View File

@ -28,7 +28,7 @@ public class ItemUpgrade extends ItemMulti implements IUpgrade, WDItem {
@Override
public boolean onRemove(@Nonnull TileEntityScreen tes, @Nonnull BlockSide screenSide, @Nullable Player player, @Nonnull ItemStack is) {
if(DefaultUpgrade.LASERMOUSE.matches(is))
if(DefaultUpgrade.LASERMOUSE.matchesLaserMouse(is))
tes.clearLaserUser(screenSide);
return false;