Skip to content

Commit 7f35f27

Browse files
committed
fix errors
1 parent 882b397 commit 7f35f27

File tree

5 files changed

+43
-33
lines changed

5 files changed

+43
-33
lines changed

src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.cleanroommc.modularui.factory;
22

3-
import com.cleanroommc.modularui.ModularUI;
43
import com.cleanroommc.modularui.api.JeiSettings;
54
import com.cleanroommc.modularui.api.UIFactory;
5+
import com.cleanroommc.modularui.holoui.HoloScreenEntity;
66
import com.cleanroommc.modularui.holoui.HoloUI;
77
import com.cleanroommc.modularui.holoui.ScreenEntityRender;
88
import com.cleanroommc.modularui.network.NetworkHandler;
99
import com.cleanroommc.modularui.network.packets.OpenGuiPacket;
10-
import com.cleanroommc.modularui.network.packets.SyncHoloPacket;
1110
import com.cleanroommc.modularui.screen.*;
1211
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
1312
import com.cleanroommc.modularui.widget.WidgetTree;
@@ -29,6 +28,8 @@
2928
import io.netty.buffer.Unpooled;
3029
import org.jetbrains.annotations.NotNull;
3130

31+
import java.util.List;
32+
3233
public class HoloGuiManager extends GuiManager {
3334

3435

@@ -40,23 +41,27 @@ public static <T extends GuiData> void open(@NotNull UIFactory<T> factory, @NotN
4041
guiData.setJeiSettings(JeiSettings.DUMMY);
4142
PanelSyncManager syncManager = new PanelSyncManager();
4243
ModularPanel panel = factory.createPanel(guiData, syncManager);
43-
if (HoloUI.isOpen(panel)) {
44-
HoloUI.builder()
44+
List<HoloScreenEntity> screens = player.world.getEntities(HoloScreenEntity.class, entity -> entity.isName(panel.getName()));
45+
if (!screens.isEmpty()) {
46+
for (HoloScreenEntity screen : screens) {
47+
screen.setDead();
48+
}
49+
/*HoloUI.builder()
4550
.inFrontOf(player, 5, true)
46-
.reposition(panel.getName(), player);
51+
.reposition(player, screens);
4752
NetworkHandler.sendToPlayer(new SyncHoloPacket(panel.getName()), player);
4853
ModularUI.LOGGER.warn("reposition the holo, sync to client");
49-
return;
54+
return;*/
5055
}
5156
WidgetTree.collectSyncValues(syncManager, panel);
52-
ModularContainer container = new ModularContainer(null);
57+
ModularContainer container = new ModularContainer(player, syncManager, panel.getName());
5358
HoloUI.builder()
5459
.screenScale(0.5f)
5560
.inFrontOf(player, 5, true)
5661
.open(screen -> {
5762
screen.setContainer(container);
5863
screen.setPanel(panel);
59-
HoloUI.registerSyncedHoloUI(panel, screen);
64+
//HoloUI.registerSyncedHoloUI(panel, screen);
6065
}, player.getEntityWorld());
6166
// sync to client
6267
// player.getNextWindowId();
@@ -83,7 +88,7 @@ public static <T extends GuiData> void open(int windowId, @NotNull UIFactory<T>
8388
WidgetTree.collectSyncValues(syncManager, panel);
8489
ModularScreen screen = factory.createScreen(guiData, panel);
8590
screen.getContext().setJeiSettings(jeiSettings);
86-
GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(null), screen);
91+
GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(player, syncManager, panel.getName()), screen);
8792
guiScreenWrapper.inventorySlots.windowId = windowId;
8893
HoloUI.builder()
8994
// .screenScale(0.25f)
@@ -92,15 +97,15 @@ public static <T extends GuiData> void open(int windowId, @NotNull UIFactory<T>
9297
.open(screen1 -> {
9398
screen1.setPanel(panel);
9499
screen1.setWrapper(guiScreenWrapper);
95-
HoloUI.registerSyncedHoloUI(panel, screen1);
100+
//HoloUI.registerSyncedHoloUI(panel, screen1);
96101
}, player.getEntityWorld());
97102
}
98103

99104
public static void reposition(String panel, EntityPlayer player) {
100105
HoloUI.builder()
101106
// .screenScale(0.25f)
102107
.inFrontOf(player, 5, true)
103-
.reposition(panel, player);
108+
.reposition(player, player.world.getEntities(HoloScreenEntity.class, entity -> entity.isName(panel)));
104109
}
105110

106111
//todo make this a mixin instead of using event to cancel arm animation stuff

src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.cleanroommc.modularui.holoui;
22

3-
import com.cleanroommc.modularui.screen.*;
3+
import com.cleanroommc.modularui.screen.GuiScreenWrapper;
4+
import com.cleanroommc.modularui.screen.ModularContainer;
5+
import com.cleanroommc.modularui.screen.ModularPanel;
6+
import com.cleanroommc.modularui.screen.ModularScreen;
47

58
import net.minecraft.block.Block;
69
import net.minecraft.client.Minecraft;
@@ -75,6 +78,11 @@ public ScreenOrientation getOrientation() {
7578
return ScreenOrientation.values()[this.dataManager.get(ORIENTATION)];
7679
}
7780

81+
public boolean isName(String name) {
82+
if (this.panel == null) return false;
83+
return this.panel.getName().equals(name);
84+
}
85+
7886
public Plane3D getPlane3D() {
7987
return this.plane3D;
8088
}

src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package com.cleanroommc.modularui.holoui;
22

3-
import com.cleanroommc.modularui.screen.ModularPanel;
4-
53
import net.minecraft.entity.player.EntityPlayer;
64
import net.minecraft.util.math.BlockPos;
75
import net.minecraft.util.math.Vec3d;
86
import net.minecraft.world.World;
97

10-
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
118
import org.jetbrains.annotations.ApiStatus;
129

13-
import java.util.Map;
10+
import java.util.Collection;
1411
import java.util.function.Consumer;
1512

1613
/**
@@ -19,16 +16,6 @@
1916
@ApiStatus.Experimental
2017
public class HoloUI {
2118

22-
private static final Map<String, HoloScreenEntity> syncedHolos = new Object2ObjectOpenHashMap<>();
23-
24-
public static void registerSyncedHoloUI(ModularPanel mainPanel, HoloScreenEntity entity) {
25-
syncedHolos.put(mainPanel.getName(), entity);
26-
}
27-
28-
public static boolean isOpen(ModularPanel panel) {
29-
return syncedHolos.containsKey(panel.getName());
30-
}
31-
3219
public static Builder builder() {
3320
return new Builder();
3421
}
@@ -108,13 +95,14 @@ public void open(Consumer<HoloScreenEntity> entityConsumer, World world) {
10895
// holoScreenEntity.setOrientation(this.orientation);
10996
}
11097

111-
public void reposition(String name, EntityPlayer player) {
112-
var screen = syncedHolos.get(name);
113-
screen.setPosition(this.x, this.y, this.z);
114-
screen.setOrientation(this.orientation);
115-
if (player.world.isRemote){
116-
var vec = screen.getPositionVector().subtract(player.getPositionVector());
117-
screen.getPlane3D().setNormal((float) -vec.x, 0, (float) -vec.z);
98+
public void reposition(EntityPlayer player, Collection<HoloScreenEntity> screens) {
99+
for (HoloScreenEntity screen : screens) {
100+
screen.setPosition(this.x, this.y, this.z);
101+
screen.setOrientation(this.orientation);
102+
if (player.world.isRemote) {
103+
var vec = screen.getPositionVector().subtract(player.getPositionVector());
104+
screen.getPlane3D().setNormal((float) -vec.x, 0, (float) -vec.z);
105+
}
118106
}
119107
}
120108
}

src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
public class TestHoloItem extends TestItem {
1616

1717
public static final TestHoloItem testHoloItem = new TestHoloItem();
18+
19+
public TestHoloItem() {
20+
setTranslationKey("mui.test_holo");
21+
}
22+
1823
@NotNull
1924
@Override
2025
public ActionResult<ItemStack> onItemRightClick(World world, @NotNull EntityPlayer player, @NotNull EnumHand hand) {

src/main/java/com/cleanroommc/modularui/test/TestItem.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public class TestItem extends Item implements IGuiHolder<HandGuiData> {
3737

3838
public static final TestItem testItem = new TestItem();
3939

40+
public TestItem() {
41+
setTranslationKey("mui.test");
42+
}
43+
4044
@Override
4145
public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager) {
4246
IItemHandlerModifiable itemHandler = (IItemHandlerModifiable) guiData.getUsedItemStack().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

0 commit comments

Comments
 (0)