Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 authored and ghzdude committed Jul 15, 2024
1 parent f87db35 commit d4f36d8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
27 changes: 16 additions & 11 deletions src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -29,6 +28,8 @@
import io.netty.buffer.Unpooled;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class HoloGuiManager extends GuiManager {


Expand All @@ -40,23 +41,27 @@ public static <T extends GuiData> void open(@NotNull UIFactory<T> factory, @NotN
guiData.setJeiSettings(JeiSettings.DUMMY);
PanelSyncManager syncManager = new PanelSyncManager();
ModularPanel panel = factory.createPanel(guiData, syncManager);
if (HoloUI.isOpen(panel)) {
HoloUI.builder()
List<HoloScreenEntity> 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();
Expand All @@ -83,7 +88,7 @@ public static <T extends GuiData> void open(int windowId, @NotNull UIFactory<T>
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)
Expand All @@ -92,15 +97,15 @@ public static <T extends GuiData> void open(int windowId, @NotNull UIFactory<T>
.open(screen1 -> {
screen1.setPanel(panel);
screen1.setWrapper(guiScreenWrapper);
HoloUI.registerSyncedHoloUI(panel, screen1);
//HoloUI.registerSyncedHoloUI(panel, screen1);
}, player.getEntityWorld());
}

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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
30 changes: 9 additions & 21 deletions src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -19,16 +16,6 @@
@ApiStatus.Experimental
public class HoloUI {

private static final Map<String, HoloScreenEntity> 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();
}
Expand Down Expand Up @@ -108,13 +95,14 @@ public void open(Consumer<HoloScreenEntity> 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<HoloScreenEntity> 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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> onItemRightClick(World world, @NotNull EntityPlayer player, @NotNull EnumHand hand) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/cleanroommc/modularui/test/TestItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class TestItem extends Item implements IGuiHolder<HandGuiData> {

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);
Expand Down

0 comments on commit d4f36d8

Please sign in to comment.