Skip to content

Commit

Permalink
ItemStack#hasCustomHoverName() -> has(DataComponents.CUSTOM_NAME)
Browse files Browse the repository at this point in the history
and related
  • Loading branch information
Abbie5 authored and artemisSystem committed Dec 10, 2024
1 parent a4a6746 commit ca6264b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;

Expand All @@ -29,7 +30,7 @@ public ItemOverrides getOverrides() {
return new ItemOverrides() {
@Override
public BakedModel resolve(@NotNull BakedModel model, @NotNull ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity livingEntity, int seed) {
if (stack.hasCustomHoverName()) {
if (stack.has(DataComponents.CUSTOM_NAME)) {
return TinyPotatoBlockEntityRenderer.getModelFromDisplayName(stack.getHoverName());
}
return originalModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
Expand Down Expand Up @@ -265,7 +266,7 @@ private void renderItems(TinyPotatoBlockEntity potato, Direction facing, String
case WEST -> {
if (mySon) {
ms.translate(0.95F, -0.29F, 0.9F);
if (stack.hasCustomHoverName()) {
if (stack.has(DataComponents.CUSTOM_NAME)) {
var childNameBuilder = new StringBuilder();
TinyPotatoBlockItem.isEnchantedName(stack.getHoverName(), childNameBuilder);
if (childNameBuilder.toString().equals("kingdaddydmac")) {
Expand Down Expand Up @@ -329,8 +330,10 @@ private void renderItems(TinyPotatoBlockEntity potato, Direction facing, String
ms.mulPose(VecHelper.rotateZ(180F));
ms.translate(-0.3F, -2.7F, -1.2F);
ms.mulPose(VecHelper.rotateZ(15F));
ItemStack stack = new ItemStack(BotaniaItems.infiniteFruit);
stack.set(DataComponents.CUSTOM_NAME, Component.literal("das boot"));
renderItem(ms, buffers, potato.getLevel(),
light, overlay, new ItemStack(BotaniaItems.infiniteFruit).setHoverName(Component.literal("das boot")));
light, overlay, stack);
}
case "jibril" -> {
ms.scale(1.5F, 1.5F, 1.5F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -146,7 +147,7 @@ public void interact(Player player, InteractionHand hand, ItemStack stack, Direc
}
if (!tater.isEmpty()) {
String taterGender = manyTater ? "children" : "son";
if (!manyTater && tater.hasCustomHoverName()) {
if (!manyTater && tater.has(DataComponents.CUSTOM_NAME)) {
StringBuilder childNameBuilder = new StringBuilder();
TinyPotatoBlockItem.isEnchantedName(tater.getHoverName(), childNameBuilder);
taterGender = GENDER.getOrDefault(childNameBuilder.toString(), taterGender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Containers;
Expand Down Expand Up @@ -127,7 +128,7 @@ public BlockState rotate(@NotNull BlockState state, Rotation rot) {

@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity living, ItemStack stack) {
if (stack.hasCustomHoverName() && world.getBlockEntity(pos) instanceof TinyPotatoBlockEntity tater) {
if (stack.has(DataComponents.CUSTOM_NAME) && world.getBlockEntity(pos) instanceof TinyPotatoBlockEntity tater) {
tater.name = stack.getHoverName();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.dispenser.BlockSource;
import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.tags.BlockTags;
Expand Down Expand Up @@ -63,7 +64,7 @@ public ItemStack execute(BlockSource source, ItemStack stack) {
}

AbstractMinecart entityminecart = new ManaPoolMinecartEntity(world, d0, d1 + d3, d2);
if (stack.hasCustomHoverName()) {
if (stack.has(DataComponents.CUSTOM_NAME)) {
entityminecart.setCustomName(stack.getHoverName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package vazkii.botania.common.block.flower.functional;

import net.minecraft.core.BlockPos;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void tickFlower() {
}

ItemStack nameTag = nameTagEnt.getItem();
if (nameTag.is(Items.NAME_TAG) && nameTag.hasCustomHoverName()) {
if (nameTag.is(Items.NAME_TAG) && nameTag.has(DataComponents.CUSTOM_NAME)) {
AABB renameArea = new AABB(x - RENAME_RANGE, y, z - RENAME_RANGE, x + RENAME_RANGE + 1, y + 1, z + RENAME_RANGE + 1);
Component name = nameTag.getHoverName();
List<LivingEntity> nameableEntities = level.getEntitiesOfClass(LivingEntity.class, renameArea,
Expand All @@ -91,7 +92,7 @@ public void tickFlower() {
}
}
for (ItemEntity i : nameableItems) {
i.getItem().setHoverName(name);
i.getItem().set(DataComponents.CUSTOM_NAME, name);
EntityHelper.syncItem(i);
((ServerLevel) level).sendParticles(ParticleTypes.INSTANT_EFFECT,
i.getX(), i.getY(), i.getZ(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package vazkii.botania.common.item;

import net.minecraft.core.BlockPos;
import net.minecraft.core.component.DataComponents;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
Expand Down Expand Up @@ -49,7 +50,7 @@ public InteractionResult useOn(UseOnContext context) {
}

AbstractMinecart abstractMinecartEntity = new ManaPoolMinecartEntity(world, (double) blockPos.getX() + 0.5D, (double) blockPos.getY() + 0.0625D + d, (double) blockPos.getZ() + 0.5D);
if (itemStack.hasCustomHoverName()) {
if (itemStack.has(DataComponents.CUSTOM_NAME)) {
abstractMinecartEntity.setCustomName(itemStack.getHoverName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -214,7 +215,7 @@ public void onEquipped(ItemStack stack, LivingEntity living) {
int variant = getVariant(stack);
if (variant != WING_TYPES && StringObfuscator.matchesHash(stack.getHoverName().getString(), SUPER_AWESOME_HASH)) {
ItemNBTHelper.setInt(stack, TAG_VARIANT, WING_TYPES);
stack.resetHoverName();
stack.remove(DataComponents.CUSTOM_NAME);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void releaseUsing(@NotNull ItemStack stack, @NotNull Level level, LivingE
arrow.setKnockback(knockback);
}

if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) {
if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
arrow.setRemainingFireTicks(100 * 20);
}

Expand Down

0 comments on commit ca6264b

Please sign in to comment.