Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.minetronic.masterchef.items;
- import net.minecraft.entity.LivingEntity;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.world.World;
- /**
- * The containerItem is an item which returns a specified Item after it has been used
- */
- public class ModContainerItem extends ModItem {
- private Item containerItem;
- public ModContainerItem(Item.Properties properties, Item containerItem) {
- super(properties.containerItem(containerItem));
- this.containerItem = containerItem;
- }
- /**
- * Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
- * the Item before the action is complete.
- */
- public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) {
- ItemStack itemstack = super.onItemUseFinish(stack, worldIn, entityLiving);
- if (entityLiving instanceof PlayerEntity) {
- PlayerEntity player = ((PlayerEntity) entityLiving);
- if (!player.abilities.isCreativeMode) {
- ItemStack containerItemStack = new ItemStack(containerItem);
- if (itemstack.isEmpty()) {
- System.out.println("Has itemstack: " + player.inventory.hasItemStack(containerItemStack));
- System.out.println("Stackable: " + containerItemStack.isStackable());
- if (containerItemStack.isStackable() && player.inventory.hasItemStack(containerItemStack)) {
- if (!player.addItemStackToInventory(containerItemStack)) {
- return containerItemStack;
- }
- } else {
- return containerItemStack;
- }
- } else {
- player.addItemStackToInventory(new ItemStack(containerItem));
- return itemstack;
- }
- }
- }
- return itemstack;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement