mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +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;
|
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.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerBag;
|
import de.ellpeck.actuallyadditions.mod.inventory.ContainerBag;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler.GuiTypes;
|
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler.GuiTypes;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
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.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.EnumRarity;
|
import net.minecraft.item.EnumRarity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -32,61 +26,44 @@ import net.minecraft.util.EnumActionResult;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
public class ItemBag extends ItemBase{
|
public class ItemBag extends ItemBase {
|
||||||
|
|
||||||
public final boolean isVoid;
|
public final boolean isVoid;
|
||||||
|
|
||||||
public ItemBag(String name, boolean isVoid){
|
public ItemBag(String name, boolean isVoid) {
|
||||||
super(name);
|
super(name);
|
||||||
this.isVoid = isVoid;
|
this.isVoid = isVoid;
|
||||||
this.setMaxStackSize(1);
|
this.setMaxStackSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack stack, @Nullable World playerIn, List<String> tooltip, ITooltipFlag advanced){
|
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||||
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){
|
|
||||||
ItemStack stack = playerIn.getHeldItem(hand);
|
ItemStack stack = playerIn.getHeldItem(hand);
|
||||||
if(!this.isVoid){
|
if (!this.isVoid) {
|
||||||
TileEntity tile = worldIn.getTileEntity(pos);
|
TileEntity tile = worldIn.getTileEntity(pos);
|
||||||
if(tile != null && tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)){
|
if (tile != null && tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) {
|
||||||
if(!worldIn.isRemote){
|
if (!worldIn.isRemote) {
|
||||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
|
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
|
||||||
if(handler != null){
|
if (handler != null) {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
|
||||||
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerBag.getSlotAmount(this.isVoid));
|
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerBag.getSlotAmount(this.isVoid));
|
||||||
ItemDrill.loadSlotsFromNBT(inv, stack);
|
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);
|
ItemStack invStack = inv.getStackInSlot(j);
|
||||||
if(StackUtil.isValid(invStack)){
|
if (StackUtil.isValid(invStack)) {
|
||||||
for(int i = 0; i < handler.getSlots(); i++){
|
for (int i = 0; i < handler.getSlots(); i++) {
|
||||||
ItemStack remain = handler.insertItem(i, invStack, false);
|
ItemStack remain = handler.insertItem(i, invStack, false);
|
||||||
if(!ItemStack.areItemStacksEqual(remain, invStack)){
|
if (!ItemStack.areItemStacksEqual(remain, invStack)) {
|
||||||
inv.setStackInSlot(j, remain.copy());
|
inv.setStackInSlot(j, remain.copy());
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
||||||
if(!StackUtil.isValid(remain)){
|
if (!StackUtil.isValid(remain)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +71,7 @@ public class ItemBag extends ItemBase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(changed){
|
if (changed) {
|
||||||
ItemDrill.writeSlotsToNBT(inv, stack);
|
ItemDrill.writeSlotsToNBT(inv, stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,20 +83,20 @@ public class ItemBag extends ItemBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||||
if(!world.isRemote && hand == EnumHand.MAIN_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);
|
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));
|
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumRarity getRarity(ItemStack stack){
|
public EnumRarity getRarity(ItemStack stack) {
|
||||||
return this.isVoid ? EnumRarity.RARE : EnumRarity.UNCOMMON;
|
return this.isVoid ? EnumRarity.RARE : EnumRarity.UNCOMMON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound getNBTShareTag(ItemStack stack){
|
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue