mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 19:29:17 +00:00
Add greenhouse hatch and add IItemHandler integreation, thanks to CovertJaguar
This commit is contained in:
1 parent
3d25bd8626
commit
86a93b29c0
55 files changed
+1919
-884
No files matched your search
@@ -26,13 +26,11 @@ public class ItemBeealyzer extends ItemWithGui {
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
ItemInventoryBeealyzer inventory = new ItemInventoryBeealyzer(player, heldItem);
|
||||
return new GuiBeealyzer(player, inventory);
|
||||
return new GuiBeealyzer(player, new ItemInventoryBeealyzer(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
ItemInventoryBeealyzer inventory = new ItemInventoryBeealyzer(player, heldItem);
|
||||
return new ContainerAlyzer(inventory, player);
|
||||
return new ContainerAlyzer(new ItemInventoryBeealyzer(player, heldItem), player);
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,8 @@ import forestry.apiculture.worldgen.Hive;
|
||||
import forestry.apiculture.worldgen.HiveDecorator;
|
||||
import forestry.apiculture.worldgen.HiveDescriptionSwarmer;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.inventory.iterators.IExtInvSlot;
|
||||
import forestry.core.inventory.iterators.InventoryIterator;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.IActivatable;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
@@ -116,7 +116,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory,
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(getInternalInventory())) {
|
||||
for (IExtInvSlot slot : InventoryIterator.getIterable(getInternalInventory())) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
for (Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) {
|
||||
if (ItemStackUtil.isIdenticalItem(entry.getKey(), stack)) {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) CovertJaguar, 2011-2016 *
|
||||
* http://railcraft.info *
|
||||
* *
|
||||
* This code is the property of CovertJaguar *
|
||||
* and may only be used with explicit written *
|
||||
* permission unless otherwise specified on the *
|
||||
* license page at http://railcraft.info/wiki/info:license. *
|
||||
******************************************************************************/
|
||||
|
||||
package forestry.core.inventory;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
/**
|
||||
* Created by CovertJaguar on 3/15/2016 for Railcraft.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class InventoryObject {
|
||||
private Object inventory;
|
||||
|
||||
public InventoryObject(IInventory inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
public InventoryObject(IItemHandler inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,11 @@ public class InventoryPlain implements IInventory, INbtWritable, INbtReadable {
|
||||
private final String name;
|
||||
private final int stackLimit;
|
||||
|
||||
public InventoryPlain(int size) {
|
||||
this(size, null, 64);
|
||||
}
|
||||
|
||||
|
||||
public InventoryPlain(int size, String name) {
|
||||
this(size, name, 64);
|
||||
}
|
||||
@@ -82,6 +87,9 @@ public class InventoryPlain implements IInventory, INbtWritable, INbtReadable {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if(name == null){
|
||||
return "Plain";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -106,7 +114,7 @@ public class InventoryPlain implements IInventory, INbtWritable, INbtReadable {
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return true;
|
||||
return name != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+16
-2
@@ -8,8 +8,22 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.models;
|
||||
package forestry.core.inventory;
|
||||
|
||||
public class ModelGreenhouseSprinkler {
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
|
||||
public class ItemHandlerItemInventory<I extends ItemInventory> extends InvWrapper {
|
||||
|
||||
private I itemInventory;
|
||||
|
||||
public ItemHandlerItemInventory(I inv) {
|
||||
super(inv);
|
||||
|
||||
itemInventory = inv;
|
||||
}
|
||||
|
||||
public I getItemInventory() {
|
||||
return itemInventory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,10 +17,15 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import forestry.core.tiles.IFilterSlotDelegate;
|
||||
|
||||
public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
|
||||
public abstract class ItemInventory implements IInventory, IFilterSlotDelegate, ICapabilityProvider {
|
||||
private static final String KEY_SLOTS = "Slots";
|
||||
private static final String KEY_UID = "UID";
|
||||
private static final Random rand = new Random();
|
||||
@@ -286,4 +291,19 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
}
|
||||
|
||||
IItemHandler handler = new ItemHandlerItemInventory(this);
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){
|
||||
return (T) handler;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
||||
}
|
||||
}
|
||||
@@ -17,32 +17,32 @@ import forestry.core.utils.InventoryUtil;
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class ArrayStackFilter implements IStackFilter {
|
||||
public class ArrayStackFilter extends StackFilter {
|
||||
|
||||
private final ItemStack[] stacks;
|
||||
private final ItemStack[] stacks;
|
||||
|
||||
public ArrayStackFilter(ItemStack... stacks) {
|
||||
this.stacks = stacks;
|
||||
}
|
||||
public ArrayStackFilter(ItemStack... stacks) {
|
||||
this.stacks = stacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack stack) {
|
||||
if (stacks.length == 0 || !hasFilter()) {
|
||||
return true;
|
||||
}
|
||||
return InventoryUtil.isItemEqual(stack, stacks);
|
||||
}
|
||||
@Override
|
||||
public boolean apply(final ItemStack stack) {
|
||||
if (stacks.length == 0 || !hasFilter()) {
|
||||
return true;
|
||||
}
|
||||
return InventoryUtil.isItemEqual(stack, stacks);
|
||||
}
|
||||
|
||||
public ItemStack[] getStacks() {
|
||||
return stacks;
|
||||
}
|
||||
public ItemStack[] getStacks() {
|
||||
return stacks;
|
||||
}
|
||||
|
||||
private boolean hasFilter() {
|
||||
for (ItemStack filter : stacks) {
|
||||
if (filter != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean hasFilter() {
|
||||
for (ItemStack filter : stacks) {
|
||||
if (filter != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+12
-10
@@ -10,24 +10,26 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.filters;
|
||||
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class InvertedStackFilter implements IStackFilter {
|
||||
public class ExclusionStackFilter extends StackFilter {
|
||||
|
||||
private final IStackFilter filter;
|
||||
private final ItemStack[] exclude;
|
||||
|
||||
public InvertedStackFilter(IStackFilter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
public ExclusionStackFilter(ItemStack... exclude) {
|
||||
this.exclude = exclude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
@Override
|
||||
public boolean apply(final ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return false;
|
||||
}
|
||||
return !filter.matches(stack);
|
||||
}
|
||||
return !InventoryUtil.isItemEqual(stack, exclude);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,16 +10,21 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.filters;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* This interface is used with several of the functions in IItemTransfer to
|
||||
* provide a convenient means of dealing with entire classes of items without
|
||||
* having to specify each item individually.
|
||||
* This interface is used to provide a convenient means of dealing with entire classes of items without having to specify each item individually.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public interface IStackFilter {
|
||||
public interface IStackFilter extends Predicate<ItemStack> {
|
||||
|
||||
boolean matches(ItemStack stack);
|
||||
StackFilter and(@Nonnull Predicate<? super ItemStack>... other);
|
||||
|
||||
StackFilter or(@Nonnull Predicate<? super ItemStack>... other);
|
||||
|
||||
StackFilter negate();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.filters;
|
||||
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class InventoryStackFilter extends StackFilter {
|
||||
|
||||
private final IInventory inv;
|
||||
|
||||
public InventoryStackFilter(IInventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(final ItemStack stack) {
|
||||
return InventoryUtil.containsItem(inv, stack);
|
||||
}
|
||||
}
|
||||
@@ -10,40 +10,113 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.filters;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemFood;
|
||||
import net.minecraft.item.ItemSeeds;
|
||||
import com.google.common.base.Predicate;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This interface is used with several of the functions in IItemTransfer to
|
||||
* provide a convenient means of dealing with entire classes of items without
|
||||
* having to specify each item individually.
|
||||
* This class is used to provide a convenient means of dealing with entire classes of items without having to specify each item individually.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public enum StackFilter implements IStackFilter {
|
||||
@SuppressWarnings("unused")
|
||||
public class StackFilter implements IStackFilter {
|
||||
/**
|
||||
* Railcraft adds the following IItemTypes during preInit: ALL, FUEL, TRACK, MINECART, BALLAST, FEED
|
||||
* <p/>
|
||||
* Feel free to grab them from here or define your own.
|
||||
*/
|
||||
public static final Map<String, IStackFilter> standardFilters = new HashMap<String, IStackFilter>();
|
||||
|
||||
ALL {
|
||||
@Override
|
||||
public boolean matches(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
FUEL {
|
||||
@Override
|
||||
public boolean matches(ItemStack stack) {
|
||||
return TileEntityFurnace.getItemBurnTime(stack) > 0;
|
||||
}
|
||||
},
|
||||
FEED {
|
||||
@Override
|
||||
public boolean matches(ItemStack stack) {
|
||||
return stack.getItem() instanceof ItemFood || stack.getItem() == Items.wheat || stack.getItem() instanceof ItemSeeds;
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public boolean apply(@Nullable final ItemStack input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final StackFilter and(@Nonnull final Predicate<? super ItemStack>... other) {
|
||||
Objects.requireNonNull(other);
|
||||
return new StackFilter() {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
for (Predicate<? super ItemStack> filter : other) {
|
||||
if (!filter.apply(stack)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return StackFilter.this.apply(stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public final StackFilter or(@Nonnull final Predicate<? super ItemStack>... other) {
|
||||
Objects.requireNonNull(other);
|
||||
return new StackFilter() {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
for (Predicate<? super ItemStack> filter : other) {
|
||||
if (filter.apply(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return StackFilter.this.apply(stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public final StackFilter negate() {
|
||||
return new StackFilter() {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
return !StackFilter.this.apply(stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static StackFilter buildAnd(@Nonnull final Predicate<? super ItemStack>... filters) {
|
||||
return new StackFilter() {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
Objects.requireNonNull(stack);
|
||||
for (Predicate<? super ItemStack> filter : filters) {
|
||||
if (!filter.apply(stack)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static StackFilter buildOr(@Nonnull final Predicate<? super ItemStack>... filters) {
|
||||
return new StackFilter() {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
Objects.requireNonNull(stack);
|
||||
for (Predicate<? super ItemStack> filter : filters) {
|
||||
if (filter.apply(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static StackFilter invert(@Nonnull final Predicate<? super ItemStack> filter) {
|
||||
return new StackFilter() {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
return !filter.apply(stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean matches(ItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.filters;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This interface is used with several of the functions in IItemTransfer to
|
||||
* provide a convenient means of dealing with entire classes of items without
|
||||
* having to specify each item individually.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public enum StandardStackFilters implements IStackFilter {
|
||||
|
||||
ALL {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
FUEL {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
return TileEntityFurnace.getItemBurnTime(stack) > 0;
|
||||
}
|
||||
},
|
||||
FEED {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
return stack.getItem() instanceof ItemFood || stack.getItem() == Items.wheat || stack.getItem() instanceof ItemSeeds;
|
||||
}
|
||||
};
|
||||
|
||||
public static void initialize() {
|
||||
for (StandardStackFilters type : StandardStackFilters.values()) {
|
||||
StackFilter.standardFilters.put(type.name(), type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean apply(ItemStack stack);
|
||||
|
||||
@Override
|
||||
public final StackFilter and(@Nonnull final Predicate<? super ItemStack>... other) {
|
||||
Objects.requireNonNull(other);
|
||||
return new StackFilter() {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
for (Predicate<? super ItemStack> filter : other) {
|
||||
if (!filter.apply(stack)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return StandardStackFilters.this.apply(stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public final StackFilter or(@Nonnull final Predicate<? super ItemStack>... other) {
|
||||
Objects.requireNonNull(other);
|
||||
return new StackFilter() {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
for (Predicate<? super ItemStack> filter : other) {
|
||||
if (filter.apply(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return StandardStackFilters.this.apply(stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public final StackFilter negate() {
|
||||
return new StackFilter() {
|
||||
@Override
|
||||
public boolean apply(ItemStack stack) {
|
||||
return !StandardStackFilters.this.apply(stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
|
||||
package forestry.core.inventory.iterators;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This interface extends IInvSlot by allowing you to modify a slot directly.
|
||||
* This is only valid on inventories backed by IInventory.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Created by CovertJaguar on 3/16/2016 for Railcraft.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public interface IExtInvSlot extends IInvSlot {
|
||||
/**
|
||||
* Sets the current ItemStack in the slot.
|
||||
*/
|
||||
void setStackInSlot(ItemStack stack);
|
||||
}
|
||||
Executable → Regular
+12
-7
@@ -8,25 +8,30 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.wrappers;
|
||||
package forestry.core.inventory.iterators;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This Interface represents an abstract inventory slot. It provides a unified interface for interfacing with Inventories.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public interface IInvSlot {
|
||||
|
||||
boolean canPutStackInSlot(ItemStack stack);
|
||||
boolean canPutStackInSlot(ItemStack stack);
|
||||
|
||||
boolean canTakeStackFromSlot(ItemStack stack);
|
||||
boolean canTakeStackFromSlot(ItemStack stack);
|
||||
|
||||
ItemStack decreaseStackInSlot();
|
||||
ItemStack decreaseStackInSlot();
|
||||
|
||||
ItemStack getStackInSlot();
|
||||
/**
|
||||
* It is not legal to edit the stack returned from this function.
|
||||
*/
|
||||
ItemStack getStackInSlot();
|
||||
|
||||
void setStackInSlot(ItemStack stack);
|
||||
// void setStackInSlot(ItemStack stack);
|
||||
|
||||
int getIndex();
|
||||
int getIndex();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.iterators;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.inventory.InventoryObject;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public abstract class InventoryIterator<T extends IInvSlot> implements Iterable<T> {
|
||||
|
||||
public static InventoryIterator<IExtInvSlot> getIterable(IInventory inv) {
|
||||
if (inv instanceof ISidedInventory) {
|
||||
return new SidedInventoryIterator((ISidedInventory) inv);
|
||||
}
|
||||
return new StandardInventoryIterator(inv);
|
||||
}
|
||||
|
||||
public static InventoryIterator<IInvSlot> getIterable(IItemHandler inv) {
|
||||
return new ItemHandlerInventoryIterator(inv);
|
||||
}
|
||||
|
||||
public static InventoryIterator<? extends IInvSlot> getIterable(InventoryObject inv) {
|
||||
if (inv.getObject() instanceof ISidedInventory) {
|
||||
return new SidedInventoryIterator((ISidedInventory) inv.getObject());
|
||||
}
|
||||
if (inv.getObject() instanceof IInventory) {
|
||||
return new StandardInventoryIterator((IInventory) inv.getObject());
|
||||
}
|
||||
if (inv.getObject() instanceof IItemHandler) {
|
||||
return new ItemHandlerInventoryIterator((IItemHandler) inv.getObject());
|
||||
}
|
||||
throw new RuntimeException("Invalid Inventory Object");
|
||||
}
|
||||
|
||||
public Iterable<T> notNull() {
|
||||
List<T> filledSlots = new ArrayList<T>(32);
|
||||
for (T slot : this) {
|
||||
if (slot.getStackInSlot() != null) {
|
||||
filledSlots.add(slot);
|
||||
}
|
||||
}
|
||||
return filledSlots;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.iterators;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class ItemHandlerInventoryIterator extends InventoryIterator<IInvSlot> {
|
||||
|
||||
private final IItemHandler inv;
|
||||
|
||||
protected ItemHandlerInventoryIterator(IItemHandler inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IInvSlot> iterator() {
|
||||
return new Iterator<IInvSlot>() {
|
||||
int slot = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return slot < inv.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInvSlot next() {
|
||||
return new InvSlot(slot++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Remove not supported.");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private class InvSlot implements IInvSlot {
|
||||
|
||||
protected final int slot;
|
||||
|
||||
public InvSlot(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPutStackInSlot(ItemStack stack) {
|
||||
return inv.insertItem(slot, stack, true) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStackFromSlot(ItemStack stack) {
|
||||
return inv.extractItem(slot, 1, true) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decreaseStackInSlot() {
|
||||
return inv.extractItem(slot, 1, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot() {
|
||||
return InventoryUtil.makeSafe(inv.getStackInSlot(slot));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.iterators;
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class SidedInventoryIterator extends StandardInventoryIterator {
|
||||
|
||||
private final ISidedInventory inv;
|
||||
|
||||
protected SidedInventoryIterator(ISidedInventory inv) {
|
||||
super(inv);
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IExtInvSlot> iterator() {
|
||||
return new Iterator<IExtInvSlot>() {
|
||||
int[] slots = inv.getSlotsForFace(EnumFacing.DOWN);
|
||||
int index = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return slots != null && index < slots.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExtInvSlot next() {
|
||||
return new InvSlot(slots[index++]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Remove not supported.");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private class InvSlot extends StandardInventoryIterator.InvSlot implements IExtInvSlot {
|
||||
|
||||
public InvSlot(int slot) {
|
||||
super(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPutStackInSlot(ItemStack stack) {
|
||||
return inv.canInsertItem(slot, stack, EnumFacing.DOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStackFromSlot(ItemStack stack) {
|
||||
return inv.canExtractItem(slot, stack, EnumFacing.DOWN);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
|
||||
package forestry.core.inventory.iterators;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class StandardInventoryIterator extends InventoryIterator<IExtInvSlot> {
|
||||
|
||||
private final IInventory inv;
|
||||
private final int invSize;
|
||||
|
||||
protected StandardInventoryIterator(IInventory inv) {
|
||||
this.inv = inv;
|
||||
this.invSize = inv.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IExtInvSlot> iterator() {
|
||||
return new Iterator<IExtInvSlot>() {
|
||||
int slot = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return slot < invSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExtInvSlot next() {
|
||||
return new InvSlot(slot++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Remove not supported.");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
class InvSlot implements IExtInvSlot {
|
||||
|
||||
protected final int slot;
|
||||
|
||||
public InvSlot(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot() {
|
||||
return inv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(ItemStack stack) {
|
||||
inv.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPutStackInSlot(ItemStack stack) {
|
||||
return inv.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStackFromSlot(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decreaseStackInSlot() {
|
||||
return inv.decrStackSize(slot, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ItemStack stack = getStackInSlot();
|
||||
return "SlotNum = " + slot + " Stack = " + (stack == null ? "null" : getStackInSlot().toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,177 +10,132 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.manipulators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.inventory.InventoryObject;
|
||||
import forestry.core.inventory.filters.IStackFilter;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.inventory.iterators.IExtInvSlot;
|
||||
import forestry.core.inventory.iterators.IInvSlot;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class InventoryManipulator {
|
||||
public abstract class InventoryManipulator<T extends IInvSlot> implements Iterable<T> {
|
||||
|
||||
private final IInventory inv;
|
||||
public static InventoryManipulator<IExtInvSlot> get(IInventory inv) {
|
||||
return new StandardInventoryManipulator(inv);
|
||||
}
|
||||
|
||||
public static InventoryManipulator get(IInventory inv) {
|
||||
return new InventoryManipulator(inv);
|
||||
}
|
||||
public static InventoryManipulator<IInvSlot> get(IItemHandler inv) {
|
||||
return new ItemHandlerInventoryManipulator(inv);
|
||||
}
|
||||
|
||||
protected InventoryManipulator(IInventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
protected Iterable<IInvSlot> getSlots() {
|
||||
return InventoryIterator.getIterable(inv);
|
||||
}
|
||||
|
||||
public boolean canAddStack(ItemStack stack) {
|
||||
return tryAddStack(stack) == null;
|
||||
}
|
||||
|
||||
public ItemStack tryAddStack(ItemStack stack) {
|
||||
return addStack(stack, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to add the stack to the inventory.
|
||||
*
|
||||
* @return The remainder
|
||||
*/
|
||||
public ItemStack addStack(ItemStack stack) {
|
||||
return addStack(stack, true);
|
||||
}
|
||||
|
||||
private ItemStack addStack(ItemStack stack, boolean doAdd) {
|
||||
if (stack == null || stack.stackSize <= 0) {
|
||||
return null;
|
||||
public static InventoryManipulator<? extends IInvSlot> get(InventoryObject inv) {
|
||||
if (inv.getObject() instanceof IInventory) {
|
||||
return new StandardInventoryManipulator((IInventory) inv.getObject());
|
||||
}
|
||||
stack = stack.copy();
|
||||
List<IInvSlot> filledSlots = new ArrayList<>(inv.getSizeInventory());
|
||||
List<IInvSlot> emptySlots = new ArrayList<>(inv.getSizeInventory());
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(inv)) {
|
||||
if (slot.canPutStackInSlot(stack)) {
|
||||
if (slot.getStackInSlot() == null) {
|
||||
emptySlots.add(slot);
|
||||
} else {
|
||||
filledSlots.add(slot);
|
||||
}
|
||||
}
|
||||
if (inv.getObject() instanceof IItemHandler) {
|
||||
return new ItemHandlerInventoryManipulator((IItemHandler) inv.getObject());
|
||||
}
|
||||
throw new RuntimeException("Invalid Inventory Object");
|
||||
}
|
||||
|
||||
int injected = 0;
|
||||
injected = tryPut(filledSlots, stack, injected, doAdd);
|
||||
injected = tryPut(emptySlots, stack, injected, doAdd);
|
||||
stack.stackSize -= injected;
|
||||
if (stack.stackSize <= 0) {
|
||||
return null;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
protected InventoryManipulator() {
|
||||
}
|
||||
|
||||
private int tryPut(List<IInvSlot> slots, ItemStack stack, int injected, boolean doAdd) {
|
||||
if (injected >= stack.stackSize) {
|
||||
return injected;
|
||||
}
|
||||
for (IInvSlot slot : slots) {
|
||||
ItemStack stackInSlot = slot.getStackInSlot();
|
||||
if (stackInSlot == null || InventoryUtil.isItemEqual(stackInSlot, stack)) {
|
||||
int used = addToSlot(slot, stack, stack.stackSize - injected, doAdd);
|
||||
if (used > 0) {
|
||||
injected += used;
|
||||
if (injected >= stack.stackSize) {
|
||||
return injected;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return injected;
|
||||
}
|
||||
public boolean canAddStack(ItemStack stack) {
|
||||
return tryAddStack(stack) == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param available Amount we can move
|
||||
* @return Return the number of items moved.
|
||||
*/
|
||||
private int addToSlot(IInvSlot slot, ItemStack stack, int available, boolean doAdd) {
|
||||
int max = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit());
|
||||
public ItemStack tryAddStack(ItemStack stack) {
|
||||
return addStack(stack, false);
|
||||
}
|
||||
|
||||
ItemStack stackInSlot = slot.getStackInSlot();
|
||||
if (stackInSlot == null) {
|
||||
int wanted = Math.min(available, max);
|
||||
if (doAdd) {
|
||||
stackInSlot = stack.copy();
|
||||
stackInSlot.stackSize = wanted;
|
||||
slot.setStackInSlot(stackInSlot);
|
||||
}
|
||||
return wanted;
|
||||
}
|
||||
/**
|
||||
* Attempt to add the stack to the inventory.
|
||||
*
|
||||
* @return The remainder
|
||||
*/
|
||||
public ItemStack addStack(ItemStack stack) {
|
||||
return addStack(stack, true);
|
||||
}
|
||||
|
||||
if (!InventoryUtil.isItemEqual(stack, stackInSlot)) {
|
||||
return 0;
|
||||
}
|
||||
protected abstract ItemStack addStack(ItemStack stack, boolean doAdd);
|
||||
|
||||
int wanted = max - stackInSlot.stackSize;
|
||||
if (wanted <= 0) {
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* Returns true if an item matching the filter can be removed from the
|
||||
* inventory.
|
||||
*/
|
||||
public boolean canRemoveItem(IStackFilter filter) {
|
||||
return tryRemoveItem(filter) == null;
|
||||
}
|
||||
|
||||
if (wanted > available) {
|
||||
wanted = available;
|
||||
}
|
||||
/**
|
||||
* Returns the item that would be returned if an item matching the filter
|
||||
* was removed. Does not modify the inventory.
|
||||
*/
|
||||
public ItemStack tryRemoveItem(IStackFilter filter) {
|
||||
for (IInvSlot slot : this) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
|
||||
ItemStack output = stack.copy();
|
||||
output.stackSize = 1;
|
||||
return output;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (doAdd) {
|
||||
stackInSlot.stackSize += wanted;
|
||||
slot.setStackInSlot(stackInSlot);
|
||||
}
|
||||
return wanted;
|
||||
}
|
||||
|
||||
public boolean canRemoveItem(IStackFilter filter) {
|
||||
return tryRemoveItem(filter) == null;
|
||||
}
|
||||
|
||||
public ItemStack tryRemoveItem(IStackFilter filter) {
|
||||
for (IInvSlot slot : getSlots()) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null && slot.canTakeStackFromSlot(stack) && filter.matches(stack)) {
|
||||
ItemStack output = stack.copy();
|
||||
output.stackSize = 1;
|
||||
return output;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack removeItem(IStackFilter filter) {
|
||||
for (IInvSlot slot : getSlots()) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null && slot.canTakeStackFromSlot(stack) && filter.matches(stack)) {
|
||||
/**
|
||||
* Removed an item matching the filter.
|
||||
*/
|
||||
public ItemStack removeItem(IStackFilter filter) {
|
||||
for (IInvSlot slot : this) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
|
||||
return slot.decreaseStackInSlot();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack moveItem(IInventory dest, IStackFilter filter) {
|
||||
InventoryManipulator imDest = InventoryManipulator.get(dest);
|
||||
for (IInvSlot slot : getSlots()) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null && slot.canTakeStackFromSlot(stack) && filter.matches(stack)) {
|
||||
stack = stack.copy();
|
||||
stack.stackSize = 1;
|
||||
stack = imDest.addStack(stack);
|
||||
if (stack == null) {
|
||||
public boolean canRemoveItems(IStackFilter filter, int maxAmount) {
|
||||
List<ItemStack> outputList = removeItem(filter, maxAmount, false);
|
||||
int found = 0;
|
||||
for (ItemStack stack : outputList) {
|
||||
found += stack.stackSize;
|
||||
}
|
||||
return found == maxAmount;
|
||||
}
|
||||
|
||||
public List<ItemStack> removeItems(IStackFilter filter, int maxAmount) {
|
||||
return removeItem(filter, maxAmount, true);
|
||||
}
|
||||
|
||||
protected abstract List<ItemStack> removeItem(IStackFilter filter, int maxAmount, boolean doRemove);
|
||||
|
||||
public ItemStack moveItem(IInventory dest, IStackFilter filter) {
|
||||
return moveItem(new InventoryObject(dest), filter);
|
||||
}
|
||||
|
||||
public ItemStack moveItem(InventoryObject dest, IStackFilter filter) {
|
||||
InventoryManipulator imDest = InventoryManipulator.get(dest);
|
||||
for (IInvSlot slot : this) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
|
||||
stack = stack.copy();
|
||||
stack.stackSize = 1;
|
||||
stack = imDest.addStack(stack);
|
||||
if (stack == null) {
|
||||
return slot.decreaseStackInSlot();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.manipulators;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.inventory.filters.IStackFilter;
|
||||
import forestry.core.inventory.iterators.IInvSlot;
|
||||
import forestry.core.inventory.iterators.InventoryIterator;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class ItemHandlerInventoryManipulator extends InventoryManipulator<IInvSlot> {
|
||||
|
||||
private final IItemHandler inv;
|
||||
|
||||
protected ItemHandlerInventoryManipulator(IItemHandler inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IInvSlot> iterator() {
|
||||
return InventoryIterator.getIterable(inv).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack addStack(ItemStack stack, boolean doAdd) {
|
||||
if (stack == null || stack.stackSize <= 0) {
|
||||
return null;
|
||||
}
|
||||
stack = stack.copy();
|
||||
List<IInvSlot> filledSlots = new ArrayList<IInvSlot>(inv.getSlots());
|
||||
List<IInvSlot> emptySlots = new ArrayList<IInvSlot>(inv.getSlots());
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(inv)) {
|
||||
if (slot.canPutStackInSlot(stack)) {
|
||||
if (slot.getStackInSlot() == null) {
|
||||
emptySlots.add(slot);
|
||||
} else {
|
||||
filledSlots.add(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int injected = 0;
|
||||
injected = tryPut(filledSlots, stack, injected, doAdd);
|
||||
injected = tryPut(emptySlots, stack, injected, doAdd);
|
||||
stack.stackSize -= injected;
|
||||
if (stack.stackSize <= 0) {
|
||||
return null;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
private int tryPut(List<IInvSlot> slots, ItemStack stack, int injected, boolean doAdd) {
|
||||
if (injected >= stack.stackSize) {
|
||||
return injected;
|
||||
}
|
||||
for (IInvSlot slot : slots) {
|
||||
ItemStack stackToInsert = stack.copy();
|
||||
stackToInsert.stackSize = stack.stackSize - injected;
|
||||
ItemStack remainder = inv.insertItem(slot.getIndex(), stackToInsert, !doAdd);
|
||||
if (remainder == null) {
|
||||
return injected;
|
||||
}
|
||||
injected += remainder.stackSize;
|
||||
if (injected >= stack.stackSize) {
|
||||
return injected;
|
||||
}
|
||||
}
|
||||
return injected;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ItemStack> removeItem(IStackFilter filter, int maxAmount, boolean doRemove) {
|
||||
int amountNeeded = maxAmount;
|
||||
List<ItemStack> outputList = new ArrayList<ItemStack>();
|
||||
for (IInvSlot slot : this) {
|
||||
if (amountNeeded <= 0) {
|
||||
break;
|
||||
}
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
|
||||
ItemStack removed = inv.extractItem(slot.getIndex(), amountNeeded, !doRemove);
|
||||
if (removed != null) {
|
||||
amountNeeded -= removed.stackSize;
|
||||
outputList.add(removed);
|
||||
}
|
||||
}
|
||||
}
|
||||
return outputList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.manipulators;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.inventory.filters.IStackFilter;
|
||||
import forestry.core.inventory.iterators.IExtInvSlot;
|
||||
import forestry.core.inventory.iterators.InventoryIterator;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class StandardInventoryManipulator extends InventoryManipulator<IExtInvSlot> {
|
||||
|
||||
private final IInventory inv;
|
||||
|
||||
protected StandardInventoryManipulator(IInventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IExtInvSlot> iterator() {
|
||||
return InventoryIterator.getIterable(inv).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack addStack(ItemStack stack, boolean doAdd) {
|
||||
if (stack == null || stack.stackSize <= 0) {
|
||||
return null;
|
||||
}
|
||||
stack = stack.copy();
|
||||
List<IExtInvSlot> filledSlots = new ArrayList<IExtInvSlot>(inv.getSizeInventory());
|
||||
List<IExtInvSlot> emptySlots = new ArrayList<IExtInvSlot>(inv.getSizeInventory());
|
||||
for (IExtInvSlot slot : this) {
|
||||
if (slot.canPutStackInSlot(stack)) {
|
||||
if (slot.getStackInSlot() == null) {
|
||||
emptySlots.add(slot);
|
||||
} else {
|
||||
filledSlots.add(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int injected = 0;
|
||||
injected = tryPut(filledSlots, stack, injected, doAdd);
|
||||
injected = tryPut(emptySlots, stack, injected, doAdd);
|
||||
stack.stackSize -= injected;
|
||||
if (stack.stackSize <= 0) {
|
||||
return null;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
private int tryPut(List<IExtInvSlot> slots, ItemStack stack, int injected, boolean doAdd) {
|
||||
if (injected >= stack.stackSize) {
|
||||
return injected;
|
||||
}
|
||||
for (IExtInvSlot slot : slots) {
|
||||
ItemStack stackInSlot = slot.getStackInSlot();
|
||||
if (stackInSlot == null || InventoryUtil.isItemEqual(stackInSlot, stack)) {
|
||||
int used = addToSlot(slot, stack, stack.stackSize - injected, doAdd);
|
||||
if (used > 0) {
|
||||
injected += used;
|
||||
if (injected >= stack.stackSize) {
|
||||
return injected;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return injected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param available Amount we can move
|
||||
* @return Return the number of items moved.
|
||||
*/
|
||||
private int addToSlot(IExtInvSlot slot, ItemStack stack, int available, boolean doAdd) {
|
||||
int max = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit());
|
||||
|
||||
ItemStack stackInSlot = slot.getStackInSlot();
|
||||
if (stackInSlot == null) {
|
||||
int wanted = Math.min(available, max);
|
||||
if (doAdd) {
|
||||
stackInSlot = stack.copy();
|
||||
stackInSlot.stackSize = wanted;
|
||||
slot.setStackInSlot(stackInSlot);
|
||||
}
|
||||
return wanted;
|
||||
}
|
||||
|
||||
if (!InventoryUtil.isItemEqual(stack, stackInSlot)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wanted = max - stackInSlot.stackSize;
|
||||
if (wanted <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (wanted > available) {
|
||||
wanted = available;
|
||||
}
|
||||
|
||||
if (doAdd) {
|
||||
stackInSlot.stackSize += wanted;
|
||||
slot.setStackInSlot(stackInSlot);
|
||||
}
|
||||
return wanted;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ItemStack> removeItem(IStackFilter filter, int maxAmount, boolean doRemove) {
|
||||
int amountNeeded = maxAmount;
|
||||
List<ItemStack> outputList = new ArrayList<ItemStack>();
|
||||
for (IExtInvSlot slot : this) {
|
||||
if (amountNeeded <= 0) {
|
||||
break;
|
||||
}
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
|
||||
ItemStack output = stack.copy();
|
||||
if (output.stackSize >= amountNeeded) {
|
||||
output.stackSize = amountNeeded;
|
||||
if (doRemove) {
|
||||
stack.stackSize -= amountNeeded;
|
||||
if (stack.stackSize <= 0) {
|
||||
stack = null;
|
||||
}
|
||||
slot.setStackInSlot(stack);
|
||||
}
|
||||
amountNeeded = 0;
|
||||
outputList.add(output);
|
||||
} else {
|
||||
amountNeeded -= output.stackSize;
|
||||
outputList.add(output);
|
||||
if (doRemove) {
|
||||
slot.setStackInSlot(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return outputList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -219,4 +219,4 @@ public class ChestWrapper implements IInventory {
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
|
||||
package forestry.core.inventory.wrappers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
/**
|
||||
* Created by CovertJaguar on 3/6/2016 for Railcraft.
|
||||
*/
|
||||
public abstract class InvWrapperBase implements IInventory {
|
||||
|
||||
private final IInventory inv;
|
||||
private boolean checkItems = true;
|
||||
|
||||
public InvWrapperBase(IInventory inv) {
|
||||
this(inv, true);
|
||||
}
|
||||
|
||||
public InvWrapperBase(IInventory inv, boolean checkItems) {
|
||||
this.inv = inv;
|
||||
this.checkItems = checkItems;
|
||||
}
|
||||
|
||||
public IInventory getBaseInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inv.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return inv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
return inv.decrStackSize(slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot) {
|
||||
return inv.removeStackFromSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
inv.setInventorySlotContents(slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return inv.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatComponent getDisplayName() {
|
||||
return inv.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
inv.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return inv.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player) {
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player) {
|
||||
inv.closeInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return inv.hasCustomName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return !checkItems || inv.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return inv.getField(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
inv.setField(id, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return inv.getFieldCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
inv.clear();
|
||||
}
|
||||
|
||||
public boolean checkItems() {
|
||||
return checkItems;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,133 +10,56 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.wrappers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import forestry.core.inventory.InventoryPlain;
|
||||
import forestry.core.inventory.iterators.IExtInvSlot;
|
||||
import forestry.core.inventory.iterators.InventoryIterator;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
|
||||
/**
|
||||
* Creates a deep copy of an existing IInventory.
|
||||
*
|
||||
* <p/>
|
||||
* Useful for performing inventory manipulations and then examining the results
|
||||
* without affecting the original inventory.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class InventoryCopy implements IInventory {
|
||||
public class InventoryCopy extends InvWrapperBase {
|
||||
|
||||
private final IInventory orignal;
|
||||
private final ItemStack contents[];
|
||||
private InventoryPlain copy;
|
||||
|
||||
public InventoryCopy(IInventory orignal) {
|
||||
this.orignal = orignal;
|
||||
contents = new ItemStack[orignal.getSizeInventory()];
|
||||
InventoryUtil.deepCopyInventoryContents(orignal, this);
|
||||
}
|
||||
public InventoryCopy(IInventory original) {
|
||||
super(original);
|
||||
this.copy = new InventoryPlain(original.getSizeInventory());
|
||||
for (IExtInvSlot slot : InventoryIterator.getIterable(original)) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null) {
|
||||
copy.setInventorySlotContents(slot.getIndex(), stack.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return contents.length;
|
||||
}
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
copy.setInventorySlotContents(slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return contents[i];
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return copy.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (contents[i] != null) {
|
||||
if (contents[i].stackSize <= j) {
|
||||
ItemStack itemstack = contents[i];
|
||||
contents[i] = null;
|
||||
markDirty();
|
||||
return itemstack;
|
||||
}
|
||||
ItemStack itemstack1 = contents[i].splitStack(j);
|
||||
if (contents[i].stackSize <= 0) {
|
||||
contents[i] = null;
|
||||
}
|
||||
markDirty();
|
||||
return itemstack1;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
return copy.decrStackSize(slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
contents[i] = itemstack;
|
||||
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
|
||||
itemstack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot) {
|
||||
return copy.removeStackFromSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return orignal.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatComponent getDisplayName() {
|
||||
return orignal.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return orignal.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void markDirty() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer entityplayer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer entityplayer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot) {
|
||||
return orignal.removeStackFromSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return orignal.hasCustomName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return orignal.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.wrappers;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class InventoryIterator implements Iterable<IInvSlot> {
|
||||
|
||||
public static Iterable<IInvSlot> getIterable(IInventory inv) {
|
||||
if (inv instanceof ISidedInventory) {
|
||||
return new SidedInventoryIterator((ISidedInventory) inv);
|
||||
}
|
||||
return new InventoryIterator(inv);
|
||||
}
|
||||
|
||||
private final IInventory inv;
|
||||
private final int invSize;
|
||||
|
||||
private InventoryIterator(IInventory inv) {
|
||||
this.inv = inv;
|
||||
this.invSize = inv != null ? inv.getSizeInventory() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IInvSlot> iterator() {
|
||||
return new Iterator<IInvSlot>() {
|
||||
int slot = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return slot < invSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInvSlot next() {
|
||||
return new InvSlot(slot++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Remove not supported.");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private class InvSlot implements IInvSlot {
|
||||
|
||||
private final int slot;
|
||||
|
||||
public InvSlot(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot() {
|
||||
return inv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(ItemStack stack) {
|
||||
inv.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPutStackInSlot(ItemStack stack) {
|
||||
return inv.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStackFromSlot(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decreaseStackInSlot() {
|
||||
return inv.decrStackSize(slot, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Copyright (c) CovertJaguar, 2014 http://railcraft.info
|
||||
*
|
||||
* This code is the property of CovertJaguar
|
||||
* and may only be used with explicit written
|
||||
* permission unless otherwise specified on the
|
||||
* license page at http://railcraft.info/wiki/info:license.
|
||||
*/
|
||||
package forestry.core.inventory.wrappers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
/**
|
||||
* Wrapper class used to specify part of an existing inventory to be treated as
|
||||
@@ -23,152 +18,72 @@ import net.minecraft.util.IChatComponent;
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class InventoryMapper implements IInventory {
|
||||
public class InventoryMapper extends InvWrapperBase implements IInventory {
|
||||
|
||||
private final IInventory inv;
|
||||
private final int start;
|
||||
private final int size;
|
||||
private int stackSizeLimit = -1;
|
||||
private boolean checkItems = true;
|
||||
private final IInventory inv;
|
||||
private final int start;
|
||||
private final int size;
|
||||
private int stackSizeLimit = -1;
|
||||
|
||||
public InventoryMapper(IInventory inv, EnumFacing side) {
|
||||
this(inv, getInventoryStart(inv, side), getInventorySize(inv, side));
|
||||
}
|
||||
public InventoryMapper(IInventory inv) {
|
||||
this(inv, 0, inv.getSizeInventory(), true);
|
||||
}
|
||||
|
||||
public InventoryMapper(IInventory inv) {
|
||||
this(inv, 0, inv.getSizeInventory(), true);
|
||||
}
|
||||
public InventoryMapper(IInventory inv, boolean checkItems) {
|
||||
this(inv, 0, inv.getSizeInventory(), checkItems);
|
||||
}
|
||||
|
||||
public InventoryMapper(IInventory inv, boolean checkItems) {
|
||||
this(inv, 0, inv.getSizeInventory(), checkItems);
|
||||
}
|
||||
/**
|
||||
* Creates a new InventoryMapper
|
||||
*
|
||||
* @param inv The backing inventory
|
||||
* @param start The starting index
|
||||
* @param size The size of the new inventory, take care not to exceed the
|
||||
* end of the backing inventory
|
||||
*/
|
||||
public InventoryMapper(IInventory inv, int start, int size) {
|
||||
this(inv, start, size, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new InventoryMapper
|
||||
*
|
||||
* @param inv The backing inventory
|
||||
* @param start The starting index
|
||||
* @param size The size of the new inventory, take care not to exceed the
|
||||
* end of the backing inventory
|
||||
*/
|
||||
public InventoryMapper(IInventory inv, int start, int size) {
|
||||
this(inv, start, size, true);
|
||||
}
|
||||
public InventoryMapper(IInventory inv, int start, int size, boolean checkItems) {
|
||||
super(inv, checkItems);
|
||||
this.inv = inv;
|
||||
this.start = start;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public InventoryMapper(IInventory inv, int start, int size, boolean checkItems) {
|
||||
this.inv = inv;
|
||||
this.start = start;
|
||||
this.size = size;
|
||||
this.checkItems = checkItems;
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return size;
|
||||
}
|
||||
|
||||
protected static int getInventorySize(IInventory inv, EnumFacing side) {
|
||||
return inv.getSizeInventory();
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return inv.getStackInSlot(start + slot);
|
||||
}
|
||||
|
||||
protected static int getInventoryStart(IInventory inv, EnumFacing side) {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
return inv.decrStackSize(start + slot, amount);
|
||||
}
|
||||
|
||||
public IInventory getBaseInventory() {
|
||||
return inv;
|
||||
}
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
inv.setInventorySlotContents(start + slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return size;
|
||||
}
|
||||
public void setStackSizeLimit(int limit) {
|
||||
stackSizeLimit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return inv.getStackInSlot(start + slot);
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return stackSizeLimit > 0 ? stackSizeLimit : inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
return inv.decrStackSize(start + slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
inv.setInventorySlotContents(start + slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return inv.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatComponent getDisplayName() {
|
||||
return inv.getDisplayName();
|
||||
}
|
||||
|
||||
public void setStackSizeLimit(int limit) {
|
||||
stackSizeLimit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return stackSizeLimit > 0 ? stackSizeLimit : inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
inv.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return inv.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer entityplayer) {
|
||||
inv.openInventory(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer entityplayer) {
|
||||
inv.closeInventory(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot) {
|
||||
return inv.removeStackFromSlot(start + slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return inv.hasCustomName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
if (checkItems) {
|
||||
return inv.isItemValidForSlot(start + slot, stack);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return inv.getField(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return inv.getFieldCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
inv.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
inv.setField(id, value);
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return !checkItems() || inv.isItemValidForSlot(start + slot, stack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.wrappers;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class SidedInventoryIterator implements Iterable<IInvSlot> {
|
||||
|
||||
private final ISidedInventory inv;
|
||||
|
||||
SidedInventoryIterator(ISidedInventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IInvSlot> iterator() {
|
||||
return new Iterator<IInvSlot>() {
|
||||
final int[] slots = inv.getSlotsForFace(EnumFacing.DOWN);
|
||||
int index = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return slots != null && index < slots.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInvSlot next() {
|
||||
return new InvSlot(slots[index++]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Remove not supported.");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private class InvSlot implements IInvSlot {
|
||||
|
||||
private final int slot;
|
||||
|
||||
public InvSlot(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot() {
|
||||
return inv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(ItemStack stack) {
|
||||
inv.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPutStackInSlot(ItemStack stack) {
|
||||
return inv.canInsertItem(slot, stack, EnumFacing.DOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStackFromSlot(ItemStack stack) {
|
||||
return inv.canExtractItem(slot, stack, EnumFacing.DOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decreaseStackInSlot() {
|
||||
return inv.decrStackSize(slot, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory.wrappers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
/**
|
||||
* Wrapper class used to bake the side variable into the object itself instead
|
||||
@@ -23,129 +20,34 @@ import net.minecraft.util.IChatComponent;
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class SidedInventoryMapper implements ISidedInventory {
|
||||
public class SidedInventoryMapper extends InvWrapperBase implements ISidedInventory {
|
||||
|
||||
private final ISidedInventory inv;
|
||||
private final EnumFacing side;
|
||||
private boolean checkItems = true;
|
||||
private final ISidedInventory inv;
|
||||
private final EnumFacing side;
|
||||
|
||||
public SidedInventoryMapper(ISidedInventory inv, EnumFacing side) {
|
||||
this(inv, side, true);
|
||||
}
|
||||
public SidedInventoryMapper(ISidedInventory inv, EnumFacing side) {
|
||||
this(inv, side, true);
|
||||
}
|
||||
|
||||
public SidedInventoryMapper(ISidedInventory inv, EnumFacing side, boolean checkItems) {
|
||||
this.inv = inv;
|
||||
this.side = side;
|
||||
this.checkItems = checkItems;
|
||||
}
|
||||
public SidedInventoryMapper(ISidedInventory inv, EnumFacing side, boolean checkItems) {
|
||||
super(inv, checkItems);
|
||||
this.inv = inv;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public IInventory getBaseInventory() {
|
||||
return inv;
|
||||
}
|
||||
@Override
|
||||
public int[] getSlotsForFace(EnumFacing side) {
|
||||
return inv.getSlotsForFace(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inv.getSizeInventory();
|
||||
}
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing s) {
|
||||
return !checkItems() || inv.canInsertItem(slot, stack, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return inv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
return inv.decrStackSize(slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
inv.setInventorySlotContents(slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return inv.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatComponent getDisplayName() {
|
||||
return inv.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
inv.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return inv.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer entityplayer) {
|
||||
inv.openInventory(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer entityplayer) {
|
||||
inv.closeInventory(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index) {
|
||||
return inv.removeStackFromSlot(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return inv.hasCustomName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return !checkItems || inv.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSlotsForFace(EnumFacing side) {
|
||||
return inv.getSlotsForFace(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing s) {
|
||||
return !checkItems || inv.canInsertItem(slot, stack, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing s) {
|
||||
return !checkItems || inv.canExtractItem(slot, stack, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return inv.getField(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
inv.setField(id, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return inv.getFieldCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
inv.clear();
|
||||
}
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing s) {
|
||||
return !checkItems() || inv.canExtractItem(slot, stack, side);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import forestry.core.circuits.ISolderingIron;
|
||||
import forestry.core.inventory.ItemInventorySolderingIron;
|
||||
|
||||
public class ItemSolderingIron extends ItemWithGui implements ISolderingIron {
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
return new GuiSolderingIron(player, new ItemInventorySolderingIron(player, heldItem));
|
||||
|
||||
@@ -274,6 +274,9 @@ public class ModelBaker implements IModelBaker {
|
||||
}
|
||||
|
||||
protected void addFace(@Nonnull EnumFacing face, boolean isEdge, Vector3f to, Vector3f from, float[] defUVs2, TextureAtlasSprite texture) {
|
||||
if(texture == null) {
|
||||
return;
|
||||
}
|
||||
faces.add(new ModelBakerFace(face, isEdge, colorIndex, to, from, defUVs2, texture));
|
||||
}
|
||||
|
||||
@@ -284,6 +287,14 @@ public class ModelBaker implements IModelBaker {
|
||||
if (flip) {
|
||||
mr = ModelRotation.X0_Y180;
|
||||
}
|
||||
|
||||
//Add baked models to the current model.
|
||||
for(IBakedModel bakedModel : bakedModels){
|
||||
for(EnumFacing gce : EnumFacing.VALUES){
|
||||
this.currentModel.getFaceQuads(gce).addAll(bakedModel.getFaceQuads(gce));
|
||||
}
|
||||
this.currentModel.getGeneralQuads().addAll(bakedModel.getGeneralQuads());
|
||||
}
|
||||
|
||||
for (ModelBakerFace face : faces) {
|
||||
final EnumFacing myFace = face.face;
|
||||
@@ -302,14 +313,6 @@ public class ModelBaker implements IModelBaker {
|
||||
}
|
||||
}
|
||||
|
||||
//Add baked models to the current model.
|
||||
for(IBakedModel bakedModel : bakedModels){
|
||||
for(EnumFacing gce : EnumFacing.VALUES){
|
||||
this.currentModel.getFaceQuads(gce).addAll(bakedModel.getFaceQuads(gce));
|
||||
}
|
||||
this.currentModel.getGeneralQuads().addAll(bakedModel.getGeneralQuads());
|
||||
}
|
||||
|
||||
return currentModel;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.gui.ContainerAnalyzer;
|
||||
import forestry.core.gui.GuiAnalyzer;
|
||||
import forestry.core.inventory.InventoryAnalyzer;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.inventory.iterators.IExtInvSlot;
|
||||
import forestry.core.inventory.iterators.InventoryIterator;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
@@ -132,8 +132,8 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
return true;
|
||||
}
|
||||
|
||||
private IInvSlot getInputSlot() {
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(invInput)) {
|
||||
private IExtInvSlot getInputSlot() {
|
||||
for (IExtInvSlot slot : InventoryIterator.getIterable(invInput)) {
|
||||
ItemStack inputStack = slot.getStackInSlot();
|
||||
if (AlleleManager.alleleRegistry.isIndividual(inputStack)) {
|
||||
return slot;
|
||||
@@ -197,7 +197,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
return;
|
||||
}
|
||||
|
||||
IInvSlot slot = getInputSlot();
|
||||
IExtInvSlot slot = getInputSlot();
|
||||
if (slot == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.core.utils;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -36,11 +37,12 @@ import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
import forestry.core.inventory.filters.ArrayStackFilter;
|
||||
import forestry.core.inventory.filters.IStackFilter;
|
||||
import forestry.core.inventory.filters.StackFilter;
|
||||
import forestry.core.inventory.filters.StandardStackFilters;
|
||||
import forestry.core.inventory.iterators.IExtInvSlot;
|
||||
import forestry.core.inventory.iterators.IInvSlot;
|
||||
import forestry.core.inventory.iterators.InventoryIterator;
|
||||
import forestry.core.inventory.manipulators.InventoryManipulator;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryCopy;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.inventory.wrappers.SidedInventoryMapper;
|
||||
import forestry.core.tiles.AdjacentTileCache;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
@@ -75,6 +77,13 @@ public abstract class InventoryUtil {
|
||||
public static boolean isWildcard(int damage) {
|
||||
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
|
||||
public static ItemStack makeSafe(ItemStack stack) {
|
||||
if (stack.stackSize <= 0) {
|
||||
return null;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more robust item comparison function.
|
||||
@@ -157,6 +166,22 @@ public abstract class InventoryUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item is equal to any one of several possible matches.
|
||||
*
|
||||
* @param stack the ItemStack to test
|
||||
* @param matches the ItemStacks to test against
|
||||
* @return true if a match is found
|
||||
*/
|
||||
public static boolean isItemEqual(ItemStack stack, Collection<ItemStack> matches) {
|
||||
for (ItemStack match : matches) {
|
||||
if (isItemEqual(stack, match)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Places an ItemStack in a destination IInventory. Will attempt to move as
|
||||
* much of the stack as possible, returning any remainder.
|
||||
@@ -180,7 +205,7 @@ public abstract class InventoryUtil {
|
||||
*/
|
||||
public static boolean moveItemStack(IInventory source, IInventory dest) {
|
||||
InventoryManipulator im = InventoryManipulator.get(dest);
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(source)) {
|
||||
for (IExtInvSlot slot : InventoryIterator.getIterable(source)) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null) {
|
||||
ItemStack remainder = im.addStack(stack);
|
||||
@@ -190,6 +215,23 @@ public abstract class InventoryUtil {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the inventory contains the specified item.
|
||||
*
|
||||
* @param inv the inventory The inventory to check
|
||||
* @param item The ItemStack to look for
|
||||
* @return true is exists
|
||||
*/
|
||||
public static boolean containsItem(IInventory inv, ItemStack item) {
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(inv)) {
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
if (stack != null && isItemEqual(stack, item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to move an ItemStack from one inventory to another.
|
||||
@@ -214,7 +256,7 @@ public abstract class InventoryUtil {
|
||||
* @return An ItemStack
|
||||
*/
|
||||
public static ItemStack removeOneItem(IInventory inv) {
|
||||
return removeOneItem(inv, StackFilter.ALL);
|
||||
return removeOneItem(inv, StandardStackFilters.ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,13 +12,13 @@ package forestry.food.items;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.items.ItemWithGui;
|
||||
import forestry.food.gui.ContainerInfuser;
|
||||
import forestry.food.gui.GuiInfuser;
|
||||
import forestry.food.inventory.ItemInventoryInfuser;
|
||||
|
||||
public class ItemInfuser extends ItemWithGui {
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
return new GuiInfuser(player.inventory, new ItemInventoryInfuser(player, heldItem));
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse;
|
||||
|
||||
import forestry.api.core.EnumCamouflageType;
|
||||
import forestry.api.greenhouse.GreenhouseManager;
|
||||
import forestry.api.greenhouse.IGreenhouseItemAccess;
|
||||
import forestry.core.config.Constants;
|
||||
@@ -22,6 +21,7 @@ import forestry.greenhouse.tiles.TileGreenhouseDoor;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDryer;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseFan;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseGearbox;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHeater;
|
||||
import forestry.greenhouse.tiles.TileGreenhousePlain;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
@@ -70,6 +70,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
GameRegistry.registerTileEntity(TileGreenhouseControl.class, "forestry.GreenhouseController");
|
||||
GameRegistry.registerTileEntity(TileGreenhousePlain.class, "forestry.GreenhousePlain");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseDoor.class, "forestry.GreenhouseDoor");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseHatch.class, "forestry.GreenhouseHatch");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,16 +97,6 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
greenhouseAccess.registerGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 14));
|
||||
greenhouseAccess.registerGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 15));
|
||||
|
||||
for(BlockGreenhouseType type : BlockGreenhouseType.VALUES){
|
||||
if(type == BlockGreenhouseType.GLASS){
|
||||
greenhouseAccess.addToCamouflageBlockBlackList(EnumCamouflageType.GLASS, blocks.getGreenhouseBlock(type));
|
||||
}else if(type == BlockGreenhouseType.DOOR){
|
||||
greenhouseAccess.addToCamouflageBlockBlackList(EnumCamouflageType.DOOR, blocks.getGreenhouseBlock(type));
|
||||
}else{
|
||||
greenhouseAccess.addToCamouflageBlockBlackList(EnumCamouflageType.DEFAULT, blocks.getGreenhouseBlock(type));
|
||||
}
|
||||
}
|
||||
|
||||
proxy.initializeModels();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,18 +42,21 @@ import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflagedBlock;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.core.CreativeTabForestry;
|
||||
import forestry.core.blocks.BlockStructure;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockPos;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDoor;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDryer;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseFan;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseGearbox;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHeater;
|
||||
import forestry.greenhouse.tiles.TileGreenhousePlain;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
@@ -192,6 +195,9 @@ public abstract class BlockGreenhouse extends BlockStructure {
|
||||
return new TileGreenhouseControl();
|
||||
case DOOR:
|
||||
return new TileGreenhouseDoor();
|
||||
case HATCH_INPUT:
|
||||
case HATCH_OUTPUT:
|
||||
return new TileGreenhouseHatch();
|
||||
default:
|
||||
return new TileGreenhousePlain();
|
||||
}
|
||||
@@ -201,6 +207,20 @@ public abstract class BlockGreenhouse extends BlockStructure {
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return createTileEntity(world, getStateFromMeta(meta));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int colorMultiplier(IBlockAccess world, BlockPos pos, int renderPass) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof ICamouflagedBlock){
|
||||
if(renderPass < 100 && BlockGreenhouse.getCamouflageBlock(world, pos) != null){
|
||||
return Block.getBlockFromItem(BlockGreenhouse.getCamouflageBlock(world, pos).getItem()).colorMultiplier(world, pos, renderPass);
|
||||
}
|
||||
|
||||
return super.colorMultiplier(world, pos, renderPass);
|
||||
}else{
|
||||
return super.colorMultiplier(world, pos, renderPass);
|
||||
}
|
||||
}
|
||||
|
||||
/* MODELS */
|
||||
@Override
|
||||
@@ -259,6 +279,21 @@ public abstract class BlockGreenhouse extends BlockStructure {
|
||||
|
||||
return block == this ? false : super.shouldSideBeRendered(worldIn, pos, side);
|
||||
}
|
||||
|
||||
public static <G extends TileEntity & IGreenhouseComponent & ICamouflageHandler & ICamouflagedBlock> ItemStack getCamouflageBlock(IBlockAccess world, BlockPos pos){
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof IGreenhouseComponent && tile instanceof ICamouflageHandler && tile instanceof ICamouflagedBlock){
|
||||
G greenhouse = (G) tile;
|
||||
IGreenhouseControllerInternal greenhouseController = (IGreenhouseControllerInternal) greenhouse.getMultiblockLogic().getController();
|
||||
|
||||
ICamouflageHandler camouflageHandler = greenhouse;
|
||||
if(greenhouse.getCamouflageBlock(greenhouse.getCamouflageType()) == null && greenhouseController.getCamouflageBlock(greenhouse.getCamouflageType()) != null){
|
||||
camouflageHandler = greenhouseController;
|
||||
}
|
||||
return camouflageHandler.getCamouflageBlock(greenhouse.getCamouflageType());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
|
||||
@@ -9,15 +9,22 @@ import javax.annotation.Nullable;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse.State;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHatch;
|
||||
|
||||
public enum BlockGreenhouseType {
|
||||
PLAIN,
|
||||
GLASS,
|
||||
HATCH_INPUT(true),
|
||||
HATCH_OUTPUT(true),
|
||||
GEARBOX(true),
|
||||
VALVE(true),
|
||||
FAN(true, true),
|
||||
@@ -40,6 +47,9 @@ public enum BlockGreenhouseType {
|
||||
private static final int TYPE_HEATER_ON = 7;
|
||||
private static final int TYPE_DRYER = 8;
|
||||
private static final int TYPE_CONTROL = 9;
|
||||
private static final int TYPE_HATCH_INPUT = 10;
|
||||
private static final int TYPE_HATCH_OUTPUT = 11;
|
||||
private static final int TYPE_HATCH = 12;
|
||||
|
||||
public final boolean hasOverlaySprite;
|
||||
public final boolean activatable;
|
||||
@@ -74,7 +84,10 @@ public enum BlockGreenhouseType {
|
||||
TextureManager.registerSprite("blocks/greenhouse/heater.off"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/heater.off"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/dryer"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/control")
|
||||
TextureManager.registerSprite("blocks/greenhouse/control"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/hatch_input"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/hatch_output"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/hatch")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -82,7 +95,11 @@ public enum BlockGreenhouseType {
|
||||
* @return The texture sprite from the type and the {@link IBlockState} of the greenhouse block
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static TextureAtlasSprite getSprite(BlockGreenhouseType type, @Nullable IBlockState state) {
|
||||
public static TextureAtlasSprite getSprite(BlockGreenhouseType type, EnumFacing facing, @Nullable IBlockState state, @Nullable IBlockAccess world, @Nullable BlockPos pos) {
|
||||
TileEntity tile = null;
|
||||
if(world != null && pos != null){
|
||||
tile = world.getTileEntity(pos);
|
||||
}
|
||||
switch (type) {
|
||||
case PLAIN:
|
||||
return sprites.get(TYPE_PLAIN);
|
||||
@@ -108,6 +125,21 @@ public enum BlockGreenhouseType {
|
||||
return sprites.get(TYPE_DRYER);
|
||||
case CONTROL:
|
||||
return sprites.get(TYPE_CONTROL);
|
||||
case HATCH_OUTPUT:
|
||||
case HATCH_INPUT:
|
||||
if(tile == null || facing == null || !(tile instanceof TileGreenhouseHatch)){
|
||||
return sprites.get(TYPE_HATCH);
|
||||
}
|
||||
TileGreenhouseHatch hatch = (TileGreenhouseHatch) tile;
|
||||
if(hatch.getOutwardsDir() == null){
|
||||
return sprites.get(TYPE_HATCH);
|
||||
}
|
||||
if(hatch.getOutwardsDir() == facing){
|
||||
return sprites.get(TYPE_HATCH_OUTPUT);
|
||||
}else if(hatch.getOutwardsDir().getOpposite() == facing){
|
||||
return sprites.get(TYPE_HATCH_INPUT);
|
||||
}
|
||||
return null;
|
||||
default:
|
||||
return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class ContainerGreenhouse extends ContainerTile<TileGreenhouse> {
|
||||
public ContainerGreenhouse(InventoryPlayer playerInventory, TileGreenhouse tile) {
|
||||
super(tile, playerInventory, 8, 84);
|
||||
|
||||
addSlotToContainer(new SlotFiltered(tile, 0, 53, 37));
|
||||
addSlotToContainer(new SlotFiltered(tile, 0, 125, 37));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,17 +26,15 @@ public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse, TileGr
|
||||
super(Constants.TEXTURE_PATH_GUI + "/greenhouse.png", new ContainerGreenhouse(player.inventory, tile), tile);
|
||||
|
||||
//Add the water tank
|
||||
widgetManager.add(new TankWidget(widgetManager, 80, 16, 0).setOverlayOrigin(176, 0));
|
||||
widgetManager.add(new TankWidget(widgetManager, 152, 16, 0).setOverlayOrigin(176, 0));
|
||||
|
||||
//Add the multiblock camouflage slots
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 152, 16, inventory.getMultiblockLogic().getController(), EnumCamouflageType.DEFAULT));
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 152, 37, inventory.getMultiblockLogic().getController(), EnumCamouflageType.GLASS));
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 152, 58, inventory.getMultiblockLogic().getController(), EnumCamouflageType.DOOR));
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 16, inventory.getMultiblockLogic().getController(), EnumCamouflageType.DEFAULT));
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 37, inventory.getMultiblockLogic().getController(), EnumCamouflageType.GLASS));
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 58, inventory.getMultiblockLogic().getController(), EnumCamouflageType.DOOR));
|
||||
|
||||
//Add the tile camouflage slots
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 16, inventory, EnumCamouflageType.DEFAULT));
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 37, inventory, EnumCamouflageType.GLASS));
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 58, inventory, EnumCamouflageType.DOOR));
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 35, 37, inventory, tile.getCamouflageType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,7 +65,7 @@ public class WidgetCamouflageSlot extends Widget {
|
||||
if(stack != null && Block.getBlockFromItem(stack.getItem()) != null){
|
||||
Block block = Block.getBlockFromItem(stack.getItem());
|
||||
|
||||
if(!GreenhouseManager.greenhouseItemAccess.isOnCamouflageBlockBlackList(type, stack) && (type == EnumCamouflageType.DEFAULT && block.isOpaqueCube() && block.isNormalCube(player.worldObj, camouflageHandler.getCoordinates()) || type == EnumCamouflageType.GLASS && GreenhouseManager.greenhouseItemAccess.isGreenhouseGlass(stack))){
|
||||
if(!GreenhouseManager.greenhouseItemAccess.isOnCamouflageBlockBlackList(type, stack) && (type == EnumCamouflageType.DEFAULT && block.isOpaqueCube() && !block.hasTileEntity(block.getStateFromMeta(stack.getItemDamage())) && block.isNormalCube(player.worldObj, camouflageHandler.getCoordinates()) || type == EnumCamouflageType.GLASS && GreenhouseManager.greenhouseItemAccess.isGreenhouseGlass(stack))){
|
||||
camouflageHandler.setCamouflageBlock(type, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ package forestry.greenhouse.models;
|
||||
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouse;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BlockModelShapes;
|
||||
@@ -21,6 +19,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
|
||||
@@ -28,10 +27,12 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflagedBlock;
|
||||
import forestry.api.core.IModelBaker;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.core.models.ModelBlockOverlay;
|
||||
|
||||
public class ModelGreenhouse extends ModelBlockOverlay<BlockGreenhouse> {
|
||||
public class ModelGreenhouse<G extends TileEntity & IGreenhouseComponent & ICamouflageHandler & ICamouflagedBlock> extends ModelBlockOverlay<BlockGreenhouse> {
|
||||
|
||||
public ModelGreenhouse() {
|
||||
super(BlockGreenhouse.class);
|
||||
@@ -39,26 +40,15 @@ public class ModelGreenhouse extends ModelBlockOverlay<BlockGreenhouse> {
|
||||
|
||||
@Override
|
||||
protected void bakeInventoryBlock(BlockGreenhouse block, ItemStack item, IModelBaker baker) {
|
||||
bakeBlockModel(block, null, null, baker, null);
|
||||
bakeBlockModel(block, null, null, null, baker, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bakeWorldBlock(BlockGreenhouse block, IBlockAccess world, BlockPos pos, IExtendedBlockState stateExtended, IModelBaker baker) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(!(tile instanceof TileGreenhouse)){
|
||||
return;
|
||||
}
|
||||
TileGreenhouse greenhouse = (TileGreenhouse) tile;
|
||||
IGreenhouseControllerInternal greenhouseController = greenhouse.getMultiblockLogic().getController();
|
||||
|
||||
ICamouflageHandler camouflageHandler = greenhouse;
|
||||
if(greenhouse.getCamouflageBlock(greenhouse.getCamouflageType()) == null && greenhouseController.getCamouflageBlock(greenhouse.getCamouflageType()) != null){
|
||||
camouflageHandler = greenhouseController;
|
||||
}
|
||||
bakeBlockModel(block, pos, stateExtended, baker, camouflageHandler.getCamouflageBlock(greenhouse.getCamouflageType()));
|
||||
bakeBlockModel(block, world, pos, stateExtended, baker, BlockGreenhouse.getCamouflageBlock(world, pos));
|
||||
}
|
||||
|
||||
private void bakeBlockModel(@Nonnull BlockGreenhouse block, @Nullable BlockPos pos, @Nullable IExtendedBlockState stateExtended, @Nonnull IModelBaker baker, @Nullable ItemStack camouflageBlock){
|
||||
private void bakeBlockModel(@Nonnull BlockGreenhouse block, @Nullable IBlockAccess world, @Nullable BlockPos pos, @Nullable IExtendedBlockState stateExtended, @Nonnull IModelBaker baker, @Nullable ItemStack camouflageBlock){
|
||||
if(camouflageBlock != null){
|
||||
BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
|
||||
|
||||
@@ -67,18 +57,22 @@ public class ModelGreenhouse extends ModelBlockOverlay<BlockGreenhouse> {
|
||||
|
||||
//Bake the default blocks
|
||||
else if(block.getGreenhouseType() == BlockGreenhouseType.GLASS){
|
||||
TextureAtlasSprite glassSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null);
|
||||
TextureAtlasSprite glassSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos);
|
||||
|
||||
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null), 100);
|
||||
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos), 100);
|
||||
baker.setParticleSprite(glassSprite);
|
||||
}else{
|
||||
TextureAtlasSprite plainSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null);
|
||||
TextureAtlasSprite plainSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos);
|
||||
|
||||
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null), 100);
|
||||
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos), 100);
|
||||
baker.setParticleSprite(plainSprite);
|
||||
}
|
||||
if(block.getGreenhouseType().hasOverlaySprite){
|
||||
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(block.getGreenhouseType(), stateExtended), 101);
|
||||
TextureAtlasSprite[] sprite = new TextureAtlasSprite[6];
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
sprite[facing.ordinal()] = BlockGreenhouseType.getSprite(block.getGreenhouseType(), facing, stateExtended, world, pos);
|
||||
}
|
||||
baker.addBlockModel(block, pos, sprite, 101);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,23 +71,23 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry<Multib
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
|
||||
if(nbttagcompound.hasKey("CamouflageBlock")){
|
||||
camouflageBlock = ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("CamouflageBlock"));
|
||||
if(data.hasKey("CamouflageBlock")){
|
||||
camouflageBlock = ItemStack.loadItemStackFromNBT(data.getCompoundTag("CamouflageBlock"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
|
||||
|
||||
if(camouflageBlock != null){
|
||||
NBTTagCompound nbtTag = new NBTTagCompound();
|
||||
camouflageBlock.writeToNBT(nbtTag);
|
||||
nbttagcompound.setTag("CamouflageBlock", nbtTag);
|
||||
data.setTag("CamouflageBlock", nbtTag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,399 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import forestry.api.core.EnumCamouflageType;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflagedBlock;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.api.multiblock.MultiblockTileEntityBase;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.gui.IHintSource;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse;
|
||||
import forestry.greenhouse.network.packets.PacketCamouflageUpdate;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
|
||||
public class TileGreenhouseHatch extends MultiblockTileEntityBase<MultiblockLogicGreenhouse> implements IGreenhouseComponent, IHintSource, IErrorLogicSource, IRestrictedAccess, ICamouflageHandler, ICamouflagedBlock, IFluidHandler, IEnergyProvider, IEnergyReceiver {
|
||||
|
||||
EnumFacing outwards;
|
||||
private ItemStack camouflageBlock;
|
||||
|
||||
@Nullable
|
||||
private GameProfile owner;
|
||||
|
||||
public TileGreenhouseHatch() {
|
||||
super(new MultiblockLogicGreenhouse());
|
||||
outwards = null;
|
||||
camouflageBlock = null;
|
||||
}
|
||||
|
||||
public EnumFacing getOutwardsDir() {
|
||||
return outwards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) {
|
||||
worldObj.notifyBlockOfStateChange(getPos(), worldObj.getBlockState(pos).getBlock());
|
||||
markDirty();
|
||||
|
||||
recalculateOutwardsDirection(minCoord, maxCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMachineBroken() {
|
||||
worldObj.notifyBlockOfStateChange(getPos(), worldObj.getBlockState(pos).getBlock());
|
||||
markDirty();
|
||||
outwards = null;
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
|
||||
if(data.hasKey("CamouflageBlock")){
|
||||
camouflageBlock = ItemStack.loadItemStackFromNBT(data.getCompoundTag("CamouflageBlock"));
|
||||
}
|
||||
|
||||
if (data.hasKey("owner")) {
|
||||
NBTTagCompound ownerNbt = data.getCompoundTag("owner");
|
||||
this.owner = PlayerUtil.readGameProfileFromNBT(ownerNbt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
|
||||
|
||||
if(camouflageBlock != null){
|
||||
NBTTagCompound nbtTag = new NBTTagCompound();
|
||||
camouflageBlock.writeToNBT(nbtTag);
|
||||
data.setTag("CamouflageBlock", nbtTag);
|
||||
}
|
||||
|
||||
if (this.owner != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
PlayerUtil.writeGameProfile(nbt, owner);
|
||||
data.setTag("owner", nbt);
|
||||
}
|
||||
}
|
||||
|
||||
/* IMultiblockComponent */
|
||||
@Nullable
|
||||
@Override
|
||||
public final GameProfile getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public final void setOwner(@Nonnull GameProfile owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/* CONSTRUCTION MATERIAL */
|
||||
@Override
|
||||
public void setCamouflageBlock(EnumCamouflageType type, ItemStack camouflageBlock) {
|
||||
this.camouflageBlock = camouflageBlock;
|
||||
|
||||
if (worldObj != null) {
|
||||
if (worldObj.isRemote) {
|
||||
worldObj.markBlockForUpdate(getPos());
|
||||
} else {
|
||||
Proxies.net.sendToServer(new PacketCamouflageUpdate(this, type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCamouflageBlock(EnumCamouflageType type) {
|
||||
return camouflageBlock;
|
||||
}
|
||||
|
||||
/* TILEFORESTRY */
|
||||
@Override
|
||||
protected void encodeDescriptionPacket(NBTTagCompound packetData) {
|
||||
super.encodeDescriptionPacket(packetData);
|
||||
if(camouflageBlock != null){
|
||||
NBTTagCompound nbtTag = new NBTTagCompound();
|
||||
camouflageBlock.writeToNBT(nbtTag);
|
||||
packetData.setTag("CamouflageBlock", nbtTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeDescriptionPacket(NBTTagCompound packetData) {
|
||||
super.decodeDescriptionPacket(packetData);
|
||||
if(packetData.hasKey("CamouflageBlock")){
|
||||
setCamouflageBlock(getCamouflageType(), ItemStack.loadItemStackFromNBT(packetData.getCompoundTag("CamouflageBlock")));
|
||||
}
|
||||
}
|
||||
|
||||
/* IHintSource */
|
||||
@Override
|
||||
public List<String> getHints() {
|
||||
return Config.hints.get("greenhouse");
|
||||
}
|
||||
|
||||
/* IErrorLogicSource */
|
||||
@Override
|
||||
public IErrorLogic getErrorLogic() {
|
||||
return getMultiblockLogic().getController().getErrorLogic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAccessHandler getAccessHandler() {
|
||||
return getMultiblockLogic().getController().getAccessHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
getMultiblockLogic().getController().onSwitchAccess(oldAccess, newAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumCamouflageType getCamouflageType() {
|
||||
if(getBlockType() instanceof BlockGreenhouse && ((BlockGreenhouse)getBlockType()).getGreenhouseType() == BlockGreenhouseType.GLASS){
|
||||
return EnumCamouflageType.GLASS;
|
||||
}
|
||||
return EnumCamouflageType.DEFAULT;
|
||||
}
|
||||
|
||||
private IInventory getOutwardsInventory(){
|
||||
if(getOutwardsTile() == null){
|
||||
return null;
|
||||
}
|
||||
return TileUtil.getInventoryFromTile(getOutwardsTile(), outwards.getOpposite());
|
||||
}
|
||||
|
||||
private TileEntity getOutwardsTile(){
|
||||
if(outwards == null || worldObj == null || pos == null){
|
||||
return null;
|
||||
}
|
||||
return worldObj.getTileEntity(getPos().offset(outwards));
|
||||
}
|
||||
|
||||
private IFluidHandler getOutwardFluidHandler(){
|
||||
TileEntity tile = getOutwardsTile();
|
||||
if(tile == null || !(tile instanceof IFluidHandler)){
|
||||
return null;
|
||||
}
|
||||
return (IFluidHandler) tile;
|
||||
}
|
||||
|
||||
private IEnergyConnection getOutwardEnergyConnection(){
|
||||
TileEntity tile = getOutwardsTile();
|
||||
if(tile == null || !(tile instanceof IEnergyConnection)){
|
||||
return null;
|
||||
}
|
||||
return (IEnergyConnection) tile;
|
||||
}
|
||||
|
||||
private IEnergyHandler getOutwardEnergyHandler(){
|
||||
TileEntity tile = getOutwardsTile();
|
||||
if(tile == null || !(tile instanceof IEnergyHandler)){
|
||||
return null;
|
||||
}
|
||||
return (IEnergyHandler) tile;
|
||||
}
|
||||
|
||||
private IEnergyReceiver getOutwardEnergyReceiver(){
|
||||
TileEntity tile = getOutwardsTile();
|
||||
if(tile == null || !(tile instanceof IEnergyReceiver)){
|
||||
return null;
|
||||
}
|
||||
return (IEnergyReceiver) tile;
|
||||
}
|
||||
|
||||
private IEnergyProvider getOutwardEnergyProvider(){
|
||||
TileEntity tile = getOutwardsTile();
|
||||
if(tile == null || !(tile instanceof IEnergyProvider)){
|
||||
return null;
|
||||
}
|
||||
return (IEnergyProvider) tile;
|
||||
}
|
||||
|
||||
public void recalculateOutwardsDirection(BlockPos minCoord, BlockPos maxCoord) {
|
||||
outwards = null;
|
||||
|
||||
int facesMatching = 0;
|
||||
if(maxCoord.getX() == getPos().getX() || minCoord.getX() == getPos().getX()) { facesMatching++; }
|
||||
if(maxCoord.getY() == getPos().getY() || minCoord.getY() == getPos().getY()) { facesMatching++; }
|
||||
if(maxCoord.getZ() == getPos().getZ() || minCoord.getZ() == getPos().getZ()) { facesMatching++; }
|
||||
if(facesMatching == 1){
|
||||
if(maxCoord.getX() == getPos().getX()) {
|
||||
outwards = EnumFacing.EAST;
|
||||
}else if(minCoord.getX() == getPos().getX()) {
|
||||
outwards = EnumFacing.WEST;
|
||||
}else if(maxCoord.getZ() == getPos().getZ()) {
|
||||
outwards = EnumFacing.SOUTH;
|
||||
}else if(minCoord.getZ() == getPos().getZ()) {
|
||||
outwards = EnumFacing.NORTH;
|
||||
}else if(maxCoord.getY() == getPos().getY()) {
|
||||
outwards = EnumFacing.UP;
|
||||
}else {
|
||||
outwards = EnumFacing.DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
if(((BlockGreenhouse)getBlockType()).getGreenhouseType() != BlockGreenhouseType.HATCH_OUTPUT){
|
||||
outwards = outwards.getOpposite();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && getOutwardsTile() != null){
|
||||
return getOutwardsTile().getCapability(capability, facing);
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && getOutwardsTile() != null){
|
||||
return getOutwardsTile().hasCapability(capability, facing);
|
||||
}
|
||||
return super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
IEnergyHandler handler = getOutwardEnergyHandler();
|
||||
if(handler == null) {
|
||||
return 0;
|
||||
}
|
||||
return handler.getEnergyStored(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
IEnergyHandler handler = getOutwardEnergyHandler();
|
||||
if(handler == null) {
|
||||
return 0;
|
||||
}
|
||||
return handler.getMaxEnergyStored(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(EnumFacing from) {
|
||||
IEnergyConnection connection = getOutwardEnergyConnection();
|
||||
if(connection == null) {
|
||||
return false;
|
||||
}
|
||||
return connection.canConnectEnergy(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
|
||||
IEnergyReceiver receiver = getOutwardEnergyReceiver();
|
||||
if(receiver == null) {
|
||||
return 0;
|
||||
}
|
||||
return receiver.receiveEnergy(from, maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {
|
||||
IEnergyProvider provider = getOutwardEnergyProvider();
|
||||
if(provider == null) {
|
||||
return 0;
|
||||
}
|
||||
return provider.extractEnergy(from, maxExtract, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
|
||||
IFluidHandler handler = getOutwardFluidHandler();
|
||||
if(handler == null){
|
||||
return 0;
|
||||
}
|
||||
return handler.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain) {
|
||||
IFluidHandler handler = getOutwardFluidHandler();
|
||||
if(handler == null){
|
||||
return null;
|
||||
}
|
||||
return handler.drain(from, resource, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain) {
|
||||
IFluidHandler handler = getOutwardFluidHandler();
|
||||
if(handler == null){
|
||||
return null;
|
||||
}
|
||||
return handler.drain(from, maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(EnumFacing from, Fluid fluid) {
|
||||
IFluidHandler handler = getOutwardFluidHandler();
|
||||
if(handler == null){
|
||||
return false;
|
||||
}
|
||||
return handler.canFill(from, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(EnumFacing from, Fluid fluid) {
|
||||
IFluidHandler handler = getOutwardFluidHandler();
|
||||
if(handler == null){
|
||||
return false;
|
||||
}
|
||||
return handler.canDrain(from, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(EnumFacing from) {
|
||||
IFluidHandler handler = getOutwardFluidHandler();
|
||||
if(handler == null){
|
||||
return null;
|
||||
}
|
||||
return handler.getTankInfo(from);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ import forestry.mail.items.ItemStamps;
|
||||
public class ItemInventoryLetter extends ItemInventory implements IErrorSource, IHintSource {
|
||||
private ILetter letter;
|
||||
|
||||
public ItemInventoryLetter(EntityPlayer player, ItemStack itemstack) {
|
||||
public ItemInventoryLetter(EntityPlayer player,ItemStack itemstack) {
|
||||
super(player, 0, itemstack);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.mail.items;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.items.ItemWithGui;
|
||||
import forestry.mail.gui.ContainerCatalogue;
|
||||
import forestry.mail.gui.GuiCatalogue;
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.storage.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotFilteredInventory;
|
||||
import forestry.storage.inventory.ItemInventoryBackpack;
|
||||
|
||||
@@ -29,7 +29,6 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.storage.BackpackStowEvent;
|
||||
import forestry.api.storage.EnumBackpackType;
|
||||
@@ -38,8 +37,8 @@ import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiHandler;
|
||||
import forestry.core.inventory.ItemInventory;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.inventory.iterators.IExtInvSlot;
|
||||
import forestry.core.inventory.iterators.InventoryIterator;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
@@ -175,7 +174,7 @@ public class ItemBackpack extends ItemWithGui {
|
||||
|
||||
private static void tryChestTransfer(ItemInventoryBackpack backpackInventory, IInventory target) {
|
||||
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(backpackInventory)) {
|
||||
for (IExtInvSlot slot : InventoryIterator.getIterable(backpackInventory)) {
|
||||
ItemStack packStack = slot.getStackInSlot();
|
||||
if (packStack == null) {
|
||||
continue;
|
||||
@@ -188,7 +187,7 @@ public class ItemBackpack extends ItemWithGui {
|
||||
|
||||
private void tryChestReceive(ItemInventoryBackpack backpackInventory, IInventory target) {
|
||||
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(target)) {
|
||||
for (IExtInvSlot slot : InventoryIterator.getIterable(target)) {
|
||||
ItemStack targetStack = slot.getStackInSlot();
|
||||
if (targetStack == null) {
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user