From 7f35f27b809193e182eb3062b6310dd9e191aaa5 Mon Sep 17 00:00:00 2001 From: brachy84 Date: Sun, 7 Jul 2024 13:25:07 +0200 Subject: [PATCH] fix errors --- .../modularui/factory/HoloGuiManager.java | 27 ++++++++++------- .../modularui/holoui/HoloScreenEntity.java | 10 ++++++- .../cleanroommc/modularui/holoui/HoloUI.java | 30 ++++++------------- .../modularui/test/TestHoloItem.java | 5 ++++ .../cleanroommc/modularui/test/TestItem.java | 4 +++ 5 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index c20e358e..fa9044e1 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -1,13 +1,12 @@ package com.cleanroommc.modularui.factory; -import com.cleanroommc.modularui.ModularUI; import com.cleanroommc.modularui.api.JeiSettings; import com.cleanroommc.modularui.api.UIFactory; +import com.cleanroommc.modularui.holoui.HoloScreenEntity; import com.cleanroommc.modularui.holoui.HoloUI; import com.cleanroommc.modularui.holoui.ScreenEntityRender; import com.cleanroommc.modularui.network.NetworkHandler; import com.cleanroommc.modularui.network.packets.OpenGuiPacket; -import com.cleanroommc.modularui.network.packets.SyncHoloPacket; import com.cleanroommc.modularui.screen.*; import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.widget.WidgetTree; @@ -29,6 +28,8 @@ import io.netty.buffer.Unpooled; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class HoloGuiManager extends GuiManager { @@ -40,23 +41,27 @@ public static void open(@NotNull UIFactory factory, @NotN guiData.setJeiSettings(JeiSettings.DUMMY); PanelSyncManager syncManager = new PanelSyncManager(); ModularPanel panel = factory.createPanel(guiData, syncManager); - if (HoloUI.isOpen(panel)) { - HoloUI.builder() + List screens = player.world.getEntities(HoloScreenEntity.class, entity -> entity.isName(panel.getName())); + if (!screens.isEmpty()) { + for (HoloScreenEntity screen : screens) { + screen.setDead(); + } + /*HoloUI.builder() .inFrontOf(player, 5, true) - .reposition(panel.getName(), player); + .reposition(player, screens); NetworkHandler.sendToPlayer(new SyncHoloPacket(panel.getName()), player); ModularUI.LOGGER.warn("reposition the holo, sync to client"); - return; + return;*/ } WidgetTree.collectSyncValues(syncManager, panel); - ModularContainer container = new ModularContainer(null); + ModularContainer container = new ModularContainer(player, syncManager, panel.getName()); HoloUI.builder() .screenScale(0.5f) .inFrontOf(player, 5, true) .open(screen -> { screen.setContainer(container); screen.setPanel(panel); - HoloUI.registerSyncedHoloUI(panel, screen); + //HoloUI.registerSyncedHoloUI(panel, screen); }, player.getEntityWorld()); // sync to client // player.getNextWindowId(); @@ -83,7 +88,7 @@ public static void open(int windowId, @NotNull UIFactory WidgetTree.collectSyncValues(syncManager, panel); ModularScreen screen = factory.createScreen(guiData, panel); screen.getContext().setJeiSettings(jeiSettings); - GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(null), screen); + GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(player, syncManager, panel.getName()), screen); guiScreenWrapper.inventorySlots.windowId = windowId; HoloUI.builder() // .screenScale(0.25f) @@ -92,7 +97,7 @@ public static void open(int windowId, @NotNull UIFactory .open(screen1 -> { screen1.setPanel(panel); screen1.setWrapper(guiScreenWrapper); - HoloUI.registerSyncedHoloUI(panel, screen1); + //HoloUI.registerSyncedHoloUI(panel, screen1); }, player.getEntityWorld()); } @@ -100,7 +105,7 @@ public static void reposition(String panel, EntityPlayer player) { HoloUI.builder() // .screenScale(0.25f) .inFrontOf(player, 5, true) - .reposition(panel, player); + .reposition(player, player.world.getEntities(HoloScreenEntity.class, entity -> entity.isName(panel))); } //todo make this a mixin instead of using event to cancel arm animation stuff diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index 17cca24e..c574fc25 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -1,6 +1,9 @@ package com.cleanroommc.modularui.holoui; -import com.cleanroommc.modularui.screen.*; +import com.cleanroommc.modularui.screen.GuiScreenWrapper; +import com.cleanroommc.modularui.screen.ModularContainer; +import com.cleanroommc.modularui.screen.ModularPanel; +import com.cleanroommc.modularui.screen.ModularScreen; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -75,6 +78,11 @@ public ScreenOrientation getOrientation() { return ScreenOrientation.values()[this.dataManager.get(ORIENTATION)]; } + public boolean isName(String name) { + if (this.panel == null) return false; + return this.panel.getName().equals(name); + } + public Plane3D getPlane3D() { return this.plane3D; } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index c03f4fca..946a649d 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -1,16 +1,13 @@ package com.cleanroommc.modularui.holoui; -import com.cleanroommc.modularui.screen.ModularPanel; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.ApiStatus; -import java.util.Map; +import java.util.Collection; import java.util.function.Consumer; /** @@ -19,16 +16,6 @@ @ApiStatus.Experimental public class HoloUI { - private static final Map syncedHolos = new Object2ObjectOpenHashMap<>(); - - public static void registerSyncedHoloUI(ModularPanel mainPanel, HoloScreenEntity entity) { - syncedHolos.put(mainPanel.getName(), entity); - } - - public static boolean isOpen(ModularPanel panel) { - return syncedHolos.containsKey(panel.getName()); - } - public static Builder builder() { return new Builder(); } @@ -108,13 +95,14 @@ public void open(Consumer entityConsumer, World world) { // holoScreenEntity.setOrientation(this.orientation); } - public void reposition(String name, EntityPlayer player) { - var screen = syncedHolos.get(name); - screen.setPosition(this.x, this.y, this.z); - screen.setOrientation(this.orientation); - if (player.world.isRemote){ - var vec = screen.getPositionVector().subtract(player.getPositionVector()); - screen.getPlane3D().setNormal((float) -vec.x, 0, (float) -vec.z); + public void reposition(EntityPlayer player, Collection screens) { + for (HoloScreenEntity screen : screens) { + screen.setPosition(this.x, this.y, this.z); + screen.setOrientation(this.orientation); + if (player.world.isRemote) { + var vec = screen.getPositionVector().subtract(player.getPositionVector()); + screen.getPlane3D().setNormal((float) -vec.x, 0, (float) -vec.z); + } } } } diff --git a/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java index 30bfb738..6d766c92 100644 --- a/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java +++ b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java @@ -15,6 +15,11 @@ public class TestHoloItem extends TestItem { public static final TestHoloItem testHoloItem = new TestHoloItem(); + + public TestHoloItem() { + setTranslationKey("mui.test_holo"); + } + @NotNull @Override public ActionResult onItemRightClick(World world, @NotNull EntityPlayer player, @NotNull EnumHand hand) { diff --git a/src/main/java/com/cleanroommc/modularui/test/TestItem.java b/src/main/java/com/cleanroommc/modularui/test/TestItem.java index 04d3b2db..15e8f9f8 100644 --- a/src/main/java/com/cleanroommc/modularui/test/TestItem.java +++ b/src/main/java/com/cleanroommc/modularui/test/TestItem.java @@ -37,6 +37,10 @@ public class TestItem extends Item implements IGuiHolder { public static final TestItem testItem = new TestItem(); + public TestItem() { + setTranslationKey("mui.test"); + } + @Override public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager) { IItemHandlerModifiable itemHandler = (IItemHandlerModifiable) guiData.getUsedItemStack().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);