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 51 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4e5d978
first working in world screen
brachy84 May 27, 2023
ca4eb9b
replace scissor with stencil masks
brachy84 May 28, 2023
c5b777e
fixes and rename stuff
brachy84 May 28, 2023
92c0f49
holo ui's can face any direction... somewhat
brachy84 Jun 1, 2023
87f3c83
move some stuff to GuiUtils & experimental annotations
brachy84 Jun 18, 2023
1bc4286
try move to quaternion
ghzdude Feb 24, 2024
d7ca5e5
set normals
ghzdude Feb 24, 2024
6b9248a
fix in world transforms
ghzdude Feb 24, 2024
e033a67
add some comments
ghzdude Feb 24, 2024
aa9d277
flip cardinal directions to match minecraft
ghzdude Feb 24, 2024
4637375
merge if checks
ghzdude Feb 24, 2024
67e9005
store rotation info
ghzdude Feb 24, 2024
95f5048
trig fuckery
ghzdude Feb 24, 2024
fc4825d
comment
ghzdude Feb 27, 2024
7743230
move holo opening to a new item
ghzdude Feb 27, 2024
694cfca
add holo factor and manager
ghzdude Feb 27, 2024
7b19fe0
try to get mouse working
ghzdude Feb 27, 2024
0c738ee
imports
ghzdude Feb 28, 2024
046f21d
add contains check
ghzdude Feb 28, 2024
533745d
update screen and animator
ghzdude Feb 28, 2024
ecd70ce
tick screen
ghzdude Feb 28, 2024
187d695
test other orientation
ghzdude Feb 29, 2024
8fec74d
don't interact with any items in any hand
ghzdude Feb 29, 2024
5780987
don't pitch render based on looking
ghzdude Feb 29, 2024
ac939cf
move some stuff around
ghzdude Feb 29, 2024
467a629
test scale
ghzdude Feb 29, 2024
45a0329
move bool to context
ghzdude Feb 29, 2024
491cf57
use uuid instead of player
ghzdude Feb 29, 2024
145f8c3
remove unused parameter
ghzdude Feb 29, 2024
0fd3af7
handle z index correctly when holo screen
ghzdude Feb 29, 2024
2e9bbf4
add holo screen entity to context
ghzdude Feb 29, 2024
9314b93
misc
ghzdude Feb 29, 2024
a660972
handle rendering when holo screen
ghzdude Feb 29, 2024
c0aa541
work on holo screen registration
ghzdude Feb 29, 2024
8afb251
fix
ghzdude Mar 2, 2024
67008b7
partially fix block weirdness
ghzdude Mar 2, 2024
c07d0b6
fix z issues
ghzdude Mar 2, 2024
ce915ac
don't draw jei
ghzdude Mar 2, 2024
6bb682a
add tracker to holo ent
ghzdude Mar 2, 2024
3aa8d7d
improve holo syncing
ghzdude Mar 2, 2024
81fc0c8
initial reposition
ghzdude Mar 2, 2024
cc314e0
mostly working reposition
ghzdude Mar 2, 2024
092e6b3
test and fix scale
ghzdude Mar 4, 2024
b7da624
fix rebase
ghzdude Apr 8, 2024
4c904fc
fix errors
brachy84 Jul 7, 2024
664ded7
partially fix rebase
ghzdude Oct 3, 2024
aa44802
commit whatever this is
ghzdude Oct 29, 2024
745afa7
screen actually renders now
ghzdude Dec 20, 2024
b97f405
fix item position
ghzdude Dec 21, 2024
e839387
interaction kinda works
ghzdude Dec 21, 2024
66680e8
draw debug screen
ghzdude Dec 21, 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()]);
}
}
143 changes: 143 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,143 @@
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.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);
}, 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,8 @@
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.api.IMuiScreen;
import com.cleanroommc.modularui.api.MCHelper;
import com.cleanroommc.modularui.screen.*;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
Expand All @@ -26,8 +26,8 @@
@ApiStatus.Experimental
public class HoloScreenEntity extends Entity {

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

Expand All @@ -40,22 +40,34 @@ public HoloScreenEntity(World world) {
this(world, new Plane3D());
}

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

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

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

public GuiContainerWrapper getWrapper() {
public IMuiScreen getWrapper() {
return this.wrapper;
}

public void spawnInWorld() {
getEntityWorld().spawnEntity(this);
if (world.isRemote)
onResize();
}

@SideOnly(Side.CLIENT)
public void onResize() {
getScreen().onResize((int) plane3D.getWidth(), (int) plane3D.getHeight());
}

public void setOrientation(ScreenOrientation orientation) {
Expand All @@ -66,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 All @@ -84,18 +101,23 @@ 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 (w != this.wrapper.width || h != this.wrapper.height) {
this.wrapper.onResize(Minecraft.getMinecraft(), w, h);
if (this.wrapper == null) {
this.getEntityWorld().removeEntity(this);
return;
}
var wrapper = this.wrapper.getGuiScreen();
if (w != wrapper.width || h != wrapper.height) {
wrapper.onResize(Minecraft.getMinecraft(), w, h);
}
this.wrapper.getScreen().onUpdate();
}

this.firstUpdate = false;
Expand Down
Loading