Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Holo UI #58

Draft
wants to merge 46 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
234e2a4
first working in world screen
brachy84 May 27, 2023
315e012
replace scissor with stencil masks
brachy84 May 28, 2023
0bef1f2
fixes and rename stuff
brachy84 May 28, 2023
db31c67
holo ui's can face any direction... somewhat
brachy84 Jun 1, 2023
f925ad2
move some stuff to GuiUtils & experimental annotations
brachy84 Jun 18, 2023
b14106a
try move to quaternion
ghzdude Feb 24, 2024
761700d
set normals
ghzdude Feb 24, 2024
ebabfda
fix in world transforms
ghzdude Feb 24, 2024
03d6e8a
add some comments
ghzdude Feb 24, 2024
e658da2
flip cardinal directions to match minecraft
ghzdude Feb 24, 2024
22ffe0e
merge if checks
ghzdude Feb 24, 2024
86a6e3c
store rotation info
ghzdude Feb 24, 2024
fca0b05
trig fuckery
ghzdude Feb 24, 2024
9b8dae7
comment
ghzdude Feb 27, 2024
042a38a
move holo opening to a new item
ghzdude Feb 27, 2024
aabd8af
add holo factor and manager
ghzdude Feb 27, 2024
e87a056
try to get mouse working
ghzdude Feb 27, 2024
2d9df99
imports
ghzdude Feb 28, 2024
1094834
add contains check
ghzdude Feb 28, 2024
ce7f504
update screen and animator
ghzdude Feb 28, 2024
7e56c19
tick screen
ghzdude Feb 28, 2024
569039c
test other orientation
ghzdude Feb 29, 2024
b85fdd0
don't interact with any items in any hand
ghzdude Feb 29, 2024
10314b9
don't pitch render based on looking
ghzdude Feb 29, 2024
7b731c7
move some stuff around
ghzdude Feb 29, 2024
452a6bc
test scale
ghzdude Feb 29, 2024
9d0b27a
move bool to context
ghzdude Feb 29, 2024
6783256
use uuid instead of player
ghzdude Feb 29, 2024
3ecd0a4
remove unused parameter
ghzdude Feb 29, 2024
4ac5ee0
handle z index correctly when holo screen
ghzdude Feb 29, 2024
26b0005
add holo screen entity to context
ghzdude Feb 29, 2024
a424b05
misc
ghzdude Feb 29, 2024
c5cb39d
handle rendering when holo screen
ghzdude Feb 29, 2024
0a1d204
work on holo screen registration
ghzdude Feb 29, 2024
2bb3036
fix
ghzdude Mar 2, 2024
f03e9e3
partially fix block weirdness
ghzdude Mar 2, 2024
145f70d
fix z issues
ghzdude Mar 2, 2024
1128981
don't draw jei
ghzdude Mar 2, 2024
c0d12e2
add tracker to holo ent
ghzdude Mar 2, 2024
62d1e70
improve holo syncing
ghzdude Mar 2, 2024
c8bf5f4
initial reposition
ghzdude Mar 2, 2024
8f2c0ca
mostly working reposition
ghzdude Mar 2, 2024
686c6f8
test and fix scale
ghzdude Mar 4, 2024
e84b75f
fix rebase
ghzdude Apr 8, 2024
f7cc59c
fix errors
brachy84 Jul 7, 2024
92764ea
partially fix rebase
ghzdude Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/cleanroommc/modularui/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class CommonProxy {
void preInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(CommonProxy.class);
MinecraftForge.EVENT_BUS.register(GuiManager.class);
MinecraftForge.EVENT_BUS.register(HoloGuiManager.class);

if (ModularUIConfig.enableTestGuis) {
MinecraftForge.EVENT_BUS.register(TestBlock.class);
Expand All @@ -40,6 +41,7 @@ void preInit(FMLPreInitializationEvent event) {
NetworkHandler.init();

GuiFactories.init();
GuiManager.registerFactory(HoloGuiFactory.INSTANCE);
}

void postInit(FMLPostInitializationEvent event) {
Expand All @@ -61,6 +63,7 @@ public static void registerBlocks(RegistryEvent.Register<EntityEntry> event) {
.id("modular_screen", 0)
.name("ModularScreen")
.entity(HoloScreenEntity.class)
.tracker(100, 20, false)
.factory(HoloScreenEntity::new)
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public class GuiManager {

private static final Object2ObjectMap<String, UIFactory<?>> FACTORIES = new Object2ObjectOpenHashMap<>(16);
protected static final Object2ObjectMap<String, UIFactory<?>> FACTORIES = new Object2ObjectOpenHashMap<>(16);

private static IMuiScreen lastMui;
private static final List<EntityPlayer> openedContainers = new ArrayList<>(4);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.cleanroommc.modularui.factory;

import com.cleanroommc.modularui.api.IGuiHolder;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.PacketBuffer;

import net.minecraft.util.EnumHand;

import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class HoloGuiFactory extends AbstractUIFactory<HandGuiData>{

public static final HoloGuiFactory INSTANCE = new HoloGuiFactory();

protected HoloGuiFactory() {
super("mui:holo");
}

public static void open(EntityPlayerMP player, EnumHand hand) {
Objects.requireNonNull(player);
Objects.requireNonNull(hand);
HandGuiData guiData = new HandGuiData(player, hand);
HoloGuiManager.open(INSTANCE, guiData, player);
}
@Override
public @NotNull IGuiHolder<HandGuiData> getGuiHolder(HandGuiData data) {
return Objects.requireNonNull(castGuiHolder(data.getUsedItemStack().getItem()), "Item was not a gui holder!");
}

@Override
public void writeGuiData(HandGuiData guiData, PacketBuffer buffer) {
buffer.writeByte(guiData.getHand().ordinal());
}

@Override
public @NotNull HandGuiData readGuiData(EntityPlayer player, PacketBuffer buffer) {
return new HandGuiData(player, EnumHand.values()[buffer.readByte()]);
}
}
145 changes: 145 additions & 0 deletions src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.cleanroommc.modularui.factory;

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.screen.*;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.widget.WidgetTree;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import io.netty.buffer.Unpooled;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class HoloGuiManager extends GuiManager {


private static GuiScreenWrapper lastMui;

public static <T extends GuiData> void open(@NotNull UIFactory<T> factory, @NotNull T guiData, EntityPlayerMP player) {
if (player instanceof FakePlayer) return;
// create panel, collect sync handlers and create container
guiData.setJeiSettings(JeiSettings.DUMMY);
PanelSyncManager syncManager = new PanelSyncManager();
ModularPanel panel = factory.createPanel(guiData, syncManager);
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(player, screens);
NetworkHandler.sendToPlayer(new SyncHoloPacket(panel.getName()), player);
ModularUI.LOGGER.warn("reposition the holo, sync to client");
return;*/
}
WidgetTree.collectSyncValues(syncManager, panel);
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);
}, player.getEntityWorld());
// sync to client
// player.getNextWindowId();
// player.closeContainer();
// int windowId = player.currentWindowId;
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
factory.writeGuiData(guiData, buffer);
NetworkHandler.sendToPlayer(new OpenGuiPacket<>(0, factory, buffer), player);
// open container // this mimics forge behaviour
// player.openContainer = container;
// player.openContainer.windowId = windowId;
// player.openContainer.addListener(player);
// finally invoke event
MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container));
}

