Skip to content

Commit db20a22

Browse files
committed
mostly working reposition
1 parent b428b91 commit db20a22

4 files changed

Lines changed: 58 additions & 2 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
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;
1011
import com.cleanroommc.modularui.screen.*;
1112
import com.cleanroommc.modularui.value.sync.GuiSyncManager;
1213
import com.cleanroommc.modularui.widget.WidgetTree;
1314

1415
import net.minecraft.client.Minecraft;
1516
import net.minecraft.client.entity.EntityPlayerSP;
17+
import net.minecraft.entity.player.EntityPlayer;
1618
import net.minecraft.entity.player.EntityPlayerMP;
1719
import net.minecraft.network.PacketBuffer;
1820
import net.minecraftforge.client.event.GuiOpenEvent;
@@ -41,7 +43,8 @@ public static <T extends GuiData> void open(@NotNull UIFactory<T> factory, @NotN
4143
if (HoloUI.isOpen(panel)) {
4244
HoloUI.builder()
4345
.inFrontOf(player, 5, true)
44-
.reposition(panel.getName());
46+
.reposition(panel.getName(), player);
47+
NetworkHandler.sendToPlayer(new SyncHoloPacket(panel.getName()), player);
4548
ModularUI.LOGGER.warn("reposition the holo, sync to client");
4649
return;
4750
}
@@ -91,6 +94,13 @@ public static <T extends GuiData> void open(int windowId, @NotNull UIFactory<T>
9194
}, player.getEntityWorld());
9295
}
9396

97+
public static void reposition(String panel, EntityPlayer player) {
98+
HoloUI.builder()
99+
// .screenScale(0.25f)
100+
.inFrontOf(player, 5, true)
101+
.reposition(panel, player);
102+
}
103+
94104
//todo make this a mixin instead of using event to cancel arm animation stuff
95105
@SideOnly(Side.CLIENT)
96106
@SubscribeEvent

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,14 @@ public void open(Consumer<HoloScreenEntity> entityConsumer, World world) {
108108
// holoScreenEntity.setOrientation(this.orientation);
109109
}
110110

111-
public void reposition(String name) {
111+
public void reposition(String name, EntityPlayer player) {
112112
var screen = syncedHolos.get(name);
113113
screen.setPosition(this.x, this.y, this.z);
114114
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);
118+
}
115119
}
116120
}
117121
}

src/main/java/com/cleanroommc/modularui/network/NetworkHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static void init() {
2525
registerC2S(PacketSyncHandler.class);
2626
registerC2S(SyncConfig.class);
2727
registerS2C(OpenGuiPacket.class);
28+
registerS2C(SyncHoloPacket.class);
2829
//registerC2S(OpenGuiHandshake.class);
2930
}
3031

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.cleanroommc.modularui.network.packets;
2+
3+
import com.cleanroommc.modularui.factory.HoloGuiManager;
4+
import com.cleanroommc.modularui.network.IPacket;
5+
6+
import com.cleanroommc.modularui.network.NetworkUtils;
7+
8+
import net.minecraft.client.Minecraft;
9+
import net.minecraft.client.network.NetHandlerPlayClient;
10+
import net.minecraft.network.PacketBuffer;
11+
12+
import org.jetbrains.annotations.Nullable;
13+
14+
import java.io.IOException;
15+
16+
public class SyncHoloPacket implements IPacket {
17+
18+
String panel;
19+
20+
public SyncHoloPacket() {}
21+
22+
public SyncHoloPacket(String panel) {
23+
this.panel = panel;
24+
}
25+
26+
@Override
27+
public void write(PacketBuffer buf) throws IOException {
28+
NetworkUtils.writeStringSafe(buf, this.panel);
29+
}
30+
31+
@Override
32+
public void read(PacketBuffer buf) throws IOException {
33+
this.panel = NetworkUtils.readStringSafe(buf);
34+
}
35+
36+
@Override
37+
public @Nullable IPacket executeClient(NetHandlerPlayClient handler) {
38+
HoloGuiManager.reposition(this.panel, Minecraft.getMinecraft().player);
39+
return null;
40+
}
41+
}

0 commit comments

Comments
 (0)