From 9e7343128dc9e93253f35709011298c43f651853 Mon Sep 17 00:00:00 2001 From: Mysticpasta1 Date: Sun, 31 Dec 2023 06:33:50 -0600 Subject: [PATCH] it works almost - run client :D --- build.gradle | 2 + .../HolographicRenders.java | 45 +++++++-- .../projector/ItemProjectionHandler.java | 14 +-- .../client/HolographicRendersClient.java | 6 +- .../client/RenderDataProvider.java | 4 +- .../client/TextboxScreenRoot.java | 41 ++++++++ .../client/TextureRenderLayer.java | 4 +- .../client/WidgetScreenRoot.java | 13 +++ .../gui/ProjectorScreen.java | 95 +++++++++++-------- .../gui/ProjectorScreenHandler.java | 46 ++++----- .../holographicrenders/gui/TextboxScreen.java | 74 ++++----------- .../holographicrenders/gui/Textures.java | 17 +--- .../holographicrenders/gui/WidgetScreen.java | 68 ++++--------- .../item/AreaScannerItem.java | 3 +- .../item/EntityScannerItem.java | 13 +-- .../item/TextureScannerItem.java | 11 +-- .../item/WidgetScannerItem.java | 7 +- .../mixin/ArmorStandMixin.java | 8 +- .../mixin/WorldRendererMixin.java | 6 +- .../network/ProjectorScreenPacket.java | 2 +- 20 files changed, 236 insertions(+), 243 deletions(-) create mode 100644 src/main/java/com/mystic/holographicrenders/client/TextboxScreenRoot.java create mode 100644 src/main/java/com/mystic/holographicrenders/client/WidgetScreenRoot.java diff --git a/build.gradle b/build.gradle index 96b3c72..84bbea1 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,8 @@ dependencies { modImplementation "io.wispforest:worldmesher:${project.worldmesher_version}" include "io.wispforest:worldmesher:${project.worldmesher_version}" + modImplementation include("io.github.cottonmc:LibGui:8.1.0+1.20.1") + implementation 'com.madgag:animated-gif-lib:1.4' include 'com.madgag:animated-gif-lib:1.4' } diff --git a/src/main/java/com/mystic/holographicrenders/HolographicRenders.java b/src/main/java/com/mystic/holographicrenders/HolographicRenders.java index 4988be2..a3adb97 100644 --- a/src/main/java/com/mystic/holographicrenders/HolographicRenders.java +++ b/src/main/java/com/mystic/holographicrenders/HolographicRenders.java @@ -3,6 +3,7 @@ import com.mystic.holographicrenders.blocks.projector.ItemProjectionHandler; import com.mystic.holographicrenders.blocks.projector.ProjectorBlock; import com.mystic.holographicrenders.blocks.projector.ProjectorBlockEntity; +import com.mystic.holographicrenders.client.TextboxScreenRoot; import com.mystic.holographicrenders.gui.ProjectorScreenHandler; import com.mystic.holographicrenders.item.AreaScannerItem; import com.mystic.holographicrenders.item.EntityScannerItem; @@ -10,35 +11,54 @@ import com.mystic.holographicrenders.item.WidgetScannerItem; import com.mystic.holographicrenders.item.WidgetType; import com.mystic.holographicrenders.network.ProjectorScreenPacket; +import io.github.cottonmc.cotton.gui.client.LibGui; +import io.github.cottonmc.cotton.gui.impl.LibGuiCommon; +import io.github.cottonmc.cotton.gui.impl.client.ItemUseChecker; +import io.github.cottonmc.cotton.gui.impl.client.LibGuiClient; import io.netty.buffer.ByteBufUtil; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; +import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry; import net.fabricmc.fabric.impl.itemgroup.FabricItemGroup; +import net.fabricmc.fabric.impl.itemgroup.FabricItemGroupBuilderImpl; import net.minecraft.block.Block; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.client.MinecraftClient; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.inventory.StackReference; +import net.minecraft.item.*; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.text.Text; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.function.Supplier; + public class HolographicRenders implements ModInitializer { public static final String MOD_ID = "holographic_renders"; - public static final ItemGroup HOLOGRAPHIC_RENDERS_CREATIVE_TAB = FabricItemGroup.create(new Identifier(MOD_ID, "general")).icon(() -> new ItemStack(HolographicRenders.PROJECTOR_BLOCK)).build().setName("holographic_renders:textures/gui/hologram_tab.png"); + public static final List> MAIN_BLOCKS = new ArrayList<>(); + public static final ItemGroup owo = new FabricItemGroupBuilderImpl().icon(() -> HolographicRenders.PROJECTOR_BLOCK.asItem().getDefaultStack()).displayName(Text.literal("Holographic Renders")).entries((displayContext, entries) -> { + MAIN_BLOCKS.forEach((itemLike -> entries.add(itemLike.get()))); + }).build(); + + public static ItemConvertible addToMainTab (ItemConvertible itemLike) { + MAIN_BLOCKS.add(() -> itemLike); + return itemLike; + } public static final Item AREA_SCANNER = new AreaScannerItem(); public static final Item TEXTURE_SCANNER = new TextureScannerItem(); @@ -46,7 +66,7 @@ public class HolographicRenders implements ModInitializer { public static final Item WIDGET_SCANNER = new WidgetScannerItem(); public static final Block PROJECTOR_BLOCK = new ProjectorBlock(); - public static final Item PROJECTOR_ITEM = new BlockItem(PROJECTOR_BLOCK, new Item.Settings().group(HOLOGRAPHIC_RENDERS_CREATIVE_TAB)); + public static final Item PROJECTOR_ITEM = new BlockItem(PROJECTOR_BLOCK, new Item.Settings()); public static final BlockEntityType PROJECTOR_BLOCK_ENTITY = FabricBlockEntityTypeBuilder.create(ProjectorBlockEntity::new, PROJECTOR_BLOCK).build(null); public static final Identifier PROJECTOR_ID = new Identifier(MOD_ID, "projector"); @@ -59,6 +79,8 @@ public class HolographicRenders implements ModInitializer { @Override public void onInitialize() { + Properties props = System.getProperties(); + props.setProperty("libgui.allowItemUse", "true"); Registry.register(Registries.BLOCK, PROJECTOR_ID, PROJECTOR_BLOCK); Registry.register(Registries.ITEM, PROJECTOR_ID, PROJECTOR_ITEM); @@ -69,12 +91,19 @@ public void onInitialize() { Registry.register(Registries.ITEM, new Identifier(MOD_ID, "entity_scanner"), ENTITY_SCANNER); Registry.register(Registries.ITEM, new Identifier(MOD_ID, "widget_scanner"), WIDGET_SCANNER); + addToMainTab(AREA_SCANNER.asItem()); + addToMainTab(TEXTURE_SCANNER.asItem()); + addToMainTab(ENTITY_SCANNER.asItem()); + //addToMainTab(WIDGET_SCANNER.asItem()); + addToMainTab(PROJECTOR_ITEM.asItem()); + + Registry.register(Registries.ITEM_GROUP, new Identifier(MOD_ID, "group"), owo); + ServerPlayNetworking.registerGlobalReceiver(ProjectorScreenPacket.ACTION_REQUEST_ID, ProjectorScreenPacket::onActionRequest); ServerPlayNetworking.registerGlobalReceiver(new Identifier(HolographicRenders.MOD_ID, "url_packet"), (server, player, handler, buf, responseSender) -> { String url = buf.readString(); - Hand hand = buf.readEnumConstant(Hand.class); + ItemStack stack = player.getStackInHand(buf.readEnumConstant(Hand.class)); server.execute(() -> { - ItemStack stack = player.getStackInHand(hand); if(stack.getItem() instanceof TextureScannerItem) { NbtCompound tag = stack.getOrCreateNbt(); tag.putString("URL", url); diff --git a/src/main/java/com/mystic/holographicrenders/blocks/projector/ItemProjectionHandler.java b/src/main/java/com/mystic/holographicrenders/blocks/projector/ItemProjectionHandler.java index 7babd87..5ea4f53 100644 --- a/src/main/java/com/mystic/holographicrenders/blocks/projector/ItemProjectionHandler.java +++ b/src/main/java/com/mystic/holographicrenders/blocks/projector/ItemProjectionHandler.java @@ -58,13 +58,13 @@ public class ItemProjectionHandler { } }); - registerBehaviour(stack -> stack.getItem() == HolographicRenders.WIDGET_SCANNER, (be, stack) -> { - try { - return RenderDataProvider.WidgetProvider.of(WidgetType.fromId(be.getStack(0).getOrCreateNbt().getInt("Widget")), be.getPos()); - } catch (ExecutionException e) { - return RenderDataProvider.EmptyProvider.INSTANCE; - } - }); + // registerBehaviour(stack -> stack.getItem() == HolographicRenders.WIDGET_SCANNER, (be, stack) -> { + // try { + // return RenderDataProvider.WidgetProvider.of(WidgetType.fromId(be.getStack(0).getOrCreateNbt().getInt("Widget")), be.getPos()); + // } catch (ExecutionException e) { + // return RenderDataProvider.EmptyProvider.INSTANCE; + // } + // }); registerBehaviour(itemStack -> itemStack.getItem() == Items.FILLED_MAP, (be, stack) -> { return RenderDataProvider.MapProvider.of(FilledMapItem.getMapId(stack)); diff --git a/src/main/java/com/mystic/holographicrenders/client/HolographicRendersClient.java b/src/main/java/com/mystic/holographicrenders/client/HolographicRendersClient.java index 0d17eb6..edf0cd9 100644 --- a/src/main/java/com/mystic/holographicrenders/client/HolographicRendersClient.java +++ b/src/main/java/com/mystic/holographicrenders/client/HolographicRendersClient.java @@ -12,11 +12,9 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry; import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; - import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.MinecraftClient; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -41,7 +39,7 @@ public void onInitializeClient() { } }); }); - Common.textScreenRunnable = (hand -> MinecraftClient.getInstance().setScreen(new TextboxScreen(hand))); - Common.widgetScreenRunnable = (hand -> MinecraftClient.getInstance().setScreen(new WidgetScreen(hand))); + Common.textScreenRunnable = (hand -> MinecraftClient.getInstance().setScreen(new TextboxScreen(new TextboxScreenRoot(hand)))); + Common.widgetScreenRunnable = (hand -> MinecraftClient.getInstance().setScreen(new WidgetScreen(new WidgetScreenRoot(hand), hand))); } } diff --git a/src/main/java/com/mystic/holographicrenders/client/RenderDataProvider.java b/src/main/java/com/mystic/holographicrenders/client/RenderDataProvider.java index c133cc0..c4ba3c8 100644 --- a/src/main/java/com/mystic/holographicrenders/client/RenderDataProvider.java +++ b/src/main/java/com/mystic/holographicrenders/client/RenderDataProvider.java @@ -423,7 +423,7 @@ public static class TextureProvider extends RenderDataProvider { .maximumSize(20) .expireAfterAccess(20, TimeUnit.SECONDS) .removalListener((RemovalListener) notification -> MinecraftClient.getInstance().getTextureManager().destroyTexture(notification.getValue().data)) - .build(new CacheLoader() { + .build(new CacheLoader<>() { @Override public TextureProvider load(String key) { try { @@ -434,7 +434,7 @@ public TextureProvider load(String key) { Identifier id = new Identifier("missingno"); - return new TextureProvider(id, new RegularSprite(id, 16,16)); + return new TextureProvider(id, new RegularSprite(id, 16, 16)); } } }); diff --git a/src/main/java/com/mystic/holographicrenders/client/TextboxScreenRoot.java b/src/main/java/com/mystic/holographicrenders/client/TextboxScreenRoot.java new file mode 100644 index 0000000..ead4b1d --- /dev/null +++ b/src/main/java/com/mystic/holographicrenders/client/TextboxScreenRoot.java @@ -0,0 +1,41 @@ +package com.mystic.holographicrenders.client; + +import com.mystic.holographicrenders.HolographicRenders; +import io.github.cottonmc.cotton.gui.ItemSyncedGuiDescription; +import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; +import io.github.cottonmc.cotton.gui.widget.WButton; +import io.github.cottonmc.cotton.gui.widget.WGridPanel; +import io.github.cottonmc.cotton.gui.widget.WLabel; +import io.github.cottonmc.cotton.gui.widget.WTextField; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.StackReference; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.text.Text; +import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; + + +public class TextboxScreenRoot extends LightweightGuiDescription { + + public TextboxScreenRoot(Hand hand) { + WGridPanel root = new WGridPanel(); + WButton button = new WButton(); + WTextField textFieldWidget = new WTextField(Text.of("Please enter a valid URL!")); + WLabel label = new WLabel(Text.literal("Save URL")); + setRootPanel(root); + root.setSize(256, 240); + textFieldWidget.setMaxLength(90); + root.add(textFieldWidget, 0, 5, 15, 10); + root.add(button, 4, 8, 6, 20); + root.add(label, 4, 8); + root.validate(this); + button.setOnClick(() -> { + PacketByteBuf buf = PacketByteBufs.create(); + buf.writeString(textFieldWidget.getText(), 2000); + buf.writeEnumConstant(hand); + ClientPlayNetworking.send(new Identifier(HolographicRenders.MOD_ID, "url_packet"), buf); + }); + } +} \ No newline at end of file diff --git a/src/main/java/com/mystic/holographicrenders/client/TextureRenderLayer.java b/src/main/java/com/mystic/holographicrenders/client/TextureRenderLayer.java index b44581f..d1224ae 100644 --- a/src/main/java/com/mystic/holographicrenders/client/TextureRenderLayer.java +++ b/src/main/java/com/mystic/holographicrenders/client/TextureRenderLayer.java @@ -1,20 +1,18 @@ package com.mystic.holographicrenders.client; -import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mystic.holographicrenders.HolographicRenders; import com.mystic.holographicrenders.mixin.VertexConsumerProviderImmediateAccessor; import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; import net.minecraft.client.render.*; -import net.minecraft.util.Identifier; import java.util.IdentityHashMap; import java.util.Map; import java.util.Objects; import java.util.Optional; -import static net.minecraft.client.render.VertexFormats.*; +import static net.minecraft.client.render.VertexFormats.POSITION_TEXTURE; public class TextureRenderLayer extends RenderLayer { diff --git a/src/main/java/com/mystic/holographicrenders/client/WidgetScreenRoot.java b/src/main/java/com/mystic/holographicrenders/client/WidgetScreenRoot.java new file mode 100644 index 0000000..5adf756 --- /dev/null +++ b/src/main/java/com/mystic/holographicrenders/client/WidgetScreenRoot.java @@ -0,0 +1,13 @@ +package com.mystic.holographicrenders.client; + +import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; +import io.github.cottonmc.cotton.gui.widget.WGridPanel; +import net.minecraft.util.Hand; + +public class WidgetScreenRoot extends LightweightGuiDescription { + + public WidgetScreenRoot(Hand hand) { + WGridPanel root = new WGridPanel(); + root.validate(this); + } +} \ No newline at end of file diff --git a/src/main/java/com/mystic/holographicrenders/gui/ProjectorScreen.java b/src/main/java/com/mystic/holographicrenders/gui/ProjectorScreen.java index 32a2639..4d1ebbc 100644 --- a/src/main/java/com/mystic/holographicrenders/gui/ProjectorScreen.java +++ b/src/main/java/com/mystic/holographicrenders/gui/ProjectorScreen.java @@ -1,63 +1,80 @@ package com.mystic.holographicrenders.gui; -import static com.teamwizardry.librarianlib.core.util.Shorthand.vec; - import com.mojang.blaze3d.systems.RenderSystem; import com.mystic.holographicrenders.network.ProjectorScreenPacket; -import com.teamwizardry.librarianlib.facade.container.FacadeView; -import com.teamwizardry.librarianlib.facade.layers.SpriteLayer; -import com.teamwizardry.librarianlib.facade.layers.TextLayer; -import com.teamwizardry.librarianlib.facade.layers.text.TextFit; -import com.teamwizardry.librarianlib.facade.pastry.layers.PastryCheckbox; -import com.teamwizardry.librarianlib.facade.pastry.layers.PastryToggle; -import com.teamwizardry.librarianlib.mosaic.Mosaic; -import com.teamwizardry.librarianlib.mosaic.MosaicSprite; -import ll.dev.thecodewarrior.bitfont.typesetting.TextLayoutManager; - import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.widget.CheckboxWidget; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.screen.ScreenHandler; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import net.minecraft.util.Language; import java.util.function.Consumer; -public class ProjectorScreen extends FacadeView { - private static final MosaicSprite TEXTURE = new Mosaic(new Identifier("holographic_renders", "textures/gui_hologram_projector.png"), 256,256).getSprite("main"); +public class ProjectorScreen extends HandledScreen { + private static final Identifier TEXTURE = new Identifier("holographic_renders", "textures/gui_hologram_projector.png"); private boolean lightsEnabled = false; public ProjectorScreen(ProjectorScreenHandler handler, PlayerInventory inventory, Text title) { super(handler, inventory, title); - getMain().setSize(vec(Textures.main.getWidth(), Textures.main.getHeight())); - - SpriteLayer sprite = new SpriteLayer(Textures.main); - TextLayer text = new TextLayer(128, 7, Language.getInstance().get("block.holographic_renders.projector")); - text.fitToText(TextFit.BOTH); - text.setTextAlignment(TextLayoutManager.Alignment.LEFT); - sprite.add(text); - - PastryCheckbox checkbox = new PastryCheckbox(110, 39, false); - checkbox.BUS.hook(PastryToggle.StateWillChangeEvent.class, event -> client.getNetworkHandler().sendPacket(ProjectorScreenPacket.createLightAction(event.getNewState()))); - TextLayer light = new TextLayer(8, -1,"Light"); - light.fitToText(TextFit.BOTH); - light.setTextAlignment(TextLayoutManager.Alignment.LEFT); - checkbox.add(light); - checkbox.setState(handler.getLight()); - - getMain().add(sprite); - getMain().add(checkbox); - - getMain().onLayout(() -> { - text.setX(getMain().getWidth() * 0.5 - text.getWidth() * 0.5); + } + + @Override + protected void drawBackground(DrawContext matrices, float delta, int mouseX, int mouseY) { + RenderSystem.setShaderFogColor(1.0F, 1.0F, 1.0F, 1.0F); + client.getTextureManager().bindTexture(TEXTURE); + int x = (width - backgroundWidth) / 2; + int y = (height - backgroundHeight) / 2; + matrices.drawTexture(TEXTURE, x, y, 0, 0, backgroundWidth, backgroundHeight); + } + + @Override + public void render(DrawContext matrices, int mouseX, int mouseY, float delta) { + renderBackground(matrices); + super.render(matrices, mouseX, mouseY, delta); + drawMouseoverTooltip(matrices, mouseX, mouseY); + } + + @Override + protected void init() { + super.init(); + // Center the title + titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2; + + int x = (width - backgroundWidth) / 2; + int y = (height - backgroundHeight) / 2; + + CheckboxWidget lightCheckbox = new CallbackCheckboxWidget(x + 110, y + 33, Text.of("Light"), lightsEnabled, aBoolean -> { + client.getNetworkHandler().sendPacket(ProjectorScreenPacket.createLightAction(aBoolean)); }); + addDrawable(lightCheckbox); + } public void setLights(boolean lightsEnabled) { this.lightsEnabled = lightsEnabled; + reload(); + } + + private void reload() { + this.init(MinecraftClient.getInstance(), this.width, this.height); + } + + protected static class CallbackCheckboxWidget extends CheckboxWidget { + + private final Consumer changeCallback; + + public CallbackCheckboxWidget(int x, int y, Text message, boolean checked, Consumer changeCallback) { + super(x, y, 20, 20, message, checked); + this.changeCallback = changeCallback; + } + + @Override + public void onPress() { + super.onPress(); + changeCallback.accept(isChecked()); + } } -} +} \ No newline at end of file diff --git a/src/main/java/com/mystic/holographicrenders/gui/ProjectorScreenHandler.java b/src/main/java/com/mystic/holographicrenders/gui/ProjectorScreenHandler.java index a5ff523..66019a4 100644 --- a/src/main/java/com/mystic/holographicrenders/gui/ProjectorScreenHandler.java +++ b/src/main/java/com/mystic/holographicrenders/gui/ProjectorScreenHandler.java @@ -32,7 +32,7 @@ public ProjectorScreenHandler(int syncId, PlayerInventory playerInventory, Proje public ProjectorScreenHandler(int syncId, PlayerInventory playerInventory, PacketByteBuf buffer) { super(HolographicRenders.PROJECTOR_SCREEN_HANDLER, syncId); - this.blockEntity = (ProjectorBlockEntity) playerInventory.player.world.getBlockEntity(buffer.readBlockPos()); + this.blockEntity = (ProjectorBlockEntity) playerInventory.player.getWorld().getBlockEntity(buffer.readBlockPos()); this.addSlot(new Slot(blockEntity, 0, 80 + 3, 35 + 3)); @@ -50,28 +50,7 @@ public ProjectorScreenHandler(int syncId, PlayerInventory playerInventory, Packe } @Override - public boolean canUse(PlayerEntity player) { - return blockEntity.canPlayerUse(player); - } - - public boolean getLight() { - return blockEntity.lightsEnabled(); - } - - public void setLight(boolean lights) { - if (blockEntity.getWorld().isClient) { - PacketByteBuf buf = PacketByteBufs.create(); - buf.writeBlockPos(blockEntity.getPos()); - buf.writeBoolean(lights); - ClientPlayNetworking.send(new Identifier(HolographicRenders.MOD_ID, "light_packet"), buf); - } else { - blockEntity.setLightEnabled(lights); - } - } - - // Shift + Player Inv Slot - @Override - public ItemStack transferSlot(PlayerEntity player, int invSlot) { + public ItemStack quickMove(PlayerEntity player, int invSlot) { ItemStack newStack = ItemStack.EMPTY; Slot slot = this.slots.get(invSlot); @@ -91,4 +70,25 @@ public ItemStack transferSlot(PlayerEntity player, int invSlot) { return newStack; } + + @Override + public boolean canUse(PlayerEntity player) { + return blockEntity.canPlayerUse(player); + } + + public boolean getLight() { + return blockEntity.lightsEnabled(); + } + + public void setLight(boolean lights) { + if (blockEntity.getWorld().isClient) { + PacketByteBuf buf = PacketByteBufs.create(); + buf.writeBlockPos(blockEntity.getPos()); + buf.writeBoolean(lights); + ClientPlayNetworking.send(new Identifier(HolographicRenders.MOD_ID, "light_packet"), buf); + } else { + blockEntity.setLightEnabled(lights); + } + } + } diff --git a/src/main/java/com/mystic/holographicrenders/gui/TextboxScreen.java b/src/main/java/com/mystic/holographicrenders/gui/TextboxScreen.java index bc79721..8292f33 100644 --- a/src/main/java/com/mystic/holographicrenders/gui/TextboxScreen.java +++ b/src/main/java/com/mystic/holographicrenders/gui/TextboxScreen.java @@ -1,62 +1,24 @@ package com.mystic.holographicrenders.gui; -import static com.teamwizardry.librarianlib.core.util.Shorthand.vec; +import io.github.cottonmc.cotton.gui.GuiDescription; +import io.github.cottonmc.cotton.gui.client.CottonClientScreen; +import org.lwjgl.glfw.GLFW; -import java.awt.Color; - -import com.mystic.holographicrenders.HolographicRenders; -import com.teamwizardry.librarianlib.facade.FacadeScreen; -import com.teamwizardry.librarianlib.facade.layers.InputLayout; -import com.teamwizardry.librarianlib.facade.layers.RectLayer; -import com.teamwizardry.librarianlib.facade.layers.SpriteLayer; -import com.teamwizardry.librarianlib.facade.layers.StackLayout; -import com.teamwizardry.librarianlib.facade.layers.StackLayoutBuilder; -import com.teamwizardry.librarianlib.facade.layers.TextInputLayer; -import com.teamwizardry.librarianlib.facade.pastry.layers.PastryButton; -import com.teamwizardry.librarianlib.facade.pastry.layers.PastryLabel; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Hand; -import net.minecraft.util.Identifier; - -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; - -public class TextboxScreen extends FacadeScreen { - public TextboxScreen(Hand hand) { - super(LiteralText.EMPTY); - - PastryLabel label = new PastryLabel(4, 0, "Save (PNG, JPEG, GIF) URL"); - - TextInputLayer textField = new TextInputLayer(0, 0, label.getWidthi(), 9); - SpriteLayer textFieldBackground = new SpriteLayer(Textures.textfield); - textFieldBackground.setFrame(textField.getFrame().grow(2)); - textField.setPos(vec(2,2)); - textField.getContainerLayers().get(0).setColor(Color.WHITE); - textFieldBackground.add(textField); - - PastryButton button = new PastryButton("Confirm", 4, 8, 12, 11); - button.fitLabel(); - - button.hook(PastryButton.ClickEvent.class, clickEvent -> { - PacketByteBuf buf = PacketByteBufs.create(); - buf.writeString(textField.getText().getPlaintext(), 2000); - buf.writeEnumConstant(hand); - ClientPlayNetworking.send(new Identifier(HolographicRenders.MOD_ID, "url_packet"), buf); - }); - - StackLayout layout = new StackLayoutBuilder(0,0) - .add(label, textFieldBackground, button) - .alignCenterX().alignCenterY().vertical().spacing(3).fit().build(); - - getMain().setFrame(layout.getBounds().grow(5)); - - layout.setPos(vec(5, 5)); +public class TextboxScreen extends CottonClientScreen { + public TextboxScreen(GuiDescription description) { + super(description); + } - SpriteLayer background = new SpriteLayer(Textures.projector, 0,0, getMain().getWidthi(), getMain().getHeighti()); + @Override + public void init() { + super.init(); + } - getMain().add(background); - getMain().add(layout); + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if(keyCode == GLFW.GLFW_KEY_E) { + return true; + } + return super.keyPressed(keyCode, scanCode, modifiers); } -} +} \ No newline at end of file diff --git a/src/main/java/com/mystic/holographicrenders/gui/Textures.java b/src/main/java/com/mystic/holographicrenders/gui/Textures.java index a38f031..ae5e6d1 100644 --- a/src/main/java/com/mystic/holographicrenders/gui/Textures.java +++ b/src/main/java/com/mystic/holographicrenders/gui/Textures.java @@ -1,22 +1,7 @@ package com.mystic.holographicrenders.gui; -import com.teamwizardry.librarianlib.mosaic.Mosaic; -import com.teamwizardry.librarianlib.mosaic.MosaicSprite; -import com.teamwizardry.librarianlib.mosaic.Sprite; - import net.minecraft.util.Identifier; public class Textures { - public static final MosaicSprite main; - - public static final MosaicSprite projector; - public static final MosaicSprite textfield; - - static { - final Mosaic TEXTURE = new Mosaic(new Identifier("holographic_renders", "textures/gui_hologram_projector.png"), 256,256); - - main = TEXTURE.getSprite("main"); - projector = TEXTURE.getSprite("projector"); - textfield = TEXTURE.getSprite("textfield"); - } + public static final Identifier TEXTURE = new Identifier("holographic_renders", "textures/gui_hologram_projector.png"); } diff --git a/src/main/java/com/mystic/holographicrenders/gui/WidgetScreen.java b/src/main/java/com/mystic/holographicrenders/gui/WidgetScreen.java index 70f2cc7..1af1f61 100644 --- a/src/main/java/com/mystic/holographicrenders/gui/WidgetScreen.java +++ b/src/main/java/com/mystic/holographicrenders/gui/WidgetScreen.java @@ -1,71 +1,37 @@ package com.mystic.holographicrenders.gui; -import static com.teamwizardry.librarianlib.core.util.Shorthand.vec; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - import com.mystic.holographicrenders.HolographicRenders; import com.mystic.holographicrenders.item.WidgetType; -import com.teamwizardry.librarianlib.facade.FacadeScreen; -import com.teamwizardry.librarianlib.facade.layers.SpriteLayer; -import com.teamwizardry.librarianlib.facade.layers.StackLayout; -import com.teamwizardry.librarianlib.facade.layers.StackLayoutBuilder; -import com.teamwizardry.librarianlib.facade.pastry.layers.PastryButton; -import com.teamwizardry.librarianlib.facade.pastry.layers.PastryLabel; -import com.teamwizardry.librarianlib.facade.pastry.layers.dropdown.DropdownTextItem; -import com.teamwizardry.librarianlib.facade.pastry.layers.dropdown.PastryDropdown; - -import net.minecraft.client.MinecraftClient; +import io.github.cottonmc.cotton.gui.GuiDescription; +import io.github.cottonmc.cotton.gui.client.CottonClientScreen; +import io.github.cottonmc.cotton.gui.widget.WButton; +import io.github.cottonmc.cotton.gui.widget.WGridPanel; +import io.github.cottonmc.cotton.gui.widget.WLabel; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.minecraft.network.PacketByteBuf; -import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; - -public class WidgetScreen extends FacadeScreen { +public class WidgetScreen extends CottonClientScreen { private WidgetType widget = WidgetType.Blank; - public WidgetScreen(Hand hand) { - super(LiteralText.EMPTY); - - PastryLabel label = new PastryLabel(4, 0, "Select Widget"); + public WidgetScreen(GuiDescription guiDescription, Hand hand) { + super(guiDescription); - PastryDropdown dropdown; - int width = Stream.of(WidgetType.values()).map(WidgetType::toString).mapToInt(MinecraftClient.getInstance().textRenderer::getWidth).max().orElse(300); + WGridPanel root = new WGridPanel(); + WLabel label = new WLabel(Text.literal("Select Widget")); + root.add(label, 0,0, 4, 1); - dropdown = new PastryDropdown<>(0,0, width + 15, widgetType -> widget = widgetType); + WButton button = new WButton(Text.literal("Confirm")); + root.add(button, 4, 8, 12, 11); - dropdown.getItems().addAll(Arrays.stream(WidgetType.values()).map(a -> new DropdownTextItem<>(a, a.toString())).collect(Collectors.toList())); - - dropdown.select(WidgetType.Blank); - - PastryButton button = new PastryButton("Confirm", 4, 8, 12, 11); - button.fitLabel(); - - button.hook(PastryButton.ClickEvent.class, clickEvent -> { + button.setOnClick(() -> { PacketByteBuf buf = PacketByteBufs.create(); buf.writeEnumConstant(hand); buf.writeEnumConstant(widget); ClientPlayNetworking.send(new Identifier(HolographicRenders.MOD_ID, "widget_packet"), buf); }); - - StackLayout layout = new StackLayoutBuilder(0,0) - .add(label, dropdown, button) - .alignCenterX().alignCenterY().vertical().spacing(3).fit().build(); - - getMain().setFrame(layout.getBounds().grow(5)); - - layout.setPos(vec(5, 5)); - - SpriteLayer background = new SpriteLayer(Textures.projector, 0,0, getMain().getWidthi(), getMain().getHeighti()); - - getMain().add(background); - getMain().add(layout); } } diff --git a/src/main/java/com/mystic/holographicrenders/item/AreaScannerItem.java b/src/main/java/com/mystic/holographicrenders/item/AreaScannerItem.java index f1b93b6..93f5e7c 100644 --- a/src/main/java/com/mystic/holographicrenders/item/AreaScannerItem.java +++ b/src/main/java/com/mystic/holographicrenders/item/AreaScannerItem.java @@ -1,6 +1,5 @@ package com.mystic.holographicrenders.item; -import com.mystic.holographicrenders.HolographicRenders; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; @@ -20,7 +19,7 @@ public class AreaScannerItem extends Item { public AreaScannerItem() { - super(new Settings().maxCount(1).group(HolographicRenders.HOLOGRAPHIC_RENDERS_CREATIVE_TAB)); + super(new Settings().maxCount(1)); } @Override diff --git a/src/main/java/com/mystic/holographicrenders/item/EntityScannerItem.java b/src/main/java/com/mystic/holographicrenders/item/EntityScannerItem.java index 07fdbb8..0302ee9 100644 --- a/src/main/java/com/mystic/holographicrenders/item/EntityScannerItem.java +++ b/src/main/java/com/mystic/holographicrenders/item/EntityScannerItem.java @@ -1,26 +1,15 @@ package com.mystic.holographicrenders.item; -import com.mystic.holographicrenders.HolographicRenders; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; import net.minecraft.registry.Registries; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.text.TextContent; -import net.minecraft.text.TranslatableText; import net.minecraft.util.*; -import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -29,7 +18,7 @@ public class EntityScannerItem extends Item { public EntityScannerItem() { - super(new Settings().maxCount(1).group(HolographicRenders.HOLOGRAPHIC_RENDERS_CREATIVE_TAB)); + super(new Settings().maxCount(1)); } @Nullable diff --git a/src/main/java/com/mystic/holographicrenders/item/TextureScannerItem.java b/src/main/java/com/mystic/holographicrenders/item/TextureScannerItem.java index e82d96a..3aa64e1 100644 --- a/src/main/java/com/mystic/holographicrenders/item/TextureScannerItem.java +++ b/src/main/java/com/mystic/holographicrenders/item/TextureScannerItem.java @@ -1,15 +1,11 @@ package com.mystic.holographicrenders.item; import com.mystic.holographicrenders.Common; -import com.mystic.holographicrenders.HolographicRenders; -import com.mystic.holographicrenders.gui.TextboxScreen; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; -import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; @@ -22,12 +18,11 @@ public class TextureScannerItem extends Item { public TextureScannerItem() { - super(new Settings().maxCount(1).group(HolographicRenders.HOLOGRAPHIC_RENDERS_CREATIVE_TAB)); + super(new Settings().maxCount(1)); } @Override public TypedActionResult use(World world, PlayerEntity player, Hand hand) { - ItemStack itemStack = player.getStackInHand(hand); if (world.isClient && Common.textScreenRunnable != null) { @@ -41,9 +36,9 @@ public TypedActionResult use(World world, PlayerEntity player, Hand h public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { NbtCompound tag = stack.getOrCreateNbt(); if(tag.contains("URL")) { - tooltip.add(new LiteralText("URL: ").formatted(Formatting.GREEN).append(new LiteralText(tag.getString("URL")).formatted(Formatting.YELLOW))); + tooltip.add(Text.literal("URL: ").formatted(Formatting.GREEN).append(Text.literal(tag.getString("URL")).formatted(Formatting.YELLOW))); } else { - tooltip.add(new LiteralText("Empty")); + tooltip.add(Text.literal("Empty")); } } } \ No newline at end of file diff --git a/src/main/java/com/mystic/holographicrenders/item/WidgetScannerItem.java b/src/main/java/com/mystic/holographicrenders/item/WidgetScannerItem.java index b31d635..4bfb615 100644 --- a/src/main/java/com/mystic/holographicrenders/item/WidgetScannerItem.java +++ b/src/main/java/com/mystic/holographicrenders/item/WidgetScannerItem.java @@ -11,7 +11,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; -import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; @@ -21,7 +20,7 @@ public class WidgetScannerItem extends Item { public WidgetScannerItem() { - super(new Settings().maxCount(1).group(HolographicRenders.HOLOGRAPHIC_RENDERS_CREATIVE_TAB)); + super(new Settings().maxCount(1)); } @Override @@ -40,9 +39,9 @@ public TypedActionResult use(World world, PlayerEntity player, Hand h public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { NbtCompound tag = stack.getOrCreateNbt(); if(tag.contains("Widget")) { - tooltip.add(new LiteralText("Widget: ").formatted(Formatting.GREEN).append(new LiteralText(WidgetType.fromId(tag.getInt("Widget")).toString()).formatted(Formatting.YELLOW))); + tooltip.add(Text.literal("Widget: ").formatted(Formatting.GREEN).append(Text.literal(WidgetType.fromId(tag.getInt("Widget")).toString()).formatted(Formatting.YELLOW))); } else { - tooltip.add(new LiteralText("Empty")); + tooltip.add(Text.literal("Empty")); } } } \ No newline at end of file diff --git a/src/main/java/com/mystic/holographicrenders/mixin/ArmorStandMixin.java b/src/main/java/com/mystic/holographicrenders/mixin/ArmorStandMixin.java index 9879d0c..5eba434 100644 --- a/src/main/java/com/mystic/holographicrenders/mixin/ArmorStandMixin.java +++ b/src/main/java/com/mystic/holographicrenders/mixin/ArmorStandMixin.java @@ -1,9 +1,7 @@ package com.mystic.holographicrenders.mixin; import com.mystic.holographicrenders.HolographicRenders; -import com.mystic.holographicrenders.item.EntityScannerItem; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.player.PlayerEntity; @@ -14,6 +12,7 @@ import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -23,7 +22,8 @@ public abstract class ArmorStandMixin { @Shadow public abstract boolean isMarker(); - @Shadow protected abstract EquipmentSlot slotFromPosition(Vec3d vec3d); + @Unique + protected abstract EquipmentSlot slotFromPosition(Vec3d vec3d); @Shadow protected abstract boolean isSlotDisabled(EquipmentSlot slot); @@ -40,7 +40,7 @@ public void interactAt(PlayerEntity player, Vec3d hitPos, Hand hand, CallbackInf if (!this.isMarker() && itemStack.getItem() != Items.NAME_TAG) { if (player.isSpectator()) { cir.setReturnValue(ActionResult.SUCCESS); - } else if (player.world.isClient) { + } else if (player.getWorld().isClient) { cir.setReturnValue(ActionResult.CONSUME); } else { EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(itemStack); diff --git a/src/main/java/com/mystic/holographicrenders/mixin/WorldRendererMixin.java b/src/main/java/com/mystic/holographicrenders/mixin/WorldRendererMixin.java index 185f91f..6b5ff29 100644 --- a/src/main/java/com/mystic/holographicrenders/mixin/WorldRendererMixin.java +++ b/src/main/java/com/mystic/holographicrenders/mixin/WorldRendererMixin.java @@ -10,7 +10,7 @@ import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; -import net.minecraft.util.math.Matrix4f; +import org.joml.Matrix4f; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -21,7 +21,7 @@ public class WorldRendererMixin { @Inject(method = "render", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;crosshairTarget:Lnet/minecraft/util/hit/HitResult;", opcode = Opcodes.GETFIELD, ordinal = 1)) - public void drawAreaSelection(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) { + public void drawAreaSelection(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f projectionMatrix, CallbackInfo ci) { final MinecraftClient client = MinecraftClient.getInstance(); final ClientPlayerEntity player = client.player; if (player.getMainHandStack().getItem() != HolographicRenders.AREA_SCANNER) return; @@ -33,7 +33,7 @@ public void drawAreaSelection(MatrixStack matrices, float tickDelta, long limitT BlockPos origin = BlockPos.fromLong(tag.getLong("Pos1")); HitResult result = player.raycast(player.getAbilities().creativeMode ? 5.0F : 4.5F, 0, false); - BlockPos size = tag.contains("Pos2") ? BlockPos.fromLong(tag.getLong("Pos2")) : (result instanceof BlockHitResult ? ((BlockHitResult) result).getBlockPos() : new BlockPos(result.getPos())); + BlockPos size = tag.contains("Pos2") ? BlockPos.fromLong(tag.getLong("Pos2")) : (result instanceof BlockHitResult ? ((BlockHitResult) result).getBlockPos() : new BlockPos((int) result.getPos().x, (int) result.getPos().y, (int) result.getPos().z)); size = size.subtract(origin); origin = origin.add(size.getX() < 0 ? 1 : 0, size.getY() < 0 ? 1 : 0, size.getZ() < 0 ? 1 : 0); diff --git a/src/main/java/com/mystic/holographicrenders/network/ProjectorScreenPacket.java b/src/main/java/com/mystic/holographicrenders/network/ProjectorScreenPacket.java index 342b645..275de2f 100644 --- a/src/main/java/com/mystic/holographicrenders/network/ProjectorScreenPacket.java +++ b/src/main/java/com/mystic/holographicrenders/network/ProjectorScreenPacket.java @@ -9,8 +9,8 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.Packet; import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.Packet; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity;