aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Hilyard <anthony.hilyard@gmail.com>2023-12-12 17:32:09 -0800
committerAnthony Hilyard <anthony.hilyard@gmail.com>2023-12-12 17:32:09 -0800
commitf8f91c8a242fe9ad534575fe715c57217a0324be (patch)
tree2fb2bd515e4c98fb9129052705a3feeb8f2991ed
parent8f249d845ca4e3b00218e4aa71750a478541b524 (diff)
downloadIceberg-f8f91c8a242fe9ad534575fe715c57217a0324be.tar.gz
Iceberg-f8f91c8a242fe9ad534575fe715c57217a0324be.tar.bz2
Iceberg-f8f91c8a242fe9ad534575fe715c57217a0324be.zip
Fixed item NBT changing unexpectedly.
Fixed tooltip decorations being misaligned sometimes.
-rw-r--r--gradle.properties8
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java7
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java8
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/PlayerAdvancementsMixin.java6
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java17
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java4
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java14
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/ItemUtil.java12
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java2
-rw-r--r--src/main/resources/fabric.mod.json4
10 files changed, 55 insertions, 27 deletions
diff --git a/gradle.properties b/gradle.properties
index 981eacf..593b757 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -6,8 +6,8 @@ org.gradle.daemon=false
name=${rootProject.name}
group=com.anthonyhilyard.${name.toLowerCase()}
author=anthonyhilyard
-version=1.1.16
+version=1.1.18
-mcVersion=1.20.1
-fabricVersion=0.84.0+1.20.1
-loaderVersion=0.14.21
+mcVersion=1.20.2
+fabricVersion=0.91.1+1.20.2
+loaderVersion=0.15.0
diff --git a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java
index 8e3c31b..82e89e7 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java
@@ -8,18 +8,23 @@ import com.anthonyhilyard.iceberg.util.Tooltips.TitleBreakComponent;
import com.mojang.datafixers.util.Either;
import net.fabricmc.api.ClientModInitializer;
+import net.fabricmc.fabric.api.event.Event;
import net.minecraft.network.chat.FormattedText;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemStack;
public class IcebergClient implements ClientModInitializer
{
+ private static ResourceLocation earlyEventPhase = new ResourceLocation("iceberg", "early");
+
@Override
public void onInitializeClient()
{
TitleBreakComponent.registerFactory();
- RenderTooltipEvents.GATHER.register(IcebergClient::onGatherComponentsEventEnd);
+ RenderTooltipEvents.GATHER.addPhaseOrdering(earlyEventPhase, Event.DEFAULT_PHASE);
+ RenderTooltipEvents.GATHER.register(earlyEventPhase, IcebergClient::onGatherComponentsEventEnd);
// Event testing.
// CriterionCallback.EVENT.register((player, advancement, criterion) -> { Loader.LOGGER.info("CriterionCallback: {}, {}, {}", player.getName().getString(), advancement.getId().toString(), criterion); });
diff --git a/src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java b/src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java
index 0486304..7c63a03 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java
@@ -1,6 +1,6 @@
package com.anthonyhilyard.iceberg.events;
-import net.minecraft.advancements.Advancement;
+import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.world.entity.player.Player;
/**
@@ -9,13 +9,13 @@ import net.minecraft.world.entity.player.Player;
public interface CriterionCallback
{
ToggleableEvent<CriterionCallback> EVENT = ToggleableEvent.create(CriterionCallback.class,
- (listeners) -> (player, advancement, criterionKey) -> {
+ (listeners) -> (player, advancementHolder, criterionKey) -> {
for (CriterionCallback listener : listeners)
{
- listener.awardCriterion(player, advancement, criterionKey);
+ listener.awardCriterion(player, advancementHolder, criterionKey);
}
}
);
- public void awardCriterion(Player player, Advancement advancement, String criterionKey);
+ public void awardCriterion(Player player, AdvancementHolder advancementHolder, String criterionKey);
}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/PlayerAdvancementsMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/PlayerAdvancementsMixin.java
index 568036e..559192b 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/PlayerAdvancementsMixin.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/PlayerAdvancementsMixin.java
@@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
-import net.minecraft.advancements.Advancement;
+import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ServerPlayer;
@@ -20,11 +20,11 @@ public class PlayerAdvancementsMixin
private ServerPlayer player;
@Inject(method = "award", at = @At(value = "TAIL"), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
- public void onAward(Advancement advancement, String criterionKey, CallbackInfoReturnable<Boolean> callbackInfo, boolean success)
+ public void onAward(AdvancementHolder advancementHolder, String criterionKey, CallbackInfoReturnable<Boolean> callbackInfo, boolean success)
{
if (success)
{
- CriterionCallback.EVENT.invoker().awardCriterion(player, advancement, criterionKey);
+ CriterionCallback.EVENT.invoker().awardCriterion(player, advancementHolder, criterionKey);
}
}
}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java
index 90d1278..fccd4f4 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java
@@ -9,6 +9,7 @@ import java.util.function.Predicate;
import com.anthonyhilyard.iceberg.util.EntityCollector;
import com.anthonyhilyard.iceberg.util.GuiHelper;
+import com.anthonyhilyard.iceberg.util.ItemUtil;
import com.google.common.collect.Maps;
import org.joml.Matrix4f;
@@ -421,9 +422,9 @@ public class CustomItemRenderer extends ItemRenderer
BlockEntity blockEntity = entityBlock.newBlockEntity(BlockPos.ZERO, blockState);
if (blockEntity != null)
{
- if (itemStack.getTag() != null)
+ if (itemStack.hasTag())
{
- blockEntity.load(itemStack.getTag());
+ blockEntity.load(ItemUtil.getItemNBT(itemStack));
}
BlockEntityRenderer<BlockEntity> renderer = minecraft.getBlockEntityRenderDispatcher().getRenderer(blockEntity);
@@ -498,7 +499,7 @@ public class CustomItemRenderer extends ItemRenderer
}
// If the item has changed, then we need to update the armor stand.
- if (cachedArmorStandItem != Pair.of(itemStack.getItem(), itemStack.getTag()))
+ if (cachedArmorStandItem != Pair.of(itemStack.getItem(), ItemUtil.getItemNBT(itemStack)))
{
// Clear the armor stand.
for (EquipmentSlot slot : EquipmentSlot.values())
@@ -509,7 +510,7 @@ public class CustomItemRenderer extends ItemRenderer
// Equip the armor stand with the armor.
armorStand.setItemSlot(equipmentSlot, itemStack);
- cachedArmorStandItem = Pair.of(itemStack.getItem(), itemStack.getTag());
+ cachedArmorStandItem = Pair.of(itemStack.getItem(), ItemUtil.getItemNBT(itemStack));
}
return true;
}
@@ -530,7 +531,7 @@ public class CustomItemRenderer extends ItemRenderer
private boolean updateEntity(ItemStack itemStack)
{
- Pair<Item, CompoundTag> entityItem = Pair.of(itemStack.getItem(), itemStack.getTag());
+ Pair<Item, CompoundTag> entityItem = Pair.of(itemStack.getItem(), ItemUtil.getItemNBT(itemStack));
if (entity == null || cachedEntityItem != entityItem)
{
entity = getEntityFromItem(itemStack);
@@ -563,12 +564,12 @@ public class CustomItemRenderer extends ItemRenderer
}
// If the item has changed, then we need to update the horse.
- if (cachedHorseArmorItem != Pair.of(horseArmorItem.getItem(), horseArmorItem.getTag()))
+ if (cachedHorseArmorItem != Pair.of(horseArmorItem.getItem(), ItemUtil.getItemNBT(horseArmorItem)))
{
// Equip the horse with the armor.
horse.setItemSlot(EquipmentSlot.CHEST, horseArmorItem);
- cachedHorseArmorItem = Pair.of(horseArmorItem.getItem(), horseArmorItem.getTag());
+ cachedHorseArmorItem = Pair.of(horseArmorItem.getItem(), ItemUtil.getItemNBT(horseArmorItem));
}
return true;
}
@@ -610,7 +611,7 @@ public class CustomItemRenderer extends ItemRenderer
private ModelBounds getModelBounds(ItemStack itemStack, ItemDisplayContext displayContext, boolean leftHanded, PoseStack poseStack,
Quaternionf rotation, MultiBufferSource bufferSource, int packedLight, int packedOverlay, BakedModel bakedModel)
{
- Pair<Item, CompoundTag> key = Pair.of(itemStack.getItem(), itemStack.getTag());
+ Pair<Item, CompoundTag> key = Pair.of(itemStack.getItem(), ItemUtil.getItemNBT(itemStack));
if (!modelBoundsCache.containsKey(key))
{
VertexCollector vertexCollector = VertexCollector.create();
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java b/src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java
index 90acfe4..fb51ff6 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java
@@ -104,7 +104,7 @@ public class EntityCollector extends Level
List<Entity> entities = Lists.newArrayList();
Item item = itemStack.getItem();
ItemStack dummyStack = new ItemStack(item, itemStack.getCount());
- dummyStack.setTag(itemStack.getTag());
+ dummyStack.setTag(ItemUtil.getItemNBT(itemStack));
try
{
@@ -188,7 +188,7 @@ public class EntityCollector extends Level
public static <T extends Entity> boolean itemCreatesEntity(ItemStack itemStack, Class<T> targetClass)
{
- ItemClassPair key = new ItemClassPair(itemStack.getItem(), itemStack.getTag(), targetClass);
+ ItemClassPair key = new ItemClassPair(itemStack.getItem(), ItemUtil.getItemNBT(itemStack), targetClass);
boolean result = false;
if (!itemCreatesEntityResultCache.containsKey(key))
{
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java b/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java
index 8831bad..c69ab3f 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/ItemColor.java
@@ -108,8 +108,18 @@ public class ItemColor
if (result == null || result.equals(item.getDisplayName().getStyle().getColor()))
{
Minecraft mc = Minecraft.getInstance();
- List<Component> lines = item.getTooltipLines(mc.player, TooltipFlag.Default.ADVANCED);
- if (!lines.isEmpty())
+ List<Component> lines = null;
+
+ try
+ {
+ lines = item.getTooltipLines(mc.player, TooltipFlag.Default.ADVANCED);
+ }
+ catch (Exception e)
+ {
+ // An item must have misbehaved.
+ }
+
+ if (lines != null && !lines.isEmpty())
{
result = lines.get(0).getStyle().getColor();
}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/ItemUtil.java b/src/main/java/com/anthonyhilyard/iceberg/util/ItemUtil.java
new file mode 100644
index 0000000..4887e45
--- /dev/null
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/ItemUtil.java
@@ -0,0 +1,12 @@
+package com.anthonyhilyard.iceberg.util;
+
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.world.item.ItemStack;
+
+public class ItemUtil
+{
+ public static CompoundTag getItemNBT(final ItemStack item)
+ {
+ return item.hasTag() ? item.getTag().copy() : null;
+ }
+}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java b/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java
index 3e9c429..0aea56d 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java
@@ -293,7 +293,7 @@ public class Selectors
}
// Look for a tag matching the given name and value.
- return findMatchingSubtag(item.getTag(), tagName, tagValue, valueChecker);
+ return findMatchingSubtag(ItemUtil.getItemNBT(item), tagName, tagValue, valueChecker);
}
return false;
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index c74cf27..8acf018 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -28,9 +28,9 @@
],
"depends": {
- "fabricloader": ">=0.14.21",
+ "fabricloader": ">=0.14.19",
"fabric": "*",
- "minecraft": "~1.20",
+ "minecraft": "1.20.2",
"java": ">=17"
},
"suggests": {