cursors
This commit is contained in:
parent
e1ae67c7a2
commit
de2bc44a8e
|
|
@ -21,7 +21,7 @@ minecraft {
|
|||
properties 'mixin.env.remapRefMap': 'true'
|
||||
property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg"
|
||||
workingDirectory project.file('run')
|
||||
arg "-mixin.config=forgecef.mixins.json"
|
||||
arg "-mixin.config=webdisplays.mixins.json"
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
|
||||
mods {
|
||||
|
|
@ -35,7 +35,7 @@ minecraft {
|
|||
properties 'mixin.env.remapRefMap': 'true'
|
||||
property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg"
|
||||
workingDirectory project.file('run')
|
||||
arg "-mixin.config=forgecef.mixins.json"
|
||||
arg "-mixin.config=webdisplays.mixins.json"
|
||||
|
||||
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
|
|
@ -52,7 +52,7 @@ minecraft {
|
|||
properties 'mixin.env.remapRefMap': 'true'
|
||||
property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg"
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', sourceSets.main.resources.srcDirs[0]
|
||||
args '--mod', 'webdisplays', '--all', '--output', file('src/generated/resources/'), '--existing', sourceSets.main.resources.srcDirs[0]
|
||||
mods {
|
||||
webdisplays {
|
||||
source sourceSets.main
|
||||
|
|
@ -98,7 +98,7 @@ jar {
|
|||
"Implementation-Version": "${version}",
|
||||
"Implementation-Vendor" :"webdisplays",
|
||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
|
||||
"MixinConfigs": "forgecef.mixins.json"
|
||||
"MixinConfigs": "webdisplays.mixins.json"
|
||||
])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
cursors.piskel
Normal file
1
cursors.piskel
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -51,6 +51,7 @@ import net.montoyo.wd.net.client_bound.S2CMessageServerInfo;
|
|||
import net.montoyo.wd.utilities.DistSafety;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
|
|
@ -64,7 +65,14 @@ public class WebDisplays {
|
|||
public static WebDisplays INSTANCE;
|
||||
|
||||
public static SharedProxy PROXY = null;
|
||||
|
||||
|
||||
public static final boolean cursorSupport;
|
||||
|
||||
static {
|
||||
ArtifactVersion ver = ModList.get().getModFileById("forgecef").getMods().get(0).getVersion();
|
||||
cursorSupport = (ver.getMajorVersion() >= 1 && ver.getMinorVersion() >= 2 && ver.getIncrementalVersion() >= 4);
|
||||
}
|
||||
|
||||
public static WDCreativeTab CREATIVE_TAB;
|
||||
public static final ResourceLocation ADV_PAD_BREAK = new ResourceLocation("webdisplays", "webdisplays/pad_break");
|
||||
public static final String BLACKLIST_URL = "mod://webdisplays/blacklisted.html";
|
||||
|
|
|
|||
|
|
@ -5,10 +5,15 @@
|
|||
package net.montoyo.wd.client;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.ContainerScreen;
|
||||
import net.minecraft.client.multiplayer.ClientAdvancements;
|
||||
|
|
@ -67,6 +72,8 @@ import net.montoyo.wd.entity.TileEntityScreen;
|
|||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.init.ItemInit;
|
||||
import net.montoyo.wd.init.TileInit;
|
||||
import net.montoyo.wd.item.ItemLaserPointer;
|
||||
import net.montoyo.wd.item.ItemMinePad2;
|
||||
import net.montoyo.wd.item.WDItem;
|
||||
import net.montoyo.wd.miniserv.client.Client;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
|
|
@ -75,6 +82,7 @@ import net.montoyo.wd.net.server_bound.C2SMessageScreenCtrl;
|
|||
import net.montoyo.wd.net.server_bound.C2SMinepadUrl;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
|
@ -87,6 +95,93 @@ import java.util.stream.Stream;
|
|||
@Mod.EventBusSubscriber(modid = "webdisplays", value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQueryHandler, ResourceManagerReloadListener {
|
||||
|
||||
private static ClientProxy INSTANCE;
|
||||
|
||||
public ClientProxy() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
public static void blit(PoseStack p_93229_, int p_93230_, int p_93231_, int p_93232_, int p_93233_, int p_93234_, int p_93235_, int offset) {
|
||||
Gui.blit(p_93229_, p_93230_, p_93231_, offset, (float)p_93232_, (float)p_93233_, p_93234_, p_93235_, 256, 256);
|
||||
}
|
||||
|
||||
public static void renderCrosshair(Options options, int screenWidth, int screenHeight, int offset, PoseStack poseStack, CallbackInfo ci) {
|
||||
ItemStack stack = Minecraft.getInstance().player.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
ItemStack stack1 = Minecraft.getInstance().player.getItemInHand(InteractionHand.OFF_HAND);
|
||||
|
||||
if (stack.getItem() instanceof ItemMinePad2) {
|
||||
float sign = 1;
|
||||
if (Minecraft.getInstance().player.getMainArm() == HumanoidArm.LEFT) sign = -1;
|
||||
if (!MinePadRenderer.renderAtSide(sign)) {
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (stack1.getItem() instanceof ItemMinePad2) {
|
||||
float sign = -1;
|
||||
if (Minecraft.getInstance().player.getMainArm() == HumanoidArm.LEFT) sign = 1;
|
||||
if (!MinePadRenderer.renderAtSide(sign)) {
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(stack.getItem() instanceof ItemLaserPointer ||
|
||||
stack1.getItem() instanceof ItemLaserPointer))
|
||||
return;
|
||||
|
||||
if (!INSTANCE.laserPointerRenderer.isOn) {
|
||||
RenderSystem.setShaderTexture(0, new ResourceLocation(
|
||||
"webdisplays:textures/gui/cursors.png"
|
||||
));
|
||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE_MINUS_DST_COLOR, GlStateManager.DestFactor.ONE_MINUS_SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
|
||||
blit(poseStack, (screenWidth - 15) / 2, (screenHeight - 15) / 2, 240, 240, 15, 15, offset);
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
|
||||
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 || mc.hitResult.getType() == HitResult.Type.MISS)
|
||||
) {
|
||||
BlockHitResult result = raycast(64.0); //TODO: Make that distance configurable
|
||||
|
||||
BlockPos bpos = result.getBlockPos();
|
||||
|
||||
if (result.getType() != HitResult.Type.BLOCK || mc.level.getBlockState(bpos).getBlock() != BlockInit.blockScreen.get())
|
||||
return;
|
||||
|
||||
Vector3i pos = new Vector3i(result.getBlockPos());
|
||||
BlockSide side = BlockSide.values()[result.getDirection().ordinal()];
|
||||
|
||||
Multiblock.findOrigin(mc.level, pos, side, null);
|
||||
TileEntityScreen te = (TileEntityScreen) mc.level.getBlockEntity(pos.toBlock());
|
||||
|
||||
TileEntityScreen.Screen sc = te.getScreen(side);
|
||||
|
||||
if (sc == null) return;
|
||||
// if (sc.mouseType == 1) return;
|
||||
|
||||
int coordX = sc.mouseType * 15;
|
||||
int coordY = coordX / 256;
|
||||
coordX -= coordY * 256;
|
||||
|
||||
RenderSystem.setShaderTexture(0, new ResourceLocation(
|
||||
"webdisplays:textures/gui/cursors.png"
|
||||
));
|
||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE_MINUS_DST_COLOR, GlStateManager.DestFactor.ONE_MINUS_SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
|
||||
blit(poseStack, (screenWidth - 15) / 2, (screenHeight - 15) / 2, coordX, coordY, 15, 15, offset);
|
||||
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public class PadData {
|
||||
|
||||
public IBrowser view;
|
||||
|
|
@ -632,12 +727,13 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
|
|||
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 || mc.hitResult.getType() == HitResult.Type.MISS)) {
|
||||
laserPointerRenderer.isOn = true;
|
||||
BlockHitResult result = raycast(64.0); //TODO: Make that distance configurable
|
||||
|
||||
BlockPos bpos = result.getBlockPos();
|
||||
|
||||
if(result.getType() == HitResult.Type.BLOCK && mc.level.getBlockState(bpos).getBlock() == BlockInit.blockScreen.get()) {
|
||||
laserPointerRenderer.isOn = true;
|
||||
|
||||
Vector3i pos = new Vector3i(result.getBlockPos());
|
||||
BlockSide side = BlockSide.values()[result.getDirection().ordinal()];
|
||||
|
||||
|
|
@ -712,6 +808,7 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
|
|||
/**************************************** OTHER METHODS ****************************************/
|
||||
|
||||
private void laserClick(TileEntityScreen tes, BlockSide side, TileEntityScreen.Screen scr, Vector2i hit) {
|
||||
tes.handleMouseEvent(side, S2CMessageScreenUpdate.MOUSE_MOVE, hit);
|
||||
if(pointedScreen == tes && pointedScreenSide == side) {
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
|
|
@ -721,7 +818,6 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -741,7 +837,9 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
|
|||
}
|
||||
}
|
||||
|
||||
private BlockHitResult raycast(double dist) {
|
||||
private static BlockHitResult raycast(double dist) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
|
||||
Vec3 start = mc.player.getEyePosition(1.0f);
|
||||
Vec3 lookVec = mc.player.getLookAngle();
|
||||
Vec3 end = start.add(lookVec.x * dist, lookVec.y * dist, lookVec.z * dist);
|
||||
|
|
|
|||
|
|
@ -37,9 +37,8 @@ public class GuiMinePad extends WDScreen {
|
|||
this();
|
||||
this.pad = pad;
|
||||
|
||||
if (pad.view instanceof CefBrowserOsr osr) {
|
||||
osr.allowCursorChanges(true);
|
||||
}
|
||||
if (WebDisplays.cursorSupport)
|
||||
pad.view.allowCursorChanges(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -230,9 +229,10 @@ public class GuiMinePad extends WDScreen {
|
|||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
if (pad.view instanceof CefBrowserOsr osr) {
|
||||
osr.allowCursorChanges(true);
|
||||
osr.onCursorChange(null, 0);
|
||||
if (WebDisplays.cursorSupport) {
|
||||
pad.view.allowCursorChanges(false);
|
||||
if (pad.view instanceof CefBrowserOsr osr)
|
||||
osr.onCursorChange(null, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,15 +34,7 @@ public final class MinePadRenderer implements IItemRenderer {
|
|||
private float sinSwingProg1;
|
||||
private float sinSwingProg2;
|
||||
|
||||
@Override
|
||||
public final boolean render(PoseStack stack, ItemStack is, float handSideSign, float swingProgress, float equipProgress, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
//Pre-compute values
|
||||
float sqrtSwingProg = (float) Math.sqrt(swingProgress);
|
||||
sinSqrtSwingProg1 = (float) Math.sin(sqrtSwingProg * PI);
|
||||
sinSqrtSwingProg2 = (float) Math.sin(sqrtSwingProg * PI * 2.0f);
|
||||
sinSwingProg1 = (float) Math.sin(swingProgress * PI);
|
||||
sinSwingProg2 = (float) Math.sin(swingProgress * swingProgress * PI);
|
||||
|
||||
public static boolean renderAtSide(float handSideSign) {
|
||||
float relSide = handSideSign;
|
||||
if (Minecraft.getInstance().player.getMainArm() == HumanoidArm.LEFT) relSide *= -1;
|
||||
|
||||
|
|
@ -55,6 +47,20 @@ public final class MinePadRenderer implements IItemRenderer {
|
|||
(relSide > 0 && Minecraft.getInstance().player.getItemInHand(InteractionHand.OFF_HAND).getItem() instanceof ItemMinePad2)
|
||||
) sideHold = true;
|
||||
|
||||
return sideHold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean render(PoseStack stack, ItemStack is, float handSideSign, float swingProgress, float equipProgress, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
//Pre-compute values
|
||||
float sqrtSwingProg = (float) Math.sqrt(swingProgress);
|
||||
sinSqrtSwingProg1 = (float) Math.sin(sqrtSwingProg * PI);
|
||||
sinSqrtSwingProg2 = (float) Math.sin(sqrtSwingProg * PI * 2.0f);
|
||||
sinSwingProg1 = (float) Math.sin(swingProgress * PI);
|
||||
sinSwingProg2 = (float) Math.sin(swingProgress * swingProgress * PI);
|
||||
|
||||
boolean sideHold = renderAtSide(handSideSign);
|
||||
|
||||
//Render arm
|
||||
stack.pushPose();
|
||||
renderArmFirstPerson(stack, multiBufferSource, packedLight, equipProgress, handSideSign);
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ public class TileEntityScreen extends BlockEntity {
|
|||
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")];
|
||||
|
|
@ -228,7 +230,10 @@ public class TileEntityScreen extends BlockEntity {
|
|||
browser.resize(resolution.y, resolution.x);
|
||||
else
|
||||
browser.resize(resolution.x, resolution.y);
|
||||
|
||||
|
||||
if (WebDisplays.cursorSupport)
|
||||
browser.addCursorChangeListener((type) -> mouseType = type);
|
||||
|
||||
doTurnOnAnim = doAnim;
|
||||
turnOnTime = System.currentTimeMillis();
|
||||
}
|
||||
|
|
|
|||
30
src/main/java/net/montoyo/wd/mixins/OverlayMixin.java
Normal file
30
src/main/java/net/montoyo/wd/mixins/OverlayMixin.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package net.montoyo.wd.mixins;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.montoyo.wd.client.ClientProxy;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Gui.class)
|
||||
public class OverlayMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
protected Minecraft minecraft;
|
||||
|
||||
@Shadow
|
||||
protected int screenWidth;
|
||||
|
||||
@Shadow
|
||||
protected int screenHeight;
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "renderCrosshair", cancellable = true)
|
||||
public void preDrawCrosshair(PoseStack poseStack, CallbackInfo ci) {
|
||||
ClientProxy.renderCrosshair(minecraft.options, screenWidth, screenHeight, ((Gui) (Object) this).getBlitOffset(), poseStack, ci);
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,6 @@ side="BOTH"
|
|||
[[dependencies.webdisplays]]
|
||||
modId="forgecef"
|
||||
mandatory=true
|
||||
versionRange="[1.2.4, )"
|
||||
versionRange="[1.2.3, )"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
|
|
|||
BIN
src/main/resources/assets/webdisplays/textures/gui/cursors.png
Normal file
BIN
src/main/resources/assets/webdisplays/textures/gui/cursors.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
|
|
@ -22,7 +22,7 @@
|
|||
]
|
||||
},
|
||||
"mixins": [
|
||||
"webdisplays.mixin.json"
|
||||
"webdisplays.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"OverlayMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
Loading…
Reference in New Issue
Block a user