Merge remote-tracking branch 'origin/mc1.10' into mc1.10
This commit is contained in:
@@ -31,4 +31,11 @@ public class BlockDiskManipulator extends BlockNode {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
||||
((TileDiskManipulator) world.getTileEntity(pos)).onBreak();
|
||||
|
||||
super.breakBlock(world, pos, state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,7 @@ package refinedstorage.gui;
|
||||
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
import refinedstorage.container.ContainerDiskManipulator;
|
||||
import refinedstorage.gui.sidebutton.SideButtonCompare;
|
||||
import refinedstorage.gui.sidebutton.SideButtonMode;
|
||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||
import refinedstorage.gui.sidebutton.SideButtonType;
|
||||
import refinedstorage.gui.sidebutton.*;
|
||||
import refinedstorage.tile.TileDiskManipulator;
|
||||
|
||||
public class GuiDiskManipulator extends GuiBase {
|
||||
@@ -16,6 +13,7 @@ public class GuiDiskManipulator extends GuiBase {
|
||||
@Override
|
||||
public void init(int x, int y) {
|
||||
addSideButton(new SideButtonRedstoneMode(TileDiskManipulator.REDSTONE_MODE));
|
||||
addSideButton(new SideButtonIOMode(TileDiskManipulator.IO_MODE));
|
||||
addSideButton(new SideButtonType(TileDiskManipulator.TYPE));
|
||||
addSideButton(new SideButtonMode(TileDiskManipulator.MODE));
|
||||
addSideButton(new SideButtonCompare(TileDiskManipulator.COMPARE, CompareUtils.COMPARE_DAMAGE));
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package refinedstorage.gui.sidebutton;
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
import refinedstorage.tile.TileDiskManipulator;
|
||||
import refinedstorage.tile.data.TileDataManager;
|
||||
import refinedstorage.tile.data.TileDataParameter;
|
||||
|
||||
public class SideButtonIOMode extends SideButton {
|
||||
private TileDataParameter<Integer> parameter;
|
||||
|
||||
public SideButtonIOMode(TileDataParameter<Integer> parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip(GuiBase gui) {
|
||||
return TextFormatting.GREEN + gui.t("sidebutton.refinedstorage:iomode") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:iomode." + (parameter.getValue() == TileDiskManipulator.INSERT ? "insert" : "extract"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiBase gui, int x, int y) {
|
||||
gui.bindTexture("icons.png");
|
||||
|
||||
gui.drawTexture(x, y + 1, parameter.getValue() == TileDiskManipulator.EXTRACT ? 0 : 16, 160, 16, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed() {
|
||||
TileDataManager.setParameter(parameter, parameter.getValue() == TileDiskManipulator.INSERT ? TileDiskManipulator.EXTRACT : TileDiskManipulator.INSERT);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,12 @@ package refinedstorage.tile;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.datasync.DataSerializers;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
@@ -20,6 +23,8 @@ import refinedstorage.inventory.ItemValidatorBasic;
|
||||
import refinedstorage.tile.config.IComparable;
|
||||
import refinedstorage.tile.config.IFilterable;
|
||||
import refinedstorage.tile.config.IType;
|
||||
import refinedstorage.tile.data.ITileDataConsumer;
|
||||
import refinedstorage.tile.data.ITileDataProducer;
|
||||
import refinedstorage.tile.data.TileDataParameter;
|
||||
|
||||
public class TileDiskManipulator extends TileNode implements IComparable, IFilterable, IType {
|
||||
@@ -27,6 +32,20 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
public static final TileDataParameter<Integer> MODE = IFilterable.createParameter();
|
||||
public static final TileDataParameter<Integer> TYPE = IType.createParameter();
|
||||
|
||||
public static final int INSERT = 0, EXTRACT = 1;
|
||||
public static final TileDataParameter<Integer> IO_MODE = new TileDataParameter<>(DataSerializers.VARINT, INSERT, new ITileDataProducer<Integer, TileDiskManipulator>() {
|
||||
@Override
|
||||
public Integer getValue(TileDiskManipulator tile) {
|
||||
return tile.ioMode;
|
||||
}
|
||||
}, new ITileDataConsumer<Integer, TileDiskManipulator>() {
|
||||
@Override
|
||||
public void setValue(TileDiskManipulator tile, Integer value) {
|
||||
tile.ioMode = value;
|
||||
tile.markDirty();
|
||||
}
|
||||
});
|
||||
|
||||
private static final String NBT_COMPARE = "Compare";
|
||||
private static final String NBT_MODE = "Mode";
|
||||
private static final String NBT_TYPE = "Type";
|
||||
@@ -34,11 +53,19 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
private int compare = 0;
|
||||
private int mode = IFilterable.WHITELIST;
|
||||
private int type = IType.ITEMS;
|
||||
private int ioMode = INSERT;
|
||||
|
||||
private ItemStorage[] itemStorages;
|
||||
private FluidStorage[] fluidStorages;
|
||||
|
||||
public TileDiskManipulator() {
|
||||
dataManager.addWatchedParameter(COMPARE);
|
||||
dataManager.addWatchedParameter(MODE);
|
||||
dataManager.addWatchedParameter(TYPE);
|
||||
dataManager.addWatchedParameter(IO_MODE);
|
||||
|
||||
itemStorages = new ItemStorage[6];
|
||||
fluidStorages = new FluidStorage[6];
|
||||
}
|
||||
|
||||
private ItemHandlerBasic disks = new ItemHandlerBasic(12, this, new ItemValidatorBasic(RefinedStorageItems.STORAGE_DISK) {
|
||||
@@ -51,7 +78,41 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
public boolean isValid(ItemStack disk) {
|
||||
return super.isValid(disk) && FluidStorageNBT.isValid(disk);
|
||||
}
|
||||
});
|
||||
}) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && slot < 6) {
|
||||
ItemStack disk = getStackInSlot(slot);
|
||||
|
||||
if (disk == null) {
|
||||
itemStorages[slot] = null;
|
||||
fluidStorages[slot] = null;
|
||||
} else {
|
||||
if (disk.getItem() == RefinedStorageItems.STORAGE_DISK) {
|
||||
itemStorages[slot] = new ItemStorage(disk);
|
||||
} else if (disk.getItem() == RefinedStorageItems.FLUID_STORAGE_DISK) {
|
||||
fluidStorages[slot] = new FluidStorage(disk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (slot < 6) {
|
||||
if (itemStorages[slot] != null) {
|
||||
itemStorages[slot].writeToNBT();
|
||||
}
|
||||
|
||||
if (fluidStorages[slot] != null) {
|
||||
fluidStorages[slot].writeToNBT();
|
||||
}
|
||||
}
|
||||
return super.extractItem(slot, amount, simulate);
|
||||
}
|
||||
};
|
||||
|
||||
public class ItemStorage extends ItemStorageNBT {
|
||||
public ItemStorage(ItemStack disk) {
|
||||
@@ -71,6 +132,15 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
|
||||
return super.insertItem(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem(ItemStack stack, int size, int flags) {
|
||||
if (!IFilterable.canTake(itemFilters, mode, getCompare(), stack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return super.extractItem(stack, size, flags);
|
||||
}
|
||||
}
|
||||
|
||||
public class FluidStorage extends FluidStorageNBT {
|
||||
@@ -91,6 +161,15 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
|
||||
return super.insertFluid(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack extractFluid(FluidStack stack, int size, int flags) {
|
||||
if (!IFilterable.canTakeFluids(fluidFilters, mode, getCompare(), stack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return super.extractFluid(stack, size, flags);
|
||||
}
|
||||
}
|
||||
|
||||
private ItemHandlerBasic itemFilters = new ItemHandlerBasic(9, this);
|
||||
@@ -103,17 +182,111 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
|
||||
@Override
|
||||
public void updateNode() {
|
||||
int i = 0;
|
||||
ItemStack disk = disks.getStackInSlot(i);
|
||||
while (disk == null && i < 6) i++;
|
||||
if (disk == null) return;
|
||||
int slot = 0;
|
||||
if (type == IType.ITEMS) {
|
||||
while (slot < itemStorages.length && itemStorages[slot] == null) slot++;
|
||||
if (slot == itemStorages.length) return;
|
||||
ItemStorage storage = itemStorages[slot];
|
||||
if (ioMode == INSERT) {
|
||||
insertIntoNetwork(storage, slot);
|
||||
} else if (ioMode == EXTRACT) {
|
||||
extractFromNetwork(storage, slot);
|
||||
}
|
||||
|
||||
if (disk.getItem() == RefinedStorageItems.STORAGE_DISK) {
|
||||
ItemStorage storage = new ItemStorage(disk);
|
||||
} else if (disk.getItem() == RefinedStorageItems.FLUID_STORAGE_DISK) {
|
||||
FluidStorage storage = new FluidStorage(disk);
|
||||
} else if (type == IType.FLUIDS) {
|
||||
while (slot < fluidStorages.length && fluidStorages[slot] == null) slot++;
|
||||
if (slot == fluidStorages.length) return;
|
||||
FluidStorage storage = fluidStorages[slot];
|
||||
if (ioMode == INSERT) {
|
||||
insertIntoNetwork(storage, slot);
|
||||
} else if (ioMode == EXTRACT) {
|
||||
extractFromNetwork(storage, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void insertIntoNetwork(ItemStorage storage, int slot) {
|
||||
if (storage.getStored() == 0) {
|
||||
moveDriveToOutput(slot);
|
||||
return;
|
||||
}
|
||||
ItemStack extracted = null;
|
||||
int ii = 0;
|
||||
do {
|
||||
ItemStack stack = null;
|
||||
while (storage.getItems().size() > ii && stack == null) {
|
||||
stack = storage.getItems().get(ii++);
|
||||
}
|
||||
if (stack != null) {
|
||||
extracted = storage.extractItem(stack, 1, compare);
|
||||
}
|
||||
} while (storage.getItems().size() > ii && extracted == null);
|
||||
if (extracted == null) {
|
||||
moveDriveToOutput(slot);
|
||||
return;
|
||||
}
|
||||
ItemStack leftOver = network.insertItem(extracted, extracted.stackSize, false);
|
||||
if (leftOver != null) {
|
||||
storage.insertItem(leftOver, leftOver.stackSize, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void extractFromNetwork(ItemStorage storage, int slot) {
|
||||
|
||||
}
|
||||
|
||||
private void insertIntoNetwork(FluidStorage storage, int slot) {
|
||||
if (storage.getStored() == 0) {
|
||||
moveDriveToOutput(slot);
|
||||
return;
|
||||
}
|
||||
FluidStack extracted = null;
|
||||
int ii = 0;
|
||||
do {
|
||||
FluidStack stack = storage.getStacks().get(ii);
|
||||
while (stack == null && storage.getStacks().size() > ii) {
|
||||
ii++;
|
||||
}
|
||||
if (stack != null) {
|
||||
extracted = storage.extractFluid(stack, 1, compare);
|
||||
}
|
||||
} while (extracted == null && storage.getStacks().size() > ii);
|
||||
if (extracted == null) {
|
||||
moveDriveToOutput(slot);
|
||||
return;
|
||||
}
|
||||
FluidStack leftOver = network.insertFluid(extracted, extracted.amount, false);
|
||||
if (leftOver != null) {
|
||||
storage.insertFluid(leftOver, leftOver.amount, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void extractFromNetwork(FluidStorage storage, int slot) {
|
||||
}
|
||||
|
||||
private void moveDriveToOutput(int slot) {
|
||||
ItemStack disk = disks.getStackInSlot(slot);
|
||||
if (disk != null) {
|
||||
int i = 6;
|
||||
while (disks.getStackInSlot(i) != null && i < 12) {
|
||||
i++;
|
||||
}
|
||||
if (i == 12) {
|
||||
return;
|
||||
}
|
||||
if (slot < 6) {
|
||||
if (itemStorages[slot] != null) {
|
||||
itemStorages[slot].writeToNBT();
|
||||
itemStorages[slot] = null;
|
||||
}
|
||||
if (fluidStorages[slot] != null) {
|
||||
fluidStorages[slot].writeToNBT();
|
||||
fluidStorages[slot] = null;
|
||||
}
|
||||
}
|
||||
disks.extractItem(slot, 1, false);
|
||||
disks.insertItem(i, disk, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,4 +382,13 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
public void onBreak() {
|
||||
for (ItemStorage storage : itemStorages)
|
||||
if (storage != null)
|
||||
storage.writeToNBT();
|
||||
for (FluidStorage storage : fluidStorages)
|
||||
if (storage != null)
|
||||
storage.writeToNBT();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,10 @@ sidebutton.refinedstorage:mode=Mode
|
||||
sidebutton.refinedstorage:mode.whitelist=Whitelist
|
||||
sidebutton.refinedstorage:mode.blacklist=Blacklist
|
||||
|
||||
sidebutton.refinedstorage:iomode=IOMode
|
||||
sidebutton.refinedstorage:iomode.insert=Insert into network
|
||||
sidebutton.refinedstorage:iomode.extract=Extract from network
|
||||
|
||||
sidebutton.refinedstorage:type=Type
|
||||
sidebutton.refinedstorage:type.0=Items
|
||||
sidebutton.refinedstorage:type.1=Fluids
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 3.0 KiB |
Reference in New Issue
Block a user