ExtraHoppers-forge/src/main/java/net/shadowfacts/funnels/PlayerUtils.java

35 lines
1.1 KiB
Java
Raw Normal View History

2016-06-14 23:19:20 +00:00
package net.shadowfacts.funnels;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
/**
* @author shadowfacts
*/
public class PlayerUtils {
public static boolean disposePlayerItem(ItemStack stack, ItemStack dropStack, EntityPlayer entityplayer, boolean allowDrop, boolean allowReplace) {
if (entityplayer == null || entityplayer.capabilities.isCreativeMode) {
return true;
}
2016-11-20 14:36:16 +00:00
if (allowReplace && stack.getCount() <= 1) {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, ItemStack.EMPTY);
2016-06-14 23:19:20 +00:00
entityplayer.inventory.addItemStackToInventory(dropStack);
return true;
} else if (allowDrop) {
2016-11-20 14:36:16 +00:00
stack.shrink(1);
2016-06-14 23:19:20 +00:00
if (dropStack != null && !entityplayer.inventory.addItemStackToInventory(dropStack)) {
entityplayer.dropItem(dropStack, false, true);
}
return true;
}
return false;
}
public static boolean disposePlayerItem(ItemStack stack, ItemStack dropStack, EntityPlayer entityplayer, boolean allowDrop) {
return disposePlayerItem(stack, dropStack, entityplayer, allowDrop, true);
}
}