Skip to content

Commit

Permalink
Half complete GuiData commit, needs some changes most likely
Browse files Browse the repository at this point in the history
  • Loading branch information
letsgoawaydev committed Jul 21, 2024
1 parent d78441a commit 7bd4f9c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ public interface GuiData {
* @return an unmodifiable view of all currently hidden {@link GuiElement}s
*/
@NonNull Set<GuiElement> hiddenElements();

/**
* Sends a notification toast to the client.
*/
void sendToast(@NonNull String title, @NonNull String content);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.geysermc.api.connection.Connection;
import org.geysermc.geyser.api.bedrock.camera.CameraData;
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
import org.geysermc.geyser.api.bedrock.gui.GuiData;
import org.geysermc.geyser.api.command.CommandSource;
import org.geysermc.geyser.api.entity.EntityData;
import org.geysermc.geyser.api.entity.type.GeyserEntity;
Expand Down Expand Up @@ -60,6 +61,14 @@ public interface GeyserConnection extends Connection, CommandSource {
*/
@NonNull EntityData entities();

/**
* Exposes the {@link GuiData} for this connection.
* It allows you to hide GUI elements, and send notification toasts.
*
* @return the GuiData for this connection.
*/
@NonNull GuiData gui();

/**
* @param javaId the Java entity ID to look up.
* @return a {@link GeyserEntity} if present in this connection's entity tracker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,31 +242,21 @@ public boolean isCameraLocked() {

@Override
public void hideElement(GuiElement... elements) {
Objects.requireNonNull(elements);
SetHudPacket packet = new SetHudPacket();
packet.setVisibility(HudVisibility.HIDE);
Set<HudElement> elementSet = packet.getElements();

for (GuiElement element : elements) {
this.hiddenHudElements.add(element);
elementSet.add(HUD_ELEMENT_VALUES[element.id()]);
}

session.sendUpstreamPacket(packet);
session.gui().hideElement(elements);
}

@Override
public void resetElement(@NotNull @NonNull GuiElement @Nullable ... element) {

session.gui().resetElement(element);
}

@Override
public boolean isHudElementHidden(@NonNull GuiElement element) {
return false;
return session.gui().isHudElementHidden(element);
}

@Override
public @NonNull Set<GuiElement> hiddenElements() {
return null;
return session.gui().hiddenElements();
}
}
16 changes: 16 additions & 0 deletions core/src/main/java/org/geysermc/geyser/impl/gui/GeyserGuiData.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.cloudburstmc.protocol.bedrock.data.HudElement;
import org.cloudburstmc.protocol.bedrock.data.HudVisibility;
import org.cloudburstmc.protocol.bedrock.packet.SetHudPacket;
import org.cloudburstmc.protocol.bedrock.packet.ToastRequestPacket;
import org.geysermc.geyser.api.bedrock.gui.GuiData;
import org.geysermc.geyser.api.bedrock.gui.GuiElement;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.jetbrains.annotations.NotNull;

Expand All @@ -57,6 +59,12 @@ public class GeyserGuiData implements GuiData {
GuiElement.TOOL_TIPS
};

private final GeyserSession session;

public GeyserGuiData(GeyserSession session) {
this.session = session;
}

/**
* All currently hidden HUD elements
*/
Expand Down Expand Up @@ -97,6 +105,14 @@ public boolean isHudElementHidden(@NonNull GuiElement element) {
return Collections.unmodifiableSet(hiddenHudElements);
}

@Override
public void sendToast(@NonNull String title, @NonNull String content) {
ToastRequestPacket toastRequestPacket = new ToastRequestPacket();
toastRequestPacket.setTitle(title);
toastRequestPacket.setContent(content);
session.sendUpstreamPacket(toastRequestPacket);
}

/**
* Deals with hiding hud elements while in spectator.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.bedrock.camera.CameraData;
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
import org.geysermc.geyser.api.bedrock.gui.GuiData;
import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.entity.EntityData;
import org.geysermc.geyser.api.entity.type.GeyserEntity;
Expand All @@ -94,6 +95,7 @@
import org.geysermc.geyser.erosion.GeyserboundHandshakePacketHandler;
import org.geysermc.geyser.impl.camera.CameraDefinitions;
import org.geysermc.geyser.impl.camera.GeyserCameraData;
import org.geysermc.geyser.impl.gui.GeyserGuiData;
import org.geysermc.geyser.inventory.Inventory;
import org.geysermc.geyser.inventory.PlayerInventory;
import org.geysermc.geyser.inventory.recipe.GeyserRecipe;
Expand Down Expand Up @@ -557,6 +559,9 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {

private final GeyserCameraData cameraData;

private final GeyserGuiData guiData;


private final GeyserEntityData entityData;

private MinecraftProtocol protocol;
Expand All @@ -582,8 +587,10 @@ public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSessio
this.structureBlockCache = new StructureBlockCache();
this.tagCache = new TagCache();
this.worldCache = new WorldCache(this);

this.cameraData = new GeyserCameraData(this);
this.entityData = new GeyserEntityData(this);
this.guiData = new GeyserGuiData(this);

this.worldBorder = new WorldBorder(this);

Expand Down Expand Up @@ -1310,7 +1317,7 @@ public void setFlying(boolean flying) {
public void setGameMode(GameMode newGamemode) {
boolean currentlySpectator = this.gameMode == GameMode.SPECTATOR;
this.gameMode = newGamemode;
this.cameraData.handleGameModeChange(currentlySpectator, newGamemode);
this.guiData.handleGameModeChange(currentlySpectator, newGamemode);
}

/**
Expand Down Expand Up @@ -2023,6 +2030,11 @@ public void lockInputs(boolean camera, boolean movement) {
return this.entityData;
}

@Override
public @NonNull GuiData gui() {
return this.guiData;
}

@Override
public void shakeCamera(float intensity, float duration, @NonNull CameraShake type) {
this.cameraData.shakeCamera(intensity, duration, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ public void sendAdvancementToasts(GeyserSession session, ClientboundUpdateAdvanc
String frameTitle = advancement.getDisplayColor() + MinecraftLocale.getLocaleString("advancements.toast." + frameType, session.locale());
String advancementName = MessageTranslator.convertMessage(advancement.getDisplayData().getTitle(), session.locale());

ToastRequestPacket toastRequestPacket = new ToastRequestPacket();
toastRequestPacket.setTitle(frameTitle);
toastRequestPacket.setContent(advancementName);
session.sendUpstreamPacket(toastRequestPacket);
session.gui().sendToast(frameTitle, advancementName);
}
}
}
Expand Down

0 comments on commit 7bd4f9c

Please sign in to comment.