mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Added bags.
They're awesome and super useful.
This commit is contained in:
parent
561ec49fa5
commit
950b89a58c
14 changed files with 657 additions and 8 deletions
|
@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
|
|||
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost;
|
||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
@ -119,7 +120,7 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{
|
|||
compost.setInventorySlotContents(0, null);
|
||||
return true;
|
||||
}
|
||||
else if(stackPlayer.isItemEqual(slot)){
|
||||
else if(ItemUtil.canBeStacked(stackPlayer, slot)){
|
||||
int addedStackSize = Math.min(slot.stackSize, stackPlayer.getMaxStackSize()-stackPlayer.stackSize);
|
||||
ItemStack stackToAdd = stackPlayer.copy();
|
||||
stackToAdd.stackSize += addedStackSize;
|
||||
|
|
|
@ -139,6 +139,9 @@ public class CreativeTab extends CreativeTabs{
|
|||
this.add(InitBlocks.blockBlackLotus);
|
||||
this.add(InitBlocks.blockBookletStand);
|
||||
|
||||
this.add(InitItems.itemBag);
|
||||
this.add(InitItems.itemVoidBag);
|
||||
|
||||
this.add(InitItems.itemWorm);
|
||||
this.add(InitItems.itemPlayerProbe);
|
||||
this.add(InitItems.itemColorLens);
|
||||
|
|
|
@ -0,0 +1,352 @@
|
|||
/*
|
||||
* This file ("ContainerBag.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-2016 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.inventory;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotDeletion;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable;
|
||||
import de.ellpeck.actuallyadditions.mod.items.ItemBag;
|
||||
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
|
||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
public class ContainerBag extends Container implements IButtonReactor{
|
||||
|
||||
private final InventoryBag bagInventory;
|
||||
public final FilterSettings filter = new FilterSettings(0, 4, false, true, false, 0, -1000);
|
||||
private final InventoryPlayer inventory;
|
||||
private final boolean isVoid;
|
||||
public boolean autoInsert;
|
||||
private boolean oldAutoInsert;
|
||||
|
||||
public ContainerBag(InventoryPlayer inventory, boolean isVoid){
|
||||
this.inventory = inventory;
|
||||
this.bagInventory = new InventoryBag(isVoid);
|
||||
this.isVoid = isVoid;
|
||||
|
||||
for(int i = 0; i < 4; i++){
|
||||
this.addSlotToContainer(new SlotFilter(this.bagInventory, i, 155, 10+i*18));
|
||||
}
|
||||
|
||||
if(this.isVoid){
|
||||
this.addSlotToContainer(new SlotDeletion(this.bagInventory, 4, 64, 65){
|
||||
@Override
|
||||
public boolean isItemValid(@Nullable ItemStack stack){
|
||||
return ContainerBag.this.filter.check(stack, ContainerBag.this.bagInventory.slots);
|
||||
}
|
||||
});
|
||||
}
|
||||
else{
|
||||
for(int i = 0; i < 4; i++){
|
||||
for(int j = 0; j < 7; j++){
|
||||
this.addSlotToContainer(new Slot(this.bagInventory, j+i*7+4, 10+j*18, 10+i*18){
|
||||
@Override
|
||||
public boolean isItemValid(@Nullable ItemStack stack){
|
||||
return ContainerBag.this.filter.check(stack, ContainerBag.this.bagInventory.slots);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 3; i++){
|
||||
for(int j = 0; j < 9; j++){
|
||||
this.addSlotToContainer(new Slot(inventory, j+i*9+9, 8+j*18, 94+i*18));
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < 9; i++){
|
||||
if(i == inventory.currentItem){
|
||||
this.addSlotToContainer(new SlotImmovable(inventory, i, 8+i*18, 152));
|
||||
}
|
||||
else{
|
||||
this.addSlotToContainer(new Slot(inventory, i, 8+i*18, 152));
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack stack = inventory.getCurrentItem();
|
||||
if(stack != null && stack.getItem() instanceof ItemBag){
|
||||
ItemDrill.loadSlotsFromNBT(this.bagInventory.slots, inventory.getCurrentItem());
|
||||
if(stack.hasTagCompound()){
|
||||
NBTTagCompound compound = stack.getTagCompound();
|
||||
this.filter.readFromNBT(compound, "Filter");
|
||||
this.autoInsert = compound.getBoolean("AutoInsert");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getSlotAmount(boolean isVoid){
|
||||
return isVoid ? 5 : 32;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges(){
|
||||
super.detectAndSendChanges();
|
||||
|
||||
if(this.filter.needsUpdateSend() || this.autoInsert != this.oldAutoInsert){
|
||||
for(IContainerListener listener : this.listeners){
|
||||
listener.sendProgressBarUpdate(this, 0, this.filter.isWhitelist ? 1 : 0);
|
||||
listener.sendProgressBarUpdate(this, 1, this.filter.respectMeta ? 1 : 0);
|
||||
listener.sendProgressBarUpdate(this, 2, this.filter.respectNBT ? 1 : 0);
|
||||
listener.sendProgressBarUpdate(this, 3, this.filter.respectOredict);
|
||||
listener.sendProgressBarUpdate(this, 4, this.autoInsert ? 1 : 0);
|
||||
}
|
||||
this.filter.updateLasts();
|
||||
this.oldAutoInsert = this.autoInsert;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void updateProgressBar(int id, int data){
|
||||
if(id == 0){
|
||||
this.filter.isWhitelist = data == 1;
|
||||
}
|
||||
else if(id == 1){
|
||||
this.filter.respectMeta = data == 1;
|
||||
}
|
||||
else if(id == 2){
|
||||
this.filter.respectNBT = data == 1;
|
||||
}
|
||||
else if(id == 3){
|
||||
this.filter.respectOredict = data;
|
||||
}
|
||||
else if(id == 4){
|
||||
this.autoInsert = data == 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
|
||||
int inventoryStart = this.bagInventory.slots.length;
|
||||
int inventoryEnd = inventoryStart+26;
|
||||
int hotbarStart = inventoryEnd+1;
|
||||
int hotbarEnd = hotbarStart+8;
|
||||
|
||||
Slot theSlot = this.inventorySlots.get(slot);
|
||||
|
||||
if(theSlot != null && theSlot.getHasStack()){
|
||||
ItemStack newStack = theSlot.getStack();
|
||||
ItemStack currentStack = newStack.copy();
|
||||
|
||||
//Other Slots in Inventory excluded
|
||||
if(slot >= inventoryStart){
|
||||
//Shift from Inventory
|
||||
if(this.isVoid || !this.filter.check(newStack, this.bagInventory.slots) || !this.mergeItemStack(newStack, 4, 32, false)){
|
||||
if(slot >= inventoryStart && slot <= inventoryEnd){
|
||||
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
}
|
||||
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
|
||||
return null;
|
||||
}
|
||||
|
||||
if(newStack.stackSize <= 0){
|
||||
theSlot.putStack(null);
|
||||
}
|
||||
else{
|
||||
theSlot.onSlotChanged();
|
||||
}
|
||||
|
||||
if(newStack.stackSize == currentStack.stackSize){
|
||||
return null;
|
||||
}
|
||||
theSlot.onPickupFromSlot(player, newStack);
|
||||
|
||||
return currentStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
|
||||
if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){
|
||||
//Calls the Filter's SlotClick function
|
||||
return ((SlotFilter)this.getSlot(slotId)).slotClick(player);
|
||||
}
|
||||
else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer player){
|
||||
ItemStack stack = this.inventory.getCurrentItem();
|
||||
if(stack != null && stack.getItem() instanceof ItemBag){
|
||||
ItemDrill.writeSlotsToNBT(this.bagInventory.slots, this.inventory.getCurrentItem());
|
||||
NBTTagCompound compound = stack.getTagCompound();
|
||||
this.filter.writeToNBT(compound, "Filter");
|
||||
compound.setBoolean("AutoInsert", this.autoInsert);
|
||||
}
|
||||
super.onContainerClosed(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player){
|
||||
return this.bagInventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onButtonPressed(int buttonID, EntityPlayer player){
|
||||
if(buttonID == 0){
|
||||
this.autoInsert = !this.autoInsert;
|
||||
}
|
||||
else{
|
||||
this.filter.onButtonPressed(buttonID);
|
||||
}
|
||||
}
|
||||
|
||||
public static class InventoryBag implements IInventory{
|
||||
|
||||
public ItemStack[] slots;
|
||||
|
||||
public InventoryBag(boolean isVoid){
|
||||
this.slots = new ItemStack[getSlotAmount(isVoid)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "bag";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit(){
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(){
|
||||
int length = this.slots.length;
|
||||
this.slots = new ItemStack[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack){
|
||||
this.slots[i] = stack;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory(){
|
||||
return this.slots.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i){
|
||||
if(i < this.getSizeInventory()){
|
||||
return this.slots[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j){
|
||||
if(this.slots[i] != null){
|
||||
ItemStack stackAt;
|
||||
if(this.slots[i].stackSize <= j){
|
||||
stackAt = this.slots[i];
|
||||
this.slots[i] = null;
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
}
|
||||
else{
|
||||
stackAt = this.slots[i].splitStack(j);
|
||||
if(this.slots[i].stackSize <= 0){
|
||||
this.slots[i] = null;
|
||||
}
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index){
|
||||
ItemStack stack = this.slots[index];
|
||||
this.slots[index] = null;
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName(){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName(){
|
||||
return new TextComponentTranslation(this.getName());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -96,6 +96,10 @@ public class GuiHandler implements IGuiHandler{
|
|||
return new ContainerMiner(entityPlayer.inventory, tile);
|
||||
case LASER_RELAY_ITEM_WHITELIST:
|
||||
return new ContainerLaserRelayItemWhitelist(entityPlayer.inventory, tile);
|
||||
case BAG:
|
||||
return new ContainerBag(entityPlayer.inventory, false);
|
||||
case VOID_BAG:
|
||||
return new ContainerBag(entityPlayer.inventory, true);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -172,6 +176,10 @@ public class GuiHandler implements IGuiHandler{
|
|||
return new GuiBookletStand(tile);
|
||||
case LASER_RELAY_ITEM_WHITELIST:
|
||||
return new GuiLaserRelayItemWhitelist(entityPlayer.inventory, tile);
|
||||
case BAG:
|
||||
return new GuiBag(entityPlayer.inventory, false);
|
||||
case VOID_BAG:
|
||||
return new GuiBag(entityPlayer.inventory, true);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -209,7 +217,9 @@ public class GuiHandler implements IGuiHandler{
|
|||
MINER,
|
||||
BOOK_STAND,
|
||||
LASER_RELAY_ITEM_WHITELIST,
|
||||
FILTER(false);
|
||||
FILTER(false),
|
||||
BAG(false),
|
||||
VOID_BAG(false);
|
||||
|
||||
public final boolean checkTileEntity;
|
||||
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* This file ("GuiBag.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-2016 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerBag;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiBag extends GuiContainer{
|
||||
|
||||
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("guiBag");
|
||||
private static final ResourceLocation RES_LOC_VOID = AssetUtil.getGuiLocation("guiVoidBag");
|
||||
|
||||
private final ContainerBag container;
|
||||
private FilterSettingsGui filter;
|
||||
private final boolean isVoid;
|
||||
private GuiButton buttonAutoInsert;
|
||||
|
||||
public GuiBag(InventoryPlayer inventory, boolean isVoid){
|
||||
this(isVoid, new ContainerBag(inventory, isVoid));
|
||||
}
|
||||
|
||||
private GuiBag(boolean isVoid, ContainerBag container){
|
||||
super(container);
|
||||
this.xSize = 176;
|
||||
this.ySize = 90+86;
|
||||
this.isVoid = isVoid;
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
|
||||
this.filter = new FilterSettingsGui(this.container.filter, this.guiLeft+138, this.guiTop+10, this.buttonList);
|
||||
|
||||
this.buttonAutoInsert = new GuiButton(0, this.guiLeft-21, this.guiTop+8, 20, 20, (this.container.autoInsert ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"I");
|
||||
this.buttonList.add(this.buttonAutoInsert);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException{
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setInteger("ButtonID", button.id);
|
||||
data.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId());
|
||||
data.setInteger("WorldID", Minecraft.getMinecraft().theWorld.provider.getDimension());
|
||||
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen(){
|
||||
super.updateScreen();
|
||||
this.filter.update();
|
||||
|
||||
this.buttonAutoInsert.displayString = (this.container.autoInsert ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"I";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGuiContainerForegroundLayer(int x, int y){
|
||||
AssetUtil.displayNameString(this.fontRendererObj, this.xSize, -10, StringUtil.localize("container."+ModUtil.MOD_ID+"."+(this.isVoid ? "voidBag" : "bag")+".name"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGuiContainerBackgroundLayer(float f, int x, int y){
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
this.mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION);
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop+90, 0, 0, 176, 86);
|
||||
|
||||
this.mc.getTextureManager().bindTexture(this.isVoid ? RES_LOC_VOID : RES_LOC);
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks){
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.filter.drawHover(mouseX, mouseY);
|
||||
|
||||
if(this.buttonAutoInsert.isMouseOver()){
|
||||
List<String> text = new ArrayList<String>();
|
||||
text.add(TextFormatting.BOLD+"Auto-Insert "+(this.container.autoInsert ? "On" : "Off"));
|
||||
text.addAll(this.mc.fontRendererObj.listFormattedStringToWidth("Turn this on to make items that get picked up automatically go into the bag.", 200));
|
||||
this.drawHoveringText(text, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file ("SlotDeletion.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-2016 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.inventory.slot;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class SlotDeletion extends Slot{
|
||||
|
||||
public SlotDeletion(IInventory inv, int slot, int x, int y){
|
||||
super(inv, slot, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack){
|
||||
this.onSlotChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player){
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -211,9 +211,14 @@ public final class InitItems{
|
|||
public static Item itemPlayerProbe;
|
||||
public static Item itemWorm;
|
||||
|
||||
public static Item itemBag;
|
||||
public static Item itemVoidBag;
|
||||
|
||||
public static void init(){
|
||||
ModUtil.LOGGER.info("Initializing Items...");
|
||||
|
||||
itemBag = new ItemBag("itemBag", false);
|
||||
itemVoidBag = new ItemBag("itemVoidBag", true);
|
||||
itemWorm = new ItemWorm("itemWorm");
|
||||
itemPlayerProbe = new ItemPlayerProbe("itemPlayerProbe");
|
||||
itemFilter = new ItemFilter("itemFilter");
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* This file ("ItemBag.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-2016 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.items;
|
||||
|
||||
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.tile.FilterSettings;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class ItemBag extends ItemBase{
|
||||
|
||||
private final boolean isVoid;
|
||||
|
||||
public ItemBag(String name, boolean isVoid){
|
||||
super(name);
|
||||
this.isVoid = isVoid;
|
||||
this.setMaxStackSize(1);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onItemPickup(EntityItemPickupEvent event){
|
||||
EntityPlayer player = event.getEntityPlayer();
|
||||
EntityItem item = event.getItem();
|
||||
if(item != null && !item.isDead){
|
||||
ItemStack stack = item.getEntityItem();
|
||||
if(stack != null && stack.getItem() != null){
|
||||
for(int i = 0; i < player.inventory.getSizeInventory(); i++){
|
||||
if(i != player.inventory.currentItem){
|
||||
|
||||
ItemStack invStack = player.inventory.getStackInSlot(i);
|
||||
if(invStack != null && invStack.getItem() instanceof ItemBag && invStack.hasTagCompound()){
|
||||
if(invStack.getTagCompound().getBoolean("AutoInsert")){
|
||||
boolean needsSave = false;
|
||||
|
||||
boolean isVoid = ((ItemBag)invStack.getItem()).isVoid;
|
||||
ItemStack[] inventory = new ItemStack[ContainerBag.getSlotAmount(isVoid)];
|
||||
ItemDrill.loadSlotsFromNBT(inventory, invStack);
|
||||
|
||||
FilterSettings filter = new FilterSettings(0, 4, false, false, false, 0, 0);
|
||||
filter.readFromNBT(invStack.getTagCompound(), "Filter");
|
||||
if(filter.check(stack, inventory)){
|
||||
for(int j = 4; j < inventory.length; j++){
|
||||
ItemStack bagStack = inventory[j];
|
||||
if(bagStack != null){
|
||||
if(ItemUtil.canBeStacked(bagStack, stack)){
|
||||
int maxTransfer = Math.min(stack.stackSize, stack.getMaxStackSize()-bagStack.stackSize);
|
||||
if(maxTransfer > 0){
|
||||
bagStack.stackSize += maxTransfer;
|
||||
stack.stackSize -= maxTransfer;
|
||||
needsSave = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
inventory[j] = stack.copy();
|
||||
stack.stackSize = 0;
|
||||
needsSave = true;
|
||||
}
|
||||
|
||||
if(stack.stackSize <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(needsSave && !isVoid){ //void doesn't need to save as items are deleted
|
||||
ItemDrill.writeSlotsToNBT(inventory, invStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(stack.stackSize <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
|
||||
if(!world.isRemote){
|
||||
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<ItemStack>(EnumActionResult.PASS, stack);
|
||||
}
|
||||
}
|
|
@ -20,9 +20,11 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityBookletStand;
|
|||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -39,7 +41,9 @@ import java.util.UUID;
|
|||
|
||||
public final class PacketHandler{
|
||||
|
||||
public static SimpleNetworkWrapper theNetwork;
|
||||
public static final List<IDataHandler> DATA_HANDLERS = new ArrayList<IDataHandler>();
|
||||
|
||||
public static final IDataHandler PARTICLE_HANDLER = new IDataHandler(){
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -75,6 +79,19 @@ public final class PacketHandler{
|
|||
}
|
||||
}
|
||||
};
|
||||
public static final IDataHandler GUI_BUTTON_TO_CONTAINER_HANDLER = new IDataHandler(){
|
||||
@Override
|
||||
public void handleData(NBTTagCompound compound){
|
||||
World world = DimensionManager.getWorld(compound.getInteger("WorldID"));
|
||||
Entity entity = world.getEntityByID(compound.getInteger("PlayerID"));
|
||||
if(entity != null && entity instanceof EntityPlayer){
|
||||
Container container = ((EntityPlayer)entity).openContainer;
|
||||
if(container != null && container instanceof IButtonReactor){
|
||||
((IButtonReactor)container).onButtonPressed(compound.getInteger("ButtonID"), (EntityPlayer)entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
public static final IDataHandler GUI_NUMBER_TO_TILE_HANDLER = new IDataHandler(){
|
||||
@Override
|
||||
public void handleData(NBTTagCompound compound){
|
||||
|
@ -111,7 +128,6 @@ public final class PacketHandler{
|
|||
}
|
||||
}
|
||||
};
|
||||
public static SimpleNetworkWrapper theNetwork;
|
||||
public static final IDataHandler BOOKLET_STAND_BUTTON_HANDLER = new IDataHandler(){
|
||||
@Override
|
||||
public void handleData(NBTTagCompound compound){
|
||||
|
@ -162,5 +178,6 @@ public final class PacketHandler{
|
|||
DATA_HANDLERS.add(GUI_NUMBER_TO_TILE_HANDLER);
|
||||
DATA_HANDLERS.add(CHANGE_PLAYER_DATA_HANDLER);
|
||||
DATA_HANDLERS.add(PLAYER_DATA_TO_CLIENT_HANDLER);
|
||||
DATA_HANDLERS.add(GUI_BUTTON_TO_CONTAINER_HANDLER);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
|||
|
||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -154,7 +155,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
}
|
||||
}
|
||||
//If ESD has enough Space & Item in question is on whitelist
|
||||
if(tempStack != null && (this.slots[0] == null || (tempStack.isItemEqual(this.slots[0]) && this.slots[0].stackSize < maxSize)) && this.checkBothFilters(tempStack, false)){
|
||||
if(tempStack != null && (this.slots[0] == null || (ItemUtil.canBeStacked(tempStack, this.slots[0]) && this.slots[0].stackSize < maxSize)) && this.checkBothFilters(tempStack, false)){
|
||||
//Deal with ISided
|
||||
if(theSided != null){
|
||||
//Check if Item can be inserted from any Side (Because Sidedness gets ignored!)
|
||||
|
@ -183,7 +184,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
if(can){
|
||||
//If ESD already has Items
|
||||
if(this.slots[0] != null){
|
||||
if(theStack.isItemEqual(this.slots[0])){
|
||||
if(ItemUtil.canBeStacked(theStack, this.slots[0])){
|
||||
//If the StackSize is smaller than the space the ESD has left
|
||||
if(theStack.stackSize <= maxSize-this.slots[0].stackSize){
|
||||
this.slots[0].stackSize += theStack.stackSize;
|
||||
|
@ -247,7 +248,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
maxSize = theInventory.getInventoryStackLimit();
|
||||
}
|
||||
}
|
||||
if(theInventory.isItemValidForSlot(i, this.slots[0]) && (tempStack == null || (tempStack.isItemEqual(this.slots[0]) && tempStack.stackSize < maxSize)) && this.checkBothFilters(this.slots[0], true)){
|
||||
if(theInventory.isItemValidForSlot(i, this.slots[0]) && (tempStack == null || (ItemUtil.canBeStacked(tempStack, this.slots[0]) && tempStack.stackSize < maxSize)) && this.checkBothFilters(this.slots[0], true)){
|
||||
if(theSided != null){
|
||||
for(int j = 0; j <= 5; j++){
|
||||
if(theSided.canInsertItem(i, this.slots[0], EnumFacing.values()[j])){
|
||||
|
@ -271,7 +272,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
if(can){
|
||||
if(theStack != null){
|
||||
ItemStack copiedStack = theStack.copy();
|
||||
if(copiedStack.isItemEqual(this.slots[0])){
|
||||
if(ItemUtil.canBeStacked(copiedStack, this.slots[0])){
|
||||
if(this.slots[0].stackSize <= maxSize-copiedStack.stackSize){
|
||||
copiedStack.stackSize += this.slots[0].stackSize;
|
||||
this.slots[0] = null;
|
||||
|
|
|
@ -124,4 +124,8 @@ public final class ItemUtil{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canBeStacked(ItemStack stack1, ItemStack stack2){
|
||||
return ItemStack.areItemsEqual(stack1, stack2) && ItemStack.areItemStackTagsEqual(stack1, stack2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -312,7 +312,7 @@ public final class WorldUtil{
|
|||
for(int i = start; i < end; i++){
|
||||
if(shouldAlwaysWork || ((!(inventory instanceof ISidedInventory) || ((ISidedInventory)inventory).canInsertItem(i, stackToPutIn, side)) && inventory.isItemValidForSlot(i, stackToPutIn))){
|
||||
ItemStack stackInQuestion = inventory.getStackInSlot(i);
|
||||
if(stackToPutIn != null && (stackInQuestion == null || (stackInQuestion.isItemEqual(stackToPutIn) && stackInQuestion.getMaxStackSize() >= stackInQuestion.stackSize+stackToPutIn.stackSize))){
|
||||
if(stackToPutIn != null && (stackInQuestion == null || (ItemUtil.canBeStacked(stackInQuestion, stackToPutIn) && stackInQuestion.getMaxStackSize() >= stackInQuestion.stackSize+stackToPutIn.stackSize))){
|
||||
if(stackInQuestion == null){
|
||||
inventory.setInventorySlotContents(i, stackToPutIn.copy());
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
Loading…
Reference in a new issue