Skip to content

Commit

Permalink
show ominous item spawner's item
Browse files Browse the repository at this point in the history
closes #274

(cherry picked from commit 25deb73)
  • Loading branch information
deirn committed Jul 21, 2024
1 parent cff6e77 commit 325fb75
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import mcp.mobius.waila.plugin.vanilla.provider.InfestedBlockProvider;
import mcp.mobius.waila.plugin.vanilla.provider.InvisibleEntityProvider;
import mcp.mobius.waila.plugin.vanilla.provider.ItemEntityProvider;
import mcp.mobius.waila.plugin.vanilla.provider.ItemFrameProvider;
import mcp.mobius.waila.plugin.vanilla.provider.ItemHolderProvider;
import mcp.mobius.waila.plugin.vanilla.provider.JukeboxProvider;
import mcp.mobius.waila.plugin.vanilla.provider.MobEffectProvider;
import mcp.mobius.waila.plugin.vanilla.provider.MobTimerProvider;
Expand All @@ -49,6 +49,7 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.OminousItemSpawner;
import net.minecraft.world.entity.OwnableEntity;
import net.minecraft.world.entity.animal.Bee;
import net.minecraft.world.entity.animal.Panda;
Expand Down Expand Up @@ -218,10 +219,15 @@ public void register(IRegistrar registrar) {
registrar.addComponent(BoatProvider.INSTANCE, HEAD, Boat.class, 950);
registrar.addComponent(BoatProvider.INSTANCE, TAIL, Boat.class, 950);

registrar.addIcon(ItemFrameProvider.INSTANCE, ItemFrame.class);
registrar.addComponent(ItemFrameProvider.INSTANCE, HEAD, ItemFrame.class);
registrar.addComponent(ItemFrameProvider.INSTANCE, BODY, ItemFrame.class);
registrar.addComponent(ItemFrameProvider.INSTANCE, TAIL, ItemFrame.class);
registrar.addIcon(ItemHolderProvider.ITEM_FRAME, ItemFrame.class);
registrar.addComponent(ItemHolderProvider.ITEM_FRAME, HEAD, ItemFrame.class);
registrar.addComponent(ItemHolderProvider.ITEM_FRAME, BODY, ItemFrame.class);
registrar.addComponent(ItemHolderProvider.ITEM_FRAME, TAIL, ItemFrame.class);

registrar.addIcon(ItemHolderProvider.OMINOUS_ITEM_SPAWNER, OminousItemSpawner.class);
registrar.addComponent(ItemHolderProvider.OMINOUS_ITEM_SPAWNER, HEAD, OminousItemSpawner.class);
registrar.addComponent(ItemHolderProvider.OMINOUS_ITEM_SPAWNER, BODY, OminousItemSpawner.class);
registrar.addComponent(ItemHolderProvider.OMINOUS_ITEM_SPAWNER, TAIL, OminousItemSpawner.class);

registrar.addFeatureConfig(Options.BOOK_BOOKSHELF, false);
registrar.addConfig(Options.BOOK_ENCHANTMENT_DISPLAY_MODE, EnchantmentDisplayMode.CYCLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mcp.mobius.waila.plugin.vanilla.provider;

import java.util.function.Function;

import mcp.mobius.waila.api.IEntityAccessor;
import mcp.mobius.waila.api.IEntityComponentProvider;
import mcp.mobius.waila.api.IModInfo;
Expand All @@ -10,23 +12,32 @@
import mcp.mobius.waila.api.WailaConstants;
import mcp.mobius.waila.api.component.ItemComponent;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.OminousItemSpawner;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public enum ItemFrameProvider implements IEntityComponentProvider {
public enum ItemHolderProvider implements IEntityComponentProvider {

ITEM_FRAME(accessor -> accessor.<ItemFrame>getEntity().getItem()),
OMINOUS_ITEM_SPAWNER(accessor -> accessor.<OminousItemSpawner>getEntity().getItem());

INSTANCE;
final Function<IEntityAccessor, ItemStack> getter;

ItemHolderProvider(Function<IEntityAccessor, ItemStack> getter) {
this.getter = getter;
}

@Nullable
@Override
public ITooltipComponent getIcon(IEntityAccessor accessor, IPluginConfig config) {
var stack = accessor.<ItemFrame>getEntity().getItem();
var stack = getter.apply(accessor);
return stack.isEmpty() ? null : new ItemComponent(stack);
}

@Override
public void appendHead(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) {
var stack = accessor.<ItemFrame>getEntity().getItem();
var stack = getter.apply(accessor);

if (!stack.isEmpty()) {
var formatter = IWailaConfig.get().getFormatter();
Expand All @@ -40,13 +51,13 @@ public void appendHead(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig

@Override
public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) {
var stack = accessor.<ItemFrame>getEntity().getItem();
var stack = getter.apply(accessor);
ItemEntityProvider.appendBookProperties(tooltip, stack, config);
}

@Override
public void appendTail(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) {
var stack = accessor.<ItemFrame>getEntity().getItem();
var stack = getter.apply(accessor);

if (config.getBoolean(WailaConstants.CONFIG_SHOW_MOD_NAME) && !stack.isEmpty()) {
tooltip.setLine(WailaConstants.MOD_NAME_TAG, IWailaConfig.get().getFormatter().modName(IModInfo.get(stack).getName()));
Expand Down

0 comments on commit 325fb75

Please sign in to comment.