diff --git a/src/main/java/com/raoulvdberge/refinedstorage/api/autocrafting/ICraftingManager.java b/src/main/java/com/raoulvdberge/refinedstorage/api/autocrafting/ICraftingManager.java index 5fe2f3606..a0c432ebf 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/api/autocrafting/ICraftingManager.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/api/autocrafting/ICraftingManager.java @@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftin import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.IItemHandlerModifiable; @@ -35,7 +36,7 @@ public interface ICraftingManager { /** * @return named crafting pattern containers */ - Map> getNamedContainers(); + Map> getNamedContainers(); /** * Adds a crafting task. diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/API.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/API.java index 145d5833e..252a57393 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/API.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/API.java @@ -245,7 +245,6 @@ public class API implements IRSAPI { return patternRenderHandlers; } - // TODO: Remove eventually @Override public int getItemStackHashCode(ItemStack stack) { int result = stack.getItem().hashCode(); @@ -286,7 +285,6 @@ public class API implements IRSAPI { return result; } - // TODO: Remove eventually @Override public int getFluidStackHashCode(FluidStack stack) { int result = stack.getFluid().hashCode(); diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/CraftingManager.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/CraftingManager.java index 802ab1e2a..062731147 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/CraftingManager.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/CraftingManager.java @@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.ListNBT; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.IItemHandlerModifiable; @@ -34,7 +35,7 @@ public class CraftingManager implements ICraftingManager { private INetwork network; - private Map> containerInventories = new LinkedHashMap<>(); + private Map> containerInventories = new LinkedHashMap<>(); private List patterns = new ArrayList<>(); @@ -63,7 +64,7 @@ public class CraftingManager implements ICraftingManager { } @Override - public Map> getNamedContainers() { + public Map> getNamedContainers() { return containerInventories; } @@ -388,8 +389,7 @@ public class CraftingManager implements ICraftingManager { IItemHandlerModifiable handler = container.getPatternInventory(); if (handler != null) { - // TODO: Maybe use ITextComponent instead of string... - this.containerInventories.computeIfAbsent(container.getName().getFormattedText(), k -> new ArrayList<>()).add(handler); + this.containerInventories.computeIfAbsent(container.getName(), k -> new ArrayList<>()).add(handler); } } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/Network.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/Network.java index 6180ef055..3051470f2 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/Network.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/Network.java @@ -29,6 +29,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.storage.tracker.FluidStorageTrack import com.raoulvdberge.refinedstorage.apiimpl.storage.tracker.ItemStorageTracker; import com.raoulvdberge.refinedstorage.block.ControllerBlock; import com.raoulvdberge.refinedstorage.energy.BaseEnergyStorage; +import com.raoulvdberge.refinedstorage.tile.ControllerTile; import com.raoulvdberge.refinedstorage.tile.config.IRedstoneConfigurable; import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode; import com.raoulvdberge.refinedstorage.util.StackUtils; @@ -81,8 +82,7 @@ public class Network implements INetwork, IRedstoneConfigurable { this.world = world; this.type = type; this.root = new RootNetworkNode(this, world, pos); - - // TODO: Update ControllerTile.NODES when graph changes? + this.nodeGraph.addListener(() -> ((ControllerTile) world.getTileEntity(pos)).getDataManager().sendParameterToWatchers(ControllerTile.NODES)); } public RootNetworkNode getRoot() { diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/security/SecurityManager.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/security/SecurityManager.java index b1adf6bc3..627dd03b1 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/security/SecurityManager.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/security/SecurityManager.java @@ -24,7 +24,7 @@ public class SecurityManager implements ISecurityManager { @Override public boolean hasPermission(Permission permission, PlayerEntity player) { - OpList ops = player.getServer().getPlayerList().getOppedPlayers(); // TODO does that work? + OpList ops = player.getServer().getPlayerList().getOppedPlayers(); if (ops.getEntry(player.getGameProfile()) != null) { return true; diff --git a/src/main/java/com/raoulvdberge/refinedstorage/block/CrafterManagerBlock.java b/src/main/java/com/raoulvdberge/refinedstorage/block/CrafterManagerBlock.java index 5d15c8338..aa5df0b32 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/block/CrafterManagerBlock.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/block/CrafterManagerBlock.java @@ -17,11 +17,8 @@ import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; -import net.minecraftforge.items.IItemHandlerModifiable; import javax.annotation.Nullable; -import java.util.List; -import java.util.Map; public class CrafterManagerBlock extends NetworkNodeBlock { public CrafterManagerBlock() { @@ -53,23 +50,7 @@ public class CrafterManagerBlock extends NetworkNodeBlock { return NetworkUtils.attempt(world, pos, hit.getFace(), player, () -> NetworkHooks.openGui( (ServerPlayerEntity) player, new CrafterManagerContainerProvider((CrafterManagerTile) world.getTileEntity(pos)), - buf -> { - buf.writeBlockPos(pos); - - Map> containerData = ((CrafterManagerTile) world.getTileEntity(pos)).getNode().getNetwork().getCraftingManager().getNamedContainers(); - - buf.writeInt(containerData.size()); - - for (Map.Entry> entry : containerData.entrySet()) { - buf.writeString(entry.getKey()); - - int slots = 0; - for (IItemHandlerModifiable handler : entry.getValue()) { - slots += handler.getSlots(); - } - buf.writeInt(slots); - } - } + buf -> CrafterManagerContainerProvider.writeToBuffer(buf, world, pos) ), Permission.MODIFY, Permission.AUTOCRAFTING); } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/container/CrafterManagerContainer.java b/src/main/java/com/raoulvdberge/refinedstorage/container/CrafterManagerContainer.java index 13b033cfc..1adc8472a 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/container/CrafterManagerContainer.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/container/CrafterManagerContainer.java @@ -15,6 +15,7 @@ import com.raoulvdberge.refinedstorage.tile.CrafterManagerTile; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.util.text.ITextComponent; import net.minecraftforge.items.IItemHandlerModifiable; import javax.annotation.Nonnull; @@ -47,10 +48,10 @@ public class CrafterManagerContainer extends BaseContainer { addPlayerInventory(8, screenInfoProvider.getYPlayerInventory()); if (crafterManager.getNetwork() != null) { - for (Map.Entry> entry : crafterManager.getNetwork().getCraftingManager().getNamedContainers().entrySet()) { + for (Map.Entry> entry : crafterManager.getNetwork().getCraftingManager().getNamedContainers().entrySet()) { for (IItemHandlerModifiable handler : entry.getValue()) { for (int i = 0; i < handler.getSlots(); ++i) { - addSlot(new CrafterManagerSlot(handler, i, 0, 0, true, screenInfoProvider, this.crafterManager)); + addSlot(new CrafterManagerSlot(handler, i, 0, 0, true, screenInfoProvider, crafterManager)); } } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/container/factory/CrafterManagerContainerFactory.java b/src/main/java/com/raoulvdberge/refinedstorage/container/factory/CrafterManagerContainerFactory.java index f4edd130e..37164bad1 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/container/factory/CrafterManagerContainerFactory.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/container/factory/CrafterManagerContainerFactory.java @@ -3,7 +3,6 @@ package com.raoulvdberge.refinedstorage.container.factory; import com.raoulvdberge.refinedstorage.container.CrafterManagerContainer; import com.raoulvdberge.refinedstorage.screen.EmptyScreenInfoProvider; import com.raoulvdberge.refinedstorage.tile.CrafterManagerTile; -import com.raoulvdberge.refinedstorage.util.PacketBufferUtils; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.BlockPos; @@ -22,7 +21,7 @@ public class CrafterManagerContainerFactory implements IContainerFactory> containerData = ((CrafterManagerTile) world.getTileEntity(pos)).getNode().getNetwork().getCraftingManager().getNamedContainers(); + + buf.writeInt(containerData.size()); + + for (Map.Entry> entry : containerData.entrySet()) { + buf.writeTextComponent(entry.getKey()); + + int slots = 0; + for (IItemHandlerModifiable handler : entry.getValue()) { + slots += handler.getSlots(); + } + + buf.writeInt(slots); + } + } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/funkylocomotion/IntegrationFunkyLocomotion.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/funkylocomotion/IntegrationFunkyLocomotion.java deleted file mode 100644 index 44091fed0..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/funkylocomotion/IntegrationFunkyLocomotion.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.funkylocomotion; - -/* -public final class IntegrationFunkyLocomotion { - public static boolean isLoaded() { - return Loader.isModLoaded("funkylocomotion"); - } -} -*/ diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/funkylocomotion/MoveFactoryNetworkNode.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/funkylocomotion/MoveFactoryNetworkNode.java deleted file mode 100644 index c41aa67c9..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/funkylocomotion/MoveFactoryNetworkNode.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.funkylocomotion; -/* -import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode; -import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager; -import com.raoulvdberge.refinedstorage.apiimpl.API; -import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode; -import com.raoulvdberge.refinedstorage.tile.TileNode; -import com.rwtema.funkylocomotion.api.IMoveFactory; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -public class MoveFactoryNetworkNode implements IMoveFactory { - private static final String NBT_DIRECTION = "Direction"; - private static final String NBT_NODE = "Node"; - private static final String NBT_NODE_ID = "NodeID"; - private static final String NBT_BLOCK = "Block"; - private static final String NBT_META = "Meta"; - private static final String NBT_TILE = "Tile"; - - @Override - public CompoundNBT destroyBlock(World world, BlockPos pos) { - INetworkNodeManager manager = API.instance().getNetworkNodeManager(world); - - INetworkNode node = manager.getNode(pos); - - TileNode tile = (TileNode) world.getTileEntity(pos); - - CompoundNBT tag = new CompoundNBT(); - - tag.putInt(NBT_DIRECTION, tile.getDirection().ordinal()); - tag.put(NBT_NODE, node.write(new CompoundNBT())); - tag.setString(NBT_NODE_ID, node.getId()); - - // Funky Locomotion requires this - IBlockState state = world.getBlockState(pos); - tag.setString(NBT_BLOCK, Block.REGISTRY.getNameForObject(state.getBlock()).toString()); - tag.putInt(NBT_META, state.getBlock().getMetaFromState(state)); - tag.put(NBT_TILE, tile.writeToNBT(new CompoundNBT())); - - manager.removeNode(pos); // Avoid inventory dropping - manager.markForSaving(); - - return tag; - } - - @Override - @SuppressWarnings("deprecation") - public boolean recreateBlock(World world, BlockPos pos, CompoundNBT tag) { - NetworkNode node = (NetworkNode) API.instance().getNetworkNodeRegistry().get(tag.getString(NBT_NODE_ID)).create(tag.getCompound(NBT_NODE), world, pos); - node.setThrottlingDisabled(); - - INetworkNodeManager manager = API.instance().getNetworkNodeManager(world); - - manager.setNode(pos, node); - manager.markForSaving(); - - Block block = Block.REGISTRY.getObject(new ResourceLocation(tag.getString(NBT_BLOCK))); - world.setBlockState(pos, block.getStateFromMeta(tag.getInteger(NBT_META))); - - TileEntity tile = world.getTileEntity(pos); - if (tile instanceof TileNode) { - ((TileNode) tile).setDirection(EnumFacing.byIndex(tag.getInteger(NBT_DIRECTION))); - - tile.markDirty(); - } - - return true; - } -} - */ \ No newline at end of file diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/funkylocomotion/MoveFactoryRegisterer.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/funkylocomotion/MoveFactoryRegisterer.java deleted file mode 100644 index ba2ad2d73..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/funkylocomotion/MoveFactoryRegisterer.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.funkylocomotion; -/* -import com.raoulvdberge.refinedstorage.block.BlockBase; -import com.raoulvdberge.refinedstorage.block.BlockNode; -import com.rwtema.funkylocomotion.api.FunkyRegistry; -import net.minecraft.block.Block; - -import java.util.List; - -public class MoveFactoryRegisterer { - public static void register(List blocks) { - for (Block block : blocks) { - if (block instanceof BlockNode) { - FunkyRegistry.INSTANCE.registerMoveFactoryBlock(block, new MoveFactoryNetworkNode()); - } - } - } -} -*/ diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/GhostIngredientHandler.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/GhostIngredientHandler.java index 5a2d8dc59..8c683b609 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/GhostIngredientHandler.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/GhostIngredientHandler.java @@ -37,7 +37,7 @@ public class GhostIngredientHandler implements IGhostIngredientHandler output) { - if (value instanceof ICraftingPattern) { - ICraftingPattern pattern = (ICraftingPattern) value; - - output.put("outputs", pattern.getOutputs()); - output.put("inputs", pattern.getInputs()); - - if (pattern.isProcessing()) { - output.put("fluidInputs", pattern.getFluidInputs()); - output.put("fluidOutputs", pattern.getFluidOutputs()); - } else { - output.put("byproducts", pattern.getByproducts()); - } - - output.put("processing", pattern.isProcessing()); - output.put("oredict", pattern.isOredict()); - } - } -} -*/ \ No newline at end of file diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/ConverterCraftingRequestInfo.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/ConverterCraftingRequestInfo.java deleted file mode 100644 index 68f98555d..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/ConverterCraftingRequestInfo.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.oc; -/* -import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingRequestInfo; -import li.cil.oc.api.driver.Converter; - -import java.util.Map; - -public class ConverterCraftingRequestInfo implements Converter { - @Override - public void convert(Object value, Map map) { - if (value instanceof ICraftingRequestInfo) { - map.put("item", ((ICraftingRequestInfo) value).getItem()); - map.put("fluid", ((ICraftingRequestInfo) value).getFluid()); - } - } -} -*/ \ No newline at end of file diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/ConverterCraftingTask.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/ConverterCraftingTask.java deleted file mode 100644 index 546b65ef6..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/ConverterCraftingTask.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.oc; -/* -import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask; -import li.cil.oc.api.driver.Converter; - -import java.util.Map; - -public class ConverterCraftingTask implements Converter { - @Override - public void convert(Object value, Map output) { - if (value instanceof ICraftingTask) { - ICraftingTask task = (ICraftingTask) value; - - output.put("stack", task.getRequested()); - output.put("missing", task.getMissing().getStacks()); - output.put("missingFluids", task.getMissingFluids().getStacks()); - output.put("pattern", task.getPattern()); - output.put("quantity", task.getQuantity()); - } - } -} -*/ \ No newline at end of file diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/DriverNetwork.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/DriverNetwork.java deleted file mode 100644 index 7e6b8025c..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/DriverNetwork.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.oc; -/* -import com.raoulvdberge.refinedstorage.api.network.INetwork; -import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy; -import li.cil.oc.api.Driver; -import li.cil.oc.api.driver.DriverBlock; -import li.cil.oc.api.network.ManagedEnvironment; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -public class DriverNetwork implements DriverBlock { - @Override - public boolean worksWith(World world, BlockPos pos, EnumFacing facing) { - TileEntity tile = world.getTileEntity(pos); - - // Avoid bug #1855 (https://github.com/raoulvdberge/refinedstorage/issues/1855) - if (tile instanceof INetwork) { - return false; - } - - return tile != null && tile.hasCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, facing); - } - - @Override - public ManagedEnvironment createEnvironment(World world, BlockPos pos, EnumFacing facing) { - return new EnvironmentNetwork(world.getTileEntity(pos).getCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, facing).getNode()); - } - - public static void register() { - Driver.add(new DriverNetwork()); - - Driver.add(new ConverterCraftingPattern()); - Driver.add(new ConverterCraftingTask()); - Driver.add(new ConverterCraftingRequestInfo()); - } -} -*/ \ No newline at end of file diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/EnvironmentNetwork.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/EnvironmentNetwork.java deleted file mode 100644 index 44fed3f85..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/EnvironmentNetwork.java +++ /dev/null @@ -1,458 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.oc; - -/* -import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern; -import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask; -import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTaskError; -import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode; -import com.raoulvdberge.refinedstorage.api.storage.IStorage; -import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk; -import com.raoulvdberge.refinedstorage.api.util.Action; -import com.raoulvdberge.refinedstorage.api.util.IComparer; -import com.raoulvdberge.refinedstorage.apiimpl.API; -import li.cil.oc.api.Network; -import li.cil.oc.api.machine.Arguments; -import li.cil.oc.api.machine.Callback; -import li.cil.oc.api.machine.Context; -import li.cil.oc.api.network.Visibility; -import li.cil.oc.api.prefab.AbstractManagedEnvironment; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.CapabilityItemHandler; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.ItemHandlerHelper; - -import java.util.*; - -import static com.raoulvdberge.refinedstorage.api.util.IComparer.COMPARE_DAMAGE; -import static com.raoulvdberge.refinedstorage.api.util.IComparer.COMPARE_NBT; - -public class EnvironmentNetwork extends AbstractManagedEnvironment { - protected final INetworkNode node; - - public EnvironmentNetwork(INetworkNode node) { - this.node = node; - - setNode(Network.newNode(this, Visibility.Network).withComponent("refinedstorage", Visibility.Network).create()); - } - - @Callback(doc = "function():boolean -- Whether the node is connected.") - public Object[] isConnected(final Context context, final Arguments args) { - return new Object[]{node.canUpdate()}; - } - - @Callback(doc = "function():number -- Gets the energy usage of this network.") - public Object[] getEnergyUsage(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - return new Object[]{node.getNetwork().getEnergyUsage()}; - } - - @Callback(doc = "function():table -- Gets the crafting tasks of this network.") - public Object[] getTasks(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - return new Object[]{node.getNetwork().getCraftingManager().getTasks()}; - } - - @Callback(doc = "function(stack:table):table -- Get one pattern of this network.") - public Object[] getPattern(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - ItemStack stack = args.checkItemStack(0); - return new Object[]{node.getNetwork().getCraftingManager().getPattern(stack)}; - } - - @Callback(doc = "function(stack:table):table -- Get one fluid pattern of this network.") - public Object[] getFluidPattern(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - FluidStack stack = checkFluid(args.checkTable(0), 1000); - return new Object[]{node.getNetwork().getCraftingManager().getPattern(stack)}; - } - - @Callback(doc = "function():table -- Gets the patterns of this network.") - public Object[] getPatterns(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - List patterns = new LinkedList<>(); - for (ICraftingPattern pattern : node.getNetwork().getCraftingManager().getPatterns()) { - if (!pattern.getOutputs().isEmpty()) { - patterns.addAll(pattern.getOutputs()); - } - } - - return new Object[]{patterns}; - } - - @Callback(doc = "function():table -- Gets the fluid patterns of this network.") - public Object[] getFluidPatterns(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - List patterns = new LinkedList<>(); - for (ICraftingPattern pattern : node.getNetwork().getCraftingManager().getPatterns()) { - if (!pattern.getFluidOutputs().isEmpty()) { - patterns.addAll(pattern.getFluidOutputs()); - } - } - - return new Object[]{patterns}; - } - - @Callback(doc = "function(stack:table):boolean -- Whether a crafting pattern exists for this item.") - public Object[] hasPattern(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - ItemStack stack = args.checkItemStack(0); - - return new Object[]{node.getNetwork().getCraftingManager().getPattern(stack) != null}; - } - - @Callback(doc = "function(stack:table):boolean -- Whether a crafting pattern exists for this fluid.") - public Object[] hasFluidPattern(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - FluidStack stack = checkFluid(args.checkTable(0), 1000); - - return new Object[]{node.getNetwork().getCraftingManager().getPattern(stack) != null}; - } - - @Callback(doc = "function(stack:table[, count: number[, canSchedule: boolean]]):table -- Schedules a crafting task.") - public Object[] scheduleTask(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{"not connected"}; - } - - ItemStack stack = args.checkItemStack(0); - int amount = args.optInteger(1, 1); - - ICraftingTask task = node.getNetwork().getCraftingManager().create(stack, amount); - if (task == null) { - throw new IllegalArgumentException("Could not create crafting task"); - } - - ICraftingTaskError error = task.calculate(); - - if (error == null && !task.hasMissing() && args.optBoolean(2, true)) { - node.getNetwork().getCraftingManager().add(task); - } - - return new Object[]{task}; - } - - @Callback(doc = "function(stack:table[, count: number[, canSchedule: boolean]]):table -- Schedules a fluid crafting task.") - public Object[] scheduleFluidTask(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{"not connected"}; - } - - FluidStack stack = checkFluid(args.checkTable(0), args.optInteger(1, Fluid.BUCKET_VOLUME)); - - ICraftingTask task = node.getNetwork().getCraftingManager().create(stack, stack.amount); - if (task == null) { - throw new IllegalArgumentException("Could not create crafting task"); - } - - ICraftingTaskError error = task.calculate(); - - if (error == null && !task.hasMissing() && args.optBoolean(2, true)) { - node.getNetwork().getCraftingManager().add(task); - } - - return new Object[]{task}; - } - - @Callback(doc = "function(stack:table):number -- Cancels a task and returns the amount of tasks cancelled.") - public Object[] cancelTask(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - ItemStack stack = args.checkItemStack(0); - - int count = 0; - for (ICraftingTask task : node.getNetwork().getCraftingManager().getTasks()) { - if (task.getRequested().getItem() != null) { - if (API.instance().getComparer().isEqual(task.getRequested().getItem(), stack, COMPARE_NBT | COMPARE_DAMAGE)) { - node.getNetwork().getCraftingManager().cancel(task.getId()); - - count++; - } - } - } - - return new Object[]{count}; - } - - @Callback(doc = "function(stack:table):number -- Cancels a fluid task and returns the amount of tasks cancelled.") - public Object[] cancelFluidTask(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - FluidStack stack = checkFluid(args.checkTable(0), 1000); - - int count = 0; - for (ICraftingTask task : node.getNetwork().getCraftingManager().getTasks()) { - if (task.getRequested().getFluid() != null) { - if (API.instance().getComparer().isEqual(task.getRequested().getFluid(), stack, COMPARE_NBT)) { - node.getNetwork().getCraftingManager().cancel(task.getId()); - - count++; - } - } - } - - return new Object[]{count}; - } - - @Callback(doc = "function(stack:table[, amount:number[, direction:number]]):table -- Extracts a fluid from the network.") - public Object[] extractFluid(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - // First and second argument: fluid and amount. - FluidStack stack = checkFluid(args.checkTable(0), args.checkInteger(1)); - - // Third argument: which direction to extract to - EnumFacing facing = EnumFacing.byIndex(args.optInteger(2, 0)); - - // Get the tile-entity on the specified side - TileEntity targetEntity = node.getNetwork().world().getTileEntity(node.getPos().offset(facing)); - if (targetEntity == null || !targetEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite())) { - throw new IllegalArgumentException("No fluid tank on the given side"); - } - - FluidStack extractedSim = node.getNetwork().extractFluid(stack, stack.amount, Action.SIMULATE); - if (extractedSim == null || extractedSim.amount <= 0) { - return new Object[]{null, "could not extract the specified fluid"}; - } - - // Simulate inserting the fluid and see how much we were able to insert - IFluidHandler handler = targetEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite()); - int filledAmountSim = handler.fill(extractedSim, false); - if (filledAmountSim <= 0) { - return new Object[]{0}; - } - - // Actually do it and return how much fluid we've inserted - FluidStack extracted = node.getNetwork().extractFluid(stack, stack.amount, Action.PERFORM); - handler.fill(extracted, true); - - return new Object[]{filledAmountSim}; - } - - @Callback(doc = "function(stack:table):table -- Gets a fluid from the network.") - public Object[] getFluid(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - FluidStack needle = checkFluid(args.checkTable(0), 1000); - - return new Object[]{node.getNetwork().getFluidStorageCache().getList().get(needle)}; - } - - @Callback(doc = "function():table -- Gets a list of all fluids in this network.") - public Object[] getFluids(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - return new Object[]{node.getNetwork().getFluidStorageCache().getList().getStacks()}; - } - - @Callback(doc = "function(stack:table[, count:number[, direction:number]]):table -- Extracts an item from the network.") - public Object[] extractItem(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - // First argument: the itemstack to extract - ItemStack stack = args.checkItemStack(0); - - // Second argument: the number of items to extract, at least 1 ... - int count = Math.max(1, args.optInteger(1, 1)); - - // ... and at most a full stack - count = Math.min(count, stack.getMaxStackSize()); - - // Third argument: which direction to extract to - EnumFacing facing = EnumFacing.byIndex(args.optInteger(2, 0)); - - // Get the tile-entity on the specified side - TileEntity targetEntity = node.getNetwork().world().getTileEntity(node.getPos().offset(facing)); - if (targetEntity == null || !targetEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite())) { - throw new IllegalArgumentException("No inventory on the given side"); - } - - // Simulate extracting the item and get the amount of items that can be extracted - ItemStack extracted = node.getNetwork().extractItem(stack, count, Action.SIMULATE); - if (extracted == null) { - return new Object[]{null, "could not extract the specified item"}; - } - - int transferableAmount = extracted.getCount(); - - // Simulate inserting the item and see how many we were able to insert - IItemHandler handler = targetEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()); - ItemStack remainder = ItemHandlerHelper.insertItemStacked(handler, extracted, true); - if (!remainder.isEmpty()) { - transferableAmount -= remainder.getCount(); - } - - // Abort early if we can not insert items - if (transferableAmount <= 0) { - return new Object[]{0}; - } - - // Actually do it and return how many items we've inserted - extracted = node.getNetwork().extractItem(stack, transferableAmount, Action.PERFORM); - if (extracted != null) { - remainder = ItemHandlerHelper.insertItemStacked(handler, extracted, false); - - if (!remainder.isEmpty()) { - node.getNetwork().insertItem(remainder, remainder.getCount(), Action.PERFORM); - } - } - - return new Object[]{transferableAmount}; - } - - @Callback(doc = "function(stack:table[, compareMeta:boolean[, compareNBT:boolean]]):table -- Gets an item from the network.") - public Object[] getItem(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - ItemStack stack = args.checkItemStack(0); - boolean compareMeta = args.optBoolean(1, true); - boolean compareNBT = args.optBoolean(2, true); - - int flags = 0; - - if (compareMeta) { - flags |= IComparer.COMPARE_DAMAGE; - } - - if (compareNBT) { - flags |= IComparer.COMPARE_NBT; - } - - return new Object[]{node.getNetwork().getItemStorageCache().getList().get(stack, flags)}; - } - - @Callback(doc = "function():table -- Gets a list of all items in this network.") - public Object[] getItems(final Context context, final Arguments args) { - if (node.getNetwork() == null) { - return new Object[]{null, "not connected"}; - } - - return new Object[]{node.getNetwork().getItemStorageCache().getList().getStacks()}; - } - - @Callback(doc = "function():table -- Gets a list of all connected storage disks and blocks in this network.") - public Object[] getStorages(final Context context, final Arguments args) { - int totalItemStored = 0; - int totalItemCapacity = 0; - - int totalFluidStored = 0; - int totalFluidCapacity = 0; - - List> devices = new ArrayList<>(); - - if (node.getNetwork() != null) { - for (IStorage s : node.getNetwork().getItemStorageCache().getStorages()) { - if (s instanceof IStorageDisk) { - IStorageDisk disk = (IStorageDisk) s; - - HashMap data = new HashMap<>(); - - data.put("type", "item"); - data.put("usage", disk.getStored()); - data.put("capacity", disk.getCapacity()); - - totalItemStored += disk.getStored(); - totalItemCapacity += disk.getCapacity(); - - devices.add(data); - } - } - - for (IStorage s : node.getNetwork().getFluidStorageCache().getStorages()) { - if (s instanceof IStorageDisk) { - IStorageDisk disk = (IStorageDisk) s; - - HashMap data = new HashMap<>(); - - data.put("type", "fluid"); - data.put("usage", disk.getStored()); - data.put("capacity", disk.getCapacity()); - - totalFluidStored += disk.getStored(); - totalFluidCapacity += disk.getCapacity(); - - devices.add(data); - } - } - } - - HashMap itemTotals = new HashMap<>(); - itemTotals.put("usage", totalItemStored); - itemTotals.put("capacity", totalItemCapacity); - - HashMap fluidTotals = new HashMap<>(); - fluidTotals.put("usage", totalFluidStored); - fluidTotals.put("capacity", totalFluidCapacity); - - HashMap totals = new HashMap<>(); - totals.put("item", itemTotals); - totals.put("fluid", fluidTotals); - - HashMap response = new HashMap<>(); - response.put("total", totals); - response.put("devices", devices); - - return new Object[]{response}; - } - - private FluidStack checkFluid(Map fluidMap, int amount) { - if (!fluidMap.containsKey("name") || !(fluidMap.get("name") instanceof String) || ((String) fluidMap.get("name")).length() == 0) { - throw new IllegalArgumentException("no fluid name"); - } - String fluid = (String) fluidMap.get("name"); - - amount = Math.max(1, amount); - - FluidStack stack = FluidRegistry.getFluidStack(fluid, amount); - if (stack == null) { - throw new IllegalArgumentException("invalid fluid stack, does not exist"); - } - - return stack; - } -} -*/ diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/IntegrationOC.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/IntegrationOC.java deleted file mode 100644 index a0e6882e5..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/oc/IntegrationOC.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.oc; - -/* -import net.minecraftforge.fml.common.Loader; - -public final class IntegrationOC { - private static final String ID = "opencomputers"; - - public static boolean isLoaded() { - return Loader.isModLoaded(ID); - } -} -*/ \ No newline at end of file diff --git a/src/main/java/com/raoulvdberge/refinedstorage/inventory/item/FilterItemHandler.java b/src/main/java/com/raoulvdberge/refinedstorage/inventory/item/FilterItemHandler.java index 06fac7180..3cc78862a 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/inventory/item/FilterItemHandler.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/inventory/item/FilterItemHandler.java @@ -47,7 +47,7 @@ public class FilterItemHandler extends BaseItemHandler { } } - if (EffectiveSide.get() == LogicalSide.CLIENT) { // TODO check + if (EffectiveSide.get() == LogicalSide.CLIENT) { BaseScreen.executeLater(GridScreen.class, grid -> grid.getView().sort()); } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/item/WrenchItem.java b/src/main/java/com/raoulvdberge/refinedstorage/item/WrenchItem.java index 794dfed87..fcde62f6e 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/item/WrenchItem.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/item/WrenchItem.java @@ -1,8 +1,9 @@ package com.raoulvdberge.refinedstorage.item; import com.raoulvdberge.refinedstorage.RS; +import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy; import com.raoulvdberge.refinedstorage.api.network.security.Permission; -import com.raoulvdberge.refinedstorage.tile.NetworkNodeTile; +import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability; import com.raoulvdberge.refinedstorage.util.WorldUtils; import net.minecraft.block.BlockState; import net.minecraft.item.Item; @@ -30,13 +31,16 @@ public class WrenchItem extends Item { TileEntity tile = ctx.getWorld().getTileEntity(ctx.getPos()); - // TODO - Better INetworkNode check - if (tile instanceof NetworkNodeTile && - ((NetworkNodeTile) tile).getNode().getNetwork() != null && - !((NetworkNodeTile) tile).getNode().getNetwork().getSecurityManager().hasPermission(Permission.BUILD, ctx.getPlayer())) { - WorldUtils.sendNoPermissionMessage(ctx.getPlayer()); + if (tile != null) { + INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY, ctx.getFace().getOpposite()).orElse(null); - return ActionResultType.FAIL; + if (proxy != null && + proxy.getNode().getNetwork() != null && + !proxy.getNode().getNetwork().getSecurityManager().hasPermission(Permission.BUILD, ctx.getPlayer())) { + WorldUtils.sendNoPermissionMessage(ctx.getPlayer()); + + return ActionResultType.FAIL; + } } BlockState state = ctx.getWorld().getBlockState(ctx.getPos()); diff --git a/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyCommon.java b/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyCommon.java index 1ab3dfd7a..3068fe432 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyCommon.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyCommon.java @@ -11,10 +11,6 @@ public class ProxyCommon { } public void init(FMLInitializationEvent e) { - if (IntegrationOC.isLoaded()) { - DriverNetwork.register(); - } - if (IntegrationCraftingTweaks.isLoaded()) { IntegrationCraftingTweaks.register(); } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/screen/CraftingMonitorScreen.java b/src/main/java/com/raoulvdberge/refinedstorage/screen/CraftingMonitorScreen.java index 8ec83d578..815d512a0 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/screen/CraftingMonitorScreen.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/screen/CraftingMonitorScreen.java @@ -59,7 +59,7 @@ public class CraftingMonitorScreen extends BaseScreen @Override public void drawTooltip(int x, int y, int xSize, int ySize, FontRenderer fontRenderer) { - List textLines = Lists.newArrayList(requested.getItem() != null ? requested.getItem().getDisplayName().getFormattedText() : requested.getFluid().getDisplayName().getFormattedText()); // TODO + List textLines = Lists.newArrayList(requested.getItem() != null ? requested.getItem().getDisplayName().getFormattedText() : requested.getFluid().getDisplayName().getFormattedText()); List smallTextLines = Lists.newArrayList(); int totalSecs = (int) (System.currentTimeMillis() - executionStarted) / 1000;