commit
d9e75f6ada
|
|
@ -79,6 +79,8 @@ dependencies {
|
|||
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")
|
||||
|
||||
implementation fg.deobf("curse.maven:vivecraft-667903:4409427")
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
|
|
|||
|
|
@ -5,34 +5,26 @@
|
|||
package net.montoyo.wd.block;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.montoyo.wd.core.DefaultPeripheral;
|
||||
import net.montoyo.wd.core.IPeripheral;
|
||||
import net.montoyo.wd.entity.TileEntityKeyboard;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.item.ItemLinker;
|
||||
import net.montoyo.wd.net.Messages;
|
||||
import net.montoyo.wd.net.client.CMessageCloseGui;
|
||||
|
|
|
|||
|
|
@ -126,7 +126,26 @@ public class BlockScreen extends BaseEntityBlock {
|
|||
|
||||
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?
|
||||
for (BlockSide value : BlockSide.values()) {
|
||||
Vector3i vec = new Vector3i(p_60517_.getX(), p_60517_.getY(), p_60517_.getZ());
|
||||
Multiblock.findOrigin(p_60516_, vec, value, null);
|
||||
BlockPos bp = new BlockPos(vec.x, vec.y, vec.z);
|
||||
if (!bp.equals(p_60517_)) {
|
||||
p_60516_.removeBlockEntity(bp);
|
||||
p_60516_.setBlock(
|
||||
bp, p_60516_.getBlockState(bp).setValue(hasTE, false),
|
||||
11
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -184,10 +203,11 @@ public class BlockScreen extends BaseEntityBlock {
|
|||
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
} else if(sneaking) {
|
||||
Util.toast(player, "turnOn");
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
// else if(sneaking) {
|
||||
// Util.toast(player, "turnOn");
|
||||
// return InteractionResult.SUCCESS;
|
||||
// }
|
||||
|
||||
Vector2i size = Multiblock.measure(world, pos, side);
|
||||
if(size.x < 2 || size.y < 2) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import net.minecraft.network.chat.Component;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
import net.montoyo.wd.client.gui.controls.Button;
|
||||
|
|
@ -25,8 +26,11 @@ import net.montoyo.wd.utilities.TypeData;
|
|||
import net.montoyo.wd.utilities.Util;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.cef.browser.CefBrowserOsr;
|
||||
import org.vivecraft.gameplay.VRPlayer;
|
||||
import org.vivecraft.gameplay.screenhandlers.KeyboardHandler;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
|
@ -64,6 +68,30 @@ public class GuiKeyboard extends WDScreen {
|
|||
vars.put("showWarning", showWarning ? 1.0 : 0.0);
|
||||
}
|
||||
|
||||
private static final boolean vivecraftPresent;
|
||||
|
||||
static {
|
||||
boolean vivePres = false;
|
||||
if (ModList.get().isLoaded("vivecraft")) vivePres = true;
|
||||
// I believe the non-mixin version of vivecraft is not a proper mod, so
|
||||
// detect the mod reflectively if the mod is not found
|
||||
else {
|
||||
try {
|
||||
Class<?> clazz = Class.forName("org.vivecraft.gameplay.screenhandlers.KeyboardHandler");
|
||||
//noinspection ConstantConditions
|
||||
if (clazz == null) vivePres = false;
|
||||
else {
|
||||
Method m = clazz.getMethod("setOverlayShowing", boolean.class);
|
||||
//noinspection ConstantConditions
|
||||
vivePres = m != null;
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
vivePres = false;
|
||||
}
|
||||
}
|
||||
vivecraftPresent = vivePres;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
|
@ -109,60 +137,47 @@ public class GuiKeyboard extends WDScreen {
|
|||
|
||||
defaultBackground = showWarning;
|
||||
syncTicks = 5;
|
||||
|
||||
if (vivecraftPresent)
|
||||
if (VRPlayer.get() != null)
|
||||
KeyboardHandler.setOverlayShowing(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
if (vivecraftPresent)
|
||||
if (VRPlayer.get() != null)
|
||||
KeyboardHandler.setOverlayShowing(false);
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
key(keyCode, scanCode, true, modifiers);
|
||||
if(quitOnEscape && keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
}
|
||||
evStack.add(new TypeData(TypeData.Action.PRESS, keyCode, modifiers));
|
||||
if (!evStack.isEmpty() && !syncRequested())
|
||||
requestSync();
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char codePoint, int modifiers) {
|
||||
evStack.add(new TypeData(TypeData.Action.TYPE, codePoint, modifiers));
|
||||
if (!evStack.isEmpty() && !syncRequested())
|
||||
requestSync();
|
||||
return super.charTyped(codePoint, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
|
||||
key(keyCode, scanCode, false, modifiers);
|
||||
evStack.add(new TypeData(TypeData.Action.RELEASE, keyCode, modifiers));
|
||||
if (!evStack.isEmpty() && !syncRequested())
|
||||
requestSync();
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
public void key(int keyCode, int scanCode, boolean pressed, int mod) {
|
||||
if (pressed) {
|
||||
if(quitOnEscape && keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
}
|
||||
|
||||
int chr = CefBrowserOsr.remapKeycode(keyCode, (char) keyCode, mod);
|
||||
evStack.add(new TypeData(TypeData.Action.PRESS, chr, mod));
|
||||
evStack.add(new TypeData(TypeData.Action.RELEASE, chr, mod));
|
||||
|
||||
if (keyCode != 0)
|
||||
evStack.add(new TypeData(TypeData.Action.TYPE, chr, mod));
|
||||
|
||||
if (!evStack.isEmpty() && !syncRequested())
|
||||
requestSync();
|
||||
}
|
||||
}
|
||||
|
||||
public int getChar(int keyCode, int scanCode) {
|
||||
String keystr = GLFW.glfwGetKeyName(keyCode, scanCode);
|
||||
if(keystr == null){
|
||||
keystr = "\0";
|
||||
}
|
||||
if(keyCode == GLFW.GLFW_KEY_ENTER){
|
||||
return 13;
|
||||
}
|
||||
if (keyCode == GLFW.GLFW_KEY_SPACE) {
|
||||
return 32;
|
||||
}
|
||||
if(keystr.length() == 0){
|
||||
return -1;
|
||||
}
|
||||
if(hasShiftDown()) {
|
||||
keystr = keystr.toUpperCase(Locale.ROOT);
|
||||
return CefBrowserOsr.remapKeycode(keyCode, keystr.charAt(keystr.length() - 1), 0);
|
||||
} else {
|
||||
return CefBrowserOsr.remapKeycode(keyCode, keystr.charAt(keystr.length() - 1), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sync() {
|
||||
if(!evStack.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -786,9 +786,9 @@ public class TileEntityScreen extends BlockEntity{
|
|||
|
||||
for(TypeData ev : data) {
|
||||
switch (ev.getAction()) {
|
||||
case PRESS -> scr.browser.injectKeyPressedByKeyCode(ev.getKeyCode(), (char) ev.getKeyCode(), 0);
|
||||
case RELEASE -> scr.browser.injectKeyReleasedByKeyCode(ev.getKeyCode(), (char) ev.getKeyCode(), 0);
|
||||
case TYPE -> scr.browser.injectKeyTyped(ev.getKeyCode(), 0);
|
||||
case PRESS -> scr.browser.injectKeyPressedByKeyCode(ev.getKeyCode(), (char) ev.getKeyCode(), ev.getModifier());
|
||||
case RELEASE -> scr.browser.injectKeyReleasedByKeyCode(ev.getKeyCode(), (char) ev.getKeyCode(), ev.getModifier());
|
||||
case TYPE -> scr.browser.injectKeyTyped(ev.getKeyCode(), ev.getModifier());
|
||||
default -> throw new RuntimeException("Invalid type action '" + ev.getAction() + '\'');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public class ItemLinker extends Item implements WDItem {
|
|||
}
|
||||
|
||||
Vector3i pos = new Vector3i(context.getClickedPos());
|
||||
BlockSide side = BlockSide.values()[context.getHorizontalDirection().ordinal()];
|
||||
BlockSide side = BlockSide.values()[context.getClickedFace().ordinal()];
|
||||
Multiblock.findOrigin(context.getLevel(), pos, side, null);
|
||||
|
||||
BlockEntity te = context.getLevel().getBlockEntity(pos.toBlock());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user