2016-06-07 23:17:06 +02:00
|
|
|
/*
|
|
|
|
* This file ("ItemFilter.java") is part of the Actually Additions mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2016-06-07 23:17:06 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.items;
|
|
|
|
|
2024-03-12 21:31:29 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-06-07 23:17:06 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
2018-06-23 01:39:30 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
2016-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.network.chat.Component;
|
|
|
|
import net.minecraft.world.InteractionHand;
|
|
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
|
|
import net.minecraft.world.SimpleMenuProvider;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.item.TooltipFlag;
|
|
|
|
import net.minecraft.world.level.Level;
|
2024-03-04 20:21:48 +01:00
|
|
|
import net.neoforged.api.distmarker.Dist;
|
|
|
|
import net.neoforged.api.distmarker.OnlyIn;
|
2016-06-07 23:17:06 +02:00
|
|
|
|
2021-03-01 21:23:52 +01:00
|
|
|
import javax.annotation.Nullable;
|
2021-02-26 22:15:48 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class ItemFilter extends ItemBase {
|
2016-06-07 23:17:06 +02:00
|
|
|
|
2021-03-01 21:23:52 +01:00
|
|
|
public ItemFilter() {
|
2021-08-22 17:09:06 +02:00
|
|
|
super(ActuallyItems.defaultProps().stacksTo(1));
|
2016-06-07 23:17:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
|
|
|
if (!world.isClientSide && hand == InteractionHand.MAIN_HAND) {
|
2024-03-12 21:31:29 +01:00
|
|
|
player.openMenu(new SimpleMenuProvider((windowId, inv, playerEnt) -> new ContainerFilter(windowId, inv), Component.translatable("container." + ActuallyAdditions.MODID + ".filter")));
|
2021-03-01 21:23:52 +01:00
|
|
|
// player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.FILTER.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ);
|
2016-06-07 23:17:06 +02:00
|
|
|
}
|
2024-03-02 21:23:08 +01:00
|
|
|
return InteractionResultHolder.pass(player.getItemInHand(hand));
|
2016-06-07 23:17:06 +02:00
|
|
|
}
|
|
|
|
|
2021-12-30 18:30:01 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2016-06-07 23:17:06 +02:00
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
2021-08-22 17:09:06 +02:00
|
|
|
super.appendHoverText(stack, worldIn, tooltip, flagIn);
|
2017-06-17 00:48:49 +02:00
|
|
|
|
2018-06-23 01:39:30 +02:00
|
|
|
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerFilter.SLOT_AMOUNT);
|
2021-11-25 21:27:45 +01:00
|
|
|
DrillItem.loadSlotsFromNBT(inv, stack);
|
2019-05-02 09:10:29 +02:00
|
|
|
for (int i = 0; i < inv.getSlots(); i++) {
|
2016-11-27 11:37:55 +01:00
|
|
|
ItemStack slot = inv.getStackInSlot(i);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(slot)) {
|
2021-08-22 17:09:06 +02:00
|
|
|
tooltip.add(slot.getItem().getName(slot));
|
2016-06-07 23:17:06 +02:00
|
|
|
}
|
2017-06-29 18:36:33 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-07 23:17:06 +02:00
|
|
|
}
|