feat: Allow changing the goggle overlay tooltip icon (#5900)

* feat: allow changing the goggle overlay tooltip icon

* change method name
This commit is contained in:
IThundxr 2024-03-16 14:31:05 -04:00 committed by GitHub
parent 8ffc4ef96a
commit c4098b31b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 6 deletions

View file

@ -81,7 +81,7 @@ public class GoggleOverlayRenderer {
lastHovered = pos;
pos = proxiedOverlayPosition(world, pos);
BlockEntity be = world.getBlockEntity(pos);
boolean wearingGoggles = GogglesItem.isWearingGoggles(mc.player);
@ -91,11 +91,16 @@ public class GoggleOverlayRenderer {
boolean goggleAddedInformation = false;
boolean hoverAddedInformation = false;
ItemStack item = AllItems.GOGGLES.asStack();
List<Component> tooltip = new ArrayList<>();
if (hasGoggleInformation && wearingGoggles) {
boolean isShifting = mc.player.isShiftKeyDown();
IHaveGoggleInformation gte = (IHaveGoggleInformation) be;
goggleAddedInformation = gte.addToGoggleTooltip(tooltip, mc.player.isShiftKeyDown());
goggleAddedInformation = gte.addToGoggleTooltip(tooltip, isShifting);
item = gte.getIcon(isShifting);
}
if (hasHoveringInformation) {
@ -143,7 +148,7 @@ public class GoggleOverlayRenderer {
}
if (!pistonFound) {
hoverTicks = 0;
hoverTicks = 0;
return;
}
if (!tooltip.isEmpty())
@ -155,7 +160,7 @@ public class GoggleOverlayRenderer {
}
if (tooltip.isEmpty()) {
hoverTicks = 0;
hoverTicks = 0;
return;
}
@ -203,13 +208,13 @@ public class GoggleOverlayRenderer {
RemovedGuiUtils.drawHoveringText(poseStack, tooltip, posX, posY, width, height, -1, colorBackground.getRGB(),
colorBorderTop.getRGB(), colorBorderBot.getRGB(), mc.font);
ItemStack item = AllItems.GOGGLES.asStack();
GuiGameElement.of(item)
.at(posX + 10, posY - 16, 450)
.render(poseStack);
poseStack.popPose();
}
public static BlockPos proxiedOverlayPosition(Level level, BlockPos pos) {
BlockState targetedState = level.getBlockState(pos);
if (targetedState.getBlock() instanceof IProxyHoveringInformation proxy)

View file

@ -3,12 +3,14 @@ package com.simibubi.create.content.equipment.goggles;
import java.util.List;
import java.util.Optional;
import com.simibubi.create.AllItems;
import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.LangBuilder;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
@ -40,6 +42,17 @@ public interface IHaveGoggleInformation {
return false;
}
/**
* this method will be called when looking at a BlockEntity that implemented this
* interface
* <p>
* return the item of your choosing after checking for any logic you wish, and the goggle on the goggle
* tooltip will be replaced with the item you have returned
*/
default ItemStack getIcon(boolean isPlayerSneaking) {
return AllItems.GOGGLES.asStack();
}
default boolean containedFluidTooltip(List<Component> tooltip, boolean isPlayerSneaking,
LazyOptional<IFluidHandler> handler) {
Optional<IFluidHandler> resolve = handler.resolve();