Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.tacz.guns.api.item.IAmmoBox;
import com.tacz.guns.inventory.tooltip.AmmoBoxTooltip;
import com.tacz.guns.item.GunTooltipPart;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
Expand All @@ -28,22 +29,38 @@ public ClientAmmoBoxTooltip(AmmoBoxTooltip tooltip) {

@Override
public int getHeight() {
if (shouldNotRender()) {
return 0;
}
return 28;
}

@Override
public int getWidth(Font font) {
if (shouldNotRender()) {
return 0;
}
return Math.max(font.width(ammoName), font.width(count)) + 22;
}

@Override
public void renderText(Font font, int pX, int pY, Matrix4f matrix4f, MultiBufferSource.BufferSource bufferSource) {
if (shouldNotRender()) {
return;
}
font.drawInBatch(ammoName, pX + 20, pY + 4, 0xffaa00, false, matrix4f, bufferSource, Font.DisplayMode.NORMAL, 0, 0xF000F0);
font.drawInBatch(count, pX + 20, pY + 15, 0x666666, false, matrix4f, bufferSource, Font.DisplayMode.NORMAL, 0, 0xF000F0);
}

@Override
public void renderImage(Font pFont, int pX, int pY, GuiGraphics pGuiGraphics) {
if (shouldNotRender()) {
return;
}
pGuiGraphics.renderItem(ammo, pX, pY + 5);
}

private boolean shouldNotRender() {
return GunTooltipPart.hideFlagsPresent(ammo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.tacz.guns.client.resource.ClientAssetManager;
import com.tacz.guns.client.resource.pojo.PackInfo;
import com.tacz.guns.inventory.tooltip.AttachmentItemTooltip;
import com.tacz.guns.item.GunTooltipPart;
import com.tacz.guns.resource.pojo.data.attachment.AttachmentData;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.Font;
Expand All @@ -34,6 +35,7 @@

public class ClientAttachmentItemTooltip implements ClientTooltipComponent {
private static final Cache<ResourceLocation, List<ItemStack>> CACHE = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.SECONDS).build();
private final ItemStack itemStack;
private final ResourceLocation attachmentId;
private final List<Component> components = Lists.newArrayList();
private final MutableComponent tips = Component.translatable("tooltip.tacz.attachment.yaw.shift");
Expand All @@ -42,6 +44,7 @@ public class ClientAttachmentItemTooltip implements ClientTooltipComponent {
private List<ItemStack> showGuns = Lists.newArrayList();

public ClientAttachmentItemTooltip(AttachmentItemTooltip tooltip) {
this.itemStack = tooltip.getItemStack();
this.attachmentId = tooltip.getAttachmentId();
this.addText(tooltip.getType());
this.getShowGuns();
Expand Down Expand Up @@ -72,6 +75,9 @@ private static List<ItemStack> getAllAllowGuns(List<ItemStack> output, ResourceL

@Override
public int getHeight() {
if (shouldNotRender()) {
return 0;
}
if (!Screen.hasShiftDown()) {
return components.size() * 10 + 28;
}
Expand All @@ -80,6 +86,9 @@ public int getHeight() {

@Override
public int getWidth(Font font) {
if (shouldNotRender()) {
return 0;
}
int[] width = new int[]{0};
if (packInfo != null) {
width[0] = Math.max(width[0], font.width(packInfo) + 4);
Expand All @@ -98,6 +107,9 @@ public int getWidth(Font font) {

@Override
public void renderText(Font font, int pX, int pY, Matrix4f matrix4f, MultiBufferSource.BufferSource bufferSource) {
if (shouldNotRender()) {
return;
}
int yOffset = pY;
for (Component component : this.components) {
font.drawInBatch(component, pX, yOffset, 0xffaa00, false, matrix4f, bufferSource, Font.DisplayMode.NORMAL, 0, 0xF000F0);
Expand All @@ -117,7 +129,7 @@ public void renderText(Font font, int pX, int pY, Matrix4f matrix4f, MultiBuffer

@Override
public void renderImage(Font font, int mouseX, int mouseY, GuiGraphics gui) {
if (!Screen.hasShiftDown()) {
if (!Screen.hasShiftDown() || shouldNotRender()) {
return;
}
int minY = components.size() * 10 + 3;
Expand Down Expand Up @@ -181,4 +193,8 @@ private void addText(AttachmentType type) {
});
});
}

private boolean shouldNotRender() {
return GunTooltipPart.hideFlagsPresent(itemStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
import com.tacz.guns.api.item.attachment.AttachmentType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemStack;

public class AttachmentItemTooltip implements TooltipComponent {
private final ItemStack itemStack;
private final ResourceLocation attachmentId;
private final AttachmentType type;

public AttachmentItemTooltip(ResourceLocation attachmentId, AttachmentType type) {
public AttachmentItemTooltip(ItemStack itemStack, ResourceLocation attachmentId, AttachmentType type) {
this.itemStack = itemStack;
this.attachmentId = attachmentId;
this.type = type;
}

public ItemStack getItemStack() {
return itemStack;
}

public ResourceLocation getAttachmentId() {
return attachmentId;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/tacz/guns/item/AmmoBoxItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ public static void fillItemCategory(CreativeModeTab.Output output) {

@Override
public Optional<TooltipComponent> getTooltipImage(ItemStack stack) {
if (GunTooltipPart.hideFlagsPresent(stack)) {
return Optional.empty();
}
if (!(stack.getItem() instanceof IAmmoBox iAmmoBox)) {
return Optional.empty();
}
Expand All @@ -271,6 +274,9 @@ public Optional<TooltipComponent> getTooltipImage(ItemStack stack) {

@Override
public void appendHoverText(ItemStack stack, @Nullable Level pLevel, List<Component> components, TooltipFlag isAdvanced) {
if (GunTooltipPart.hideFlagsPresent(stack)) {
return;
}
if (isAllTypeCreative(stack)) {
components.add(Component.translatable("tooltip.tacz.ammo_box.usage.all_type_creative").withStyle(ChatFormatting.GOLD));
return;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/tacz/guns/item/AmmoItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public BlockEntityWithoutLevelRenderer getCustomRenderer() {
@Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> components, TooltipFlag isAdvanced) {
if (GunTooltipPart.hideFlagsPresent(stack)) {
return;
}
ResourceLocation ammoId = this.getAmmoId(stack);
TimelessAPI.getClientAmmoIndex(ammoId).ifPresent(index -> {
String tooltipKey = index.getTooltipKey();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tacz/guns/item/AttachmentItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ public AttachmentType getType(ItemStack attachmentStack) {

@Override
public Optional<TooltipComponent> getTooltipImage(ItemStack stack) {
return Optional.of(new AttachmentItemTooltip(this.getAttachmentId(stack), this.getType(stack)));
return Optional.of(new AttachmentItemTooltip(stack, this.getAttachmentId(stack), this.getType(stack)));
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/tacz/guns/item/GunTooltipPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public int getMask() {
return this.mask;
}

public static boolean hideFlagsPresent(ItemStack stack) {
return getHideFlags(stack) != 0;
}

public static int getHideFlags(ItemStack stack) {
CompoundTag tag = stack.getTag();
if (tag != null && tag.contains("HideFlags", Tag.TAG_ANY_NUMERIC)) {
Expand Down