|
1 | 1 | package com.cleanroommc.modularui.holoui; |
2 | 2 |
|
3 | | -import com.cleanroommc.modularui.screen.GuiScreenWrapper; |
4 | 3 | import com.cleanroommc.modularui.screen.ModularPanel; |
5 | 4 |
|
6 | | -import net.minecraft.client.Minecraft; |
7 | 5 | import net.minecraft.entity.player.EntityPlayer; |
8 | | -import net.minecraft.util.ResourceLocation; |
9 | 6 | import net.minecraft.util.math.BlockPos; |
10 | 7 | import net.minecraft.util.math.Vec3d; |
| 8 | +import net.minecraft.world.World; |
11 | 9 |
|
12 | 10 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; |
13 | 11 | import org.jetbrains.annotations.ApiStatus; |
14 | | -import org.jetbrains.annotations.Nullable; |
15 | 12 |
|
16 | 13 | import java.util.Map; |
| 14 | +import java.util.function.Consumer; |
17 | 15 |
|
18 | 16 | /** |
19 | 17 | * Highly experimental |
20 | 18 | */ |
21 | 19 | @ApiStatus.Experimental |
22 | 20 | public class HoloUI { |
23 | 21 |
|
24 | | - private final Map<ResourceLocation, Data> syncedHolos = new Object2ObjectOpenHashMap<>(); |
25 | | - private static final HoloUI INSTANCE = new HoloUI(); |
| 22 | + private static final Map<String, HoloScreenEntity> syncedHolos = new Object2ObjectOpenHashMap<>(); |
26 | 23 |
|
27 | | - public static void registerSyncedHoloUI(ResourceLocation loc, ModularPanel mainPanel, GuiScreenWrapper screenWrapperSupplier) { |
28 | | - var old = INSTANCE.register(loc, mainPanel, screenWrapperSupplier); |
29 | | -// if (old != null && old.getPanel() != null) { |
30 | | -// old.getPanel().closeIfOpen(true); |
31 | | -// } |
| 24 | + public static void registerSyncedHoloUI(ModularPanel mainPanel, HoloScreenEntity entity) { |
| 25 | + syncedHolos.put(mainPanel.getName(), entity); |
32 | 26 | } |
33 | 27 |
|
34 | | - private Data register(ResourceLocation location, ModularPanel panelSupplier, GuiScreenWrapper screenWrapperSupplier) { |
35 | | - return this.syncedHolos.put(location, new Data(panelSupplier, screenWrapperSupplier)); |
| 28 | + public static boolean isOpen(ModularPanel panel) { |
| 29 | + return syncedHolos.containsKey(panel.getName()); |
36 | 30 | } |
37 | 31 |
|
38 | 32 | public static Builder builder() { |
@@ -97,40 +91,27 @@ public Builder plane(Plane3D plane) { |
97 | 91 | return this; |
98 | 92 | } |
99 | 93 |
|
100 | | - public void open(GuiScreenWrapper wrapper) { |
| 94 | + public void open(Consumer<HoloScreenEntity> entityConsumer, World world) { |
101 | 95 | // JeiSettingsImpl jeiSettings = new JeiSettingsImpl(); |
102 | 96 | // jeiSettings.disableJei(); |
103 | 97 | // screen.getContext().setJeiSettings(jeiSettings); |
104 | | - wrapper.getScreen().getContext().isHoloScreen = true; |
105 | | - HoloScreenEntity holoScreenEntity = new HoloScreenEntity(Minecraft.getMinecraft().world, this.plane3D); |
106 | | - holoScreenEntity.setPosition(this.x, this.y, this.z); |
107 | | - holoScreenEntity.setWrapper(wrapper); |
108 | | - holoScreenEntity.spawnInWorld(); |
109 | | - holoScreenEntity.setOrientation(this.orientation); |
110 | | - } |
111 | | - } |
112 | | - |
113 | | - public static class Data { |
114 | | - private final ModularPanel panelSupplier; |
115 | | - @Nullable |
116 | | - private final GuiScreenWrapper screenWrapperSupplier; |
117 | | - |
118 | | - Data(ModularPanel panelSupplier, GuiScreenWrapper screenWrapperSupplier) { |
119 | | - this.panelSupplier = panelSupplier; |
120 | | - this.screenWrapperSupplier = screenWrapperSupplier; |
121 | | - } |
122 | | - |
123 | | - Data(ModularPanel panelSupplier) { |
124 | | - this.panelSupplier = panelSupplier; |
125 | | - this.screenWrapperSupplier = null; |
126 | | - } |
127 | 98 |
|
128 | | - public ModularPanel getPanel() { |
129 | | - return panelSupplier; |
| 99 | +// wrapper.getScreen().getContext().isHoloScreen = true; |
| 100 | + HoloScreenEntity screen = new HoloScreenEntity(world, this.plane3D); |
| 101 | + screen.setPosition(this.x, this.y, this.z); |
| 102 | + screen.setOrientation(this.orientation); |
| 103 | + entityConsumer.accept(screen); |
| 104 | + screen.spawnInWorld(); |
| 105 | +// holoScreenEntity.setPosition(this.x, this.y, this.z); |
| 106 | +// holoScreenEntity.setWrapper(wrapper); |
| 107 | +// holoScreenEntity.spawnInWorld(); |
| 108 | +// holoScreenEntity.setOrientation(this.orientation); |
130 | 109 | } |
131 | 110 |
|
132 | | - public GuiScreenWrapper getScreenWrapper() { |
133 | | - return screenWrapperSupplier; |
| 111 | + public void reposition(String name) { |
| 112 | + var screen = syncedHolos.get(name); |
| 113 | + screen.setPosition(this.x, this.y, this.z); |
| 114 | + screen.setOrientation(this.orientation); |
134 | 115 | } |
135 | 116 | } |
136 | 117 | } |
0 commit comments