mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-05-29 04:03:37 +02:00
61 lines
2.5 KiB
Java
61 lines
2.5 KiB
Java
/*
|
|
* 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
|
|
*
|
|
* © 2015-2017 Ellpeck
|
|
*/
|
|
|
|
package de.ellpeck.actuallyadditions.mod.items;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
|
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
|
import net.minecraft.client.util.ITooltipFlag;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.ActionResult;
|
|
import net.minecraft.util.Hand;
|
|
import net.minecraft.util.text.ITextComponent;
|
|
import net.minecraft.util.text.StringTextComponent;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.fml.network.NetworkHooks;
|
|
|
|
import javax.annotation.Nullable;
|
|
import java.util.List;
|
|
|
|
public class ItemFilter extends ItemBase {
|
|
|
|
public ItemFilter() {
|
|
super(ActuallyItems.defaultProps().maxStackSize(1));
|
|
}
|
|
|
|
@Override
|
|
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
|
|
if (!world.isRemote && hand == Hand.MAIN_HAND) {
|
|
NetworkHooks.openGui((ServerPlayerEntity) player, new SimpleNamedContainerProvider((windowId, inv, playerEnt) -> new ContainerFilter(windowId, inv), StringTextComponent.EMPTY));
|
|
// player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.FILTER.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ);
|
|
}
|
|
return ActionResult.resultPass(player.getHeldItem(hand));
|
|
}
|
|
|
|
@Override
|
|
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
|
super.addInformation(stack, worldIn, tooltip, flagIn);
|
|
|
|
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerFilter.SLOT_AMOUNT);
|
|
ItemDrill.loadSlotsFromNBT(inv, stack);
|
|
for (int i = 0; i < inv.getSlots(); i++) {
|
|
ItemStack slot = inv.getStackInSlot(i);
|
|
if (StackUtil.isValid(slot)) {
|
|
tooltip.add(slot.getItem().getDisplayName(slot));
|
|
}
|
|
}
|
|
}
|
|
}
|