diff --git a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java index 27c1f9e51..9aad89936 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java +++ b/src/main/java/de/srendi/advancedperipherals/client/ClientRegistry.java @@ -5,6 +5,7 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.renderer.DistanceDetectorRenderer; import de.srendi.advancedperipherals.client.screens.InventoryManagerScreen; +import de.srendi.advancedperipherals.client.screens.KeyboardScreen; import de.srendi.advancedperipherals.client.screens.SaddleTurtleScreen; import de.srendi.advancedperipherals.client.screens.SmartGlassesScreen; import de.srendi.advancedperipherals.client.smartglasses.OverlayModuleOverlay; @@ -43,6 +44,7 @@ public static void registerModels(ModelEvent.RegisterAdditional event) { public static void onClientSetup(FMLClientSetupEvent event) { MenuScreens.register(APContainerTypes.INVENTORY_MANAGER_CONTAINER.get(), InventoryManagerScreen::new); MenuScreens.register(APContainerTypes.SMART_GLASSES_CONTAINER.get(), SmartGlassesScreen::new); + MenuScreens.register(APContainerTypes.KEYBOARD_CONTAINER.get(), KeyboardScreen::new); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.CHUNKY_TURTLE.get(), TurtleUpgradeModeller.flatItem()); ComputerCraftAPIClient.registerTurtleUpgradeModeller(CCRegistration.COMPASS_TURTLE.get(), TurtleUpgradeModeller.flatItem()); diff --git a/src/main/java/de/srendi/advancedperipherals/client/screens/KeyboardScreen.java b/src/main/java/de/srendi/advancedperipherals/client/screens/KeyboardScreen.java new file mode 100644 index 000000000..8c44430c5 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/client/screens/KeyboardScreen.java @@ -0,0 +1,46 @@ +package de.srendi.advancedperipherals.client.screens; + +import com.mojang.blaze3d.vertex.PoseStack; +import de.srendi.advancedperipherals.client.screens.base.BaseScreen; +import de.srendi.advancedperipherals.common.container.KeyboardContainer; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import org.jetbrains.annotations.NotNull; + +/** + * A simple screen but without any rendering calls. Used to unlock the mouse so we can freely write stuff + */ +public class KeyboardScreen extends BaseScreen { + + public KeyboardScreen(KeyboardContainer screenContainer, Inventory inv, Component titleIn) { + super(screenContainer, inv, titleIn); + } + + @Override + public void render(@NotNull PoseStack matrixStack, int x, int y, float partialTicks) { + } + + @Override + protected void renderBg(@NotNull PoseStack matrixStack, float partialTicks, int x, int y) { + } + + @Override + public void renderBackground(@NotNull PoseStack pPoseStack) { + } + + @Override + public int getSizeX() { + return 256; + } + + @Override + public int getSizeY() { + return 256; + } + + @Override + public ResourceLocation getTexture() { + return null; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/container/KeyboardContainer.java b/src/main/java/de/srendi/advancedperipherals/common/container/KeyboardContainer.java new file mode 100644 index 000000000..53f98bc5c --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/container/KeyboardContainer.java @@ -0,0 +1,24 @@ +package de.srendi.advancedperipherals.common.container; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.container.base.BaseContainer; +import de.srendi.advancedperipherals.common.setup.APContainerTypes; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; + +public class KeyboardContainer extends BaseContainer { + + public KeyboardContainer(int id, Inventory inventory, BlockPos pos, Level level) { + super(APContainerTypes.KEYBOARD_CONTAINER.get(), id, inventory, pos, level); + AdvancedPeripherals.debug("test"); + } + + @Override + public boolean stillValid(@NotNull Player playerIn) { + return true; + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/KeyboardItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/KeyboardItem.java new file mode 100644 index 000000000..1708096c2 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/items/KeyboardItem.java @@ -0,0 +1,40 @@ +package de.srendi.advancedperipherals.common.items; + +import de.srendi.advancedperipherals.common.container.KeyboardContainer; +import de.srendi.advancedperipherals.common.items.base.BaseItem; +import de.srendi.advancedperipherals.common.items.base.IInventoryItem; +import net.minecraft.network.chat.Component; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class KeyboardItem extends BaseItem implements IInventoryItem { + + public KeyboardItem() { + super(new Properties().stacksTo(1)); + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public MenuProvider createContainer(Player playerEntity, ItemStack itemStack) { + return new MenuProvider() { + @NotNull + @Override + public Component getDisplayName() { + return Component.literal(""); + } + + @Override + public AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory playerInv, @NotNull Player player) { + return new KeyboardContainer(pContainerId, playerInv, player.blockPosition(), player.getLevel()); + } + }; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/items/base/BaseItem.java b/src/main/java/de/srendi/advancedperipherals/common/items/base/BaseItem.java index bc95f02d1..1645898f4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/items/base/BaseItem.java +++ b/src/main/java/de/srendi/advancedperipherals/common/items/base/BaseItem.java @@ -39,7 +39,11 @@ public InteractionResultHolder use(Level worldIn, Player playerIn, In if (this instanceof IInventoryItem inventoryItem) { ServerPlayer serverPlayerEntity = (ServerPlayer) playerIn; ItemStack stack = playerIn.getItemInHand(handIn); - NetworkHooks.openScreen(serverPlayerEntity, inventoryItem.createContainer(playerIn, stack), buf -> buf.writeItem(stack)); + NetworkHooks.openScreen(serverPlayerEntity, inventoryItem.createContainer(playerIn, stack), buf -> { + buf.writeBlockPos(playerIn.blockPosition()); + buf.writeItem(stack); + } + ); } return super.use(worldIn, playerIn, handIn); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java index b51d363b3..e50f7a866 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APContainerTypes.java @@ -3,6 +3,7 @@ import dan200.computercraft.shared.network.container.ComputerContainerData; import dan200.computercraft.shared.network.container.ContainerData; import de.srendi.advancedperipherals.common.container.InventoryManagerContainer; +import de.srendi.advancedperipherals.common.container.KeyboardContainer; import de.srendi.advancedperipherals.common.container.SmartGlassesContainer; import net.minecraft.core.BlockPos; import net.minecraft.world.inventory.MenuType; @@ -18,6 +19,12 @@ public class APContainerTypes { return new InventoryManagerContainer(windowId, inv, pos, level); })); + public static final RegistryObject> KEYBOARD_CONTAINER = APRegistration.CONTAINER_TYPES.register("keyboard_container", () -> IForgeMenuType.create((windowId, inv, data) -> { + BlockPos pos = data.readBlockPos(); + Level level = inv.player.getCommandSenderWorld(); + return new KeyboardContainer(windowId, inv, pos, level); + })); + public static final RegistryObject> SMART_GLASSES_CONTAINER = APRegistration.CONTAINER_TYPES.register("smart_glasses_container", () -> ContainerData.toType(ComputerContainerData::new, (id, inv, data) -> new SmartGlassesContainer(id, player -> true, null, data, inv, data.displayStack()) )); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java index 23ba2dc15..77347e515 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/APItems.java @@ -18,6 +18,7 @@ public class APItems { public static final RegistryObject OVERLAY_MODULE = APRegistration.ITEMS.register("overlay_module", OverlayGlassesItem::new); public static final RegistryObject HOTKEY_MODULE = APRegistration.ITEMS.register("hotkey_module", HotkeyModuleItem::new); public static final RegistryObject NIGHT_VISION_MODULE = APRegistration.ITEMS.register("nightvision_module", NightVisionModuleItem::new); + public static final RegistryObject KEYBOARD = APRegistration.ITEMS.register("keyboard", KeyboardItem::new); public static final RegistryObject COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true)); public static final RegistryObject MEMORY_CARD = APRegistration.ITEMS.register("memory_card", MemoryCardItem::new); public static final RegistryObject END_AUTOMATA_CORE = APRegistration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore));