Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…and simple screen to unlock the mouse
  • Loading branch information
SirEndii committed Sep 23, 2024
1 parent 8b95891 commit 8bc766d
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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<KeyboardContainer> {

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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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());
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public InteractionResultHolder<ItemStack> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +19,12 @@ public class APContainerTypes {
return new InventoryManagerContainer(windowId, inv, pos, level);
}));

public static final RegistryObject<MenuType<KeyboardContainer>> 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<MenuType<SmartGlassesContainer>> 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())
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class APItems {
public static final RegistryObject<OverlayGlassesItem> OVERLAY_MODULE = APRegistration.ITEMS.register("overlay_module", OverlayGlassesItem::new);
public static final RegistryObject<HotkeyModuleItem> HOTKEY_MODULE = APRegistration.ITEMS.register("hotkey_module", HotkeyModuleItem::new);
public static final RegistryObject<NightVisionModuleItem> NIGHT_VISION_MODULE = APRegistration.ITEMS.register("nightvision_module", NightVisionModuleItem::new);
public static final RegistryObject<KeyboardItem> KEYBOARD = APRegistration.ITEMS.register("keyboard", KeyboardItem::new);
public static final RegistryObject<Item> COMPUTER_TOOL = APRegistration.ITEMS.register("computer_tool", () -> new APItem(new Item.Properties().stacksTo(1), () -> true));
public static final RegistryObject<Item> MEMORY_CARD = APRegistration.ITEMS.register("memory_card", MemoryCardItem::new);
public static final RegistryObject<Item> END_AUTOMATA_CORE = APRegistration.ITEMS.register("end_automata_core", () -> new APItem(new Item.Properties().stacksTo(1), APConfig.METAPHYSICS_CONFIG.enableEndAutomataCore));
Expand Down

0 comments on commit 8bc766d

Please sign in to comment.