mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-08 08:20:29 +00:00
Initial pass of the API breaking changes for 1.19.3 (#1232)
- Remove deprecated API members in prep for 1.19.3. This allows us to remove the mc-stubs and forge-stubs projects. - Make several methods take a MinecraftServer instead of a Level (or nothing at all). - Remove I prefixes from a whole bunch of interfaces, making things a little more consistent with Java conventions. This avoids touching the "main" interfaces people consume for now. I want to do that another Minecraft version, to avoid making the update too painful. - Remove IFileSystem and associated getters. This has never worked very well and I don't think has got much (any?) usage.
This commit is contained in:
parent
95c57e843d
commit
87c6d3aef6
@ -10,7 +10,6 @@ java {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api(project(":core-api"))
|
api(project(":core-api"))
|
||||||
compileOnly(project(":forge-stubs"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.javadoc {
|
tasks.javadoc {
|
||||||
|
@ -5,31 +5,26 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api;
|
package dan200.computercraft.api;
|
||||||
|
|
||||||
import dan200.computercraft.api.detail.BlockReference;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.detail.DetailRegistry;
|
import dan200.computercraft.api.filesystem.WritableMount;
|
||||||
import dan200.computercraft.api.detail.IDetailProvider;
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
|
||||||
import dan200.computercraft.api.lua.GenericSource;
|
import dan200.computercraft.api.lua.GenericSource;
|
||||||
|
import dan200.computercraft.api.lua.ILuaAPI;
|
||||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
import dan200.computercraft.api.media.IMediaProvider;
|
import dan200.computercraft.api.media.MediaProvider;
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
import dan200.computercraft.api.network.PacketNetwork;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
|
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
|
||||||
import dan200.computercraft.impl.ComputerCraftAPIService;
|
import dan200.computercraft.impl.ComputerCraftAPIService;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -51,16 +46,16 @@ public final class ComputerCraftAPI {
|
|||||||
* <p>
|
* <p>
|
||||||
* Use in conjunction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
|
* Use in conjunction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
|
||||||
*
|
*
|
||||||
* @param world The world for which the save dir should be created. This should be the server side world object.
|
* @param server The server for which the save dir should be created.
|
||||||
* @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk"
|
* @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk"
|
||||||
* @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
|
* @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
|
||||||
* <p>
|
* <p>
|
||||||
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now
|
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now
|
||||||
* available for writing.
|
* available for writing.
|
||||||
* @see #createSaveDirMount(Level, String, long)
|
* @see #createSaveDirMount(MinecraftServer, String, long)
|
||||||
*/
|
*/
|
||||||
public static int createUniqueNumberedSaveDir(Level world, String parentSubPath) {
|
public static int createUniqueNumberedSaveDir(MinecraftServer server, String parentSubPath) {
|
||||||
return getInstance().createUniqueNumberedSaveDir(world, parentSubPath);
|
return getInstance().createUniqueNumberedSaveDir(server, parentSubPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,21 +64,21 @@ public final class ComputerCraftAPI {
|
|||||||
* Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the
|
* Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the
|
||||||
* users save directory onto a computers file system.
|
* users save directory onto a computers file system.
|
||||||
*
|
*
|
||||||
* @param world The world for which the save dir can be found. This should be the server side world object.
|
* @param server The server which the save dir can be found.
|
||||||
* @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".
|
* @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".
|
||||||
* Use createUniqueNumberedSaveDir() to create a new numbered folder to use.
|
* Use createUniqueNumberedSaveDir() to create a new numbered folder to use.
|
||||||
* @param capacity The amount of data that can be stored in the directory before it fills up, in bytes.
|
* @param capacity The amount of data that can be stored in the directory before it fills up, in bytes.
|
||||||
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable()
|
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable()
|
||||||
* to mount this on a Computers' file system.
|
* to mount this on a Computers' file system.
|
||||||
* @see #createUniqueNumberedSaveDir(Level, String)
|
* @see #createUniqueNumberedSaveDir(MinecraftServer, String)
|
||||||
* @see IComputerAccess#mount(String, IMount)
|
* @see IComputerAccess#mount(String, Mount)
|
||||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
* @see IComputerAccess#mountWritable(String, WritableMount)
|
||||||
* @see IMount
|
* @see Mount
|
||||||
* @see IWritableMount
|
* @see WritableMount
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static IWritableMount createSaveDirMount(Level world, String subPath, long capacity) {
|
public static WritableMount createSaveDirMount(MinecraftServer server, String subPath, long capacity) {
|
||||||
return getInstance().createSaveDirMount(world, subPath, capacity);
|
return getInstance().createSaveDirMount(server, subPath, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,29 +92,17 @@ public final class ComputerCraftAPI {
|
|||||||
* "/data/computercraft/lua/rom". We construct a mount for that with
|
* "/data/computercraft/lua/rom". We construct a mount for that with
|
||||||
* {@code createResourceMount("computercraft", "lua/rom")}.
|
* {@code createResourceMount("computercraft", "lua/rom")}.
|
||||||
*
|
*
|
||||||
|
* @param server The current Minecraft server, from which to read resources from.
|
||||||
* @param domain The domain under which to look for resources. eg: "mymod".
|
* @param domain The domain under which to look for resources. eg: "mymod".
|
||||||
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
|
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
|
||||||
* @return The mount, or {@code null} if it could be created for some reason.
|
* @return The mount, or {@code null} if it could be created for some reason.
|
||||||
* @see IComputerAccess#mount(String, IMount)
|
* @see IComputerAccess#mount(String, Mount)
|
||||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
* @see IComputerAccess#mountWritable(String, WritableMount)
|
||||||
* @see IMount
|
* @see Mount
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static IMount createResourceMount(String domain, String subPath) {
|
public static Mount createResourceMount(MinecraftServer server, String domain, String subPath) {
|
||||||
return getInstance().createResourceMount(domain, subPath);
|
return getInstance().createResourceMount(server, domain, subPath);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
|
|
||||||
*
|
|
||||||
* @param provider The peripheral provider to register.
|
|
||||||
* @see IPeripheral
|
|
||||||
* @see IPeripheralProvider
|
|
||||||
* @deprecated Use {@code dan200.computercraft.api.ForgeComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void registerPeripheralProvider(IPeripheralProvider provider) {
|
|
||||||
getInstance().registerPeripheralProvider(provider);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,25 +115,13 @@ public final class ComputerCraftAPI {
|
|||||||
getInstance().registerGenericSource(source);
|
getInstance().registerGenericSource(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a capability that can be used by generic peripherals.
|
|
||||||
*
|
|
||||||
* @param capability The capability to register.
|
|
||||||
* @see GenericSource
|
|
||||||
* @deprecated Use {@code dan200.computercraft.api.ForgeComputerCraftAPI} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void registerGenericCapability(Capability<?> capability) {
|
|
||||||
getInstance().registerGenericCapability(capability);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a bundled redstone provider to provide bundled redstone output for blocks.
|
* Registers a bundled redstone provider to provide bundled redstone output for blocks.
|
||||||
*
|
*
|
||||||
* @param provider The bundled redstone provider to register.
|
* @param provider The bundled redstone provider to register.
|
||||||
* @see IBundledRedstoneProvider
|
* @see BundledRedstoneProvider
|
||||||
*/
|
*/
|
||||||
public static void registerBundledRedstoneProvider(IBundledRedstoneProvider provider) {
|
public static void registerBundledRedstoneProvider(BundledRedstoneProvider provider) {
|
||||||
getInstance().registerBundledRedstoneProvider(provider);
|
getInstance().registerBundledRedstoneProvider(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +133,7 @@ public final class ComputerCraftAPI {
|
|||||||
* @param side The side to extract the bundled redstone output from.
|
* @param side The side to extract the bundled redstone output from.
|
||||||
* @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned.
|
* @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned.
|
||||||
* If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
|
* If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
|
||||||
* @see IBundledRedstoneProvider
|
* @see BundledRedstoneProvider
|
||||||
*/
|
*/
|
||||||
public static int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side) {
|
public static int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side) {
|
||||||
return getInstance().getBundledRedstoneOutput(world, pos, side);
|
return getInstance().getBundledRedstoneOutput(world, pos, side);
|
||||||
@ -172,38 +143,33 @@ public final class ComputerCraftAPI {
|
|||||||
* Registers a media provider to provide {@link IMedia} implementations for Items.
|
* Registers a media provider to provide {@link IMedia} implementations for Items.
|
||||||
*
|
*
|
||||||
* @param provider The media provider to register.
|
* @param provider The media provider to register.
|
||||||
* @see IMediaProvider
|
* @see MediaProvider
|
||||||
*/
|
*/
|
||||||
public static void registerMediaProvider(IMediaProvider provider) {
|
public static void registerMediaProvider(MediaProvider provider) {
|
||||||
getInstance().registerMediaProvider(provider);
|
getInstance().registerMediaProvider(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to get the game-wide wireless network.
|
* Attempt to get the game-wide wireless network.
|
||||||
*
|
*
|
||||||
|
* @param server The current Minecraft server.
|
||||||
* @return The global wireless network, or {@code null} if it could not be fetched.
|
* @return The global wireless network, or {@code null} if it could not be fetched.
|
||||||
*/
|
*/
|
||||||
public static IPacketNetwork getWirelessNetwork() {
|
public static PacketNetwork getWirelessNetwork(MinecraftServer server) {
|
||||||
return getInstance().getWirelessNetwork();
|
return getInstance().getWirelessNetwork(server);
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerAPIFactory(ILuaAPIFactory factory) {
|
|
||||||
getInstance().registerAPIFactory(factory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a detail provider to provide additional details for blocks, fluids and items when inspected by methods
|
* Register a custom {@link ILuaAPI}, which may be added onto all computers without requiring a peripheral.
|
||||||
* such as {@code turtle.getItemDetail()} or {@code turtle.inspect()}.
|
* <p>
|
||||||
|
* Before implementing this interface, consider alternative methods of providing methods. It is generally preferred
|
||||||
|
* to use peripherals to provide functionality to users.
|
||||||
*
|
*
|
||||||
* @param type The type of object that this provider can provide details for. Should be {@link BlockReference},
|
* @param factory The factory for your API subclass.
|
||||||
* {@code net.minecraftforge.fluids.FluidStack} or {@link ItemStack}.
|
* @see ILuaAPIFactory
|
||||||
* @param provider The detail provider to register.
|
|
||||||
* @param <T> The type of object that this provider can provide details for.
|
|
||||||
* @deprecated Use {@link DetailRegistry#addProvider(IDetailProvider)} to register your provider.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true)
|
public static void registerAPIFactory(ILuaAPIFactory factory) {
|
||||||
public static <T> void registerDetailProvider(Class<T> type, IDetailProvider<T> provider) {
|
getInstance().registerAPIFactory(factory);
|
||||||
getInstance().registerDetailProvider(type, provider);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -211,27 +177,19 @@ public final class ComputerCraftAPI {
|
|||||||
*
|
*
|
||||||
* @param element The element to construct it for
|
* @param element The element to construct it for
|
||||||
* @return The element's node
|
* @return The element's node
|
||||||
* @see IWiredElement#getNode()
|
* @see WiredElement#getNode()
|
||||||
*/
|
*/
|
||||||
public static IWiredNode createWiredNodeForElement(IWiredElement element) {
|
public static WiredNode createWiredNodeForElement(WiredElement element) {
|
||||||
return getInstance().createWiredNodeForElement(element);
|
return getInstance().createWiredNodeForElement(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the wired network element for a block in world.
|
* Register a refuel handler for turtles. This may be used to provide alternative fuel sources, such as consuming RF
|
||||||
|
* batteries.
|
||||||
*
|
*
|
||||||
* @param world The world the block exists in
|
* @param handler The turtle refuel handler.
|
||||||
* @param pos The position the block exists in
|
* @see TurtleRefuelHandler#refuel(ITurtleAccess, ItemStack, int, int)
|
||||||
* @param side The side to extract the network element from
|
|
||||||
* @return The element's node
|
|
||||||
* @see IWiredElement#getNode()
|
|
||||||
* @deprecated Use {@code dan200.computercraft.api.ForgeComputerCraftAPI#getWiredElementAt(BlockGetter, BlockPos, Direction)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static LazyOptional<IWiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side) {
|
|
||||||
return getInstance().getWiredElementAt(world, pos, side);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerRefuelHandler(TurtleRefuelHandler handler) {
|
public static void registerRefuelHandler(TurtleRefuelHandler handler) {
|
||||||
getInstance().registerRefuelHandler(handler);
|
getInstance().registerRefuelHandler(handler);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import java.util.Objects;
|
|||||||
*
|
*
|
||||||
* @param <T> The type the stack's item must have.
|
* @param <T> The type the stack's item must have.
|
||||||
*/
|
*/
|
||||||
public abstract class BasicItemDetailProvider<T> implements IDetailProvider<ItemStack> {
|
public abstract class BasicItemDetailProvider<T> implements DetailProvider<ItemStack> {
|
||||||
private final Class<T> itemType;
|
private final Class<T> itemType;
|
||||||
private final @Nullable String namespace;
|
private final @Nullable String namespace;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import java.util.Map;
|
|||||||
* @see DetailRegistry
|
* @see DetailRegistry
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface IDetailProvider<T> {
|
public interface DetailProvider<T> {
|
||||||
/**
|
/**
|
||||||
* Provide additional details for the given object. This method is called by functions such as
|
* Provide additional details for the given object. This method is called by functions such as
|
||||||
* {@code turtle.getItemDetail()} and {@code turtle.inspect()}. New properties should be added to the given
|
* {@code turtle.getItemDetail()} and {@code turtle.inspect()}. New properties should be added to the given
|
@ -25,9 +25,9 @@ public interface DetailRegistry<T> {
|
|||||||
* Registers a detail provider.
|
* Registers a detail provider.
|
||||||
*
|
*
|
||||||
* @param provider The detail provider to register.
|
* @param provider The detail provider to register.
|
||||||
* @see IDetailProvider
|
* @see DetailProvider
|
||||||
*/
|
*/
|
||||||
void addProvider(IDetailProvider<T> provider);
|
void addProvider(DetailProvider<T> provider);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute basic details about an object. This is cheaper than computing all details operation, and so is suitable
|
* Compute basic details about an object. This is cheaper than computing all details operation, and so is suitable
|
||||||
|
@ -5,11 +5,14 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.media;
|
package dan200.computercraft.api.media;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
|
import dan200.computercraft.api.filesystem.WritableMount;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -17,7 +20,7 @@ import javax.annotation.Nullable;
|
|||||||
* Represents an item that can be placed in a disk drive and used by a Computer.
|
* Represents an item that can be placed in a disk drive and used by a Computer.
|
||||||
* <p>
|
* <p>
|
||||||
* Implement this interface on your {@link Item} class to allow it to be used in the drive. Alternatively, register
|
* Implement this interface on your {@link Item} class to allow it to be used in the drive. Alternatively, register
|
||||||
* a {@link IMediaProvider}.
|
* a {@link MediaProvider}.
|
||||||
*/
|
*/
|
||||||
public interface IMedia {
|
public interface IMedia {
|
||||||
/**
|
/**
|
||||||
@ -68,16 +71,16 @@ public interface IMedia {
|
|||||||
* be mounted onto the filesystem of the computer while the media is in the disk drive.
|
* be mounted onto the filesystem of the computer while the media is in the disk drive.
|
||||||
*
|
*
|
||||||
* @param stack The {@link ItemStack} to modify.
|
* @param stack The {@link ItemStack} to modify.
|
||||||
* @param world The world in which the item and disk drive reside.
|
* @param level The world in which the item and disk drive reside.
|
||||||
* @return The mount, or null if this item does not represent an item with data. If the mount returned also
|
* @return The mount, or null if this item does not represent an item with data. If the mount returned also
|
||||||
* implements {@link dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable()
|
* implements {@link WritableMount}, it will mounted using mountWritable()
|
||||||
* @see IMount
|
* @see Mount
|
||||||
* @see dan200.computercraft.api.filesystem.IWritableMount
|
* @see WritableMount
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
* @see ComputerCraftAPI#createSaveDirMount(MinecraftServer, String, long)
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(String, String)
|
* @see ComputerCraftAPI#createResourceMount(MinecraftServer, String, String)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
default IMount createDataMount(ItemStack stack, Level world) {
|
default Mount createDataMount(ItemStack stack, ServerLevel level) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,16 @@ import javax.annotation.Nullable;
|
|||||||
/**
|
/**
|
||||||
* This interface is used to provide {@link IMedia} implementations for {@link ItemStack}.
|
* This interface is used to provide {@link IMedia} implementations for {@link ItemStack}.
|
||||||
*
|
*
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider)
|
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(MediaProvider)
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface IMediaProvider {
|
public interface MediaProvider {
|
||||||
/**
|
/**
|
||||||
* Produce an IMedia implementation from an ItemStack.
|
* Produce an IMedia implementation from an ItemStack.
|
||||||
*
|
*
|
||||||
* @param stack The stack from which to extract the media information.
|
* @param stack The stack from which to extract the media information.
|
||||||
* @return An {@link IMedia} implementation, or {@code null} if the item is not something you wish to handle
|
* @return An {@link IMedia} implementation, or {@code null} if the item is not something you wish to handle
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider)
|
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(MediaProvider)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
IMedia getMedia(ItemStack stack);
|
IMedia getMedia(ItemStack stack);
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.api.network;
|
package dan200.computercraft.api.network;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a packet which may be sent across a {@link IPacketNetwork}.
|
* Represents a packet which may be sent across a {@link PacketNetwork}.
|
||||||
*
|
*
|
||||||
* @param channel The channel to send the packet along. Receiving devices should only process packets from on
|
* @param channel The channel to send the packet along. Receiving devices should only process packets from on
|
||||||
* channels they are listening to.
|
* channels they are listening to.
|
||||||
@ -14,16 +14,16 @@ package dan200.computercraft.api.network;
|
|||||||
* @param payload The contents of this packet. This should be a "valid" Lua object, safe for queuing as an
|
* @param payload The contents of this packet. This should be a "valid" Lua object, safe for queuing as an
|
||||||
* event or returning from a peripheral call.
|
* event or returning from a peripheral call.
|
||||||
* @param sender The object which sent this packet.
|
* @param sender The object which sent this packet.
|
||||||
* @see IPacketSender
|
* @see PacketSender
|
||||||
* @see IPacketNetwork#transmitSameDimension(Packet, double)
|
* @see PacketNetwork#transmitSameDimension(Packet, double)
|
||||||
* @see IPacketNetwork#transmitInterdimensional(Packet)
|
* @see PacketNetwork#transmitInterdimensional(Packet)
|
||||||
* @see IPacketReceiver#receiveDifferentDimension(Packet)
|
* @see PacketReceiver#receiveDifferentDimension(Packet)
|
||||||
* @see IPacketReceiver#receiveSameDimension(Packet, double)
|
* @see PacketReceiver#receiveSameDimension(Packet, double)
|
||||||
*/
|
*/
|
||||||
public record Packet(
|
public record Packet(
|
||||||
int channel,
|
int channel,
|
||||||
int replyChannel,
|
int replyChannel,
|
||||||
Object payload,
|
Object payload,
|
||||||
IPacketSender sender
|
PacketSender sender
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
@ -10,22 +10,22 @@ package dan200.computercraft.api.network;
|
|||||||
* A packet network represents a collection of devices which can send and receive packets.
|
* A packet network represents a collection of devices which can send and receive packets.
|
||||||
*
|
*
|
||||||
* @see Packet
|
* @see Packet
|
||||||
* @see IPacketReceiver
|
* @see PacketReceiver
|
||||||
*/
|
*/
|
||||||
public interface IPacketNetwork {
|
public interface PacketNetwork {
|
||||||
/**
|
/**
|
||||||
* Add a receiver to the network.
|
* Add a receiver to the network.
|
||||||
*
|
*
|
||||||
* @param receiver The receiver to register to the network.
|
* @param receiver The receiver to register to the network.
|
||||||
*/
|
*/
|
||||||
void addReceiver(IPacketReceiver receiver);
|
void addReceiver(PacketReceiver receiver);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a receiver from the network.
|
* Remove a receiver from the network.
|
||||||
*
|
*
|
||||||
* @param receiver The device to remove from the network.
|
* @param receiver The device to remove from the network.
|
||||||
*/
|
*/
|
||||||
void removeReceiver(IPacketReceiver receiver);
|
void removeReceiver(PacketReceiver receiver);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether this network is wireless.
|
* Determine whether this network is wireless.
|
||||||
@ -41,7 +41,7 @@ public interface IPacketNetwork {
|
|||||||
* @param packet The packet to send.
|
* @param packet The packet to send.
|
||||||
* @param range The maximum distance this packet will be sent.
|
* @param range The maximum distance this packet will be sent.
|
||||||
* @see #transmitInterdimensional(Packet)
|
* @see #transmitInterdimensional(Packet)
|
||||||
* @see IPacketReceiver#receiveSameDimension(Packet, double)
|
* @see PacketReceiver#receiveSameDimension(Packet, double)
|
||||||
*/
|
*/
|
||||||
void transmitSameDimension(Packet packet, double range);
|
void transmitSameDimension(Packet packet, double range);
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public interface IPacketNetwork {
|
|||||||
*
|
*
|
||||||
* @param packet The packet to send.
|
* @param packet The packet to send.
|
||||||
* @see #transmitSameDimension(Packet, double)
|
* @see #transmitSameDimension(Packet, double)
|
||||||
* @see IPacketReceiver#receiveDifferentDimension(Packet)
|
* @see PacketReceiver#receiveDifferentDimension(Packet)
|
||||||
*/
|
*/
|
||||||
void transmitInterdimensional(Packet packet);
|
void transmitInterdimensional(Packet packet);
|
||||||
}
|
}
|
@ -10,9 +10,9 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object on an {@link IPacketNetwork}, capable of receiving packets.
|
* An object on an {@link PacketNetwork}, capable of receiving packets.
|
||||||
*/
|
*/
|
||||||
public interface IPacketReceiver {
|
public interface PacketReceiver {
|
||||||
/**
|
/**
|
||||||
* Get the world in which this packet receiver exists.
|
* Get the world in which this packet receiver exists.
|
||||||
*
|
*
|
||||||
@ -37,7 +37,7 @@ public interface IPacketReceiver {
|
|||||||
* @return The maximum distance this device can send and receive messages.
|
* @return The maximum distance this device can send and receive messages.
|
||||||
* @see #isInterdimensional()
|
* @see #isInterdimensional()
|
||||||
* @see #receiveSameDimension(Packet packet, double)
|
* @see #receiveSameDimension(Packet packet, double)
|
||||||
* @see IPacketNetwork#transmitInterdimensional(Packet)
|
* @see PacketNetwork#transmitInterdimensional(Packet)
|
||||||
*/
|
*/
|
||||||
double getRange();
|
double getRange();
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public interface IPacketReceiver {
|
|||||||
* @return Whether this receiver receives packets from other dimensions.
|
* @return Whether this receiver receives packets from other dimensions.
|
||||||
* @see #getRange()
|
* @see #getRange()
|
||||||
* @see #receiveDifferentDimension(Packet)
|
* @see #receiveDifferentDimension(Packet)
|
||||||
* @see IPacketNetwork#transmitInterdimensional(Packet)
|
* @see PacketNetwork#transmitInterdimensional(Packet)
|
||||||
*/
|
*/
|
||||||
boolean isInterdimensional();
|
boolean isInterdimensional();
|
||||||
|
|
||||||
@ -61,8 +61,8 @@ public interface IPacketReceiver {
|
|||||||
* @param distance The distance this packet has travelled from the source.
|
* @param distance The distance this packet has travelled from the source.
|
||||||
* @see Packet
|
* @see Packet
|
||||||
* @see #getRange()
|
* @see #getRange()
|
||||||
* @see IPacketNetwork#transmitSameDimension(Packet, double)
|
* @see PacketNetwork#transmitSameDimension(Packet, double)
|
||||||
* @see IPacketNetwork#transmitInterdimensional(Packet)
|
* @see PacketNetwork#transmitInterdimensional(Packet)
|
||||||
*/
|
*/
|
||||||
void receiveSameDimension(Packet packet, double distance);
|
void receiveSameDimension(Packet packet, double distance);
|
||||||
|
|
||||||
@ -72,8 +72,8 @@ public interface IPacketReceiver {
|
|||||||
* @param packet The packet to receive. Generally you should check that you are listening on the given channel and,
|
* @param packet The packet to receive. Generally you should check that you are listening on the given channel and,
|
||||||
* if so, queue the appropriate modem event.
|
* if so, queue the appropriate modem event.
|
||||||
* @see Packet
|
* @see Packet
|
||||||
* @see IPacketNetwork#transmitInterdimensional(Packet)
|
* @see PacketNetwork#transmitInterdimensional(Packet)
|
||||||
* @see IPacketNetwork#transmitSameDimension(Packet, double)
|
* @see PacketNetwork#transmitSameDimension(Packet, double)
|
||||||
* @see #isInterdimensional()
|
* @see #isInterdimensional()
|
||||||
*/
|
*/
|
||||||
void receiveDifferentDimension(Packet packet);
|
void receiveDifferentDimension(Packet packet);
|
@ -10,9 +10,9 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object on a {@link IPacketNetwork}, capable of sending packets.
|
* An object on a {@link PacketNetwork}, capable of sending packets.
|
||||||
*/
|
*/
|
||||||
public interface IPacketSender {
|
public interface PacketSender {
|
||||||
/**
|
/**
|
||||||
* Get the world in which this packet sender exists.
|
* Get the world in which this packet sender exists.
|
||||||
*
|
*
|
@ -11,21 +11,21 @@ import dan200.computercraft.api.ComputerCraftAPI;
|
|||||||
/**
|
/**
|
||||||
* An object which may be part of a wired network.
|
* An object which may be part of a wired network.
|
||||||
* <p>
|
* <p>
|
||||||
* Elements should construct a node using {@link ComputerCraftAPI#createWiredNodeForElement(IWiredElement)}. This acts
|
* Elements should construct a node using {@link ComputerCraftAPI#createWiredNodeForElement(WiredElement)}. This acts
|
||||||
* as a proxy for all network objects. Whilst the node may change networks, an element's node should remain constant
|
* as a proxy for all network objects. Whilst the node may change networks, an element's node should remain constant
|
||||||
* for its lifespan.
|
* for its lifespan.
|
||||||
* <p>
|
* <p>
|
||||||
* Elements are generally tied to a block or tile entity in world. In such as case, one should provide the
|
* Elements are generally tied to a block or tile entity in world. In such as case, one should provide the
|
||||||
* {@link IWiredElement} capability for the appropriate sides.
|
* {@link WiredElement} capability for the appropriate sides.
|
||||||
*/
|
*/
|
||||||
public interface IWiredElement extends IWiredSender {
|
public interface WiredElement extends WiredSender {
|
||||||
/**
|
/**
|
||||||
* Called when objects on the network change. This may occur when network nodes are added or removed, or when
|
* Called when objects on the network change. This may occur when network nodes are added or removed, or when
|
||||||
* peripherals change.
|
* peripherals change.
|
||||||
*
|
*
|
||||||
* @param change The change which occurred.
|
* @param change The change which occurred.
|
||||||
* @see IWiredNetworkChange
|
* @see WiredNetworkChange
|
||||||
*/
|
*/
|
||||||
default void networkChanged(IWiredNetworkChange change) {
|
default void networkChanged(WiredNetworkChange change) {
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,20 +10,20 @@ import dan200.computercraft.api.peripheral.IPeripheral;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wired network is composed of one of more {@link IWiredNode}s, a set of connections between them, and a series
|
* A wired network is composed of one of more {@link WiredNode}s, a set of connections between them, and a series
|
||||||
* of peripherals.
|
* of peripherals.
|
||||||
* <p>
|
* <p>
|
||||||
* Networks from a connected graph. This means there is some path between all nodes on the network. Further more, if
|
* Networks from a connected graph. This means there is some path between all nodes on the network. Further more, if
|
||||||
* there is some path between two nodes then they must be on the same network. {@link IWiredNetwork} will automatically
|
* there is some path between two nodes then they must be on the same network. {@link WiredNetwork} will automatically
|
||||||
* handle the merging and splitting of networks (and thus changing of available nodes and peripherals) as connections
|
* handle the merging and splitting of networks (and thus changing of available nodes and peripherals) as connections
|
||||||
* change.
|
* change.
|
||||||
* <p>
|
* <p>
|
||||||
* This does mean one can not rely on the network remaining consistent between subsequent operations. Consequently,
|
* This does mean one can not rely on the network remaining consistent between subsequent operations. Consequently,
|
||||||
* it is generally preferred to use the methods provided by {@link IWiredNode}.
|
* it is generally preferred to use the methods provided by {@link WiredNode}.
|
||||||
*
|
*
|
||||||
* @see IWiredNode#getNetwork()
|
* @see WiredNode#getNetwork()
|
||||||
*/
|
*/
|
||||||
public interface IWiredNetwork {
|
public interface WiredNetwork {
|
||||||
/**
|
/**
|
||||||
* Create a connection between two nodes.
|
* Create a connection between two nodes.
|
||||||
* <p>
|
* <p>
|
||||||
@ -34,10 +34,10 @@ public interface IWiredNetwork {
|
|||||||
* @return {@code true} if a connection was created or {@code false} if the connection already exists.
|
* @return {@code true} if a connection was created or {@code false} if the connection already exists.
|
||||||
* @throws IllegalStateException If neither node is on the network.
|
* @throws IllegalStateException If neither node is on the network.
|
||||||
* @throws IllegalArgumentException If {@code left} and {@code right} are equal.
|
* @throws IllegalArgumentException If {@code left} and {@code right} are equal.
|
||||||
* @see IWiredNode#connectTo(IWiredNode)
|
* @see WiredNode#connectTo(WiredNode)
|
||||||
* @see IWiredNetwork#connect(IWiredNode, IWiredNode)
|
* @see WiredNetwork#connect(WiredNode, WiredNode)
|
||||||
*/
|
*/
|
||||||
boolean connect(IWiredNode left, IWiredNode right);
|
boolean connect(WiredNode left, WiredNode right);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a connection between this node and another.
|
* Destroy a connection between this node and another.
|
||||||
@ -49,10 +49,10 @@ public interface IWiredNetwork {
|
|||||||
* @return {@code true} if a connection was destroyed or {@code false} if no connection exists.
|
* @return {@code true} if a connection was destroyed or {@code false} if no connection exists.
|
||||||
* @throws IllegalArgumentException If either node is not on the network.
|
* @throws IllegalArgumentException If either node is not on the network.
|
||||||
* @throws IllegalArgumentException If {@code left} and {@code right} are equal.
|
* @throws IllegalArgumentException If {@code left} and {@code right} are equal.
|
||||||
* @see IWiredNode#disconnectFrom(IWiredNode)
|
* @see WiredNode#disconnectFrom(WiredNode)
|
||||||
* @see IWiredNetwork#connect(IWiredNode, IWiredNode)
|
* @see WiredNetwork#connect(WiredNode, WiredNode)
|
||||||
*/
|
*/
|
||||||
boolean disconnect(IWiredNode left, IWiredNode right);
|
boolean disconnect(WiredNode left, WiredNode right);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sever all connections this node has, removing it from this network.
|
* Sever all connections this node has, removing it from this network.
|
||||||
@ -64,9 +64,9 @@ public interface IWiredNetwork {
|
|||||||
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the
|
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the
|
||||||
* only element.
|
* only element.
|
||||||
* @throws IllegalArgumentException If the node is not in the network.
|
* @throws IllegalArgumentException If the node is not in the network.
|
||||||
* @see IWiredNode#remove()
|
* @see WiredNode#remove()
|
||||||
*/
|
*/
|
||||||
boolean remove(IWiredNode node);
|
boolean remove(WiredNode node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the peripherals a node provides.
|
* Update the peripherals a node provides.
|
||||||
@ -77,7 +77,7 @@ public interface IWiredNetwork {
|
|||||||
* @param node The node to attach peripherals for.
|
* @param node The node to attach peripherals for.
|
||||||
* @param peripherals The new peripherals for this node.
|
* @param peripherals The new peripherals for this node.
|
||||||
* @throws IllegalArgumentException If the node is not in the network.
|
* @throws IllegalArgumentException If the node is not in the network.
|
||||||
* @see IWiredNode#updatePeripherals(Map)
|
* @see WiredNode#updatePeripherals(Map)
|
||||||
*/
|
*/
|
||||||
void updatePeripherals(IWiredNode node, Map<String, IPeripheral> peripherals);
|
void updatePeripherals(WiredNode node, Map<String, IPeripheral> peripherals);
|
||||||
}
|
}
|
@ -12,9 +12,9 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Represents a change to the objects on a wired network.
|
* Represents a change to the objects on a wired network.
|
||||||
*
|
*
|
||||||
* @see IWiredElement#networkChanged(IWiredNetworkChange)
|
* @see WiredElement#networkChanged(WiredNetworkChange)
|
||||||
*/
|
*/
|
||||||
public interface IWiredNetworkChange {
|
public interface WiredNetworkChange {
|
||||||
/**
|
/**
|
||||||
* A set of peripherals which have been removed. Note that there may be entries with the same name
|
* A set of peripherals which have been removed. Note that there may be entries with the same name
|
||||||
* in the added and removed set, but with a different peripheral.
|
* in the added and removed set, but with a different peripheral.
|
@ -5,13 +5,13 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.network.wired;
|
package dan200.computercraft.api.network.wired;
|
||||||
|
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
import dan200.computercraft.api.network.PacketNetwork;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wired nodes act as a layer between {@link IWiredElement}s and {@link IWiredNetwork}s.
|
* Wired nodes act as a layer between {@link WiredElement}s and {@link WiredNetwork}s.
|
||||||
* <p>
|
* <p>
|
||||||
* Firstly, a node acts as a packet network, capable of sending and receiving modem messages to connected nodes. These
|
* Firstly, a node acts as a packet network, capable of sending and receiving modem messages to connected nodes. These
|
||||||
* methods may be safely used on any thread.
|
* methods may be safely used on any thread.
|
||||||
@ -23,13 +23,13 @@ import java.util.Map;
|
|||||||
* Wired nodes also provide several convenience methods for interacting with a wired network. These should only ever
|
* Wired nodes also provide several convenience methods for interacting with a wired network. These should only ever
|
||||||
* be used on the main server thread.
|
* be used on the main server thread.
|
||||||
*/
|
*/
|
||||||
public interface IWiredNode extends IPacketNetwork {
|
public interface WiredNode extends PacketNetwork {
|
||||||
/**
|
/**
|
||||||
* The associated element for this network node.
|
* The associated element for this network node.
|
||||||
*
|
*
|
||||||
* @return This node's element.
|
* @return This node's element.
|
||||||
*/
|
*/
|
||||||
IWiredElement getElement();
|
WiredElement getElement();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The network this node is currently connected to. Note that this may change
|
* The network this node is currently connected to. Note that this may change
|
||||||
@ -39,7 +39,7 @@ public interface IWiredNode extends IPacketNetwork {
|
|||||||
*
|
*
|
||||||
* @return This node's network.
|
* @return This node's network.
|
||||||
*/
|
*/
|
||||||
IWiredNetwork getNetwork();
|
WiredNetwork getNetwork();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a connection from this node to another.
|
* Create a connection from this node to another.
|
||||||
@ -48,10 +48,10 @@ public interface IWiredNode extends IPacketNetwork {
|
|||||||
*
|
*
|
||||||
* @param node The other node to connect to.
|
* @param node The other node to connect to.
|
||||||
* @return {@code true} if a connection was created or {@code false} if the connection already exists.
|
* @return {@code true} if a connection was created or {@code false} if the connection already exists.
|
||||||
* @see IWiredNetwork#connect(IWiredNode, IWiredNode)
|
* @see WiredNetwork#connect(WiredNode, WiredNode)
|
||||||
* @see IWiredNode#disconnectFrom(IWiredNode)
|
* @see WiredNode#disconnectFrom(WiredNode)
|
||||||
*/
|
*/
|
||||||
default boolean connectTo(IWiredNode node) {
|
default boolean connectTo(WiredNode node) {
|
||||||
return getNetwork().connect(this, node);
|
return getNetwork().connect(this, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +63,10 @@ public interface IWiredNode extends IPacketNetwork {
|
|||||||
* @param node The other node to disconnect from.
|
* @param node The other node to disconnect from.
|
||||||
* @return {@code true} if a connection was destroyed or {@code false} if no connection exists.
|
* @return {@code true} if a connection was destroyed or {@code false} if no connection exists.
|
||||||
* @throws IllegalArgumentException If {@code node} is not on the same network.
|
* @throws IllegalArgumentException If {@code node} is not on the same network.
|
||||||
* @see IWiredNetwork#disconnect(IWiredNode, IWiredNode)
|
* @see WiredNetwork#disconnect(WiredNode, WiredNode)
|
||||||
* @see IWiredNode#connectTo(IWiredNode)
|
* @see WiredNode#connectTo(WiredNode)
|
||||||
*/
|
*/
|
||||||
default boolean disconnectFrom(IWiredNode node) {
|
default boolean disconnectFrom(WiredNode node) {
|
||||||
return getNetwork().disconnect(this, node);
|
return getNetwork().disconnect(this, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ public interface IWiredNode extends IPacketNetwork {
|
|||||||
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the
|
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the
|
||||||
* only element.
|
* only element.
|
||||||
* @throws IllegalArgumentException If the node is not in the network.
|
* @throws IllegalArgumentException If the node is not in the network.
|
||||||
* @see IWiredNetwork#remove(IWiredNode)
|
* @see WiredNetwork#remove(WiredNode)
|
||||||
*/
|
*/
|
||||||
default boolean remove() {
|
default boolean remove() {
|
||||||
return getNetwork().remove(this);
|
return getNetwork().remove(this);
|
||||||
@ -92,7 +92,7 @@ public interface IWiredNode extends IPacketNetwork {
|
|||||||
* that your network element owns.
|
* that your network element owns.
|
||||||
*
|
*
|
||||||
* @param peripherals The new peripherals for this node.
|
* @param peripherals The new peripherals for this node.
|
||||||
* @see IWiredNetwork#updatePeripherals(IWiredNode, Map)
|
* @see WiredNetwork#updatePeripherals(WiredNode, Map)
|
||||||
*/
|
*/
|
||||||
default void updatePeripherals(Map<String, IPeripheral> peripherals) {
|
default void updatePeripherals(Map<String, IPeripheral> peripherals) {
|
||||||
getNetwork().updatePeripherals(this, peripherals);
|
getNetwork().updatePeripherals(this, peripherals);
|
@ -5,16 +5,16 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.network.wired;
|
package dan200.computercraft.api.network.wired;
|
||||||
|
|
||||||
import dan200.computercraft.api.network.IPacketSender;
|
import dan200.computercraft.api.network.PacketSender;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object on a {@link IWiredNetwork} capable of sending packets.
|
* An object on a {@link WiredNetwork} capable of sending packets.
|
||||||
* <p>
|
* <p>
|
||||||
* Unlike a regular {@link IPacketSender}, this must be associated with the node you are attempting to
|
* Unlike a regular {@link PacketSender}, this must be associated with the node you are attempting to
|
||||||
* to send the packet from.
|
* to send the packet from.
|
||||||
*/
|
*/
|
||||||
public interface IWiredSender extends IPacketSender {
|
public interface WiredSender extends PacketSender {
|
||||||
/**
|
/**
|
||||||
* The node in the network representing this object.
|
* The node in the network representing this object.
|
||||||
* <p>
|
* <p>
|
||||||
@ -23,5 +23,5 @@ public interface IWiredSender extends IPacketSender {
|
|||||||
*
|
*
|
||||||
* @return The node for this element.
|
* @return The node for this element.
|
||||||
*/
|
*/
|
||||||
IWiredNode getNode();
|
WiredNode getNode();
|
||||||
}
|
}
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.pocket;
|
package dan200.computercraft.api.pocket;
|
||||||
|
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractPocketUpgrade(ResourceLocation id, ItemStack stack) {
|
protected AbstractPocketUpgrade(ResourceLocation id, ItemStack stack) {
|
||||||
this(id, IUpgradeBase.getDefaultAdjective(id), stack);
|
this(id, UpgradeBase.getDefaultAdjective(id), stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.api.pocket;
|
package dan200.computercraft.api.pocket;
|
||||||
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -23,7 +23,7 @@ import javax.annotation.Nullable;
|
|||||||
*
|
*
|
||||||
* @see PocketUpgradeSerialiser For how to register a pocket computer upgrade.
|
* @see PocketUpgradeSerialiser For how to register a pocket computer upgrade.
|
||||||
*/
|
*/
|
||||||
public interface IPocketUpgrade extends IUpgradeBase {
|
public interface IPocketUpgrade extends UpgradeBase {
|
||||||
/**
|
/**
|
||||||
* Creates a peripheral for the pocket computer.
|
* Creates a peripheral for the pocket computer.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.api.pocket;
|
package dan200.computercraft.api.pocket;
|
||||||
|
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||||
import dan200.computercraft.impl.upgrades.SerialiserWithCraftingItem;
|
import dan200.computercraft.impl.upgrades.SerialiserWithCraftingItem;
|
||||||
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
|
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
|
||||||
@ -15,8 +15,6 @@ import net.minecraft.resources.ResourceKey;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||||
import net.minecraftforge.registries.IForgeRegistry;
|
|
||||||
import net.minecraftforge.registries.RegistryManager;
|
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -37,18 +35,6 @@ public interface PocketUpgradeSerialiser<T extends IPocketUpgrade> extends Upgra
|
|||||||
*/
|
*/
|
||||||
ResourceKey<Registry<PocketUpgradeSerialiser<?>>> REGISTRY_ID = ResourceKey.createRegistryKey(new ResourceLocation(ComputerCraftAPI.MOD_ID, "pocket_upgrade_serialiser"));
|
ResourceKey<Registry<PocketUpgradeSerialiser<?>>> REGISTRY_ID = ResourceKey.createRegistryKey(new ResourceLocation(ComputerCraftAPI.MOD_ID, "pocket_upgrade_serialiser"));
|
||||||
|
|
||||||
/**
|
|
||||||
* The associated registry.
|
|
||||||
*
|
|
||||||
* @return The registry for pocket upgrade serialisers.
|
|
||||||
* @see #REGISTRY_ID
|
|
||||||
* @deprecated Use {@link #REGISTRY_ID} directly.
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
static IForgeRegistry<PocketUpgradeSerialiser<?>> registry() {
|
|
||||||
return RegistryManager.ACTIVE.getRegistry(REGISTRY_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an upgrade serialiser for a simple upgrade. This is similar to a {@link SimpleRecipeSerializer}, but for
|
* Create an upgrade serialiser for a simple upgrade. This is similar to a {@link SimpleRecipeSerializer}, but for
|
||||||
* upgrades.
|
* upgrades.
|
||||||
@ -73,7 +59,7 @@ public interface PocketUpgradeSerialiser<T extends IPocketUpgrade> extends Upgra
|
|||||||
* Create an upgrade serialiser for a simple upgrade whose crafting item can be specified.
|
* Create an upgrade serialiser for a simple upgrade whose crafting item can be specified.
|
||||||
*
|
*
|
||||||
* @param factory Generate a new upgrade with a specific ID and crafting item. The returned upgrade's
|
* @param factory Generate a new upgrade with a specific ID and crafting item. The returned upgrade's
|
||||||
* {@link IUpgradeBase#getCraftingItem()} <strong>MUST</strong> equal the provided item.
|
* {@link UpgradeBase#getCraftingItem()} <strong>MUST</strong> equal the provided item.
|
||||||
* @param <T> The type of the generated upgrade.
|
* @param <T> The type of the generated upgrade.
|
||||||
* @return The serialiser for this upgrade.
|
* @return The serialiser for this upgrade.
|
||||||
* @see #simple(Function) For upgrades whose crafting stack should not vary.
|
* @see #simple(Function) For upgrades whose crafting stack should not vary.
|
||||||
|
@ -5,18 +5,18 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.redstone;
|
package dan200.computercraft.api.redstone;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface is used to provide bundled redstone output for blocks.
|
* This interface is used to provide bundled redstone output for blocks.
|
||||||
*
|
*
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
|
* @see ComputerCraftAPI#registerBundledRedstoneProvider(BundledRedstoneProvider)
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface IBundledRedstoneProvider {
|
public interface BundledRedstoneProvider {
|
||||||
/**
|
/**
|
||||||
* Produce an bundled redstone output from a block location.
|
* Produce an bundled redstone output from a block location.
|
||||||
*
|
*
|
||||||
@ -25,7 +25,7 @@ public interface IBundledRedstoneProvider {
|
|||||||
* @param side The side to extract the bundled redstone output from.
|
* @param side The side to extract the bundled redstone output from.
|
||||||
* @return A number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to
|
* @return A number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to
|
||||||
* handle this block.
|
* handle this block.
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
|
* @see ComputerCraftAPI#registerBundledRedstoneProvider(BundledRedstoneProvider)
|
||||||
*/
|
*/
|
||||||
int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side);
|
int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side);
|
||||||
}
|
}
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.turtle;
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade(ResourceLocation id, TurtleUpgradeType type, ItemStack stack) {
|
protected AbstractTurtleUpgrade(ResourceLocation id, TurtleUpgradeType type, ItemStack stack) {
|
||||||
this(id, type, IUpgradeBase.getDefaultAdjective(id), stack);
|
this(id, type, UpgradeBase.getDefaultAdjective(id), stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,7 +15,6 @@ import net.minecraft.nbt.CompoundTag;
|
|||||||
import net.minecraft.world.Container;
|
import net.minecraft.world.Container;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ public interface ITurtleAccess {
|
|||||||
/**
|
/**
|
||||||
* Determine if this turtle has been removed.
|
* Determine if this turtle has been removed.
|
||||||
* <p>
|
* <p>
|
||||||
* It's possible for a turtle to be removed while a {@link ITurtleCommand} is executed, for instance if interacting
|
* It's possible for a turtle to be removed while a {@link TurtleCommand} is executed, for instance if interacting
|
||||||
* with a block causes the turtle to be blown up. It's recommended you check the turtle is still present before
|
* with a block causes the turtle to be blown up. It's recommended you check the turtle is still present before
|
||||||
* trying to interact with it again.
|
* trying to interact with it again.
|
||||||
* <p>
|
* <p>
|
||||||
@ -156,23 +155,9 @@ public interface ITurtleAccess {
|
|||||||
* Note: this inventory should only be accessed and modified on the server thread.
|
* Note: this inventory should only be accessed and modified on the server thread.
|
||||||
*
|
*
|
||||||
* @return This turtle's inventory
|
* @return This turtle's inventory
|
||||||
* @see #getItemHandler()
|
|
||||||
*/
|
*/
|
||||||
Container getInventory();
|
Container getInventory();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the inventory of this turtle as an {@link IItemHandlerModifiable}.
|
|
||||||
* <p>
|
|
||||||
* Note: this inventory should only be accessed and modified on the server thread.
|
|
||||||
*
|
|
||||||
* @return This turtle's inventory
|
|
||||||
* @see #getInventory()
|
|
||||||
* @see IItemHandlerModifiable
|
|
||||||
* @deprecated Use {@link #getInventory()} directly.
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
IItemHandlerModifiable getItemHandler();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether this turtle will require fuel when performing actions.
|
* Determine whether this turtle will require fuel when performing actions.
|
||||||
*
|
*
|
||||||
@ -239,10 +224,10 @@ public interface ITurtleAccess {
|
|||||||
* @return The objects the command returned when executed. you should probably return these to the player
|
* @return The objects the command returned when executed. you should probably return these to the player
|
||||||
* unchanged if called from a peripheral method.
|
* unchanged if called from a peripheral method.
|
||||||
* @throws UnsupportedOperationException When attempting to execute a command on the client side.
|
* @throws UnsupportedOperationException When attempting to execute a command on the client side.
|
||||||
* @see ITurtleCommand
|
* @see TurtleCommand
|
||||||
* @see MethodResult#pullEvent(String, ILuaCallback)
|
* @see MethodResult#pullEvent(String, ILuaCallback)
|
||||||
*/
|
*/
|
||||||
MethodResult executeCommand(ITurtleCommand command);
|
MethodResult executeCommand(TurtleCommand command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start playing a specific animation. This will prevent other turtle commands from executing until
|
* Start playing a specific animation. This will prevent other turtle commands from executing until
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.api.turtle;
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -24,7 +24,7 @@ import javax.annotation.Nullable;
|
|||||||
*
|
*
|
||||||
* @see TurtleUpgradeSerialiser For how to register a turtle upgrade.
|
* @see TurtleUpgradeSerialiser For how to register a turtle upgrade.
|
||||||
*/
|
*/
|
||||||
public interface ITurtleUpgrade extends IUpgradeBase {
|
public interface ITurtleUpgrade extends UpgradeBase {
|
||||||
/**
|
/**
|
||||||
* Return whether this turtle adds a tool or a peripheral to the turtle.
|
* Return whether this turtle adds a tool or a peripheral to the turtle.
|
||||||
*
|
*
|
||||||
|
@ -7,12 +7,12 @@ package dan200.computercraft.api.turtle;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for objects executing custom turtle commands, used with {@link ITurtleAccess#executeCommand(ITurtleCommand)}.
|
* An interface for objects executing custom turtle commands, used with {@link ITurtleAccess#executeCommand(TurtleCommand)}.
|
||||||
*
|
*
|
||||||
* @see ITurtleAccess#executeCommand(ITurtleCommand)
|
* @see ITurtleAccess#executeCommand(TurtleCommand)
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ITurtleCommand {
|
public interface TurtleCommand {
|
||||||
/**
|
/**
|
||||||
* Will be called by the turtle on the main thread when it is time to execute the custom command.
|
* Will be called by the turtle on the main thread when it is time to execute the custom command.
|
||||||
* <p>
|
* <p>
|
||||||
@ -21,7 +21,7 @@ public interface ITurtleCommand {
|
|||||||
*
|
*
|
||||||
* @param turtle Access to the turtle for whom the command was issued.
|
* @param turtle Access to the turtle for whom the command was issued.
|
||||||
* @return A result, indicating whether this action succeeded or not.
|
* @return A result, indicating whether this action succeeded or not.
|
||||||
* @see ITurtleAccess#executeCommand(ITurtleCommand)
|
* @see ITurtleAccess#executeCommand(TurtleCommand)
|
||||||
* @see TurtleCommandResult#success()
|
* @see TurtleCommandResult#success()
|
||||||
* @see TurtleCommandResult#failure(String)
|
* @see TurtleCommandResult#failure(String)
|
||||||
* @see TurtleCommandResult
|
* @see TurtleCommandResult
|
@ -12,7 +12,7 @@ import javax.annotation.Nullable;
|
|||||||
/**
|
/**
|
||||||
* Used to indicate the result of executing a turtle command.
|
* Used to indicate the result of executing a turtle command.
|
||||||
*
|
*
|
||||||
* @see ITurtleCommand#execute(ITurtleAccess)
|
* @see TurtleCommand#execute(ITurtleAccess)
|
||||||
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
|
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
|
||||||
*/
|
*/
|
||||||
public final class TurtleCommandResult {
|
public final class TurtleCommandResult {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.api.turtle;
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||||
import dan200.computercraft.impl.upgrades.SerialiserWithCraftingItem;
|
import dan200.computercraft.impl.upgrades.SerialiserWithCraftingItem;
|
||||||
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
|
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
|
||||||
@ -16,8 +16,6 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||||
import net.minecraftforge.registries.IForgeRegistry;
|
|
||||||
import net.minecraftforge.registries.RegistryManager;
|
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -72,18 +70,6 @@ public interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade> extends Upgra
|
|||||||
*/
|
*/
|
||||||
ResourceKey<Registry<TurtleUpgradeSerialiser<?>>> REGISTRY_ID = ResourceKey.createRegistryKey(new ResourceLocation(ComputerCraftAPI.MOD_ID, "turtle_upgrade_serialiser"));
|
ResourceKey<Registry<TurtleUpgradeSerialiser<?>>> REGISTRY_ID = ResourceKey.createRegistryKey(new ResourceLocation(ComputerCraftAPI.MOD_ID, "turtle_upgrade_serialiser"));
|
||||||
|
|
||||||
/**
|
|
||||||
* The associated registry.
|
|
||||||
*
|
|
||||||
* @return The registry for pocket upgrade serialisers.
|
|
||||||
* @see #REGISTRY_ID
|
|
||||||
* @deprecated Use {@link #REGISTRY_ID} directly.
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
static IForgeRegistry<TurtleUpgradeSerialiser<?>> registry() {
|
|
||||||
return RegistryManager.ACTIVE.getRegistry(REGISTRY_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an upgrade serialiser for a simple upgrade. This is similar to a {@link SimpleRecipeSerializer}, but for
|
* Create an upgrade serialiser for a simple upgrade. This is similar to a {@link SimpleRecipeSerializer}, but for
|
||||||
* upgrades.
|
* upgrades.
|
||||||
@ -108,7 +94,7 @@ public interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade> extends Upgra
|
|||||||
* Create an upgrade serialiser for a simple upgrade whose crafting item can be specified.
|
* Create an upgrade serialiser for a simple upgrade whose crafting item can be specified.
|
||||||
*
|
*
|
||||||
* @param factory Generate a new upgrade with a specific ID and crafting item. The returned upgrade's
|
* @param factory Generate a new upgrade with a specific ID and crafting item. The returned upgrade's
|
||||||
* {@link IUpgradeBase#getCraftingItem()} <strong>MUST</strong> equal the provided item.
|
* {@link UpgradeBase#getCraftingItem()} <strong>MUST</strong> equal the provided item.
|
||||||
* @param <T> The type of the generated upgrade.
|
* @param <T> The type of the generated upgrade.
|
||||||
* @return The serialiser for this upgrade.
|
* @return The serialiser for this upgrade.
|
||||||
* @see #simple(Function) For upgrades whose crafting stack should not vary.
|
* @see #simple(Function) For upgrades whose crafting stack should not vary.
|
||||||
|
@ -17,7 +17,7 @@ import java.util.Objects;
|
|||||||
/**
|
/**
|
||||||
* Common functionality between {@link ITurtleUpgrade} and {@link IPocketUpgrade}.
|
* Common functionality between {@link ITurtleUpgrade} and {@link IPocketUpgrade}.
|
||||||
*/
|
*/
|
||||||
public interface IUpgradeBase {
|
public interface UpgradeBase {
|
||||||
/**
|
/**
|
||||||
* Gets a unique identifier representing this type of turtle upgrade. eg: "computercraft:wireless_modem"
|
* Gets a unique identifier representing this type of turtle upgrade. eg: "computercraft:wireless_modem"
|
||||||
* or "my_mod:my_upgrade".
|
* or "my_mod:my_upgrade".
|
@ -37,7 +37,7 @@ import java.util.function.Function;
|
|||||||
* @param <T> The base class of upgrades.
|
* @param <T> The base class of upgrades.
|
||||||
* @param <R> The upgrade serialiser to register for.
|
* @param <R> The upgrade serialiser to register for.
|
||||||
*/
|
*/
|
||||||
public abstract class UpgradeDataProvider<T extends IUpgradeBase, R extends UpgradeSerialiser<? extends T>> implements DataProvider {
|
public abstract class UpgradeDataProvider<T extends UpgradeBase, R extends UpgradeSerialiser<? extends T>> implements DataProvider {
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
private final DataGenerator generator;
|
private final DataGenerator generator;
|
||||||
|
@ -22,13 +22,13 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
* @see TurtleUpgradeSerialiser
|
* @see TurtleUpgradeSerialiser
|
||||||
* @see PocketUpgradeSerialiser
|
* @see PocketUpgradeSerialiser
|
||||||
*/
|
*/
|
||||||
public interface UpgradeSerialiser<T extends IUpgradeBase> {
|
public interface UpgradeSerialiser<T extends UpgradeBase> {
|
||||||
/**
|
/**
|
||||||
* Read this upgrade from a JSON file in a datapack.
|
* Read this upgrade from a JSON file in a datapack.
|
||||||
*
|
*
|
||||||
* @param id The ID of this upgrade.
|
* @param id The ID of this upgrade.
|
||||||
* @param object The JSON object to load this upgrade from.
|
* @param object The JSON object to load this upgrade from.
|
||||||
* @return The constructed upgrade, with a {@link IUpgradeBase#getUpgradeID()} equal to {@code id}.
|
* @return The constructed upgrade, with a {@link UpgradeBase#getUpgradeID()} equal to {@code id}.
|
||||||
* @see net.minecraft.util.GsonHelper For additional JSON helper methods.
|
* @see net.minecraft.util.GsonHelper For additional JSON helper methods.
|
||||||
*/
|
*/
|
||||||
T fromJson(ResourceLocation id, JsonObject object);
|
T fromJson(ResourceLocation id, JsonObject object);
|
||||||
@ -38,7 +38,7 @@ public interface UpgradeSerialiser<T extends IUpgradeBase> {
|
|||||||
*
|
*
|
||||||
* @param id The ID of this upgrade.
|
* @param id The ID of this upgrade.
|
||||||
* @param buffer The buffer object to read this upgrade from.
|
* @param buffer The buffer object to read this upgrade from.
|
||||||
* @return The constructed upgrade, with a {@link IUpgradeBase#getUpgradeID()} equal to {@code id}.
|
* @return The constructed upgrade, with a {@link UpgradeBase#getUpgradeID()} equal to {@code id}.
|
||||||
*/
|
*/
|
||||||
T fromNetwork(ResourceLocation id, FriendlyByteBuf buffer);
|
T fromNetwork(ResourceLocation id, FriendlyByteBuf buffer);
|
||||||
|
|
||||||
|
@ -8,25 +8,21 @@ package dan200.computercraft.impl;
|
|||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.detail.BlockReference;
|
import dan200.computercraft.api.detail.BlockReference;
|
||||||
import dan200.computercraft.api.detail.DetailRegistry;
|
import dan200.computercraft.api.detail.DetailRegistry;
|
||||||
import dan200.computercraft.api.detail.IDetailProvider;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.WritableMount;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
|
||||||
import dan200.computercraft.api.lua.GenericSource;
|
import dan200.computercraft.api.lua.GenericSource;
|
||||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
||||||
import dan200.computercraft.api.media.IMediaProvider;
|
import dan200.computercraft.api.media.MediaProvider;
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
import dan200.computercraft.api.network.PacketNetwork;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
|
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -45,45 +41,27 @@ public interface ComputerCraftAPIService {
|
|||||||
|
|
||||||
String getInstalledVersion();
|
String getInstalledVersion();
|
||||||
|
|
||||||
int createUniqueNumberedSaveDir(Level world, String parentSubPath);
|
int createUniqueNumberedSaveDir(MinecraftServer server, String parentSubPath);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
IWritableMount createSaveDirMount(Level world, String subPath, long capacity);
|
WritableMount createSaveDirMount(MinecraftServer server, String subPath, long capacity);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
IMount createResourceMount(String domain, String subPath);
|
Mount createResourceMount(MinecraftServer server, String domain, String subPath);
|
||||||
// TODO(1.19.3): Make this take a MinecraftServer argument.
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
default void registerPeripheralProvider(IPeripheralProvider provider) {
|
|
||||||
throw new UnsupportedOperationException("Can only register peripheral provider on Forge");
|
|
||||||
}
|
|
||||||
|
|
||||||
void registerGenericSource(GenericSource source);
|
void registerGenericSource(GenericSource source);
|
||||||
|
|
||||||
@Deprecated
|
void registerBundledRedstoneProvider(BundledRedstoneProvider provider);
|
||||||
default void registerGenericCapability(Capability<?> capability) {
|
|
||||||
throw new UnsupportedOperationException("Can only register Capability on Forge");
|
|
||||||
}
|
|
||||||
|
|
||||||
void registerBundledRedstoneProvider(IBundledRedstoneProvider provider);
|
|
||||||
|
|
||||||
int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side);
|
int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side);
|
||||||
|
|
||||||
void registerMediaProvider(IMediaProvider provider);
|
void registerMediaProvider(MediaProvider provider);
|
||||||
|
|
||||||
IPacketNetwork getWirelessNetwork();
|
PacketNetwork getWirelessNetwork(MinecraftServer server);
|
||||||
|
|
||||||
void registerAPIFactory(ILuaAPIFactory factory);
|
void registerAPIFactory(ILuaAPIFactory factory);
|
||||||
|
|
||||||
@Deprecated
|
WiredNode createWiredNodeForElement(WiredElement element);
|
||||||
<T> void registerDetailProvider(Class<T> type, IDetailProvider<T> provider);
|
|
||||||
|
|
||||||
IWiredNode createWiredNodeForElement(IWiredElement element);
|
|
||||||
|
|
||||||
default LazyOptional<IWiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side) {
|
|
||||||
throw new UnsupportedOperationException("Can only call getWiredElementAt on Forge");
|
|
||||||
}
|
|
||||||
|
|
||||||
void registerRefuelHandler(TurtleRefuelHandler handler);
|
void registerRefuelHandler(TurtleRefuelHandler handler);
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.impl.upgrades;
|
package dan200.computercraft.impl.upgrades;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
@ -24,7 +24,7 @@ import java.util.function.BiFunction;
|
|||||||
* @param <T> The upgrade that this class can serialise and deserialise.
|
* @param <T> The upgrade that this class can serialise and deserialise.
|
||||||
*/
|
*/
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public abstract class SerialiserWithCraftingItem<T extends IUpgradeBase> implements UpgradeSerialiser<T> {
|
public abstract class SerialiserWithCraftingItem<T extends UpgradeBase> implements UpgradeSerialiser<T> {
|
||||||
private final BiFunction<ResourceLocation, ItemStack, T> factory;
|
private final BiFunction<ResourceLocation, ItemStack, T> factory;
|
||||||
|
|
||||||
protected SerialiserWithCraftingItem(BiFunction<ResourceLocation, ItemStack, T> factory) {
|
protected SerialiserWithCraftingItem(BiFunction<ResourceLocation, ItemStack, T> factory) {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.impl.upgrades;
|
package dan200.computercraft.impl.upgrades;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
@ -22,7 +22,7 @@ import java.util.function.Function;
|
|||||||
* @param <T> The upgrade that this class can serialise and deserialise.
|
* @param <T> The upgrade that this class can serialise and deserialise.
|
||||||
*/
|
*/
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public abstract class SimpleSerialiser<T extends IUpgradeBase> implements UpgradeSerialiser<T> {
|
public abstract class SimpleSerialiser<T extends UpgradeBase> implements UpgradeSerialiser<T> {
|
||||||
private final Function<ResourceLocation, T> constructor;
|
private final Function<ResourceLocation, T> constructor;
|
||||||
|
|
||||||
public SimpleSerialiser(Function<ResourceLocation, T> constructor) {
|
public SimpleSerialiser(Function<ResourceLocation, T> constructor) {
|
||||||
|
@ -21,14 +21,12 @@ dependencies {
|
|||||||
clientImplementation(clientClasses(project(":common-api")))
|
clientImplementation(clientClasses(project(":common-api")))
|
||||||
|
|
||||||
compileOnly(libs.bundles.externalMods.common)
|
compileOnly(libs.bundles.externalMods.common)
|
||||||
compileOnly(project(":forge-stubs"))
|
|
||||||
|
|
||||||
compileOnly(libs.mixin)
|
compileOnly(libs.mixin)
|
||||||
annotationProcessorEverywhere(libs.autoService)
|
annotationProcessorEverywhere(libs.autoService)
|
||||||
|
|
||||||
testImplementation(testFixtures(project(":core")))
|
testImplementation(testFixtures(project(":core")))
|
||||||
testImplementation(libs.bundles.test)
|
testImplementation(libs.bundles.test)
|
||||||
testImplementation(project(":forge-stubs"))
|
|
||||||
testRuntimeOnly(libs.bundles.testRuntime)
|
testRuntimeOnly(libs.bundles.testRuntime)
|
||||||
|
|
||||||
testModImplementation(testFixtures(project(":core")))
|
testModImplementation(testFixtures(project(":core")))
|
||||||
|
@ -11,7 +11,7 @@ import com.google.gson.JsonObject;
|
|||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.pocket.PocketUpgradeDataProvider;
|
import dan200.computercraft.api.pocket.PocketUpgradeDataProvider;
|
||||||
import dan200.computercraft.api.turtle.TurtleUpgradeDataProvider;
|
import dan200.computercraft.api.turtle.TurtleUpgradeDataProvider;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import dan200.computercraft.core.metrics.Metric;
|
import dan200.computercraft.core.metrics.Metric;
|
||||||
import dan200.computercraft.core.metrics.Metrics;
|
import dan200.computercraft.core.metrics.Metrics;
|
||||||
import dan200.computercraft.shared.ModRegistry;
|
import dan200.computercraft.shared.ModRegistry;
|
||||||
@ -272,8 +272,8 @@ public final class LanguageProvider implements DataProvider {
|
|||||||
Registries.ITEMS.stream()
|
Registries.ITEMS.stream()
|
||||||
.filter(x -> Registries.ITEMS.getKey(x).getNamespace().equals(ComputerCraftAPI.MOD_ID))
|
.filter(x -> Registries.ITEMS.getKey(x).getNamespace().equals(ComputerCraftAPI.MOD_ID))
|
||||||
.map(Item::getDescriptionId),
|
.map(Item::getDescriptionId),
|
||||||
turtleUpgrades.getGeneratedUpgrades().stream().map(IUpgradeBase::getUnlocalisedAdjective),
|
turtleUpgrades.getGeneratedUpgrades().stream().map(UpgradeBase::getUnlocalisedAdjective),
|
||||||
pocketUpgrades.getGeneratedUpgrades().stream().map(IUpgradeBase::getUnlocalisedAdjective),
|
pocketUpgrades.getGeneratedUpgrades().stream().map(UpgradeBase::getUnlocalisedAdjective),
|
||||||
Metric.metrics().values().stream().map(x -> AggregatedMetric.TRANSLATION_PREFIX + x.name() + ".name"),
|
Metric.metrics().values().stream().map(x -> AggregatedMetric.TRANSLATION_PREFIX + x.name() + ".name"),
|
||||||
getConfigKeys(ConfigSpec.serverSpec),
|
getConfigKeys(ConfigSpec.serverSpec),
|
||||||
getConfigKeys(ConfigSpec.clientSpec)
|
getConfigKeys(ConfigSpec.clientSpec)
|
||||||
|
@ -7,21 +7,20 @@ package dan200.computercraft.impl;
|
|||||||
|
|
||||||
import dan200.computercraft.api.detail.BlockReference;
|
import dan200.computercraft.api.detail.BlockReference;
|
||||||
import dan200.computercraft.api.detail.DetailRegistry;
|
import dan200.computercraft.api.detail.DetailRegistry;
|
||||||
import dan200.computercraft.api.detail.IDetailProvider;
|
import dan200.computercraft.api.filesystem.WritableMount;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
|
||||||
import dan200.computercraft.api.lua.GenericSource;
|
import dan200.computercraft.api.lua.GenericSource;
|
||||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
||||||
import dan200.computercraft.api.media.IMediaProvider;
|
import dan200.computercraft.api.media.MediaProvider;
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
import dan200.computercraft.api.network.PacketNetwork;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
|
||||||
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
|
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
|
||||||
import dan200.computercraft.core.apis.ApiFactories;
|
import dan200.computercraft.core.apis.ApiFactories;
|
||||||
import dan200.computercraft.core.asm.GenericMethod;
|
import dan200.computercraft.core.asm.GenericMethod;
|
||||||
import dan200.computercraft.core.filesystem.FileMount;
|
import dan200.computercraft.core.filesystem.FileMount;
|
||||||
import dan200.computercraft.impl.detail.DetailRegistryImpl;
|
import dan200.computercraft.impl.detail.DetailRegistryImpl;
|
||||||
import dan200.computercraft.impl.network.wired.WiredNode;
|
import dan200.computercraft.impl.network.wired.WiredNodeImpl;
|
||||||
import dan200.computercraft.shared.computer.core.ServerContext;
|
import dan200.computercraft.shared.computer.core.ServerContext;
|
||||||
import dan200.computercraft.shared.details.BlockDetails;
|
import dan200.computercraft.shared.details.BlockDetails;
|
||||||
import dan200.computercraft.shared.details.ItemDetails;
|
import dan200.computercraft.shared.details.ItemDetails;
|
||||||
@ -54,19 +53,15 @@ public abstract class AbstractComputerCraftAPI implements ComputerCraftAPIServic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int createUniqueNumberedSaveDir(Level world, String parentSubPath) {
|
public final int createUniqueNumberedSaveDir(MinecraftServer server, String parentSubPath) {
|
||||||
var server = world.getServer();
|
|
||||||
if (server == null) throw new IllegalArgumentException("Cannot find server from provided level");
|
|
||||||
return ServerContext.get(server).getNextId(parentSubPath);
|
return ServerContext.get(server).getNextId(parentSubPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final @Nullable IWritableMount createSaveDirMount(Level world, String subPath, long capacity) {
|
public final @Nullable WritableMount createSaveDirMount(MinecraftServer server, String subPath, long capacity) {
|
||||||
var server = world.getServer();
|
var root = ServerContext.get(server).storageDir().toFile();
|
||||||
if (server == null) throw new IllegalArgumentException("Cannot find server from provided level");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new FileMount(new File(ServerContext.get(server).storageDir().toFile(), subPath), capacity);
|
return new FileMount(new File(root, subPath), capacity);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -78,7 +73,7 @@ public abstract class AbstractComputerCraftAPI implements ComputerCraftAPIServic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void registerBundledRedstoneProvider(IBundledRedstoneProvider provider) {
|
public final void registerBundledRedstoneProvider(BundledRedstoneProvider provider) {
|
||||||
BundledRedstone.register(provider);
|
BundledRedstone.register(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +83,12 @@ public abstract class AbstractComputerCraftAPI implements ComputerCraftAPIServic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void registerMediaProvider(IMediaProvider provider) {
|
public final void registerMediaProvider(MediaProvider provider) {
|
||||||
MediaProviders.register(provider);
|
MediaProviders.register(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final IPacketNetwork getWirelessNetwork() {
|
public final PacketNetwork getWirelessNetwork(MinecraftServer server) {
|
||||||
return WirelessNetwork.getUniversal();
|
return WirelessNetwork.getUniversal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,13 +97,11 @@ public abstract class AbstractComputerCraftAPI implements ComputerCraftAPIServic
|
|||||||
ApiFactories.register(factory);
|
ApiFactories.register(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final IWiredNode createWiredNodeForElement(IWiredElement element) {
|
public final WiredNode createWiredNodeForElement(WiredElement element) {
|
||||||
return new WiredNode(element);
|
return new WiredNodeImpl(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerRefuelHandler(TurtleRefuelHandler handler) {
|
public void registerRefuelHandler(TurtleRefuelHandler handler) {
|
||||||
TurtleRefuelHandlers.register(handler);
|
TurtleRefuelHandlers.register(handler);
|
||||||
@ -123,17 +116,4 @@ public abstract class AbstractComputerCraftAPI implements ComputerCraftAPIServic
|
|||||||
public final DetailRegistry<BlockReference> getBlockInWorldDetailRegistry() {
|
public final DetailRegistry<BlockReference> getBlockInWorldDetailRegistry() {
|
||||||
return blockDetails;
|
return blockDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> void registerDetailProvider(Class<T> type, IDetailProvider<T> provider) {
|
|
||||||
if (type == ItemStack.class) {
|
|
||||||
itemStackDetails.addProvider((IDetailProvider<ItemStack>) provider);
|
|
||||||
} else if (type == BlockReference.class) {
|
|
||||||
blockDetails.addProvider((IDetailProvider<BlockReference>) provider);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unknown detail provider " + type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.impl;
|
package dan200.computercraft.impl;
|
||||||
|
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
|
||||||
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
|
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
@ -19,12 +19,12 @@ import java.util.Objects;
|
|||||||
public final class BundledRedstone {
|
public final class BundledRedstone {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BundledRedstone.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BundledRedstone.class);
|
||||||
|
|
||||||
private static final ArrayList<IBundledRedstoneProvider> providers = new ArrayList<>();
|
private static final ArrayList<BundledRedstoneProvider> providers = new ArrayList<>();
|
||||||
|
|
||||||
private BundledRedstone() {
|
private BundledRedstone() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void register(IBundledRedstoneProvider provider) {
|
public static synchronized void register(BundledRedstoneProvider provider) {
|
||||||
Objects.requireNonNull(provider, "provider cannot be null");
|
Objects.requireNonNull(provider, "provider cannot be null");
|
||||||
if (!providers.contains(provider)) providers.add(provider);
|
if (!providers.contains(provider)) providers.add(provider);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.impl;
|
package dan200.computercraft.impl;
|
||||||
|
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
import dan200.computercraft.api.media.IMediaProvider;
|
import dan200.computercraft.api.media.MediaProvider;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -19,12 +19,12 @@ import java.util.Set;
|
|||||||
public final class MediaProviders {
|
public final class MediaProviders {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MediaProviders.class);
|
private static final Logger LOG = LoggerFactory.getLogger(MediaProviders.class);
|
||||||
|
|
||||||
private static final Set<IMediaProvider> providers = new LinkedHashSet<>();
|
private static final Set<MediaProvider> providers = new LinkedHashSet<>();
|
||||||
|
|
||||||
private MediaProviders() {
|
private MediaProviders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void register(IMediaProvider provider) {
|
public static synchronized void register(MediaProvider provider) {
|
||||||
Objects.requireNonNull(provider, "provider cannot be null");
|
Objects.requireNonNull(provider, "provider cannot be null");
|
||||||
providers.add(provider);
|
providers.add(provider);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ package dan200.computercraft.impl;
|
|||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
@ -36,11 +36,11 @@ import java.util.stream.Collectors;
|
|||||||
* @see TurtleUpgrades
|
* @see TurtleUpgrades
|
||||||
* @see PocketUpgrades
|
* @see PocketUpgrades
|
||||||
*/
|
*/
|
||||||
public class UpgradeManager<R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase> extends SimpleJsonResourceReloadListener {
|
public class UpgradeManager<R extends UpgradeSerialiser<? extends T>, T extends UpgradeBase> extends SimpleJsonResourceReloadListener {
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||||
|
|
||||||
public record UpgradeWrapper<R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase>(
|
public record UpgradeWrapper<R extends UpgradeSerialiser<? extends T>, T extends UpgradeBase>(
|
||||||
String id, T upgrade, R serialiser, String modId
|
String id, T upgrade, R serialiser, String modId
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.impl.detail;
|
package dan200.computercraft.impl.detail;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.detail.DetailProvider;
|
||||||
import dan200.computercraft.api.detail.DetailRegistry;
|
import dan200.computercraft.api.detail.DetailRegistry;
|
||||||
import dan200.computercraft.api.detail.IDetailProvider;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -16,16 +16,16 @@ import java.util.*;
|
|||||||
* @param <T> The type of object that this registry provides details for.
|
* @param <T> The type of object that this registry provides details for.
|
||||||
*/
|
*/
|
||||||
public class DetailRegistryImpl<T> implements DetailRegistry<T> {
|
public class DetailRegistryImpl<T> implements DetailRegistry<T> {
|
||||||
private final Collection<IDetailProvider<T>> providers = new ArrayList<>();
|
private final Collection<DetailProvider<T>> providers = new ArrayList<>();
|
||||||
private final IDetailProvider<T> basic;
|
private final DetailProvider<T> basic;
|
||||||
|
|
||||||
public DetailRegistryImpl(IDetailProvider<T> basic) {
|
public DetailRegistryImpl(DetailProvider<T> basic) {
|
||||||
this.basic = basic;
|
this.basic = basic;
|
||||||
providers.add(basic);
|
providers.add(basic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void addProvider(IDetailProvider<T> provider) {
|
public synchronized void addProvider(DetailProvider<T> provider) {
|
||||||
Objects.requireNonNull(provider, "provider cannot be null");
|
Objects.requireNonNull(provider, "provider cannot be null");
|
||||||
if (!providers.contains(provider)) providers.add(provider);
|
if (!providers.contains(provider)) providers.add(provider);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public final class InvariantChecker {
|
|||||||
private InvariantChecker() {
|
private InvariantChecker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkNode(WiredNode node) {
|
public static void checkNode(WiredNodeImpl node) {
|
||||||
if (!ENABLED) return;
|
if (!ENABLED) return;
|
||||||
|
|
||||||
var network = node.network;
|
var network = node.network;
|
||||||
@ -41,7 +41,7 @@ public final class InvariantChecker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkNetwork(WiredNetwork network) {
|
public static void checkNetwork(WiredNetworkImpl network) {
|
||||||
if (!ENABLED) return;
|
if (!ENABLED) return;
|
||||||
|
|
||||||
for (var node : network.nodes) checkNode(node);
|
for (var node : network.nodes) checkNode(node);
|
||||||
|
@ -5,44 +5,44 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.impl.network.wired;
|
package dan200.computercraft.impl.network.wired;
|
||||||
|
|
||||||
import dan200.computercraft.api.network.wired.IWiredNetworkChange;
|
import dan200.computercraft.api.network.wired.WiredNetworkChange;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public final class WiredNetworkChange implements IWiredNetworkChange {
|
final class WiredNetworkChangeImpl implements WiredNetworkChange {
|
||||||
private static final WiredNetworkChange EMPTY = new WiredNetworkChange(Collections.emptyMap(), Collections.emptyMap());
|
private static final WiredNetworkChangeImpl EMPTY = new WiredNetworkChangeImpl(Collections.emptyMap(), Collections.emptyMap());
|
||||||
|
|
||||||
private final Map<String, IPeripheral> removed;
|
private final Map<String, IPeripheral> removed;
|
||||||
private final Map<String, IPeripheral> added;
|
private final Map<String, IPeripheral> added;
|
||||||
|
|
||||||
private WiredNetworkChange(Map<String, IPeripheral> removed, Map<String, IPeripheral> added) {
|
private WiredNetworkChangeImpl(Map<String, IPeripheral> removed, Map<String, IPeripheral> added) {
|
||||||
this.removed = removed;
|
this.removed = removed;
|
||||||
this.added = added;
|
this.added = added;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WiredNetworkChange changed(Map<String, IPeripheral> removed, Map<String, IPeripheral> added) {
|
static WiredNetworkChangeImpl changed(Map<String, IPeripheral> removed, Map<String, IPeripheral> added) {
|
||||||
return new WiredNetworkChange(Collections.unmodifiableMap(removed), Collections.unmodifiableMap(added));
|
return new WiredNetworkChangeImpl(Collections.unmodifiableMap(removed), Collections.unmodifiableMap(added));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WiredNetworkChange added(Map<String, IPeripheral> added) {
|
static WiredNetworkChangeImpl added(Map<String, IPeripheral> added) {
|
||||||
return added.isEmpty() ? EMPTY : new WiredNetworkChange(Collections.emptyMap(), Collections.unmodifiableMap(added));
|
return added.isEmpty() ? EMPTY : new WiredNetworkChangeImpl(Collections.emptyMap(), Collections.unmodifiableMap(added));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WiredNetworkChange removed(Map<String, IPeripheral> removed) {
|
static WiredNetworkChangeImpl removed(Map<String, IPeripheral> removed) {
|
||||||
return removed.isEmpty() ? EMPTY : new WiredNetworkChange(Collections.unmodifiableMap(removed), Collections.emptyMap());
|
return removed.isEmpty() ? EMPTY : new WiredNetworkChangeImpl(Collections.unmodifiableMap(removed), Collections.emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WiredNetworkChange changeOf(Map<String, IPeripheral> oldPeripherals, Map<String, IPeripheral> newPeripherals) {
|
static WiredNetworkChangeImpl changeOf(Map<String, IPeripheral> oldPeripherals, Map<String, IPeripheral> newPeripherals) {
|
||||||
// Handle the trivial cases, where all peripherals have been added or removed.
|
// Handle the trivial cases, where all peripherals have been added or removed.
|
||||||
if (oldPeripherals.isEmpty() && newPeripherals.isEmpty()) {
|
if (oldPeripherals.isEmpty() && newPeripherals.isEmpty()) {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
} else if (oldPeripherals.isEmpty()) {
|
} else if (oldPeripherals.isEmpty()) {
|
||||||
return new WiredNetworkChange(Collections.emptyMap(), newPeripherals);
|
return new WiredNetworkChangeImpl(Collections.emptyMap(), newPeripherals);
|
||||||
} else if (newPeripherals.isEmpty()) {
|
} else if (newPeripherals.isEmpty()) {
|
||||||
return new WiredNetworkChange(oldPeripherals, Collections.emptyMap());
|
return new WiredNetworkChangeImpl(oldPeripherals, Collections.emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, IPeripheral> added = new HashMap<>(newPeripherals);
|
Map<String, IPeripheral> added = new HashMap<>(newPeripherals);
|
||||||
@ -80,13 +80,13 @@ public final class WiredNetworkChange implements IWiredNetworkChange {
|
|||||||
return added.isEmpty() && removed.isEmpty();
|
return added.isEmpty() && removed.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcast(Iterable<WiredNode> nodes) {
|
void broadcast(Iterable<WiredNodeImpl> nodes) {
|
||||||
if (!isEmpty()) {
|
if (!isEmpty()) {
|
||||||
for (var node : nodes) node.element.networkChanged(this);
|
for (var node : nodes) node.element.networkChanged(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcast(WiredNode node) {
|
void broadcast(WiredNodeImpl node) {
|
||||||
if (!isEmpty()) {
|
if (!isEmpty()) {
|
||||||
node.element.networkChanged(this);
|
node.element.networkChanged(this);
|
||||||
}
|
}
|
@ -7,30 +7,30 @@ package dan200.computercraft.impl.network.wired;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import dan200.computercraft.api.network.Packet;
|
import dan200.computercraft.api.network.Packet;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNetwork;
|
import dan200.computercraft.api.network.wired.WiredNetwork;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.locks.ReadWriteLock;
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
public final class WiredNetwork implements IWiredNetwork {
|
final class WiredNetworkImpl implements WiredNetwork {
|
||||||
final ReadWriteLock lock = new ReentrantReadWriteLock();
|
final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
Set<WiredNode> nodes;
|
Set<WiredNodeImpl> nodes;
|
||||||
private Map<String, IPeripheral> peripherals = new HashMap<>();
|
private Map<String, IPeripheral> peripherals = new HashMap<>();
|
||||||
|
|
||||||
WiredNetwork(WiredNode node) {
|
WiredNetworkImpl(WiredNodeImpl node) {
|
||||||
nodes = new HashSet<>(1);
|
nodes = new HashSet<>(1);
|
||||||
nodes.add(node);
|
nodes.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
private WiredNetwork(HashSet<WiredNode> nodes) {
|
private WiredNetworkImpl(HashSet<WiredNodeImpl> nodes) {
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean connect(IWiredNode nodeU, IWiredNode nodeV) {
|
public boolean connect(WiredNode nodeU, WiredNode nodeV) {
|
||||||
var wiredU = checkNode(nodeU);
|
var wiredU = checkNode(nodeU);
|
||||||
var wiredV = checkNode(nodeV);
|
var wiredV = checkNode(nodeV);
|
||||||
if (nodeU == nodeV) throw new IllegalArgumentException("Cannot add a connection to oneself.");
|
if (nodeU == nodeV) throw new IllegalArgumentException("Cannot add a connection to oneself.");
|
||||||
@ -65,11 +65,11 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
peripherals.putAll(otherPeripherals);
|
peripherals.putAll(otherPeripherals);
|
||||||
|
|
||||||
if (!thisPeripherals.isEmpty()) {
|
if (!thisPeripherals.isEmpty()) {
|
||||||
WiredNetworkChange.added(thisPeripherals).broadcast(otherNodes);
|
WiredNetworkChangeImpl.added(thisPeripherals).broadcast(otherNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!otherPeripherals.isEmpty()) {
|
if (!otherPeripherals.isEmpty()) {
|
||||||
WiredNetworkChange.added(otherPeripherals).broadcast(thisNodes);
|
WiredNetworkChangeImpl.added(otherPeripherals).broadcast(thisNodes);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
other.lock.writeLock().unlock();
|
other.lock.writeLock().unlock();
|
||||||
@ -90,7 +90,7 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean disconnect(IWiredNode nodeU, IWiredNode nodeV) {
|
public boolean disconnect(WiredNode nodeU, WiredNode nodeV) {
|
||||||
var wiredU = checkNode(nodeU);
|
var wiredU = checkNode(nodeU);
|
||||||
var wiredV = checkNode(nodeV);
|
var wiredV = checkNode(nodeV);
|
||||||
if (nodeU == nodeV) throw new IllegalArgumentException("Cannot remove a connection to oneself.");
|
if (nodeU == nodeV) throw new IllegalArgumentException("Cannot remove a connection to oneself.");
|
||||||
@ -108,8 +108,8 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
// Determine if there is still some connection from u to v.
|
// Determine if there is still some connection from u to v.
|
||||||
// Note this is an inlining of reachableNodes which short-circuits
|
// Note this is an inlining of reachableNodes which short-circuits
|
||||||
// if all nodes are reachable.
|
// if all nodes are reachable.
|
||||||
Queue<WiredNode> enqueued = new ArrayDeque<>();
|
Queue<WiredNodeImpl> enqueued = new ArrayDeque<>();
|
||||||
var reachableU = new HashSet<WiredNode>();
|
var reachableU = new HashSet<WiredNodeImpl>();
|
||||||
|
|
||||||
reachableU.add(wiredU);
|
reachableU.add(wiredU);
|
||||||
enqueued.add(wiredU);
|
enqueued.add(wiredU);
|
||||||
@ -127,7 +127,7 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
|
|
||||||
// Create a new network with all U-reachable nodes/edges and remove them
|
// Create a new network with all U-reachable nodes/edges and remove them
|
||||||
// from the existing graph.
|
// from the existing graph.
|
||||||
var networkU = new WiredNetwork(reachableU);
|
var networkU = new WiredNetworkImpl(reachableU);
|
||||||
networkU.lock.writeLock().lock();
|
networkU.lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
// Remove nodes from this network
|
// Remove nodes from this network
|
||||||
@ -141,9 +141,9 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast changes
|
// Broadcast changes
|
||||||
if (!peripherals.isEmpty()) WiredNetworkChange.removed(peripherals).broadcast(networkU.nodes);
|
if (!peripherals.isEmpty()) WiredNetworkChangeImpl.removed(peripherals).broadcast(networkU.nodes);
|
||||||
if (!networkU.peripherals.isEmpty()) {
|
if (!networkU.peripherals.isEmpty()) {
|
||||||
WiredNetworkChange.removed(networkU.peripherals).broadcast(nodes);
|
WiredNetworkChangeImpl.removed(networkU.peripherals).broadcast(nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
InvariantChecker.checkNetwork(this);
|
InvariantChecker.checkNetwork(this);
|
||||||
@ -161,7 +161,7 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(IWiredNode node) {
|
public boolean remove(WiredNode node) {
|
||||||
var wired = checkNode(node);
|
var wired = checkNode(node);
|
||||||
|
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
@ -177,7 +177,7 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
nodes.remove(wired);
|
nodes.remove(wired);
|
||||||
for (var neighbour : neighbours) neighbour.neighbours.remove(wired);
|
for (var neighbour : neighbours) neighbour.neighbours.remove(wired);
|
||||||
|
|
||||||
var wiredNetwork = new WiredNetwork(wired);
|
var wiredNetwork = new WiredNetworkImpl(wired);
|
||||||
|
|
||||||
// If we're a leaf node in the graph (only one neighbour) then we don't need to
|
// If we're a leaf node in the graph (only one neighbour) then we don't need to
|
||||||
// check for network splitting
|
// check for network splitting
|
||||||
@ -203,14 +203,14 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
// A split may cause 2..neighbours.size() separate networks, so we
|
// A split may cause 2..neighbours.size() separate networks, so we
|
||||||
// iterate through our neighbour list, generating child networks.
|
// iterate through our neighbour list, generating child networks.
|
||||||
neighbours.removeAll(reachable);
|
neighbours.removeAll(reachable);
|
||||||
var maximals = new ArrayList<WiredNetwork>(neighbours.size() + 1);
|
var maximals = new ArrayList<WiredNetworkImpl>(neighbours.size() + 1);
|
||||||
maximals.add(wiredNetwork);
|
maximals.add(wiredNetwork);
|
||||||
maximals.add(new WiredNetwork(reachable));
|
maximals.add(new WiredNetworkImpl(reachable));
|
||||||
|
|
||||||
while (!neighbours.isEmpty()) {
|
while (!neighbours.isEmpty()) {
|
||||||
reachable = reachableNodes(neighbours.iterator().next());
|
reachable = reachableNodes(neighbours.iterator().next());
|
||||||
neighbours.removeAll(reachable);
|
neighbours.removeAll(reachable);
|
||||||
maximals.add(new WiredNetwork(reachable));
|
maximals.add(new WiredNetworkImpl(reachable));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var network : maximals) network.lock.writeLock().lock();
|
for (var network : maximals) network.lock.writeLock().lock();
|
||||||
@ -233,7 +233,7 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
|
|
||||||
// Then broadcast network changes once all nodes are finalised
|
// Then broadcast network changes once all nodes are finalised
|
||||||
for (var network : maximals) {
|
for (var network : maximals) {
|
||||||
WiredNetworkChange.changeOf(peripherals, network.peripherals).broadcast(network.nodes);
|
WiredNetworkChangeImpl.changeOf(peripherals, network.peripherals).broadcast(network.nodes);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
for (var network : maximals) network.lock.writeLock().unlock();
|
for (var network : maximals) network.lock.writeLock().unlock();
|
||||||
@ -249,7 +249,7 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePeripherals(IWiredNode node, Map<String, IPeripheral> newPeripherals) {
|
public void updatePeripherals(WiredNode node, Map<String, IPeripheral> newPeripherals) {
|
||||||
var wired = checkNode(node);
|
var wired = checkNode(node);
|
||||||
Objects.requireNonNull(peripherals, "peripherals cannot be null");
|
Objects.requireNonNull(peripherals, "peripherals cannot be null");
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
if (wired.network != this) throw new IllegalStateException("Node is not on this network");
|
if (wired.network != this) throw new IllegalStateException("Node is not on this network");
|
||||||
|
|
||||||
var oldPeripherals = wired.peripherals;
|
var oldPeripherals = wired.peripherals;
|
||||||
var change = WiredNetworkChange.changeOf(oldPeripherals, newPeripherals);
|
var change = WiredNetworkChangeImpl.changeOf(oldPeripherals, newPeripherals);
|
||||||
if (change.isEmpty()) return;
|
if (change.isEmpty()) return;
|
||||||
|
|
||||||
wired.peripherals = ImmutableMap.copyOf(newPeripherals);
|
wired.peripherals = ImmutableMap.copyOf(newPeripherals);
|
||||||
@ -275,8 +275,8 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transmitPacket(WiredNode start, Packet packet, double range, boolean interdimensional) {
|
static void transmitPacket(WiredNodeImpl start, Packet packet, double range, boolean interdimensional) {
|
||||||
Map<WiredNode, TransmitPoint> points = new HashMap<>();
|
Map<WiredNodeImpl, TransmitPoint> points = new HashMap<>();
|
||||||
var transmitTo = new TreeSet<TransmitPoint>();
|
var transmitTo = new TreeSet<TransmitPoint>();
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -324,7 +324,7 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeSingleNode(WiredNode wired, WiredNetwork wiredNetwork) {
|
private void removeSingleNode(WiredNodeImpl wired, WiredNetworkImpl wiredNetwork) {
|
||||||
wiredNetwork.lock.writeLock().lock();
|
wiredNetwork.lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
// Cache all the old nodes.
|
// Cache all the old nodes.
|
||||||
@ -337,11 +337,11 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
wired.peripherals = Collections.emptyMap();
|
wired.peripherals = Collections.emptyMap();
|
||||||
|
|
||||||
// Broadcast the change
|
// Broadcast the change
|
||||||
if (!peripherals.isEmpty()) WiredNetworkChange.removed(peripherals).broadcast(wired);
|
if (!peripherals.isEmpty()) WiredNetworkChangeImpl.removed(peripherals).broadcast(wired);
|
||||||
|
|
||||||
// Now remove all peripherals from this network and broadcast the change.
|
// Now remove all peripherals from this network and broadcast the change.
|
||||||
peripherals.keySet().removeAll(wiredPeripherals.keySet());
|
peripherals.keySet().removeAll(wiredPeripherals.keySet());
|
||||||
if (!wiredPeripherals.isEmpty()) WiredNetworkChange.removed(wiredPeripherals).broadcast(nodes);
|
if (!wiredPeripherals.isEmpty()) WiredNetworkChangeImpl.removed(wiredPeripherals).broadcast(nodes);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
wiredNetwork.lock.writeLock().unlock();
|
wiredNetwork.lock.writeLock().unlock();
|
||||||
@ -349,11 +349,11 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class TransmitPoint implements Comparable<TransmitPoint> {
|
private static class TransmitPoint implements Comparable<TransmitPoint> {
|
||||||
final WiredNode node;
|
final WiredNodeImpl node;
|
||||||
double distance;
|
double distance;
|
||||||
boolean interdimensional;
|
boolean interdimensional;
|
||||||
|
|
||||||
TransmitPoint(WiredNode node, double distance, boolean interdimensional) {
|
TransmitPoint(WiredNodeImpl node, double distance, boolean interdimensional) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
this.interdimensional = interdimensional;
|
this.interdimensional = interdimensional;
|
||||||
@ -368,22 +368,22 @@ public final class WiredNetwork implements IWiredNetwork {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static WiredNode checkNode(IWiredNode node) {
|
private static WiredNodeImpl checkNode(WiredNode node) {
|
||||||
if (node instanceof WiredNode) {
|
if (node instanceof WiredNodeImpl) {
|
||||||
return (WiredNode) node;
|
return (WiredNodeImpl) node;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unknown implementation of IWiredNode: " + node);
|
throw new IllegalArgumentException("Unknown implementation of IWiredNode: " + node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashSet<WiredNode> reachableNodes(WiredNode start) {
|
private static HashSet<WiredNodeImpl> reachableNodes(WiredNodeImpl start) {
|
||||||
Queue<WiredNode> enqueued = new ArrayDeque<>();
|
Queue<WiredNodeImpl> enqueued = new ArrayDeque<>();
|
||||||
var reachable = new HashSet<WiredNode>();
|
var reachable = new HashSet<WiredNodeImpl>();
|
||||||
|
|
||||||
reachable.add(start);
|
reachable.add(start);
|
||||||
enqueued.add(start);
|
enqueued.add(start);
|
||||||
|
|
||||||
WiredNode node;
|
WiredNodeImpl node;
|
||||||
while ((node = enqueued.poll()) != null) {
|
while ((node = enqueued.poll()) != null) {
|
||||||
for (var neighbour : node.neighbours) {
|
for (var neighbour : node.neighbours) {
|
||||||
// Otherwise attempt to enqueue this neighbour as well.
|
// Otherwise attempt to enqueue this neighbour as well.
|
@ -5,39 +5,39 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.impl.network.wired;
|
package dan200.computercraft.impl.network.wired;
|
||||||
|
|
||||||
import dan200.computercraft.api.network.IPacketReceiver;
|
|
||||||
import dan200.computercraft.api.network.Packet;
|
import dan200.computercraft.api.network.Packet;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.PacketReceiver;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNetwork;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNetwork;
|
||||||
import dan200.computercraft.api.network.wired.IWiredSender;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
|
import dan200.computercraft.api.network.wired.WiredSender;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public final class WiredNode implements IWiredNode {
|
public final class WiredNodeImpl implements WiredNode {
|
||||||
private @Nullable Set<IPacketReceiver> receivers;
|
private @Nullable Set<PacketReceiver> receivers;
|
||||||
|
|
||||||
final IWiredElement element;
|
final WiredElement element;
|
||||||
Map<String, IPeripheral> peripherals = Collections.emptyMap();
|
Map<String, IPeripheral> peripherals = Collections.emptyMap();
|
||||||
|
|
||||||
final HashSet<WiredNode> neighbours = new HashSet<>();
|
final HashSet<WiredNodeImpl> neighbours = new HashSet<>();
|
||||||
volatile WiredNetwork network;
|
volatile WiredNetworkImpl network;
|
||||||
|
|
||||||
public WiredNode(IWiredElement element) {
|
public WiredNodeImpl(WiredElement element) {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
network = new WiredNetwork(this);
|
network = new WiredNetworkImpl(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void addReceiver(IPacketReceiver receiver) {
|
public synchronized void addReceiver(PacketReceiver receiver) {
|
||||||
if (receivers == null) receivers = new HashSet<>();
|
if (receivers == null) receivers = new HashSet<>();
|
||||||
receivers.add(receiver);
|
receivers.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void removeReceiver(IPacketReceiver receiver) {
|
public synchronized void removeReceiver(PacketReceiver receiver) {
|
||||||
if (receivers != null) receivers.remove(receiver);
|
if (receivers != null) receivers.remove(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,13 +66,13 @@ public final class WiredNode implements IWiredNode {
|
|||||||
@Override
|
@Override
|
||||||
public void transmitSameDimension(Packet packet, double range) {
|
public void transmitSameDimension(Packet packet, double range) {
|
||||||
Objects.requireNonNull(packet, "packet cannot be null");
|
Objects.requireNonNull(packet, "packet cannot be null");
|
||||||
if (!(packet.sender() instanceof IWiredSender) || ((IWiredSender) packet.sender()).getNode() != this) {
|
if (!(packet.sender() instanceof WiredSender) || ((WiredSender) packet.sender()).getNode() != this) {
|
||||||
throw new IllegalArgumentException("Sender is not in the network");
|
throw new IllegalArgumentException("Sender is not in the network");
|
||||||
}
|
}
|
||||||
|
|
||||||
acquireReadLock();
|
acquireReadLock();
|
||||||
try {
|
try {
|
||||||
WiredNetwork.transmitPacket(this, packet, range, false);
|
WiredNetworkImpl.transmitPacket(this, packet, range, false);
|
||||||
} finally {
|
} finally {
|
||||||
network.lock.readLock().unlock();
|
network.lock.readLock().unlock();
|
||||||
}
|
}
|
||||||
@ -81,25 +81,25 @@ public final class WiredNode implements IWiredNode {
|
|||||||
@Override
|
@Override
|
||||||
public void transmitInterdimensional(Packet packet) {
|
public void transmitInterdimensional(Packet packet) {
|
||||||
Objects.requireNonNull(packet, "packet cannot be null");
|
Objects.requireNonNull(packet, "packet cannot be null");
|
||||||
if (!(packet.sender() instanceof IWiredSender) || ((IWiredSender) packet.sender()).getNode() != this) {
|
if (!(packet.sender() instanceof WiredSender) || ((WiredSender) packet.sender()).getNode() != this) {
|
||||||
throw new IllegalArgumentException("Sender is not in the network");
|
throw new IllegalArgumentException("Sender is not in the network");
|
||||||
}
|
}
|
||||||
|
|
||||||
acquireReadLock();
|
acquireReadLock();
|
||||||
try {
|
try {
|
||||||
WiredNetwork.transmitPacket(this, packet, 0, true);
|
WiredNetworkImpl.transmitPacket(this, packet, 0, true);
|
||||||
} finally {
|
} finally {
|
||||||
network.lock.readLock().unlock();
|
network.lock.readLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IWiredElement getElement() {
|
public WiredElement getElement() {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IWiredNetwork getNetwork() {
|
public WiredNetwork getNetwork() {
|
||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
@ -7,7 +7,7 @@ package dan200.computercraft.shared;
|
|||||||
|
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.detail.IDetailProvider;
|
import dan200.computercraft.api.detail.DetailProvider;
|
||||||
import dan200.computercraft.api.detail.VanillaDetailRegistries;
|
import dan200.computercraft.api.detail.VanillaDetailRegistries;
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
|
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
|
||||||
@ -98,7 +98,7 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers ComputerCraft's registry entries and additional objects, such as {@link CauldronInteraction}s and
|
* Registers ComputerCraft's registry entries and additional objects, such as {@link CauldronInteraction}s and
|
||||||
* {@link IDetailProvider}s
|
* {@link DetailProvider}s
|
||||||
* <p>
|
* <p>
|
||||||
* The functions in this class should be called from a loader-specific class.
|
* The functions in this class should be called from a loader-specific class.
|
||||||
*/
|
*/
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.common;
|
package dan200.computercraft.shared.common;
|
||||||
|
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
|
||||||
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider {
|
public class DefaultBundledRedstoneProvider implements BundledRedstoneProvider {
|
||||||
@Override
|
@Override
|
||||||
public int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side) {
|
public int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side) {
|
||||||
return getDefaultBundledRedstoneOutput(world, pos, side);
|
return getDefaultBundledRedstoneOutput(world, pos, side);
|
||||||
|
@ -314,7 +314,7 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
|
|||||||
var computer = ServerContext.get(server).registry().get(instanceID);
|
var computer = ServerContext.get(server).registry().get(instanceID);
|
||||||
if (computer == null) {
|
if (computer == null) {
|
||||||
if (computerID < 0) {
|
if (computerID < 0) {
|
||||||
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level, IDAssigner.COMPUTER);
|
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(server, IDAssigner.COMPUTER);
|
||||||
BlockEntityHelpers.updateBlock(this);
|
BlockEntityHelpers.updateBlock(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ package dan200.computercraft.shared.computer.core;
|
|||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||||
import dan200.computercraft.core.filesystem.FileSystem;
|
import dan200.computercraft.core.filesystem.FileSystem;
|
||||||
import dan200.computercraft.core.util.IoUtil;
|
import dan200.computercraft.core.util.IoUtil;
|
||||||
@ -29,7 +29,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public final class ResourceMount implements IMount {
|
public final class ResourceMount implements Mount {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ResourceMount.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ResourceMount.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.shared.computer.core;
|
package dan200.computercraft.shared.computer.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.WritableMount;
|
||||||
import dan200.computercraft.api.lua.ILuaAPI;
|
import dan200.computercraft.api.lua.ILuaAPI;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||||
@ -245,7 +245,7 @@ public class ServerComputer implements InputHandler, ComputerEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable IWritableMount createRootMount() {
|
public @Nullable WritableMount createRootMount() {
|
||||||
return ComputerCraftAPI.createSaveDirMount(level, "computer/" + computer.getID(), Config.computerSpaceLimit);
|
return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + computer.getID(), Config.computerSpaceLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ package dan200.computercraft.shared.computer.core;
|
|||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.core.ComputerContext;
|
import dan200.computercraft.core.ComputerContext;
|
||||||
import dan200.computercraft.core.computer.ComputerThread;
|
import dan200.computercraft.core.computer.ComputerThread;
|
||||||
import dan200.computercraft.core.computer.GlobalEnvironment;
|
import dan200.computercraft.core.computer.GlobalEnvironment;
|
||||||
@ -21,7 +21,6 @@ import dan200.computercraft.shared.config.Config;
|
|||||||
import dan200.computercraft.shared.util.IDAssigner;
|
import dan200.computercraft.shared.util.IDAssigner;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.storage.LevelResource;
|
import net.minecraft.world.level.storage.LevelResource;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -156,7 +155,7 @@ public final class ServerContext {
|
|||||||
*
|
*
|
||||||
* @param kind The kind we're assigning an ID for, for instance {@code "computer"} or {@code "peripheral.monitor"}.
|
* @param kind The kind we're assigning an ID for, for instance {@code "computer"} or {@code "peripheral.monitor"}.
|
||||||
* @return The next available ID.
|
* @return The next available ID.
|
||||||
* @see ComputerCraftAPI#createUniqueNumberedSaveDir(Level, String)
|
* @see ComputerCraftAPI#createUniqueNumberedSaveDir(MinecraftServer, String)
|
||||||
*/
|
*/
|
||||||
public int getNextId(String kind) {
|
public int getNextId(String kind) {
|
||||||
return idAssigner.getNextId(kind);
|
return idAssigner.getNextId(kind);
|
||||||
@ -183,8 +182,8 @@ public final class ServerContext {
|
|||||||
|
|
||||||
private record Environment(MinecraftServer server) implements GlobalEnvironment {
|
private record Environment(MinecraftServer server) implements GlobalEnvironment {
|
||||||
@Override
|
@Override
|
||||||
public @Nullable IMount createResourceMount(String domain, String subPath) {
|
public @Nullable Mount createResourceMount(String domain, String subPath) {
|
||||||
return ComputerCraftAPI.createResourceMount(domain, subPath);
|
return ComputerCraftAPI.createResourceMount(server, domain, subPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,13 +6,14 @@
|
|||||||
package dan200.computercraft.shared.computer.items;
|
package dan200.computercraft.shared.computer.items;
|
||||||
|
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
import dan200.computercraft.shared.computer.blocks.AbstractComputerBlock;
|
import dan200.computercraft.shared.computer.blocks.AbstractComputerBlock;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.config.Config;
|
import dan200.computercraft.shared.config.Config;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
@ -63,12 +64,12 @@ public abstract class AbstractComputerItem extends BlockItem implements ICompute
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
|
public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) {
|
||||||
var family = getFamily();
|
var family = getFamily();
|
||||||
if (family != ComputerFamily.COMMAND) {
|
if (family != ComputerFamily.COMMAND) {
|
||||||
var id = getComputerID(stack);
|
var id = getComputerID(stack);
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
return ComputerCraftAPI.createSaveDirMount(world, "computer/" + id, Config.computerSpaceLimit);
|
return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + id, Config.computerSpaceLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -9,7 +9,7 @@ import dan200.computercraft.api.ComputerCraftAPI;
|
|||||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import dan200.computercraft.impl.PocketUpgrades;
|
import dan200.computercraft.impl.PocketUpgrades;
|
||||||
import dan200.computercraft.impl.TurtleUpgrades;
|
import dan200.computercraft.impl.TurtleUpgrades;
|
||||||
import dan200.computercraft.shared.pocket.items.PocketComputerItem;
|
import dan200.computercraft.shared.pocket.items.PocketComputerItem;
|
||||||
@ -245,7 +245,7 @@ public class UpgradeRecipeGenerator<T> {
|
|||||||
final Ingredient ingredient;
|
final Ingredient ingredient;
|
||||||
final @Nullable ITurtleUpgrade turtle;
|
final @Nullable ITurtleUpgrade turtle;
|
||||||
final @Nullable IPocketUpgrade pocket;
|
final @Nullable IPocketUpgrade pocket;
|
||||||
final IUpgradeBase upgrade;
|
final UpgradeBase upgrade;
|
||||||
private @Nullable ArrayList<T> recipes;
|
private @Nullable ArrayList<T> recipes;
|
||||||
|
|
||||||
UpgradeInfo(ItemStack stack, ITurtleUpgrade turtle) {
|
UpgradeInfo(ItemStack stack, ITurtleUpgrade turtle) {
|
||||||
|
@ -7,7 +7,7 @@ package dan200.computercraft.shared.media.items;
|
|||||||
|
|
||||||
import dan200.computercraft.annotations.ForgeOverride;
|
import dan200.computercraft.annotations.ForgeOverride;
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
import dan200.computercraft.core.util.Colour;
|
import dan200.computercraft.core.util.Colour;
|
||||||
import dan200.computercraft.shared.ModRegistry;
|
import dan200.computercraft.shared.ModRegistry;
|
||||||
@ -17,6 +17,7 @@ import net.minecraft.ChatFormatting;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.NonNullList;
|
import net.minecraft.core.NonNullList;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
@ -83,13 +84,13 @@ public class DiskItem extends Item implements IMedia, IColouredItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
|
public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) {
|
||||||
var diskID = getDiskID(stack);
|
var diskID = getDiskID(stack);
|
||||||
if (diskID < 0) {
|
if (diskID < 0) {
|
||||||
diskID = ComputerCraftAPI.createUniqueNumberedSaveDir(world, "disk");
|
diskID = ComputerCraftAPI.createUniqueNumberedSaveDir(level.getServer(), "disk");
|
||||||
setDiskID(stack, diskID);
|
setDiskID(stack, diskID);
|
||||||
}
|
}
|
||||||
return ComputerCraftAPI.createSaveDirMount(world, "disk/" + diskID, Config.floppySpaceLimit);
|
return ComputerCraftAPI.createSaveDirMount(level.getServer(), "disk/" + diskID, Config.floppySpaceLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDiskID(ItemStack stack) {
|
public static int getDiskID(ItemStack stack) {
|
||||||
|
@ -7,7 +7,7 @@ package dan200.computercraft.shared.media.items;
|
|||||||
|
|
||||||
import dan200.computercraft.annotations.ForgeOverride;
|
import dan200.computercraft.annotations.ForgeOverride;
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
import dan200.computercraft.core.filesystem.SubMount;
|
import dan200.computercraft.core.filesystem.SubMount;
|
||||||
import dan200.computercraft.core.util.Colour;
|
import dan200.computercraft.core.util.Colour;
|
||||||
@ -15,6 +15,7 @@ import dan200.computercraft.shared.ModRegistry;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.NonNullList;
|
import net.minecraft.core.NonNullList;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
@ -57,8 +58,8 @@ public class TreasureDiskItem extends Item implements IMedia {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
|
public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) {
|
||||||
var rootTreasure = getTreasureMount();
|
var rootTreasure = ComputerCraftAPI.createResourceMount(level.getServer(), "computercraft", "lua/treasure");
|
||||||
if (rootTreasure == null) return null;
|
if (rootTreasure == null) return null;
|
||||||
|
|
||||||
var subPath = getSubPath(stack);
|
var subPath = getSubPath(stack);
|
||||||
@ -93,10 +94,6 @@ public class TreasureDiskItem extends Item implements IMedia {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable IMount getTreasureMount() {
|
|
||||||
return ComputerCraftAPI.createResourceMount("computercraft", "lua/treasure");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getTitle(ItemStack stack) {
|
private static String getTitle(ItemStack stack) {
|
||||||
var nbt = stack.getTag();
|
var nbt = stack.getTag();
|
||||||
return nbt != null && nbt.contains(NBT_TITLE) ? nbt.getString(NBT_TITLE) : "'missingno' by how did you get this anyway?";
|
return nbt != null && nbt.contains(NBT_TITLE) ? nbt.getString(NBT_TITLE) : "'missingno' by how did you get this anyway?";
|
||||||
|
@ -9,7 +9,7 @@ import dan200.computercraft.api.pocket.IPocketUpgrade;
|
|||||||
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
|
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||||
import dan200.computercraft.impl.PocketUpgrades;
|
import dan200.computercraft.impl.PocketUpgrades;
|
||||||
import dan200.computercraft.impl.TurtleUpgrades;
|
import dan200.computercraft.impl.TurtleUpgrades;
|
||||||
@ -42,7 +42,7 @@ public class UpgradesLoadedMessage implements NetworkMessage<ClientNetworkContex
|
|||||||
pocketUpgrades = fromBytes(buf, PocketUpgradeSerialiser.REGISTRY_ID);
|
pocketUpgrades = fromBytes(buf, PocketUpgradeSerialiser.REGISTRY_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase> Map<String, UpgradeManager.UpgradeWrapper<R, T>> fromBytes(
|
private <R extends UpgradeSerialiser<? extends T>, T extends UpgradeBase> Map<String, UpgradeManager.UpgradeWrapper<R, T>> fromBytes(
|
||||||
FriendlyByteBuf buf, ResourceKey<Registry<R>> registryKey
|
FriendlyByteBuf buf, ResourceKey<Registry<R>> registryKey
|
||||||
) {
|
) {
|
||||||
var registry = PlatformHelper.get().wrap(registryKey);
|
var registry = PlatformHelper.get().wrap(registryKey);
|
||||||
@ -71,7 +71,7 @@ public class UpgradesLoadedMessage implements NetworkMessage<ClientNetworkContex
|
|||||||
toBytes(buf, PocketUpgradeSerialiser.REGISTRY_ID, pocketUpgrades);
|
toBytes(buf, PocketUpgradeSerialiser.REGISTRY_ID, pocketUpgrades);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase> void toBytes(
|
private <R extends UpgradeSerialiser<? extends T>, T extends UpgradeBase> void toBytes(
|
||||||
FriendlyByteBuf buf, ResourceKey<Registry<R>> registryKey, Map<String, UpgradeManager.UpgradeWrapper<R, T>> upgrades
|
FriendlyByteBuf buf, ResourceKey<Registry<R>> registryKey, Map<String, UpgradeManager.UpgradeWrapper<R, T>> upgrades
|
||||||
) {
|
) {
|
||||||
var registry = PlatformHelper.get().wrap(registryKey);
|
var registry = PlatformHelper.get().wrap(registryKey);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.shared.peripheral.diskdrive;
|
package dan200.computercraft.shared.peripheral.diskdrive;
|
||||||
|
|
||||||
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.WritableMount;
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.shared.common.AbstractContainerBlockEntity;
|
import dan200.computercraft.shared.common.AbstractContainerBlockEntity;
|
||||||
@ -205,7 +205,7 @@ public final class DiskDriveBlockEntity extends AbstractContainerBlockEntity {
|
|||||||
private void mountDisk(IComputerAccess computer, MountInfo info, MediaStack disk) {
|
private void mountDisk(IComputerAccess computer, MountInfo info, MediaStack disk) {
|
||||||
var mount = disk.getMount((ServerLevel) getLevel());
|
var mount = disk.getMount((ServerLevel) getLevel());
|
||||||
if (mount != null) {
|
if (mount != null) {
|
||||||
if (mount instanceof IWritableMount writable) {
|
if (mount instanceof WritableMount writable) {
|
||||||
// Try mounting at the lowest numbered "disk" name we can
|
// Try mounting at the lowest numbered "disk" name we can
|
||||||
var n = 1;
|
var n = 1;
|
||||||
while (info.mountPath == null) {
|
while (info.mountPath == null) {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.peripheral.diskdrive;
|
package dan200.computercraft.shared.peripheral.diskdrive;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
import dan200.computercraft.impl.MediaProviders;
|
import dan200.computercraft.impl.MediaProviders;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
@ -24,7 +24,7 @@ class MediaStack {
|
|||||||
final @Nullable IMedia media;
|
final @Nullable IMedia media;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private IMount mount;
|
private Mount mount;
|
||||||
|
|
||||||
MediaStack(ItemStack stack) {
|
MediaStack(ItemStack stack) {
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
@ -42,7 +42,7 @@ class MediaStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public IMount getMount(ServerLevel level) {
|
public Mount getMount(ServerLevel level) {
|
||||||
if (media == null) return null;
|
if (media == null) return null;
|
||||||
|
|
||||||
if (mount == null) mount = media.createDataMount(stack, level);
|
if (mount == null) mount = media.createDataMount(stack, level);
|
||||||
|
@ -7,10 +7,10 @@ package dan200.computercraft.shared.peripheral.modem;
|
|||||||
|
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
import dan200.computercraft.api.lua.LuaFunction;
|
import dan200.computercraft.api.lua.LuaFunction;
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
|
||||||
import dan200.computercraft.api.network.IPacketReceiver;
|
|
||||||
import dan200.computercraft.api.network.IPacketSender;
|
|
||||||
import dan200.computercraft.api.network.Packet;
|
import dan200.computercraft.api.network.Packet;
|
||||||
|
import dan200.computercraft.api.network.PacketNetwork;
|
||||||
|
import dan200.computercraft.api.network.PacketReceiver;
|
||||||
|
import dan200.computercraft.api.network.PacketSender;
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
|
||||||
@ -83,8 +83,8 @@ import java.util.Set;
|
|||||||
* <mc-recipe recipe="computercraft:wired_modem_full_from"></mc-recipe>
|
* <mc-recipe recipe="computercraft:wired_modem_full_from"></mc-recipe>
|
||||||
* </div>
|
* </div>
|
||||||
*/
|
*/
|
||||||
public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPacketReceiver {
|
public abstract class ModemPeripheral implements IPeripheral, PacketSender, PacketReceiver {
|
||||||
private @Nullable IPacketNetwork network;
|
private @Nullable PacketNetwork network;
|
||||||
private final Set<IComputerAccess> computers = new HashSet<>(1);
|
private final Set<IComputerAccess> computers = new HashSet<>(1);
|
||||||
private final ModemState state;
|
private final ModemState state;
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void setNetwork(@Nullable IPacketNetwork network) {
|
private synchronized void setNetwork(@Nullable PacketNetwork network) {
|
||||||
if (this.network == network) return;
|
if (this.network == network) return;
|
||||||
|
|
||||||
// Leave old network
|
// Leave old network
|
||||||
@ -137,7 +137,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract IPacketNetwork getNetwork();
|
protected abstract PacketNetwork getNetwork();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
package dan200.computercraft.shared.peripheral.modem.wired;
|
package dan200.computercraft.shared.peripheral.modem.wired;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.shared.ModRegistry;
|
import dan200.computercraft.shared.ModRegistry;
|
||||||
import dan200.computercraft.shared.command.text.ChatHelpers;
|
import dan200.computercraft.shared.command.text.ChatHelpers;
|
||||||
@ -67,7 +67,7 @@ public class CableBlockEntity extends BlockEntity {
|
|||||||
private boolean connectionsFormed = false;
|
private boolean connectionsFormed = false;
|
||||||
|
|
||||||
private final WiredModemElement cable = new CableElement();
|
private final WiredModemElement cable = new CableElement();
|
||||||
private final IWiredNode node = cable.getNode();
|
private final WiredNode node = cable.getNode();
|
||||||
private final TickScheduler.Token tickToken = new TickScheduler.Token(this);
|
private final TickScheduler.Token tickToken = new TickScheduler.Token(this);
|
||||||
private final WiredModemPeripheral modem = new WiredModemPeripheral(
|
private final WiredModemPeripheral modem = new WiredModemPeripheral(
|
||||||
new ModemState(() -> TickScheduler.schedule(tickToken)),
|
new ModemState(() -> TickScheduler.schedule(tickToken)),
|
||||||
@ -89,7 +89,7 @@ public class CableBlockEntity extends BlockEntity {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final ComponentAccess<IWiredElement> connectedElements = PlatformHelper.get().createWiredElementAccess(x -> connectionsChanged());
|
private final ComponentAccess<WiredElement> connectedElements = PlatformHelper.get().createWiredElementAccess(x -> connectionsChanged());
|
||||||
|
|
||||||
public CableBlockEntity(BlockEntityType<? extends CableBlockEntity> type, BlockPos pos, BlockState state) {
|
public CableBlockEntity(BlockEntityType<? extends CableBlockEntity> type, BlockPos pos, BlockState state) {
|
||||||
super(type, pos, state);
|
super(type, pos, state);
|
||||||
@ -309,7 +309,7 @@ public class CableBlockEntity extends BlockEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public IWiredElement getWiredElement(@Nullable Direction direction) {
|
public WiredElement getWiredElement(@Nullable Direction direction) {
|
||||||
return direction == null || CableBlock.canConnectIn(getBlockState(), direction) ? cable : null;
|
return direction == null || CableBlock.canConnectIn(getBlockState(), direction) ? cable : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,20 +6,20 @@
|
|||||||
package dan200.computercraft.shared.peripheral.modem.wired;
|
package dan200.computercraft.shared.peripheral.modem.wired;
|
||||||
|
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNetworkChange;
|
import dan200.computercraft.api.network.wired.WiredNetworkChange;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class WiredModemElement implements IWiredElement {
|
public abstract class WiredModemElement implements WiredElement {
|
||||||
private final IWiredNode node = ComputerCraftAPI.createWiredNodeForElement(this);
|
private final WiredNode node = ComputerCraftAPI.createWiredNodeForElement(this);
|
||||||
private final Map<String, IPeripheral> remotePeripherals = new HashMap<>();
|
private final Map<String, IPeripheral> remotePeripherals = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IWiredNode getNode() {
|
public WiredNode getNode() {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ public abstract class WiredModemElement implements IWiredElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void networkChanged(IWiredNetworkChange change) {
|
public void networkChanged(WiredNetworkChange change) {
|
||||||
synchronized (remotePeripherals) {
|
synchronized (remotePeripherals) {
|
||||||
remotePeripherals.keySet().removeAll(change.peripheralsRemoved().keySet());
|
remotePeripherals.keySet().removeAll(change.peripheralsRemoved().keySet());
|
||||||
for (var name : change.peripheralsRemoved().keySet()) {
|
for (var name : change.peripheralsRemoved().keySet()) {
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
package dan200.computercraft.shared.peripheral.modem.wired;
|
package dan200.computercraft.shared.peripheral.modem.wired;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.shared.command.text.ChatHelpers;
|
import dan200.computercraft.shared.command.text.ChatHelpers;
|
||||||
import dan200.computercraft.shared.peripheral.modem.ModemState;
|
import dan200.computercraft.shared.peripheral.modem.ModemState;
|
||||||
@ -81,9 +81,9 @@ public class WiredModemFullBlockEntity extends BlockEntity {
|
|||||||
private final TickScheduler.Token tickToken = new TickScheduler.Token(this);
|
private final TickScheduler.Token tickToken = new TickScheduler.Token(this);
|
||||||
private final ModemState modemState = new ModemState(() -> TickScheduler.schedule(tickToken));
|
private final ModemState modemState = new ModemState(() -> TickScheduler.schedule(tickToken));
|
||||||
private final WiredModemElement element = new FullElement(this);
|
private final WiredModemElement element = new FullElement(this);
|
||||||
private final IWiredNode node = element.getNode();
|
private final WiredNode node = element.getNode();
|
||||||
|
|
||||||
private final ComponentAccess<IWiredElement> connectedElements = PlatformHelper.get().createWiredElementAccess(x -> connectionsChanged());
|
private final ComponentAccess<WiredElement> connectedElements = PlatformHelper.get().createWiredElementAccess(x -> connectionsChanged());
|
||||||
|
|
||||||
private int invalidSides = 0;
|
private int invalidSides = 0;
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ public class WiredModemFullBlockEntity extends BlockEntity {
|
|||||||
node.updatePeripherals(peripherals);
|
node.updatePeripherals(peripherals);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IWiredElement getElement() {
|
public WiredElement getElement() {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,16 +6,16 @@
|
|||||||
package dan200.computercraft.shared.peripheral.modem.wired;
|
package dan200.computercraft.shared.peripheral.modem.wired;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.WritableMount;
|
||||||
import dan200.computercraft.api.lua.*;
|
import dan200.computercraft.api.lua.*;
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
import dan200.computercraft.api.network.PacketNetwork;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
import dan200.computercraft.api.network.wired.IWiredSender;
|
import dan200.computercraft.api.network.wired.WiredSender;
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
|
||||||
import dan200.computercraft.api.peripheral.NotAttachedException;
|
import dan200.computercraft.api.peripheral.NotAttachedException;
|
||||||
|
import dan200.computercraft.api.peripheral.WorkMonitor;
|
||||||
import dan200.computercraft.core.apis.PeripheralAPI;
|
import dan200.computercraft.core.apis.PeripheralAPI;
|
||||||
import dan200.computercraft.core.asm.PeripheralMethod;
|
import dan200.computercraft.core.asm.PeripheralMethod;
|
||||||
import dan200.computercraft.core.util.LuaUtil;
|
import dan200.computercraft.core.util.LuaUtil;
|
||||||
@ -30,7 +30,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
public abstract class WiredModemPeripheral extends ModemPeripheral implements IWiredSender {
|
public abstract class WiredModemPeripheral extends ModemPeripheral implements WiredSender {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(WiredModemPeripheral.class);
|
private static final Logger LOG = LoggerFactory.getLogger(WiredModemPeripheral.class);
|
||||||
|
|
||||||
private final WiredModemElement modem;
|
private final WiredModemElement modem;
|
||||||
@ -54,7 +54,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IPacketNetwork getNetwork() {
|
protected PacketNetwork getNetwork() {
|
||||||
return modem.getNode();
|
return modem.getNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
|||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IWiredNode getNode() {
|
public WiredNode getNode() {
|
||||||
return modem.getNode();
|
return modem.getNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +368,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
|||||||
// IComputerAccess implementation
|
// IComputerAccess implementation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized @Nullable String mount(String desiredLocation, IMount mount) {
|
public synchronized @Nullable String mount(String desiredLocation, Mount mount) {
|
||||||
if (!attached) throw new NotAttachedException();
|
if (!attached) throw new NotAttachedException();
|
||||||
var mounted = computer.mount(desiredLocation, mount, name);
|
var mounted = computer.mount(desiredLocation, mount, name);
|
||||||
mounts.add(mounted);
|
mounts.add(mounted);
|
||||||
@ -376,7 +376,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized @Nullable String mount(String desiredLocation, IMount mount, String driveName) {
|
public synchronized @Nullable String mount(String desiredLocation, Mount mount, String driveName) {
|
||||||
if (!attached) throw new NotAttachedException();
|
if (!attached) throw new NotAttachedException();
|
||||||
var mounted = computer.mount(desiredLocation, mount, driveName);
|
var mounted = computer.mount(desiredLocation, mount, driveName);
|
||||||
mounts.add(mounted);
|
mounts.add(mounted);
|
||||||
@ -384,7 +384,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized @Nullable String mountWritable(String desiredLocation, IWritableMount mount) {
|
public synchronized @Nullable String mountWritable(String desiredLocation, WritableMount mount) {
|
||||||
if (!attached) throw new NotAttachedException();
|
if (!attached) throw new NotAttachedException();
|
||||||
var mounted = computer.mountWritable(desiredLocation, mount, name);
|
var mounted = computer.mountWritable(desiredLocation, mount, name);
|
||||||
mounts.add(mounted);
|
mounts.add(mounted);
|
||||||
@ -392,7 +392,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized @Nullable String mountWritable(String desiredLocation, IWritableMount mount, String driveName) {
|
public synchronized @Nullable String mountWritable(String desiredLocation, WritableMount mount, String driveName) {
|
||||||
if (!attached) throw new NotAttachedException();
|
if (!attached) throw new NotAttachedException();
|
||||||
var mounted = computer.mountWritable(desiredLocation, mount, driveName);
|
var mounted = computer.mountWritable(desiredLocation, mount, driveName);
|
||||||
mounts.add(mounted);
|
mounts.add(mounted);
|
||||||
@ -419,7 +419,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IWorkMonitor getMainThreadMonitor() {
|
public WorkMonitor getMainThreadMonitor() {
|
||||||
if (!attached) throw new NotAttachedException();
|
if (!attached) throw new NotAttachedException();
|
||||||
return computer.getMainThreadMonitor();
|
return computer.getMainThreadMonitor();
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
package dan200.computercraft.shared.peripheral.modem.wireless;
|
package dan200.computercraft.shared.peripheral.modem.wireless;
|
||||||
|
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
import dan200.computercraft.api.network.PacketNetwork;
|
||||||
|
import dan200.computercraft.core.util.Nullability;
|
||||||
import dan200.computercraft.shared.config.Config;
|
import dan200.computercraft.shared.config.Config;
|
||||||
import dan200.computercraft.shared.peripheral.modem.ModemPeripheral;
|
import dan200.computercraft.shared.peripheral.modem.ModemPeripheral;
|
||||||
import dan200.computercraft.shared.peripheral.modem.ModemState;
|
import dan200.computercraft.shared.peripheral.modem.ModemState;
|
||||||
@ -51,7 +52,7 @@ public abstract class WirelessModemPeripheral extends ModemPeripheral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IPacketNetwork getNetwork() {
|
protected PacketNetwork getNetwork() {
|
||||||
return ComputerCraftAPI.getWirelessNetwork();
|
return ComputerCraftAPI.getWirelessNetwork(Nullability.assertNonNull(getLevel().getServer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.peripheral.modem.wireless;
|
package dan200.computercraft.shared.peripheral.modem.wireless;
|
||||||
|
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
|
||||||
import dan200.computercraft.api.network.IPacketReceiver;
|
|
||||||
import dan200.computercraft.api.network.Packet;
|
import dan200.computercraft.api.network.Packet;
|
||||||
|
import dan200.computercraft.api.network.PacketNetwork;
|
||||||
|
import dan200.computercraft.api.network.PacketReceiver;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -15,7 +15,7 @@ import java.util.Objects;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class WirelessNetwork implements IPacketNetwork {
|
public class WirelessNetwork implements PacketNetwork {
|
||||||
// TODO: Move this to ServerContext.
|
// TODO: Move this to ServerContext.
|
||||||
private static @Nullable WirelessNetwork universalNetwork = null;
|
private static @Nullable WirelessNetwork universalNetwork = null;
|
||||||
|
|
||||||
@ -28,16 +28,16 @@ public class WirelessNetwork implements IPacketNetwork {
|
|||||||
universalNetwork = null;
|
universalNetwork = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Set<IPacketReceiver> receivers = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
private final Set<PacketReceiver> receivers = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addReceiver(IPacketReceiver receiver) {
|
public void addReceiver(PacketReceiver receiver) {
|
||||||
Objects.requireNonNull(receiver, "device cannot be null");
|
Objects.requireNonNull(receiver, "device cannot be null");
|
||||||
receivers.add(receiver);
|
receivers.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeReceiver(IPacketReceiver receiver) {
|
public void removeReceiver(PacketReceiver receiver) {
|
||||||
Objects.requireNonNull(receiver, "device cannot be null");
|
Objects.requireNonNull(receiver, "device cannot be null");
|
||||||
receivers.remove(receiver);
|
receivers.remove(receiver);
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ public class WirelessNetwork implements IPacketNetwork {
|
|||||||
for (var device : receivers) tryTransmit(device, packet, 0, true);
|
for (var device : receivers) tryTransmit(device, packet, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void tryTransmit(IPacketReceiver receiver, Packet packet, double range, boolean interdimensional) {
|
private static void tryTransmit(PacketReceiver receiver, Packet packet, double range, boolean interdimensional) {
|
||||||
var sender = packet.sender();
|
var sender = packet.sender();
|
||||||
if (receiver.getLevel() == sender.getLevel()) {
|
if (receiver.getLevel() == sender.getLevel()) {
|
||||||
var receiveRange = Math.max(range, receiver.getRange()); // Ensure range is symmetrical
|
var receiveRange = Math.max(range, receiver.getRange()); // Ensure range is symmetrical
|
||||||
|
@ -7,7 +7,7 @@ package dan200.computercraft.shared.platform;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.shared.network.NetworkMessage;
|
import dan200.computercraft.shared.network.NetworkMessage;
|
||||||
import dan200.computercraft.shared.network.client.ClientNetworkContext;
|
import dan200.computercraft.shared.network.client.ClientNetworkContext;
|
||||||
@ -45,7 +45,6 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -204,7 +203,7 @@ public interface PlatformHelper extends dan200.computercraft.impl.PlatformHelper
|
|||||||
* include all changes, and so block updates should still be listened to.
|
* include all changes, and so block updates should still be listened to.
|
||||||
* @return The peripheral component access.
|
* @return The peripheral component access.
|
||||||
*/
|
*/
|
||||||
ComponentAccess<IWiredElement> createWiredElementAccess(Consumer<Direction> invalidate);
|
ComponentAccess<WiredElement> createWiredElementAccess(Consumer<Direction> invalidate);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if there is a wired element in the given direction. This is equivalent to
|
* Determine if there is a wired element in the given direction. This is equivalent to
|
||||||
@ -239,18 +238,6 @@ public interface PlatformHelper extends dan200.computercraft.impl.PlatformHelper
|
|||||||
@Nullable
|
@Nullable
|
||||||
ContainerTransfer getContainer(ServerLevel level, BlockPos pos, Direction side);
|
ContainerTransfer getContainer(ServerLevel level, BlockPos pos, Direction side);
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrap a vanilla Minecraft {@link Container} into Forge's {@link IItemHandlerModifiable}.
|
|
||||||
*
|
|
||||||
* @param container The container to wrap.
|
|
||||||
* @return The item handler.
|
|
||||||
* @deprecated This is only needed for backwards compatibility, and will be removed in 1.19.3.
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
default IItemHandlerModifiable wrapContainerToItemHandler(Container container) {
|
|
||||||
throw new UnsupportedOperationException("Can only create IItemHandlerModifiable on Forge");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link RecipeIngredients} for this loader.
|
* Get the {@link RecipeIngredients} for this loader.
|
||||||
*
|
*
|
||||||
|
@ -8,7 +8,7 @@ package dan200.computercraft.shared.pocket.items;
|
|||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import dan200.computercraft.annotations.ForgeOverride;
|
import dan200.computercraft.annotations.ForgeOverride;
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
import dan200.computercraft.core.computer.ComputerSide;
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
@ -192,21 +192,19 @@ public class PocketComputerItem extends Item implements IComputerItem, IMedia, I
|
|||||||
return ComputerCraftAPI.MOD_ID;
|
return ComputerCraftAPI.MOD_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PocketServerComputer createServerComputer(ServerLevel world, Entity entity, @Nullable Container inventory, ItemStack stack) {
|
public PocketServerComputer createServerComputer(ServerLevel level, Entity entity, @Nullable Container inventory, ItemStack stack) {
|
||||||
if (world.isClientSide) throw new IllegalStateException("Cannot call createServerComputer on the client");
|
|
||||||
|
|
||||||
var sessionID = getSessionID(stack);
|
var sessionID = getSessionID(stack);
|
||||||
|
|
||||||
var registry = ServerContext.get(world.getServer()).registry();
|
var registry = ServerContext.get(level.getServer()).registry();
|
||||||
var computer = (PocketServerComputer) registry.get(sessionID, getInstanceID(stack));
|
var computer = (PocketServerComputer) registry.get(sessionID, getInstanceID(stack));
|
||||||
if (computer == null) {
|
if (computer == null) {
|
||||||
var computerID = getComputerID(stack);
|
var computerID = getComputerID(stack);
|
||||||
if (computerID < 0) {
|
if (computerID < 0) {
|
||||||
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(world, IDAssigner.COMPUTER);
|
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level.getServer(), IDAssigner.COMPUTER);
|
||||||
setComputerID(stack, computerID);
|
setComputerID(stack, computerID);
|
||||||
}
|
}
|
||||||
|
|
||||||
computer = new PocketServerComputer(world, entity.blockPosition(), getComputerID(stack), getLabel(stack), getFamily());
|
computer = new PocketServerComputer(level, entity.blockPosition(), getComputerID(stack), getLabel(stack), getFamily());
|
||||||
|
|
||||||
setInstanceID(stack, computer.register());
|
setInstanceID(stack, computer.register());
|
||||||
setSessionID(stack, registry.getSessionID());
|
setSessionID(stack, registry.getSessionID());
|
||||||
@ -219,7 +217,7 @@ public class PocketComputerItem extends Item implements IComputerItem, IMedia, I
|
|||||||
|
|
||||||
if (inventory != null) inventory.setChanged();
|
if (inventory != null) inventory.setChanged();
|
||||||
}
|
}
|
||||||
computer.setLevel(world);
|
computer.setLevel(level);
|
||||||
return computer;
|
return computer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,10 +263,10 @@ public class PocketComputerItem extends Item implements IComputerItem, IMedia, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
|
public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) {
|
||||||
var id = getComputerID(stack);
|
var id = getComputerID(stack);
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
return ComputerCraftAPI.createSaveDirMount(world, "computer/" + id, Config.computerSpaceLimit);
|
return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + id, Config.computerSpaceLimit);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ package dan200.computercraft.shared.turtle.apis;
|
|||||||
import dan200.computercraft.api.detail.VanillaDetailRegistries;
|
import dan200.computercraft.api.detail.VanillaDetailRegistries;
|
||||||
import dan200.computercraft.api.lua.*;
|
import dan200.computercraft.api.lua.*;
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||||
@ -82,7 +82,7 @@ public class TurtleAPI implements ILuaAPI {
|
|||||||
return new String[]{ "turtle" };
|
return new String[]{ "turtle" };
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodResult trackCommand(ITurtleCommand command) {
|
private MethodResult trackCommand(TurtleCommand command) {
|
||||||
environment.observe(Metrics.TURTLE_OPS);
|
environment.observe(Metrics.TURTLE_OPS);
|
||||||
return turtle.executeCommand(command);
|
return turtle.executeCommand(command);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
|
|||||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||||
import dan200.computercraft.shared.config.Config;
|
import dan200.computercraft.shared.config.Config;
|
||||||
import dan200.computercraft.shared.container.InventoryDelegate;
|
import dan200.computercraft.shared.container.InventoryDelegate;
|
||||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
|
||||||
import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity;
|
import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity;
|
||||||
import dan200.computercraft.shared.util.BlockEntityHelpers;
|
import dan200.computercraft.shared.util.BlockEntityHelpers;
|
||||||
import dan200.computercraft.shared.util.Holiday;
|
import dan200.computercraft.shared.util.Holiday;
|
||||||
@ -39,7 +38,6 @@ import net.minecraft.world.level.Level;
|
|||||||
import net.minecraft.world.level.material.PushReaction;
|
import net.minecraft.world.level.material.PushReaction;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -382,12 +380,6 @@ public class TurtleBrain implements ITurtleAccess {
|
|||||||
return inventory;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public IItemHandlerModifiable getItemHandler() {
|
|
||||||
return PlatformHelper.get().wrapContainerToItemHandler(inventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFuelNeeded() {
|
public boolean isFuelNeeded() {
|
||||||
return Config.turtlesNeedFuel;
|
return Config.turtlesNeedFuel;
|
||||||
@ -436,7 +428,7 @@ public class TurtleBrain implements ITurtleAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodResult executeCommand(ITurtleCommand command) {
|
public MethodResult executeCommand(TurtleCommand command) {
|
||||||
if (getLevel().isClientSide) throw new UnsupportedOperationException("Cannot run commands on the client");
|
if (getLevel().isClientSide) throw new UnsupportedOperationException("Cannot run commands on the client");
|
||||||
if (commandQueue.size() > 16) return MethodResult.of(false, "Too many ongoing turtle commands");
|
if (commandQueue.size() > 16) return MethodResult.of(false, "Too many ongoing turtle commands");
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
|
|
||||||
public record TurtleCommandQueueEntry(int callbackID, ITurtleCommand command) {
|
public record TurtleCommandQueueEntry(int callbackID, TurtleCommand command) {
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
|
||||||
public class TurtleCompareCommand implements ITurtleCommand {
|
public class TurtleCompareCommand implements TurtleCommand {
|
||||||
private final InteractDirection direction;
|
private final InteractDirection direction;
|
||||||
|
|
||||||
public TurtleCompareCommand(InteractDirection direction) {
|
public TurtleCompareCommand(InteractDirection direction) {
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
public class TurtleCompareToCommand implements ITurtleCommand {
|
public class TurtleCompareToCommand implements TurtleCommand {
|
||||||
private final int slot;
|
private final int slot;
|
||||||
|
|
||||||
public TurtleCompareToCommand(int slot) {
|
public TurtleCompareToCommand(int slot) {
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.shared.turtle.TurtleUtil;
|
import dan200.computercraft.shared.turtle.TurtleUtil;
|
||||||
import dan200.computercraft.shared.turtle.upgrades.TurtleInventoryCrafting;
|
import dan200.computercraft.shared.turtle.upgrades.TurtleInventoryCrafting;
|
||||||
|
|
||||||
public class TurtleCraftCommand implements ITurtleCommand {
|
public class TurtleCraftCommand implements TurtleCommand {
|
||||||
private final int limit;
|
private final int limit;
|
||||||
|
|
||||||
public TurtleCraftCommand(int limit) {
|
public TurtleCraftCommand(int limit) {
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
|
|
||||||
public class TurtleDetectCommand implements ITurtleCommand {
|
public class TurtleDetectCommand implements TurtleCommand {
|
||||||
private final InteractDirection direction;
|
private final InteractDirection direction;
|
||||||
|
|
||||||
public TurtleDetectCommand(InteractDirection direction) {
|
public TurtleDetectCommand(InteractDirection direction) {
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.shared.platform.ContainerTransfer;
|
import dan200.computercraft.shared.platform.ContainerTransfer;
|
||||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||||
@ -16,7 +16,7 @@ import dan200.computercraft.shared.util.WorldUtil;
|
|||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.block.LevelEvent;
|
import net.minecraft.world.level.block.LevelEvent;
|
||||||
|
|
||||||
public class TurtleDropCommand implements ITurtleCommand {
|
public class TurtleDropCommand implements TurtleCommand {
|
||||||
private final InteractDirection direction;
|
private final InteractDirection direction;
|
||||||
private final int quantity;
|
private final int quantity;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import dan200.computercraft.impl.TurtleUpgrades;
|
|||||||
import dan200.computercraft.shared.turtle.TurtleUtil;
|
import dan200.computercraft.shared.turtle.TurtleUtil;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
public class TurtleEquipCommand implements ITurtleCommand {
|
public class TurtleEquipCommand implements TurtleCommand {
|
||||||
private final TurtleSide side;
|
private final TurtleSide side;
|
||||||
|
|
||||||
public TurtleEquipCommand(TurtleSide side) {
|
public TurtleEquipCommand(TurtleSide side) {
|
||||||
|
@ -8,10 +8,10 @@ package dan200.computercraft.shared.turtle.core;
|
|||||||
import dan200.computercraft.api.detail.BlockReference;
|
import dan200.computercraft.api.detail.BlockReference;
|
||||||
import dan200.computercraft.api.detail.VanillaDetailRegistries;
|
import dan200.computercraft.api.detail.VanillaDetailRegistries;
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
|
|
||||||
public class TurtleInspectCommand implements ITurtleCommand {
|
public class TurtleInspectCommand implements TurtleCommand {
|
||||||
private final InteractDirection direction;
|
private final InteractDirection direction;
|
||||||
|
|
||||||
public TurtleInspectCommand(InteractDirection direction) {
|
public TurtleInspectCommand(InteractDirection direction) {
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.shared.config.Config;
|
import dan200.computercraft.shared.config.Config;
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
@ -18,7 +18,7 @@ import net.minecraft.world.phys.AABB;
|
|||||||
import net.minecraft.world.phys.shapes.Shapes;
|
import net.minecraft.world.phys.shapes.Shapes;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
|
||||||
public class TurtleMoveCommand implements ITurtleCommand {
|
public class TurtleMoveCommand implements TurtleCommand {
|
||||||
private final MoveDirection direction;
|
private final MoveDirection direction;
|
||||||
|
|
||||||
public TurtleMoveCommand(MoveDirection direction) {
|
public TurtleMoveCommand(MoveDirection direction) {
|
||||||
|
@ -7,8 +7,8 @@ package dan200.computercraft.shared.turtle.core;
|
|||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||||
import dan200.computercraft.shared.turtle.TurtleUtil;
|
import dan200.computercraft.shared.turtle.TurtleUtil;
|
||||||
@ -36,7 +36,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class TurtlePlaceCommand implements ITurtleCommand {
|
public class TurtlePlaceCommand implements TurtleCommand {
|
||||||
private final InteractDirection direction;
|
private final InteractDirection direction;
|
||||||
private final Object[] extraArguments;
|
private final Object[] extraArguments;
|
||||||
|
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.impl.TurtleRefuelHandlers;
|
import dan200.computercraft.impl.TurtleRefuelHandlers;
|
||||||
|
|
||||||
public class TurtleRefuelCommand implements ITurtleCommand {
|
public class TurtleRefuelCommand implements TurtleCommand {
|
||||||
private final int limit;
|
private final int limit;
|
||||||
|
|
||||||
public TurtleRefuelCommand(int limit) {
|
public TurtleRefuelCommand(int limit) {
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.shared.platform.ContainerTransfer;
|
import dan200.computercraft.shared.platform.ContainerTransfer;
|
||||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||||
@ -20,7 +20,7 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.level.block.LevelEvent;
|
import net.minecraft.world.level.block.LevelEvent;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
|
|
||||||
public class TurtleSuckCommand implements ITurtleCommand {
|
public class TurtleSuckCommand implements TurtleCommand {
|
||||||
private final InteractDirection direction;
|
private final InteractDirection direction;
|
||||||
private final int quantity;
|
private final int quantity;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import dan200.computercraft.api.turtle.*;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class TurtleToolCommand implements ITurtleCommand {
|
public class TurtleToolCommand implements TurtleCommand {
|
||||||
private final TurtleVerb verb;
|
private final TurtleVerb verb;
|
||||||
private final InteractDirection direction;
|
private final InteractDirection direction;
|
||||||
private final @Nullable TurtleSide side;
|
private final @Nullable TurtleSide side;
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import dan200.computercraft.shared.util.InventoryUtil;
|
import dan200.computercraft.shared.util.InventoryUtil;
|
||||||
|
|
||||||
public class TurtleTransferToCommand implements ITurtleCommand {
|
public class TurtleTransferToCommand implements TurtleCommand {
|
||||||
private final int slot;
|
private final int slot;
|
||||||
private final int quantity;
|
private final int quantity;
|
||||||
|
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
package dan200.computercraft.shared.turtle.core;
|
package dan200.computercraft.shared.turtle.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||||
|
import dan200.computercraft.api.turtle.TurtleCommand;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
|
|
||||||
public class TurtleTurnCommand implements ITurtleCommand {
|
public class TurtleTurnCommand implements TurtleCommand {
|
||||||
private final TurnDirection direction;
|
private final TurnDirection direction;
|
||||||
|
|
||||||
public TurtleTurnCommand(TurnDirection direction) {
|
public TurtleTurnCommand(TurnDirection direction) {
|
||||||
|
@ -7,7 +7,7 @@ package dan200.computercraft.shared.turtle.upgrades;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
||||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
import dan200.computercraft.api.upgrades.UpgradeBase;
|
||||||
import dan200.computercraft.shared.platform.Registries;
|
import dan200.computercraft.shared.platform.Registries;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
@ -25,7 +25,7 @@ public final class TurtleToolSerialiser implements TurtleUpgradeSerialiser<Turtl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TurtleTool fromJson(ResourceLocation id, JsonObject object) {
|
public TurtleTool fromJson(ResourceLocation id, JsonObject object) {
|
||||||
var adjective = GsonHelper.getAsString(object, "adjective", IUpgradeBase.getDefaultAdjective(id));
|
var adjective = GsonHelper.getAsString(object, "adjective", UpgradeBase.getDefaultAdjective(id));
|
||||||
var toolItem = GsonHelper.getAsItem(object, "item");
|
var toolItem = GsonHelper.getAsItem(object, "item");
|
||||||
var craftingItem = GsonHelper.getAsItem(object, "craftingItem", toolItem);
|
var craftingItem = GsonHelper.getAsItem(object, "craftingItem", toolItem);
|
||||||
var damageMultiplier = GsonHelper.getAsFloat(object, "damageMultiplier", 3.0f);
|
var damageMultiplier = GsonHelper.getAsFloat(object, "damageMultiplier", 3.0f);
|
||||||
|
@ -8,8 +8,8 @@ package dan200.computercraft;
|
|||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.impl.AbstractComputerCraftAPI;
|
import dan200.computercraft.impl.AbstractComputerCraftAPI;
|
||||||
import dan200.computercraft.impl.ComputerCraftAPIService;
|
import dan200.computercraft.impl.ComputerCraftAPIService;
|
||||||
@ -139,7 +139,7 @@ public class TestPlatformHelper extends AbstractComputerCraftAPI implements Plat
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ComponentAccess<IWiredElement> createWiredElementAccess(Consumer<Direction> invalidate) {
|
public ComponentAccess<WiredElement> createWiredElementAccess(Consumer<Direction> invalidate) {
|
||||||
throw new UnsupportedOperationException("Cannot interact with the world inside tests");
|
throw new UnsupportedOperationException("Cannot interact with the world inside tests");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ public class TestPlatformHelper extends AbstractComputerCraftAPI implements Plat
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public IMount createResourceMount(String domain, String subPath) {
|
public Mount createResourceMount(MinecraftServer server, String domain, String subPath) {
|
||||||
throw new UnsupportedOperationException("Cannot create resource mount");
|
throw new UnsupportedOperationException("Cannot create resource mount");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,10 @@ package dan200.computercraft.impl.network.wired;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
import dan200.computercraft.api.network.wired.WiredElement;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNetwork;
|
import dan200.computercraft.api.network.wired.WiredNetwork;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNetworkChange;
|
import dan200.computercraft.api.network.wired.WiredNetworkChange;
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
import dan200.computercraft.api.network.wired.WiredNode;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.shared.util.DirectionUtil;
|
import dan200.computercraft.shared.util.DirectionUtil;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
@ -36,7 +36,7 @@ public class NetworkTest {
|
|||||||
bE = new NetworkElement(null, null, "b"),
|
bE = new NetworkElement(null, null, "b"),
|
||||||
cE = new NetworkElement(null, null, "c");
|
cE = new NetworkElement(null, null, "c");
|
||||||
|
|
||||||
IWiredNode
|
WiredNode
|
||||||
aN = aE.getNode(),
|
aN = aE.getNode(),
|
||||||
bN = bE.getNode(),
|
bN = bE.getNode(),
|
||||||
cN = cE.getNode();
|
cN = cE.getNode();
|
||||||
@ -76,7 +76,7 @@ public class NetworkTest {
|
|||||||
bE = new NetworkElement(null, null, "b"),
|
bE = new NetworkElement(null, null, "b"),
|
||||||
cE = new NetworkElement(null, null, "c");
|
cE = new NetworkElement(null, null, "c");
|
||||||
|
|
||||||
IWiredNode
|
WiredNode
|
||||||
aN = aE.getNode(),
|
aN = aE.getNode(),
|
||||||
bN = bE.getNode(),
|
bN = bE.getNode(),
|
||||||
cN = cE.getNode();
|
cN = cE.getNode();
|
||||||
@ -103,7 +103,7 @@ public class NetworkTest {
|
|||||||
bE = new NetworkElement(null, null, "b"),
|
bE = new NetworkElement(null, null, "b"),
|
||||||
cE = new NetworkElement(null, null, "c");
|
cE = new NetworkElement(null, null, "c");
|
||||||
|
|
||||||
IWiredNode
|
WiredNode
|
||||||
aN = aE.getNode(),
|
aN = aE.getNode(),
|
||||||
bN = bE.getNode(),
|
bN = bE.getNode(),
|
||||||
cN = cE.getNode();
|
cN = cE.getNode();
|
||||||
@ -131,7 +131,7 @@ public class NetworkTest {
|
|||||||
bE = new NetworkElement(null, null, "b"),
|
bE = new NetworkElement(null, null, "b"),
|
||||||
bbE = new NetworkElement(null, null, "b_");
|
bbE = new NetworkElement(null, null, "b_");
|
||||||
|
|
||||||
IWiredNode
|
WiredNode
|
||||||
aN = aE.getNode(),
|
aN = aE.getNode(),
|
||||||
aaN = aaE.getNode(),
|
aaN = aaE.getNode(),
|
||||||
bN = bE.getNode(),
|
bN = bE.getNode(),
|
||||||
@ -172,7 +172,7 @@ public class NetworkTest {
|
|||||||
bE = new NetworkElement(null, null, "b"),
|
bE = new NetworkElement(null, null, "b"),
|
||||||
cE = new NetworkElement(null, null, "c");
|
cE = new NetworkElement(null, null, "c");
|
||||||
|
|
||||||
IWiredNode
|
WiredNode
|
||||||
aN = aE.getNode(),
|
aN = aE.getNode(),
|
||||||
bN = bE.getNode(),
|
bN = bE.getNode(),
|
||||||
cN = cE.getNode();
|
cN = cE.getNode();
|
||||||
@ -203,7 +203,7 @@ public class NetworkTest {
|
|||||||
bbE = new NetworkElement(null, null, "b_"),
|
bbE = new NetworkElement(null, null, "b_"),
|
||||||
cE = new NetworkElement(null, null, "c");
|
cE = new NetworkElement(null, null, "c");
|
||||||
|
|
||||||
IWiredNode
|
WiredNode
|
||||||
aN = aE.getNode(),
|
aN = aE.getNode(),
|
||||||
aaN = aaE.getNode(),
|
aaN = aaE.getNode(),
|
||||||
bN = bE.getNode(),
|
bN = bE.getNode(),
|
||||||
@ -238,7 +238,7 @@ public class NetworkTest {
|
|||||||
@Test
|
@Test
|
||||||
@Disabled("Takes a long time to run, mostly for stress testing")
|
@Disabled("Takes a long time to run, mostly for stress testing")
|
||||||
public void testLarge() {
|
public void testLarge() {
|
||||||
var grid = new Grid<IWiredNode>(BRUTE_SIZE);
|
var grid = new Grid<WiredNode>(BRUTE_SIZE);
|
||||||
grid.map((existing, pos) -> new NetworkElement(null, null, "n_" + pos).getNode());
|
grid.map((existing, pos) -> new NetworkElement(null, null, "n_" + pos).getNode());
|
||||||
|
|
||||||
// Test connecting
|
// Test connecting
|
||||||
@ -297,11 +297,11 @@ public class NetworkTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class NetworkElement implements IWiredElement {
|
private static final class NetworkElement implements WiredElement {
|
||||||
private final Level world;
|
private final Level world;
|
||||||
private final Vec3 position;
|
private final Vec3 position;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final IWiredNode node;
|
private final WiredNode node;
|
||||||
private final Map<String, IPeripheral> localPeripherals = Maps.newHashMap();
|
private final Map<String, IPeripheral> localPeripherals = Maps.newHashMap();
|
||||||
private final Map<String, IPeripheral> remotePeripherals = Maps.newHashMap();
|
private final Map<String, IPeripheral> remotePeripherals = Maps.newHashMap();
|
||||||
|
|
||||||
@ -334,12 +334,12 @@ public class NetworkTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IWiredNode getNode() {
|
public WiredNode getNode() {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void networkChanged(IWiredNetworkChange change) {
|
public void networkChanged(WiredNetworkChange change) {
|
||||||
remotePeripherals.keySet().removeAll(change.peripheralsRemoved().keySet());
|
remotePeripherals.keySet().removeAll(change.peripheralsRemoved().keySet());
|
||||||
remotePeripherals.putAll(change.peripheralsAdded());
|
remotePeripherals.putAll(change.peripheralsAdded());
|
||||||
}
|
}
|
||||||
@ -406,11 +406,11 @@ public class NetworkTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<WiredNode> nodes(IWiredNetwork network) {
|
private static Set<WiredNodeImpl> nodes(WiredNetwork network) {
|
||||||
return ((WiredNetwork) network).nodes;
|
return ((WiredNetworkImpl) network).nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<WiredNode> neighbours(IWiredNode node) {
|
private static Set<WiredNodeImpl> neighbours(WiredNode node) {
|
||||||
return ((WiredNode) node).neighbours;
|
return ((WiredNodeImpl) node).neighbours;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.computer.core;
|
package dan200.computercraft.shared.computer.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
import net.minecraft.server.packs.FolderPackResources;
|
import net.minecraft.server.packs.FolderPackResources;
|
||||||
import net.minecraft.server.packs.PackType;
|
import net.minecraft.server.packs.PackType;
|
||||||
@ -25,7 +25,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class ResourceMountTest {
|
public class ResourceMountTest {
|
||||||
private IMount mount;
|
private Mount mount;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
|
@ -14,7 +14,6 @@ val docApi by configurations.registering {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly(project(":mc-stubs"))
|
|
||||||
compileOnlyApi(libs.jsr305)
|
compileOnlyApi(libs.jsr305)
|
||||||
compileOnlyApi(libs.checkerFramework)
|
compileOnlyApi(libs.checkerFramework)
|
||||||
compileOnlyApi(libs.jetbrainsAnnotations)
|
compileOnlyApi(libs.jetbrainsAnnotations)
|
||||||
|
@ -11,7 +11,7 @@ import java.nio.file.attribute.FileTime;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple version of {@link BasicFileAttributes}, which provides what information a {@link IMount} already exposes.
|
* A simple version of {@link BasicFileAttributes}, which provides what information a {@link Mount} already exposes.
|
||||||
*
|
*
|
||||||
* @param isDirectory Whether this filesystem entry is a directory.
|
* @param isDirectory Whether this filesystem entry is a directory.
|
||||||
* @param size The size of the file.
|
* @param size The size of the file.
|
||||||
|
@ -13,7 +13,7 @@ import java.util.Objects;
|
|||||||
/**
|
/**
|
||||||
* An {@link IOException} which occurred on a specific file.
|
* An {@link IOException} which occurred on a specific file.
|
||||||
* <p>
|
* <p>
|
||||||
* This may be thrown from a {@link IMount} or {@link IWritableMount} to give more information about a failure.
|
* This may be thrown from a {@link Mount} or {@link WritableMount} to give more information about a failure.
|
||||||
*/
|
*/
|
||||||
public class FileOperationException extends IOException {
|
public class FileOperationException extends IOException {
|
||||||
@Serial
|
@Serial
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
|
|
||||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
|
||||||
*/
|
|
||||||
package dan200.computercraft.api.filesystem;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a mount of the entire computer's file system.
|
|
||||||
* <p>
|
|
||||||
* This exists for use by various APIs - one should not attempt to mount it.
|
|
||||||
*/
|
|
||||||
public interface IFileSystem extends IWritableMount {
|
|
||||||
/**
|
|
||||||
* Combine two paths together, reducing them into a normalised form.
|
|
||||||
*
|
|
||||||
* @param path The main path.
|
|
||||||
* @param child The path to append.
|
|
||||||
* @return The combined, normalised path.
|
|
||||||
*/
|
|
||||||
String combine(String path, String child);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy files from one location to another.
|
|
||||||
*
|
|
||||||
* @param from The location to copy from.
|
|
||||||
* @param to The location to copy to. This should not exist.
|
|
||||||
* @throws IOException If the copy failed.
|
|
||||||
*/
|
|
||||||
void copy(String from, String to) throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move files from one location to another.
|
|
||||||
*
|
|
||||||
* @param from The location to move from.
|
|
||||||
* @param to The location to move to. This should not exist.
|
|
||||||
* @throws IOException If the move failed.
|
|
||||||
*/
|
|
||||||
void move(String from, String to) throws IOException;
|
|
||||||
}
|
|
@ -14,15 +14,15 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using
|
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using
|
||||||
* {@link IComputerAccess#mount(String, IMount)}.
|
* {@link IComputerAccess#mount(String, Mount)}.
|
||||||
* <p>
|
* <p>
|
||||||
* Typically you will not need to implement this interface yourself, and can use the factory methods from the
|
* Typically you will not need to implement this interface yourself, and can use the factory methods from the
|
||||||
* {@linkplain dan200.computercraft.api.ComputerCraftAPI the main ComputerCraft API}.
|
* {@linkplain dan200.computercraft.api.ComputerCraftAPI the main ComputerCraft API}.
|
||||||
*
|
*
|
||||||
* @see IComputerAccess#mount(String, IMount)
|
* @see IComputerAccess#mount(String, Mount)
|
||||||
* @see IWritableMount
|
* @see WritableMount
|
||||||
*/
|
*/
|
||||||
public interface IMount {
|
public interface Mount {
|
||||||
/**
|
/**
|
||||||
* Returns whether a file with a given path exists or not.
|
* Returns whether a file with a given path exists or not.
|
||||||
*
|
*
|
@ -13,17 +13,17 @@ import java.nio.channels.WritableByteChannel;
|
|||||||
import java.util.OptionalLong;
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}
|
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, Mount)}
|
||||||
* or {@link IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
|
* or {@link IComputerAccess#mountWritable(String, WritableMount)}, that can also be written to.
|
||||||
* <p>
|
* <p>
|
||||||
* Typically you will not need to implement this interface yourself, and can use the factory methods from the
|
* Typically you will not need to implement this interface yourself, and can use the factory methods from the
|
||||||
* {@linkplain dan200.computercraft.api.ComputerCraftAPI the main ComputerCraft API}.
|
* {@linkplain dan200.computercraft.api.ComputerCraftAPI the main ComputerCraft API}.
|
||||||
*
|
*
|
||||||
* @see IComputerAccess#mount(String, IMount)
|
* @see IComputerAccess#mount(String, Mount)
|
||||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
* @see IComputerAccess#mountWritable(String, WritableMount)
|
||||||
* @see IMount
|
* @see Mount
|
||||||
*/
|
*/
|
||||||
public interface IWritableMount extends IMount {
|
public interface WritableMount extends Mount {
|
||||||
/**
|
/**
|
||||||
* Creates a directory at a given path inside the virtual file system.
|
* Creates a directory at a given path inside the virtual file system.
|
||||||
*
|
*
|
@ -7,7 +7,6 @@ package dan200.computercraft.api.lua;
|
|||||||
|
|
||||||
import dan200.computercraft.api.peripheral.GenericPeripheral;
|
import dan200.computercraft.api.peripheral.GenericPeripheral;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A generic source of {@link LuaFunction} functions.
|
* A generic source of {@link LuaFunction} functions.
|
||||||
@ -44,10 +43,10 @@ public interface GenericSource {
|
|||||||
/**
|
/**
|
||||||
* A unique identifier for this generic source.
|
* A unique identifier for this generic source.
|
||||||
* <p>
|
* <p>
|
||||||
* This is currently unused, but may be used in the future to allow disabling specific sources. It is recommended
|
* While this can return an arbitrary string, it's recommended that this is formatted the same was as Minecraft's
|
||||||
* to return an identifier using your mod's ID.
|
* resource locations/identifiers, so is of the form {@code "mod_id:source_id"}.
|
||||||
*
|
*
|
||||||
* @return This source's identifier.
|
* @return This source's identifier.
|
||||||
*/
|
*/
|
||||||
ResourceLocation id();
|
String id();
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.lua;
|
package dan200.computercraft.api.lua;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IFileSystem;
|
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -15,14 +14,6 @@ import javax.annotation.Nullable;
|
|||||||
* about a computer.
|
* about a computer.
|
||||||
*/
|
*/
|
||||||
public interface IComputerSystem extends IComputerAccess {
|
public interface IComputerSystem extends IComputerAccess {
|
||||||
/**
|
|
||||||
* Get the file system for this computer.
|
|
||||||
*
|
|
||||||
* @return The computer's file system, or {@code null} if it is not initialised.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
IFileSystem getFileSystem();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the label for this computer.
|
* Get the label for this computer.
|
||||||
*
|
*
|
||||||
|
@ -23,7 +23,7 @@ public interface ILuaContext {
|
|||||||
* @throws LuaException If the task could not be queued.
|
* @throws LuaException If the task could not be queued.
|
||||||
* @see LuaFunction#mainThread() To run functions on the main thread and return their results synchronously.
|
* @see LuaFunction#mainThread() To run functions on the main thread and return their results synchronously.
|
||||||
*/
|
*/
|
||||||
long issueMainThreadTask(ILuaTask task) throws LuaException;
|
long issueMainThreadTask(LuaTask task) throws LuaException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue a task to be executed on the main server thread at the beginning of next tick, waiting for it to complete.
|
* Queue a task to be executed on the main server thread at the beginning of next tick, waiting for it to complete.
|
||||||
@ -36,7 +36,7 @@ public interface ILuaContext {
|
|||||||
* @return The objects returned by {@code task}.
|
* @return The objects returned by {@code task}.
|
||||||
* @throws LuaException If the task could not be queued, or if the task threw an exception.
|
* @throws LuaException If the task could not be queued, or if the task threw an exception.
|
||||||
*/
|
*/
|
||||||
default MethodResult executeMainThreadTask(ILuaTask task) throws LuaException {
|
default MethodResult executeMainThreadTask(LuaTask task) throws LuaException {
|
||||||
return TaskCallback.make(this, task);
|
return TaskCallback.make(this, task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public @interface LuaFunction {
|
|||||||
* Minecraft in a thread-unsafe manner.
|
* Minecraft in a thread-unsafe manner.
|
||||||
*
|
*
|
||||||
* @return Whether this function should be run on the main thread.
|
* @return Whether this function should be run on the main thread.
|
||||||
* @see ILuaContext#issueMainThreadTask(ILuaTask)
|
* @see ILuaContext#issueMainThreadTask(LuaTask)
|
||||||
*/
|
*/
|
||||||
boolean mainThread() default false;
|
boolean mainThread() default false;
|
||||||
|
|
||||||
|
@ -8,14 +8,14 @@ package dan200.computercraft.api.lua;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A task which can be executed via {@link ILuaContext#issueMainThreadTask(ILuaTask)} This will be run on the main
|
* A task which can be executed via {@link ILuaContext#issueMainThreadTask(LuaTask)} This will be run on the main
|
||||||
* thread, at the beginning of the
|
* thread, at the beginning of the
|
||||||
* next tick.
|
* next tick.
|
||||||
*
|
*
|
||||||
* @see ILuaContext#issueMainThreadTask(ILuaTask)
|
* @see ILuaContext#issueMainThreadTask(LuaTask)
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ILuaTask {
|
public interface LuaTask {
|
||||||
/**
|
/**
|
||||||
* Execute this task.
|
* Execute this task.
|
||||||
*
|
*
|
@ -34,7 +34,7 @@ final class TaskCallback implements ILuaCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static MethodResult make(ILuaContext context, ILuaTask func) throws LuaException {
|
static MethodResult make(ILuaContext context, LuaTask func) throws LuaException {
|
||||||
var task = context.issueMainThreadTask(func);
|
var task = context.issueMainThreadTask(func);
|
||||||
return new TaskCallback(task).pull;
|
return new TaskCallback(task).pull;
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.peripheral;
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.Mount;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.WritableMount;
|
||||||
import dan200.computercraft.api.lua.ILuaCallback;
|
import dan200.computercraft.api.lua.ILuaCallback;
|
||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
import dan200.computercraft.api.lua.ILuaTask;
|
import dan200.computercraft.api.lua.LuaTask;
|
||||||
import dan200.computercraft.api.lua.MethodResult;
|
import dan200.computercraft.api.lua.MethodResult;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -29,13 +29,13 @@ public interface IComputerAccess {
|
|||||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
||||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||||
* @throws NotAttachedException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see #mount(String, IMount, String)
|
* @see #mount(String, Mount, String)
|
||||||
* @see #mountWritable(String, IWritableMount)
|
* @see #mountWritable(String, WritableMount)
|
||||||
* @see #unmount(String)
|
* @see #unmount(String)
|
||||||
* @see IMount
|
* @see Mount
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
default String mount(String desiredLocation, IMount mount) {
|
default String mount(String desiredLocation, Mount mount) {
|
||||||
return mount(desiredLocation, mount, getAttachmentName());
|
return mount(desiredLocation, mount, getAttachmentName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,13 +48,13 @@ public interface IComputerAccess {
|
|||||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
||||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||||
* @throws NotAttachedException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see #mount(String, IMount)
|
* @see #mount(String, Mount)
|
||||||
* @see #mountWritable(String, IWritableMount)
|
* @see #mountWritable(String, WritableMount)
|
||||||
* @see #unmount(String)
|
* @see #unmount(String)
|
||||||
* @see IMount
|
* @see Mount
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
String mount(String desiredLocation, IMount mount, String driveName);
|
String mount(String desiredLocation, Mount mount, String driveName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount a mount onto the computer's file system in a writable mode.
|
* Mount a mount onto the computer's file system in a writable mode.
|
||||||
@ -64,12 +64,12 @@ public interface IComputerAccess {
|
|||||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
||||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||||
* @throws NotAttachedException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see #mount(String, IMount)
|
* @see #mount(String, Mount)
|
||||||
* @see #unmount(String)
|
* @see #unmount(String)
|
||||||
* @see IMount
|
* @see Mount
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
default String mountWritable(String desiredLocation, IWritableMount mount) {
|
default String mountWritable(String desiredLocation, WritableMount mount) {
|
||||||
return mountWritable(desiredLocation, mount, getAttachmentName());
|
return mountWritable(desiredLocation, mount, getAttachmentName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,16 +82,16 @@ public interface IComputerAccess {
|
|||||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
||||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||||
* @throws NotAttachedException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see #mount(String, IMount)
|
* @see #mount(String, Mount)
|
||||||
* @see #unmount(String)
|
* @see #unmount(String)
|
||||||
* @see IMount
|
* @see Mount
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
String mountWritable(String desiredLocation, IWritableMount mount, String driveName);
|
String mountWritable(String desiredLocation, WritableMount mount, String driveName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, IMount)}
|
* Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, Mount)}
|
||||||
* or {@link #mountWritable(String, IWritableMount)}.
|
* or {@link #mountWritable(String, WritableMount)}.
|
||||||
* <p>
|
* <p>
|
||||||
* When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be
|
* When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be
|
||||||
* able to access it. All directories mounted by a mount or mountWritable are automatically unmounted when the
|
* able to access it. All directories mounted by a mount or mountWritable are automatically unmounted when the
|
||||||
@ -100,12 +100,12 @@ public interface IComputerAccess {
|
|||||||
* Note that you cannot unmount another peripheral's mounts.
|
* Note that you cannot unmount another peripheral's mounts.
|
||||||
*
|
*
|
||||||
* @param location The desired location in the computers file system of the directory to unmount.
|
* @param location The desired location in the computers file system of the directory to unmount.
|
||||||
* This must be the location of a directory previously mounted by {@link #mount(String, IMount)} or
|
* This must be the location of a directory previously mounted by {@link #mount(String, Mount)} or
|
||||||
* {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
|
* {@link #mountWritable(String, WritableMount)}, as indicated by their return value.
|
||||||
* @throws NotAttachedException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @throws IllegalStateException If the mount does not exist, or was mounted by another peripheral.
|
* @throws IllegalStateException If the mount does not exist, or was mounted by another peripheral.
|
||||||
* @see #mount(String, IMount)
|
* @see #mount(String, Mount)
|
||||||
* @see #mountWritable(String, IWritableMount)
|
* @see #mountWritable(String, WritableMount)
|
||||||
*/
|
*/
|
||||||
void unmount(@Nullable String location);
|
void unmount(@Nullable String location);
|
||||||
|
|
||||||
@ -175,11 +175,11 @@ public interface IComputerAccess {
|
|||||||
IPeripheral getAvailablePeripheral(String name);
|
IPeripheral getAvailablePeripheral(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a {@link IWorkMonitor} for tasks your peripheral might execute on the main (server) thread.
|
* Get a {@link WorkMonitor} for tasks your peripheral might execute on the main (server) thread.
|
||||||
* <p>
|
* <p>
|
||||||
* This should be used to ensure your peripheral integrates with ComputerCraft's monitoring and limiting of how much
|
* This should be used to ensure your peripheral integrates with ComputerCraft's monitoring and limiting of how much
|
||||||
* server time each computer consumes. You should not need to use this if you use
|
* server time each computer consumes. You should not need to use this if you use
|
||||||
* {@link ILuaContext#issueMainThreadTask(ILuaTask)} - this is intended for mods with their own system for running
|
* {@link ILuaContext#issueMainThreadTask(LuaTask)} - this is intended for mods with their own system for running
|
||||||
* work on the main thread.
|
* work on the main thread.
|
||||||
* <p>
|
* <p>
|
||||||
* Please note that the returned implementation is <em>not</em> thread-safe, and should only be used from the main
|
* Please note that the returned implementation is <em>not</em> thread-safe, and should only be used from the main
|
||||||
@ -188,5 +188,5 @@ public interface IComputerAccess {
|
|||||||
* @return The work monitor for the main thread, or {@code null} if this computer does not have one.
|
* @return The work monitor for the main thread, or {@code null} if this computer does not have one.
|
||||||
* @throws NotAttachedException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
*/
|
*/
|
||||||
IWorkMonitor getMainThreadMonitor();
|
WorkMonitor getMainThreadMonitor();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*
|
*
|
||||||
* @see IComputerAccess#getMainThreadMonitor()
|
* @see IComputerAccess#getMainThreadMonitor()
|
||||||
*/
|
*/
|
||||||
public interface IWorkMonitor {
|
public interface WorkMonitor {
|
||||||
/**
|
/**
|
||||||
* If the owning computer is currently allowed to execute work.
|
* If the owning computer is currently allowed to execute work.
|
||||||
*
|
*
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user