mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Closes #1145
This commit is contained in:
parent
f59c431649
commit
1bec4bbff7
1 changed files with 19 additions and 42 deletions
|
@ -10,18 +10,12 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerBag;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler.GuiTypes;
|
||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -32,61 +26,44 @@ import net.minecraft.util.EnumActionResult;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class ItemBag extends ItemBase{
|
||||
public class ItemBag extends ItemBase {
|
||||
|
||||
public final boolean isVoid;
|
||||
|
||||
public ItemBag(String name, boolean isVoid){
|
||||
public ItemBag(String name, boolean isVoid) {
|
||||
super(name);
|
||||
this.isVoid = isVoid;
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable World playerIn, List<String> tooltip, ITooltipFlag advanced){
|
||||
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerBag.getSlotAmount(this.isVoid));
|
||||
ItemDrill.loadSlotsFromNBT(inv, stack);
|
||||
|
||||
int slotsTotal = inv.getSlots();
|
||||
int slotsFilled = 0;
|
||||
|
||||
for(int i = 0; i < inv.getSlots(); i++){
|
||||
if(StackUtil.isValid(inv.getStackInSlot(i))){
|
||||
slotsFilled++;
|
||||
}
|
||||
}
|
||||
tooltip.add(TextFormatting.ITALIC+String.format("%d/%d %s", slotsFilled, slotsTotal, StringUtil.localize("item."+ActuallyAdditions.MODID+".item_bag.storage")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
|
||||
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
ItemStack stack = playerIn.getHeldItem(hand);
|
||||
if(!this.isVoid){
|
||||
if (!this.isVoid) {
|
||||
TileEntity tile = worldIn.getTileEntity(pos);
|
||||
if(tile != null && tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)){
|
||||
if(!worldIn.isRemote){
|
||||
if (tile != null && tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) {
|
||||
if (!worldIn.isRemote) {
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
|
||||
if(handler != null){
|
||||
if (handler != null) {
|
||||
boolean changed = false;
|
||||
|
||||
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerBag.getSlotAmount(this.isVoid));
|
||||
ItemDrill.loadSlotsFromNBT(inv, stack);
|
||||
|
||||
for(int j = 0; j < inv.getSlots(); j++){
|
||||
for (int j = 0; j < inv.getSlots(); j++) {
|
||||
ItemStack invStack = inv.getStackInSlot(j);
|
||||
if(StackUtil.isValid(invStack)){
|
||||
for(int i = 0; i < handler.getSlots(); i++){
|
||||
if (StackUtil.isValid(invStack)) {
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
ItemStack remain = handler.insertItem(i, invStack, false);
|
||||
if(!ItemStack.areItemStacksEqual(remain, invStack)){
|
||||
if (!ItemStack.areItemStacksEqual(remain, invStack)) {
|
||||
inv.setStackInSlot(j, remain.copy());
|
||||
changed = true;
|
||||
|
||||
if(!StackUtil.isValid(remain)){
|
||||
if (!StackUtil.isValid(remain)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +71,7 @@ public class ItemBag extends ItemBase{
|
|||
}
|
||||
}
|
||||
|
||||
if(changed){
|
||||
if (changed) {
|
||||
ItemDrill.writeSlotsToNBT(inv, stack);
|
||||
}
|
||||
}
|
||||
|
@ -106,20 +83,20 @@ public class ItemBag extends ItemBase{
|
|||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
|
||||
if(!world.isRemote && hand == EnumHand.MAIN_HAND){
|
||||
player.openGui(ActuallyAdditions.INSTANCE, (this.isVoid ? GuiTypes.VOID_BAG : GuiTypes.BAG).ordinal(), world, (int)player.posX, (int)player.posY, (int)player.posZ);
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||
if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
|
||||
player.openGui(ActuallyAdditions.INSTANCE, (this.isVoid ? GuiTypes.VOID_BAG : GuiTypes.BAG).ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
}
|
||||
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumRarity getRarity(ItemStack stack){
|
||||
public EnumRarity getRarity(ItemStack stack) {
|
||||
return this.isVoid ? EnumRarity.RARE : EnumRarity.UNCOMMON;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTShareTag(ItemStack stack){
|
||||
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue