mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-22 05:02:12 +00:00
Integrate with item transferring API
This commit is contained in:
1 parent
4be3fd979c
commit
b886358726
3 files changed
+92
-2
No files matched your search
@@ -1,6 +1,7 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.github.GTNewHorizons:GTNHLib:0.8.2:dev")
|
||||
compileOnlyApi('com.github.GTNewHorizons:Angelica:1.0.0-beta62:api')
|
||||
compileOnly('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-718-GTNH:api') {transitive=false}
|
||||
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.52.64:dev') {transitive=false}
|
||||
@@ -11,4 +12,5 @@ dependencies {
|
||||
compileOnly('curse.maven:minetweaker3-224029:2255759')
|
||||
compileOnly("com.github.GTNewHorizons:Avaritia:1.77:dev")
|
||||
compileOnly("com.github.GTNewHorizons:Backhand:1.8.0:dev")
|
||||
compileOnly("org.jetbrains:annotations:26.0.2")
|
||||
}
|
||||
@@ -40,7 +40,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
modid = StorageDrawers.MOD_ID,
|
||||
name = StorageDrawers.MOD_NAME,
|
||||
version = StorageDrawers.MOD_VERSION,
|
||||
dependencies = "after:waila;",
|
||||
dependencies = "after:waila;required-after:gtnhlib;",
|
||||
guiFactory = StorageDrawers.SOURCE_PATH + "core.ModGuiFactory")
|
||||
public class StorageDrawers {
|
||||
|
||||
|
||||
+89
-1
@@ -15,9 +15,19 @@ import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.capability.CapabilityProvider;
|
||||
import com.gtnewhorizon.gtnhlib.capability.item.ItemIO;
|
||||
import com.gtnewhorizon.gtnhlib.capability.item.ItemSink;
|
||||
import com.gtnewhorizon.gtnhlib.capability.item.ItemSource;
|
||||
import com.gtnewhorizon.gtnhlib.item.AbstractInventoryIterator;
|
||||
import com.gtnewhorizon.gtnhlib.item.ImmutableItemStack;
|
||||
import com.gtnewhorizon.gtnhlib.item.InventoryIterator;
|
||||
import com.gtnewhorizon.gtnhlib.item.SimpleItemIO;
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider;
|
||||
@@ -39,9 +49,10 @@ import com.jaquadro.minecraft.storagedrawers.storage.IUpgradeProvider;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import it.unimi.dsi.fastutil.ints.IntIterators;
|
||||
|
||||
public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawerGroupInteractive, ISidedInventory,
|
||||
IUpgradeProvider, ILockable, ISealable, IProtectable, IDowngradable {
|
||||
IUpgradeProvider, ILockable, ISealable, IProtectable, IDowngradable, CapabilityProvider {
|
||||
|
||||
private IDrawer[] drawers;
|
||||
private IDrawerInventory inventory;
|
||||
@@ -977,4 +988,81 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe
|
||||
return autoSides;
|
||||
}
|
||||
}
|
||||
|
||||
private DrawerItemIO io;
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getCapability(@NotNull Class<T> capability, @NotNull ForgeDirection side) {
|
||||
if (capability == ItemSource.class || capability == ItemSink.class || capability == ItemIO.class) {
|
||||
if (io == null) io = new DrawerItemIO();
|
||||
|
||||
return capability.cast(io);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class DrawerItemIO extends SimpleItemIO {
|
||||
|
||||
private final int[] presentSlots = IntIterators.unwrap(IntIterators.fromTo(0, drawers.length));
|
||||
|
||||
@Override
|
||||
protected @NotNull InventoryIterator iterator(int[] allowedSlots) {
|
||||
return new AbstractInventoryIterator(presentSlots, allowedSlots) {
|
||||
|
||||
@Override
|
||||
protected ItemStack getStackInSlot(int slot) {
|
||||
if (slot < 0 || slot >= drawers.length) return null;
|
||||
|
||||
return drawers[slot].getStoredItemCopy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extract(int amount, boolean forced) {
|
||||
int slot = getCurrentSlot();
|
||||
|
||||
if (slot < 0 || slot >= drawers.length) return null;
|
||||
|
||||
IDrawer drawer = drawers[slot];
|
||||
|
||||
ItemStack stored = drawer.getStoredItemCopy();
|
||||
|
||||
if (stored == null) return null;
|
||||
|
||||
int toExtract = Math.min(stored.stackSize, amount);
|
||||
|
||||
stored.stackSize = toExtract;
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() - toExtract);
|
||||
|
||||
return stored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(ImmutableItemStack stack, boolean forced) {
|
||||
int slot = getCurrentSlot();
|
||||
|
||||
if (slot < 0 || slot >= drawers.length) return stack.getStackSize();
|
||||
|
||||
IDrawer drawer = drawers[slot];
|
||||
|
||||
ItemStack insertExample = stack.toStackFast();
|
||||
|
||||
if (!drawer.canItemBeStored(insertExample)) return stack.getStackSize();
|
||||
|
||||
int capacity = forced ? Integer.MAX_VALUE : drawer.getMaxCapacity(insertExample);
|
||||
int remaining = capacity - drawer.getStoredItemCount();
|
||||
|
||||
int toInsert = Math.min(remaining, stack.getStackSize());
|
||||
|
||||
if (drawer.getStoredItemPrototype() == null) {
|
||||
drawer.setStoredItemRedir(stack.toStack(1), toInsert);
|
||||
} else {
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() + toInsert);
|
||||
}
|
||||
|
||||
return stack.getStackSize() - toInsert;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user