Some Select Spectator Solutions

- All GUIs and HUDs now respect spectator mode and the hideGui option
- Fix some HUDs not reseting GL state
- Blaze burners no longer turn towards the player if they are invisible
- Ponder buttons that display the main item for a ponder tag now have a
different background color
This commit is contained in:
PepperCode1 2022-07-07 01:38:06 -07:00
parent 9970c2bd4e
commit c55cdd2bac
14 changed files with 70 additions and 21 deletions

View File

@ -104,11 +104,11 @@ public class CreateClient {
// Register overlays in reverse order // Register overlays in reverse order
OverlayRegistry.registerOverlayAbove(ForgeIngameGui.AIR_LEVEL_ELEMENT, "Create's Remaining Air", CopperBacktankArmorLayer.REMAINING_AIR_OVERLAY); OverlayRegistry.registerOverlayAbove(ForgeIngameGui.AIR_LEVEL_ELEMENT, "Create's Remaining Air", CopperBacktankArmorLayer.REMAINING_AIR_OVERLAY);
OverlayRegistry.registerOverlayAbove(ForgeIngameGui.EXPERIENCE_BAR_ELEMENT, "Create's Train Driver HUD", TrainHUD.OVERLAY); OverlayRegistry.registerOverlayAbove(ForgeIngameGui.EXPERIENCE_BAR_ELEMENT, "Create's Train Driver HUD", TrainHUD.OVERLAY);
OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Toolboxes", ToolboxHandlerClient.OVERLAY);
OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Goggle Information", GoggleOverlayRenderer.OVERLAY); OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Goggle Information", GoggleOverlayRenderer.OVERLAY);
OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Blueprints", BlueprintOverlayRenderer.OVERLAY); OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Blueprints", BlueprintOverlayRenderer.OVERLAY);
OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Linked Controller", LinkedControllerClientHandler.OVERLAY); OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Linked Controller", LinkedControllerClientHandler.OVERLAY);
OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Schematics", SCHEMATIC_HANDLER.getOverlayRenderer()); OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Schematics", SCHEMATIC_HANDLER.getOverlayRenderer());
OverlayRegistry.registerOverlayAbove(ForgeIngameGui.HOTBAR_ELEMENT, "Create's Toolboxes", ToolboxHandlerClient.OVERLAY);
} }
public static void invalidateRenderers() { public static void invalidateRenderers() {

View File

@ -21,6 +21,7 @@ import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo;
import net.minecraftforge.client.gui.ForgeIngameGui; import net.minecraftforge.client.gui.ForgeIngameGui;
import net.minecraftforge.client.gui.IIngameOverlay; import net.minecraftforge.client.gui.IIngameOverlay;
@ -106,6 +107,10 @@ public class TrainHUD {
public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width,
int height) { int height) {
Minecraft mc = Minecraft.getInstance();
if (mc.options.hideGui || mc.gameMode.getPlayerMode() == GameType.SPECTATOR)
return;
if (!(ControlsHandler.entityRef.get() instanceof CarriageContraptionEntity cce)) if (!(ControlsHandler.entityRef.get() instanceof CarriageContraptionEntity cce))
return; return;
Carriage carriage = cce.getCarriage(); Carriage carriage = cce.getCarriage();
@ -147,7 +152,7 @@ public class TrainHUD {
poseStack.popPose(); poseStack.popPose();
Font font = Minecraft.getInstance().font; Font font = mc.font;
if (currentPrompt != null && font.width(currentPrompt) < promptSize - 10) { if (currentPrompt != null && font.width(currentPrompt) < promptSize - 10) {
poseStack.pushPose(); poseStack.pushPose();
poseStack.translate(font.width(currentPrompt) / -2f + 82, -27, 100); poseStack.translate(font.width(currentPrompt) / -2f + 82, -27, 100);

View File

@ -33,6 +33,7 @@ import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TextComponent;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
@ -51,8 +52,11 @@ public class GoggleOverlayRenderer {
public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width,
int height) { int height) {
HitResult objectMouseOver = Minecraft.getInstance().hitResult; Minecraft mc = Minecraft.getInstance();
if (mc.options.hideGui || mc.gameMode.getPlayerMode() == GameType.SPECTATOR)
return;
HitResult objectMouseOver = mc.hitResult;
if (!(objectMouseOver instanceof BlockHitResult)) { if (!(objectMouseOver instanceof BlockHitResult)) {
lastHovered = null; lastHovered = null;
hoverTicks = 0; hoverTicks = 0;
@ -68,7 +72,6 @@ public class GoggleOverlayRenderer {
} }
BlockHitResult result = (BlockHitResult) objectMouseOver; BlockHitResult result = (BlockHitResult) objectMouseOver;
Minecraft mc = Minecraft.getInstance();
ClientLevel world = mc.level; ClientLevel world = mc.level;
BlockPos pos = result.getBlockPos(); BlockPos pos = result.getBlockPos();
BlockEntity te = world.getBlockEntity(pos); BlockEntity te = world.getBlockEntity(pos);

View File

@ -107,7 +107,7 @@ public class BlazeBurnerTileEntity extends SmartTileEntity {
if (!active) { if (!active) {
float target = 0; float target = 0;
LocalPlayer player = Minecraft.getInstance().player; LocalPlayer player = Minecraft.getInstance().player;
if (player != null) { if (player != null && !player.isInvisible()) {
double x; double x;
double z; double z;
if (isVirtual()) { if (isVirtual()) {

View File

@ -31,6 +31,7 @@ import net.minecraft.util.StringUtil;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.gui.ForgeIngameGui; import net.minecraftforge.client.gui.ForgeIngameGui;
import net.minecraftforge.client.gui.IIngameOverlay; import net.minecraftforge.client.gui.IIngameOverlay;
@ -106,10 +107,14 @@ public class CopperBacktankArmorLayer<T extends LivingEntity, M extends EntityMo
} }
public static void renderRemainingAirOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, int height) { public static void renderRemainingAirOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, int height) {
LocalPlayer player = Minecraft.getInstance().player; Minecraft mc = Minecraft.getInstance();
if (mc.options.hideGui || mc.gameMode.getPlayerMode() == GameType.SPECTATOR)
return;
LocalPlayer player = mc.player;
if (player == null) if (player == null)
return; return;
if (player.isSpectator() || player.isCreative()) if (player.isCreative())
return; return;
if (!player.getPersistentData() if (!player.getPersistentData()
.contains("VisualBacktankAir")) .contains("VisualBacktankAir"))

View File

@ -24,6 +24,7 @@ import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -101,11 +102,15 @@ public class ToolboxHandlerClient {
} }
public static void onKeyInput(int key, boolean pressed) { public static void onKeyInput(int key, boolean pressed) {
Minecraft mc = Minecraft.getInstance();
if (mc.gameMode.getPlayerMode() == GameType.SPECTATOR)
return;
if (key != AllKeys.TOOLBELT.getBoundCode()) if (key != AllKeys.TOOLBELT.getBoundCode())
return; return;
if (COOLDOWN > 0) if (COOLDOWN > 0)
return; return;
LocalPlayer player = Minecraft.getInstance().player; LocalPlayer player = mc.player;
if (player == null) if (player == null)
return; return;
Level level = player.level; Level level = player.level;
@ -151,11 +156,15 @@ public class ToolboxHandlerClient {
} }
public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, int height) { public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, int height) {
Minecraft mc = Minecraft.getInstance();
if (mc.options.hideGui)
return;
int x = width / 2 - 90; int x = width / 2 - 90;
int y = height - 23; int y = height - 23;
RenderSystem.enableDepthTest(); RenderSystem.enableDepthTest();
Player player = Minecraft.getInstance().player; Player player = mc.player;
CompoundTag persistentData = player.getPersistentData(); CompoundTag persistentData = player.getPersistentData();
if (!persistentData.contains("CreateToolboxData")) if (!persistentData.contains("CreateToolboxData"))
return; return;

View File

@ -32,6 +32,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.CraftingRecipe; import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.GameType;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.HitResult.Type; import net.minecraft.world.phys.HitResult.Type;
@ -60,13 +61,16 @@ public class BlueprintOverlayRenderer {
public static void tick() { public static void tick() {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
HitResult mouseOver = mc.hitResult;
BlueprintSection last = lastTargetedSection; BlueprintSection last = lastTargetedSection;
boolean sneak = mc.player.isShiftKeyDown();
lastTargetedSection = null; lastTargetedSection = null;
active = false; active = false;
noOutput = false; noOutput = false;
if (mc.gameMode.getPlayerMode() == GameType.SPECTATOR)
return;
HitResult mouseOver = mc.hitResult;
if (mouseOver == null) if (mouseOver == null)
return; return;
if (mouseOver.getType() != Type.ENTITY) if (mouseOver.getType() != Type.ENTITY)
@ -83,6 +87,7 @@ public class BlueprintOverlayRenderer {
lastTargetedSection = last; lastTargetedSection = last;
active = true; active = true;
boolean sneak = mc.player.isShiftKeyDown();
if (sectionAt != lastTargetedSection || AnimationTickHolder.getTicks() % 10 == 0 || lastSneakState != sneak) if (sectionAt != lastTargetedSection || AnimationTickHolder.getTicks() % 10 == 0 || lastSneakState != sneak)
rebuild(sectionAt, sneak); rebuild(sectionAt, sneak);
@ -236,10 +241,13 @@ public class BlueprintOverlayRenderer {
public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width,
int height) { int height) {
Minecraft mc = Minecraft.getInstance();
if (mc.options.hideGui)
return;
if (!active || empty) if (!active || empty)
return; return;
Minecraft mc = Minecraft.getInstance();
int w = 21 * ingredients.size(); int w = 21 * ingredients.size();
if (!noOutput) if (!noOutput)
@ -275,6 +283,7 @@ public class BlueprintOverlayRenderer {
resultCraftable ? x - 1 : x, resultCraftable ? y - 1 : y); resultCraftable ? x - 1 : x, resultCraftable ? y - 1 : y);
drawItemStack(poseStack, mc, x, y, result, null); drawItemStack(poseStack, mc, x, y, result, null);
} }
RenderSystem.disableBlend();
} }
public static void drawItemStack(PoseStack ms, Minecraft mc, int x, int y, ItemStack itemStack, String count) { public static void drawItemStack(PoseStack ms, Minecraft mc, int x, int y, ItemStack itemStack, String count) {

View File

@ -211,9 +211,12 @@ public class LinkedControllerClientHandler {
public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width1, public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width1,
int height1) { int height1) {
Minecraft mc = Minecraft.getInstance();
if (mc.options.hideGui)
return;
if (MODE != Mode.BIND) if (MODE != Mode.BIND)
return; return;
Minecraft mc = Minecraft.getInstance();
poseStack.pushPose(); poseStack.pushPose();
Screen tooltipScreen = new Screen(TextComponent.EMPTY) { Screen tooltipScreen = new Screen(TextComponent.EMPTY) {
@ -239,7 +242,7 @@ public class LinkedControllerClientHandler {
for (Component iTextComponent : list) for (Component iTextComponent : list)
width = Math.max(width, mc.font.width(iTextComponent)); width = Math.max(width, mc.font.width(iTextComponent));
int x = (width1 / 3) - width / 2; int x = (width1 / 3) - width / 2;
int y = height1 - height; int y = height1 - height - 24;
// TODO // TODO
tooltipScreen.renderComponentTooltip(poseStack, list, x, y); tooltipScreen.renderComponentTooltip(poseStack, list, x, y);

View File

@ -32,6 +32,7 @@ import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Mirror; import net.minecraft.world.level.block.Mirror;
@ -78,11 +79,22 @@ public class SchematicHandler {
} }
public void tick() { public void tick() {
LocalPlayer player = Minecraft.getInstance().player; Minecraft mc = Minecraft.getInstance();
if (mc.gameMode.getPlayerMode() == GameType.SPECTATOR) {
if (active) {
active = false;
syncCooldown = 0;
activeHotbarSlot = 0;
activeSchematicItem = null;
renderers.forEach(r -> r.setActive(false));
}
return;
}
if (activeSchematicItem != null && transformation != null) if (activeSchematicItem != null && transformation != null)
transformation.tick(); transformation.tick();
LocalPlayer player = mc.player;
ItemStack stack = findBlueprintInHand(player); ItemStack stack = findBlueprintInHand(player);
if (stack == null) { if (stack == null) {
active = false; active = false;
@ -222,7 +234,7 @@ public class SchematicHandler {
} }
public void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, int height) { public void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, int height) {
if (!active) if (Minecraft.getInstance().options.hideGui || !active)
return; return;
if (activeSchematicItem != null) if (activeSchematicItem != null)
this.overlay.renderOn(poseStack, activeHotbarSlot); this.overlay.renderOn(poseStack, activeHotbarSlot);

View File

@ -134,7 +134,7 @@ public class ToolSelectionScreen extends Screen {
matrixStack.popPose(); matrixStack.popPose();
} }
RenderSystem.enableBlend(); RenderSystem.disableBlend();
matrixStack.popPose(); matrixStack.popPose();
} }

View File

@ -95,6 +95,7 @@ public class Theme {
put(Key.PONDER_BUTTON_DISABLE, new Color(0x80_909090, true), new Color(0x20_909090, true)); put(Key.PONDER_BUTTON_DISABLE, new Color(0x80_909090, true), new Color(0x20_909090, true));
put(Key.PONDER_BACKGROUND_TRANSPARENT, new Color(0xdd_000000, true)); put(Key.PONDER_BACKGROUND_TRANSPARENT, new Color(0xdd_000000, true));
put(Key.PONDER_BACKGROUND_FLAT, new Color(0xff_000000, false)); put(Key.PONDER_BACKGROUND_FLAT, new Color(0xff_000000, false));
put(Key.PONDER_BACKGROUND_IMPORTANT, new Color(0xdd_0e0e20, true));
put(Key.PONDER_IDLE, new Color(0x40ffeedd, true), new Color(0x20ffeedd, true)); put(Key.PONDER_IDLE, new Color(0x40ffeedd, true), new Color(0x20ffeedd, true));
put(Key.PONDER_HOVER, new Color(0x70ffffff, true), new Color(0x30ffffff, true)); put(Key.PONDER_HOVER, new Color(0x70ffffff, true), new Color(0x30ffffff, true));
put(Key.PONDER_HIGHLIGHT, new Color(0xf0ffeedd, true), new Color(0x60ffeedd, true)); put(Key.PONDER_HIGHLIGHT, new Color(0xf0ffeedd, true), new Color(0x60ffeedd, true));
@ -162,6 +163,7 @@ public class Theme {
public static final Key PONDER_BACKGROUND_TRANSPARENT = new Key(); public static final Key PONDER_BACKGROUND_TRANSPARENT = new Key();
public static final Key PONDER_BACKGROUND_FLAT = new Key(); public static final Key PONDER_BACKGROUND_FLAT = new Key();
public static final Key PONDER_BACKGROUND_IMPORTANT = new Key();
public static final Key PONDER_IDLE = new Key(); public static final Key PONDER_IDLE = new Key();
public static final Key PONDER_HOVER = new Key(); public static final Key PONDER_HOVER = new Key();
public static final Key PONDER_HIGHLIGHT = new Key(); public static final Key PONDER_HIGHLIGHT = new Key();

View File

@ -67,7 +67,7 @@ public class PonderTag implements ScreenElement {
"Tools and Components used to assemble structures moved as an animated Contraption") "Tools and Components used to assemble structures moved as an animated Contraption")
.addToIndex(), .addToIndex(),
SAILS = create("windmill_sails").item(AllBlocks.WINDMILL_BEARING.get(), true, true) SAILS = create("windmill_sails").item(AllBlocks.WINDMILL_BEARING.get())
.defaultLang("Sails for Windmill Bearings", .defaultLang("Sails for Windmill Bearings",
"Blocks that count towards the strength of a Windmill Contraption when assembled. Each of these have equal efficiency in doing so."), "Blocks that count towards the strength of a Windmill Contraption when assembled. Each of these have equal efficiency in doing so."),

View File

@ -108,8 +108,9 @@ public class PonderTagScreen extends NavigatableSimiScreen {
.getItem() .getItem()
.getRegistryName(); .getRegistryName();
PonderButton b = new PonderButton(itemCenterX - layout.getTotalWidth() / 2 - 42, itemCenterY - 10) PonderButton b = new PonderButton(itemCenterX - layout.getTotalWidth() / 2 - 48, itemCenterY - 10)
.showing(tag.getMainItem()); .showing(tag.getMainItem());
b.withCustomBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_IMPORTANT));
if (PonderRegistry.ALL.containsKey(registryName)) { if (PonderRegistry.ALL.containsKey(registryName)) {
b.withCallback((mouseX, mouseY) -> { b.withCallback((mouseX, mouseY) -> {