@SideOnly(Side.CLIENT)
public static <T extends GuiData> void open(int windowId, @NotNull UIFactory<T> factory, @NotNull PacketBuffer data, @NotNull EntityPlayerSP player) {
T guiData = factory.readGuiData(player, data);
JeiSettingsImpl jeiSettings = new JeiSettingsImpl();
guiData.setJeiSettings(jeiSettings);
PanelSyncManager syncManager = new PanelSyncManager();
ModularPanel panel = factory.createPanel(guiData, syncManager);
WidgetTree.collectSyncValues(syncManager, panel);
ModularScreen screen = factory.createScreen(guiData, panel);
screen.getContext().setJeiSettings(jeiSettings);
GuiContainerWrapper guiScreenWrapper = new GuiContainerWrapper(new ModularContainer(player, syncManager, panel.getName()), screen);
guiScreenWrapper.inventorySlots.windowId = windowId;
HoloUI.builder()
// .screenScale(0.25f)
.inFrontOf(player, 5, true)
.screenScale(0.5f)
.open(screen1 -> {
screen1.setPanel(panel);
screen1.setWrapper(guiScreenWrapper);
//HoloUI.registerSyncedHoloUI(panel, screen1);
}, player.getEntityWorld());
}

public static void reposition(String panel, EntityPlayer player) {
HoloUI.builder()
// .screenScale(0.25f)
.inFrontOf(player, 5, true)
.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
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void onClick(InputEvent.MouseInputEvent event) {
var player = Minecraft.getMinecraft().player;
if (player != null && player.getHeldItemMainhand().isEmpty() && player.getHeldItemOffhand().isEmpty()) {
ScreenEntityRender.clickScreen(player);
}
}


@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void onGuiOpen(GuiOpenEvent event) {
if (lastMui != null && event.getGui() == null) {
if (lastMui.getScreen().getPanelManager().isOpen()) {
lastMui.getScreen().getPanelManager().closeAll();
}
lastMui.getScreen().getPanelManager().dispose();
lastMui = null;
} else if (event.getGui() instanceof GuiScreenWrapper screenWrapper) {
if (lastMui == null) {
lastMui = screenWrapper;
} else if (lastMui == event.getGui()) {
lastMui.getScreen().getPanelManager().reopen();
} else {
if (lastMui.getScreen().getPanelManager().isOpen()) {
lastMui.getScreen().getPanelManager().closeAll();
}
lastMui.getScreen().getPanelManager().dispose();
lastMui = screenWrapper;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.cleanroommc.modularui.holoui;

import com.cleanroommc.modularui.screen.GuiContainerWrapper;
import com.cleanroommc.modularui.screen.ModularContainer;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.screen.*;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
Expand All @@ -27,7 +25,8 @@
public class HoloScreenEntity extends Entity {

private GuiContainerWrapper wrapper;
private ModularScreen screen;
private ModularContainer container;
private ModularPanel panel;
private final Plane3D plane3D;
private static final DataParameter<Byte> ORIENTATION = EntityDataManager.createKey(HoloScreenEntity.class, DataSerializers.BYTE);

Expand All @@ -40,14 +39,24 @@ public HoloScreenEntity(World world) {
this(world, new Plane3D());
}

public void setScreen(ModularScreen screen) {
this.screen = screen;
this.wrapper = new GuiContainerWrapper(new ModularContainer(null), screen);
public void setWrapper(GuiContainerWrapper wrapper) {
this.wrapper = wrapper;
this.wrapper.setWorldAndResolution(Minecraft.getMinecraft(), (int) this.plane3D.getWidth(), (int) this.plane3D.getHeight());
this.getScreen().getContext().holoScreen = this;
this.getScreen().getContext().isHoloScreen = true;
setContainer(wrapper.getScreen().getContainer());
}

public void setContainer(ModularContainer container) {
this.container = container;
}

public void setPanel(ModularPanel panel) {
this.panel = panel;
}

public ModularScreen getScreen() {
return this.screen;
return this.getWrapper().getScreen();
}

public GuiContainerWrapper getWrapper() {
Expand All @@ -66,6 +75,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 All @@ -84,18 +98,22 @@ public void onEntityUpdate() {
this.prevPosZ = this.posZ;
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
if (this.world.isRemote) {
this.extinguish();
}

if (this.posY < -64.0D) {
this.outOfWorld();
}

if (this.world.isRemote) {
this.extinguish();
int w = (int) this.plane3D.getWidth(), h = (int) this.plane3D.getHeight();
if (this.wrapper == null) {
this.getEntityWorld().removeEntity(this);
return;
}
if (w != this.wrapper.width || h != this.wrapper.height) {
this.wrapper.onResize(Minecraft.getMinecraft(), w, h);
}
this.wrapper.getScreen().onUpdate();
}

this.firstUpdate = false;
Expand Down
Loading