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:
Jonathan Coates 2022-12-03 15:02:00 +00:00 committed by GitHub
parent 95c57e843d
commit 87c6d3aef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
157 changed files with 619 additions and 1272 deletions

View File

@ -10,7 +10,6 @@ java {
dependencies {
api(project(":core-api"))
compileOnly(project(":forge-stubs"))
}
tasks.javadoc {

View File

@ -5,31 +5,26 @@
*/
package dan200.computercraft.api;
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.DetailRegistry;
import dan200.computercraft.api.detail.IDetailProvider;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.filesystem.Mount;
import dan200.computercraft.api.filesystem.WritableMount;
import dan200.computercraft.api.lua.GenericSource;
import dan200.computercraft.api.lua.ILuaAPI;
import dan200.computercraft.api.lua.ILuaAPIFactory;
import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.api.media.IMediaProvider;
import dan200.computercraft.api.network.IPacketNetwork;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.media.MediaProvider;
import dan200.computercraft.api.network.PacketNetwork;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
import dan200.computercraft.impl.ComputerCraftAPIService;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import javax.annotation.Nullable;
@ -51,16 +46,16 @@ public static String getInstalledVersion() {
* <p>
* 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"
* @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
* <p>
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now
* available for writing.
* @see #createSaveDirMount(Level, String, long)
* @see #createSaveDirMount(MinecraftServer, String, long)
*/
public static int createUniqueNumberedSaveDir(Level world, String parentSubPath) {
return getInstance().createUniqueNumberedSaveDir(world, parentSubPath);
public static int createUniqueNumberedSaveDir(MinecraftServer server, String parentSubPath) {
return getInstance().createUniqueNumberedSaveDir(server, parentSubPath);
}
/**
@ -69,21 +64,21 @@ public static int createUniqueNumberedSaveDir(Level world, String parentSubPath)
* Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the
* 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".
* 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.
* @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.
* @see #createUniqueNumberedSaveDir(Level, String)
* @see IComputerAccess#mount(String, IMount)
* @see IComputerAccess#mountWritable(String, IWritableMount)
* @see IMount
* @see IWritableMount
* @see #createUniqueNumberedSaveDir(MinecraftServer, String)
* @see IComputerAccess#mount(String, Mount)
* @see IComputerAccess#mountWritable(String, WritableMount)
* @see Mount
* @see WritableMount
*/
@Nullable
public static IWritableMount createSaveDirMount(Level world, String subPath, long capacity) {
return getInstance().createSaveDirMount(world, subPath, capacity);
public static WritableMount createSaveDirMount(MinecraftServer server, String subPath, long capacity) {
return getInstance().createSaveDirMount(server, subPath, capacity);
}
/**
@ -97,29 +92,17 @@ public static IWritableMount createSaveDirMount(Level world, String subPath, lon
* "/data/computercraft/lua/rom". We construct a mount for that with
* {@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 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.
* @see IComputerAccess#mount(String, IMount)
* @see IComputerAccess#mountWritable(String, IWritableMount)
* @see IMount
* @see IComputerAccess#mount(String, Mount)
* @see IComputerAccess#mountWritable(String, WritableMount)
* @see Mount
*/
@Nullable
public static IMount createResourceMount(String domain, String subPath) {
return getInstance().createResourceMount(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);
public static Mount createResourceMount(MinecraftServer server, String domain, String subPath) {
return getInstance().createResourceMount(server, domain, subPath);
}
/**
@ -132,25 +115,13 @@ public static void registerGenericSource(GenericSource 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.
*
* @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);
}
@ -162,7 +133,7 @@ public static void registerBundledRedstoneProvider(IBundledRedstoneProvider prov
* @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.
* 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) {
return getInstance().getBundledRedstoneOutput(world, pos, side);
@ -172,38 +143,33 @@ public static int getBundledRedstoneOutput(Level world, BlockPos pos, Direction
* Registers a media provider to provide {@link IMedia} implementations for Items.
*
* @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);
}
/**
* 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.
*/
public static IPacketNetwork getWirelessNetwork() {
return getInstance().getWirelessNetwork();
}
public static void registerAPIFactory(ILuaAPIFactory factory) {
getInstance().registerAPIFactory(factory);
public static PacketNetwork getWirelessNetwork(MinecraftServer server) {
return getInstance().getWirelessNetwork(server);
}
/**
* Registers a detail provider to provide additional details for blocks, fluids and items when inspected by methods
* such as {@code turtle.getItemDetail()} or {@code turtle.inspect()}.
* Register a custom {@link ILuaAPI}, which may be added onto all computers without requiring a peripheral.
* <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},
* {@code net.minecraftforge.fluids.FluidStack} or {@link ItemStack}.
* @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.
* @param factory The factory for your API subclass.
* @see ILuaAPIFactory
*/
@Deprecated(forRemoval = true)
public static <T> void registerDetailProvider(Class<T> type, IDetailProvider<T> provider) {
getInstance().registerDetailProvider(type, provider);
public static void registerAPIFactory(ILuaAPIFactory factory) {
getInstance().registerAPIFactory(factory);
}
/**
@ -211,27 +177,19 @@ public static <T> void registerDetailProvider(Class<T> type, IDetailProvider<T>
*
* @param element The element to construct it for
* @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);
}
/**
* 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 pos The position the block exists in
* @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)}
* @param handler The turtle refuel handler.
* @see TurtleRefuelHandler#refuel(ITurtleAccess, ItemStack, int, int)
*/
@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) {
getInstance().registerRefuelHandler(handler);
}

View File

@ -18,7 +18,7 @@
*
* @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 @Nullable String namespace;

View File

@ -17,7 +17,7 @@
* @see DetailRegistry
*/
@FunctionalInterface
public interface IDetailProvider<T> {
public interface DetailProvider<T> {
/**
* 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

View File

@ -25,9 +25,9 @@ public interface DetailRegistry<T> {
* Registers a detail provider.
*
* @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

View File

@ -5,11 +5,14 @@
*/
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.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import javax.annotation.Nullable;
@ -17,7 +20,7 @@
* Represents an item that can be placed in a disk drive and used by a Computer.
* <p>
* 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 {
/**
@ -68,16 +71,16 @@ default SoundEvent getAudio(ItemStack stack) {
* be mounted onto the filesystem of the computer while the media is in the disk drive.
*
* @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
* implements {@link dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable()
* @see IMount
* @see dan200.computercraft.api.filesystem.IWritableMount
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(Level, String, long)
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(String, String)
* implements {@link WritableMount}, it will mounted using mountWritable()
* @see Mount
* @see WritableMount
* @see ComputerCraftAPI#createSaveDirMount(MinecraftServer, String, long)
* @see ComputerCraftAPI#createResourceMount(MinecraftServer, String, String)
*/
@Nullable
default IMount createDataMount(ItemStack stack, Level world) {
default Mount createDataMount(ItemStack stack, ServerLevel level) {
return null;
}
}

View File

@ -12,16 +12,16 @@
/**
* 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
public interface IMediaProvider {
public interface MediaProvider {
/**
* Produce an IMedia implementation from an ItemStack.
*
* @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
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider)
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(MediaProvider)
*/
@Nullable
IMedia getMedia(ItemStack stack);

View File

@ -6,7 +6,7 @@
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
* channels they are listening to.
@ -14,16 +14,16 @@
* @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.
* @param sender The object which sent this packet.
* @see IPacketSender
* @see IPacketNetwork#transmitSameDimension(Packet, double)
* @see IPacketNetwork#transmitInterdimensional(Packet)
* @see IPacketReceiver#receiveDifferentDimension(Packet)
* @see IPacketReceiver#receiveSameDimension(Packet, double)
* @see PacketSender
* @see PacketNetwork#transmitSameDimension(Packet, double)
* @see PacketNetwork#transmitInterdimensional(Packet)
* @see PacketReceiver#receiveDifferentDimension(Packet)
* @see PacketReceiver#receiveSameDimension(Packet, double)
*/
public record Packet(
int channel,
int replyChannel,
Object payload,
IPacketSender sender
PacketSender sender
) {
}

View File

@ -10,22 +10,22 @@
* A packet network represents a collection of devices which can send and receive packets.
*
* @see Packet
* @see IPacketReceiver
* @see PacketReceiver
*/
public interface IPacketNetwork {
public interface PacketNetwork {
/**
* Add a receiver 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.
*
* @param receiver The device to remove from the network.
*/
void removeReceiver(IPacketReceiver receiver);
void removeReceiver(PacketReceiver receiver);
/**
* Determine whether this network is wireless.
@ -41,7 +41,7 @@ public interface IPacketNetwork {
* @param packet The packet to send.
* @param range The maximum distance this packet will be sent.
* @see #transmitInterdimensional(Packet)
* @see IPacketReceiver#receiveSameDimension(Packet, double)
* @see PacketReceiver#receiveSameDimension(Packet, double)
*/
void transmitSameDimension(Packet packet, double range);
@ -51,7 +51,7 @@ public interface IPacketNetwork {
*
* @param packet The packet to send.
* @see #transmitSameDimension(Packet, double)
* @see IPacketReceiver#receiveDifferentDimension(Packet)
* @see PacketReceiver#receiveDifferentDimension(Packet)
*/
void transmitInterdimensional(Packet packet);
}

View File

@ -10,9 +10,9 @@
/**
* 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.
*
@ -37,7 +37,7 @@ public interface IPacketReceiver {
* @return The maximum distance this device can send and receive messages.
* @see #isInterdimensional()
* @see #receiveSameDimension(Packet packet, double)
* @see IPacketNetwork#transmitInterdimensional(Packet)
* @see PacketNetwork#transmitInterdimensional(Packet)
*/
double getRange();
@ -49,7 +49,7 @@ public interface IPacketReceiver {
* @return Whether this receiver receives packets from other dimensions.
* @see #getRange()
* @see #receiveDifferentDimension(Packet)
* @see IPacketNetwork#transmitInterdimensional(Packet)
* @see PacketNetwork#transmitInterdimensional(Packet)
*/
boolean isInterdimensional();
@ -61,8 +61,8 @@ public interface IPacketReceiver {
* @param distance The distance this packet has travelled from the source.
* @see Packet
* @see #getRange()
* @see IPacketNetwork#transmitSameDimension(Packet, double)
* @see IPacketNetwork#transmitInterdimensional(Packet)
* @see PacketNetwork#transmitSameDimension(Packet, double)
* @see PacketNetwork#transmitInterdimensional(Packet)
*/
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,
* if so, queue the appropriate modem event.
* @see Packet
* @see IPacketNetwork#transmitInterdimensional(Packet)
* @see IPacketNetwork#transmitSameDimension(Packet, double)
* @see PacketNetwork#transmitInterdimensional(Packet)
* @see PacketNetwork#transmitSameDimension(Packet, double)
* @see #isInterdimensional()
*/
void receiveDifferentDimension(Packet packet);

View File

@ -10,9 +10,9 @@
/**
* 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.
*

View File

@ -11,21 +11,21 @@
/**
* An object which may be part of a wired network.
* <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
* for its lifespan.
* <p>
* 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
* peripherals change.
*
* @param change The change which occurred.
* @see IWiredNetworkChange
* @see WiredNetworkChange
*/
default void networkChanged(IWiredNetworkChange change) {
default void networkChanged(WiredNetworkChange change) {
}
}

View File

@ -10,20 +10,20 @@
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.
* <p>
* 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
* change.
* <p>
* 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.
* <p>
@ -34,10 +34,10 @@ public interface IWiredNetwork {
* @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 IllegalArgumentException If {@code left} and {@code right} are equal.
* @see IWiredNode#connectTo(IWiredNode)
* @see IWiredNetwork#connect(IWiredNode, IWiredNode)
* @see WiredNode#connectTo(WiredNode)
* @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.
@ -49,10 +49,10 @@ public interface IWiredNetwork {
* @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 {@code left} and {@code right} are equal.
* @see IWiredNode#disconnectFrom(IWiredNode)
* @see IWiredNetwork#connect(IWiredNode, IWiredNode)
* @see WiredNode#disconnectFrom(WiredNode)
* @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.
@ -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
* only element.
* @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.
@ -77,7 +77,7 @@ public interface IWiredNetwork {
* @param node The node to attach peripherals for.
* @param peripherals The new peripherals for this node.
* @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);
}

View File

@ -12,9 +12,9 @@
/**
* 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
* in the added and removed set, but with a different peripheral.

View File

@ -5,13 +5,13 @@
*/
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 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>
* 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.
@ -23,13 +23,13 @@
* Wired nodes also provide several convenience methods for interacting with a wired network. These should only ever
* be used on the main server thread.
*/
public interface IWiredNode extends IPacketNetwork {
public interface WiredNode extends PacketNetwork {
/**
* The associated element for this network node.
*
* @return This node's element.
*/
IWiredElement getElement();
WiredElement getElement();
/**
* 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.
*/
IWiredNetwork getNetwork();
WiredNetwork getNetwork();
/**
* 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.
* @return {@code true} if a connection was created or {@code false} if the connection already exists.
* @see IWiredNetwork#connect(IWiredNode, IWiredNode)
* @see IWiredNode#disconnectFrom(IWiredNode)
* @see WiredNetwork#connect(WiredNode, WiredNode)
* @see WiredNode#disconnectFrom(WiredNode)
*/
default boolean connectTo(IWiredNode node) {
default boolean connectTo(WiredNode node) {
return getNetwork().connect(this, node);
}
@ -63,10 +63,10 @@ default boolean connectTo(IWiredNode node) {
* @param node The other node to disconnect from.
* @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.
* @see IWiredNetwork#disconnect(IWiredNode, IWiredNode)
* @see IWiredNode#connectTo(IWiredNode)
* @see WiredNetwork#disconnect(WiredNode, WiredNode)
* @see WiredNode#connectTo(WiredNode)
*/
default boolean disconnectFrom(IWiredNode node) {
default boolean disconnectFrom(WiredNode node) {
return getNetwork().disconnect(this, node);
}
@ -79,7 +79,7 @@ default boolean disconnectFrom(IWiredNode node) {
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the
* only element.
* @throws IllegalArgumentException If the node is not in the network.
* @see IWiredNetwork#remove(IWiredNode)
* @see WiredNetwork#remove(WiredNode)
*/
default boolean remove() {
return getNetwork().remove(this);
@ -92,7 +92,7 @@ default boolean remove() {
* that your network element owns.
*
* @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) {
getNetwork().updatePeripherals(this, peripherals);

View File

@ -5,16 +5,16 @@
*/
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>
* 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.
*/
public interface IWiredSender extends IPacketSender {
public interface WiredSender extends PacketSender {
/**
* The node in the network representing this object.
* <p>
@ -23,5 +23,5 @@ public interface IWiredSender extends IPacketSender {
*
* @return The node for this element.
*/
IWiredNode getNode();
WiredNode getNode();
}

View File

@ -5,7 +5,7 @@
*/
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.world.item.ItemStack;
@ -27,7 +27,7 @@ protected AbstractPocketUpgrade(ResourceLocation id, String adjective, ItemStack
}
protected AbstractPocketUpgrade(ResourceLocation id, ItemStack stack) {
this(id, IUpgradeBase.getDefaultAdjective(id), stack);
this(id, UpgradeBase.getDefaultAdjective(id), stack);
}
@Override

View File

@ -6,7 +6,7 @@
package dan200.computercraft.api.pocket;
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 javax.annotation.Nullable;
@ -23,7 +23,7 @@
*
* @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.
* <p>

View File

@ -6,7 +6,7 @@
package dan200.computercraft.api.pocket;
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.impl.upgrades.SerialiserWithCraftingItem;
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
@ -15,8 +15,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
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.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"));
/**
* 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
* upgrades.
@ -73,7 +59,7 @@ private Impl(Function<ResourceLocation, T> constructor) {
* 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
* {@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.
* @return The serialiser for this upgrade.
* @see #simple(Function) For upgrades whose crafting stack should not vary.

View File

@ -5,18 +5,18 @@
*/
package dan200.computercraft.api.redstone;
import dan200.computercraft.api.ComputerCraftAPI;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
/**
* This interface is used to provide bundled redstone output for blocks.
*
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
* @see ComputerCraftAPI#registerBundledRedstoneProvider(BundledRedstoneProvider)
*/
@FunctionalInterface
public interface IBundledRedstoneProvider {
public interface BundledRedstoneProvider {
/**
* 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.
* @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.
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
* @see ComputerCraftAPI#registerBundledRedstoneProvider(BundledRedstoneProvider)
*/
int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side);
}

View File

@ -5,7 +5,7 @@
*/
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.world.item.ItemStack;
@ -29,7 +29,7 @@ protected AbstractTurtleUpgrade(ResourceLocation id, TurtleUpgradeType type, Str
}
protected AbstractTurtleUpgrade(ResourceLocation id, TurtleUpgradeType type, ItemStack stack) {
this(id, type, IUpgradeBase.getDefaultAdjective(id), stack);
this(id, type, UpgradeBase.getDefaultAdjective(id), stack);
}
@Override

View File

@ -15,7 +15,6 @@
import net.minecraft.world.Container;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nullable;
@ -43,7 +42,7 @@ public interface ITurtleAccess {
/**
* Determine if this turtle has been removed.
* <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
* trying to interact with it again.
* <p>
@ -156,23 +155,9 @@ public interface ITurtleAccess {
* Note: this inventory should only be accessed and modified on the server thread.
*
* @return This turtle's inventory
* @see #getItemHandler()
*/
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.
*
@ -239,10 +224,10 @@ public interface ITurtleAccess {
* @return The objects the command returned when executed. you should probably return these to the player
* unchanged if called from a peripheral method.
* @throws UnsupportedOperationException When attempting to execute a command on the client side.
* @see ITurtleCommand
* @see TurtleCommand
* @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

View File

@ -6,7 +6,7 @@
package dan200.computercraft.api.turtle;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.upgrades.IUpgradeBase;
import dan200.computercraft.api.upgrades.UpgradeBase;
import net.minecraft.core.Direction;
import javax.annotation.Nullable;
@ -24,7 +24,7 @@
*
* @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.
*

View File

@ -7,12 +7,12 @@
/**
* 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
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.
* <p>
@ -21,7 +21,7 @@ public interface ITurtleCommand {
*
* @param turtle Access to the turtle for whom the command was issued.
* @return A result, indicating whether this action succeeded or not.
* @see ITurtleAccess#executeCommand(ITurtleCommand)
* @see ITurtleAccess#executeCommand(TurtleCommand)
* @see TurtleCommandResult#success()
* @see TurtleCommandResult#failure(String)
* @see TurtleCommandResult

View File

@ -12,7 +12,7 @@
/**
* 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)
*/
public final class TurtleCommandResult {

View File

@ -6,7 +6,7 @@
package dan200.computercraft.api.turtle;
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.impl.upgrades.SerialiserWithCraftingItem;
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
@ -16,8 +16,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeSerializer;
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.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"));
/**
* 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
* upgrades.
@ -108,7 +94,7 @@ private Impl(Function<ResourceLocation, T> constructor) {
* 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
* {@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.
* @return The serialiser for this upgrade.
* @see #simple(Function) For upgrades whose crafting stack should not vary.

View File

@ -17,7 +17,7 @@
/**
* 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"
* or "my_mod:my_upgrade".

View File

@ -37,7 +37,7 @@
* @param <T> The base class of upgrades.
* @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 final DataGenerator generator;

View File

@ -22,13 +22,13 @@
* @see TurtleUpgradeSerialiser
* @see PocketUpgradeSerialiser
*/
public interface UpgradeSerialiser<T extends IUpgradeBase> {
public interface UpgradeSerialiser<T extends UpgradeBase> {
/**
* Read this upgrade from a JSON file in a datapack.
*
* @param id The ID of this upgrade.
* @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.
*/
T fromJson(ResourceLocation id, JsonObject object);
@ -38,7 +38,7 @@ public interface UpgradeSerialiser<T extends IUpgradeBase> {
*
* @param id The ID of this upgrade.
* @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);

View File

@ -8,25 +8,21 @@
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.DetailRegistry;
import dan200.computercraft.api.detail.IDetailProvider;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.filesystem.Mount;
import dan200.computercraft.api.filesystem.WritableMount;
import dan200.computercraft.api.lua.GenericSource;
import dan200.computercraft.api.lua.ILuaAPIFactory;
import dan200.computercraft.api.media.IMediaProvider;
import dan200.computercraft.api.network.IPacketNetwork;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.api.media.MediaProvider;
import dan200.computercraft.api.network.PacketNetwork;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import org.jetbrains.annotations.ApiStatus;
import javax.annotation.Nullable;
@ -45,45 +41,27 @@ static ComputerCraftAPIService get() {
String getInstalledVersion();
int createUniqueNumberedSaveDir(Level world, String parentSubPath);
int createUniqueNumberedSaveDir(MinecraftServer server, String parentSubPath);
@Nullable
IWritableMount createSaveDirMount(Level world, String subPath, long capacity);
WritableMount createSaveDirMount(MinecraftServer server, String subPath, long capacity);
@Nullable
IMount createResourceMount(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");
}
Mount createResourceMount(MinecraftServer server, String domain, String subPath);
void registerGenericSource(GenericSource source);
@Deprecated
default void registerGenericCapability(Capability<?> capability) {
throw new UnsupportedOperationException("Can only register Capability on Forge");
}
void registerBundledRedstoneProvider(IBundledRedstoneProvider provider);
void registerBundledRedstoneProvider(BundledRedstoneProvider provider);
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);
@Deprecated
<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");
}
WiredNode createWiredNodeForElement(WiredElement element);
void registerRefuelHandler(TurtleRefuelHandler handler);

View File

@ -6,7 +6,7 @@
package dan200.computercraft.impl.upgrades;
import com.google.gson.JsonObject;
import dan200.computercraft.api.upgrades.IUpgradeBase;
import dan200.computercraft.api.upgrades.UpgradeBase;
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
@ -24,7 +24,7 @@
* @param <T> The upgrade that this class can serialise and deserialise.
*/
@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;
protected SerialiserWithCraftingItem(BiFunction<ResourceLocation, ItemStack, T> factory) {

View File

@ -6,7 +6,7 @@
package dan200.computercraft.impl.upgrades;
import com.google.gson.JsonObject;
import dan200.computercraft.api.upgrades.IUpgradeBase;
import dan200.computercraft.api.upgrades.UpgradeBase;
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
@ -22,7 +22,7 @@
* @param <T> The upgrade that this class can serialise and deserialise.
*/
@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;
public SimpleSerialiser(Function<ResourceLocation, T> constructor) {

View File

@ -21,14 +21,12 @@ dependencies {
clientImplementation(clientClasses(project(":common-api")))
compileOnly(libs.bundles.externalMods.common)
compileOnly(project(":forge-stubs"))
compileOnly(libs.mixin)
annotationProcessorEverywhere(libs.autoService)
testImplementation(testFixtures(project(":core")))
testImplementation(libs.bundles.test)
testImplementation(project(":forge-stubs"))
testRuntimeOnly(libs.bundles.testRuntime)
testModImplementation(testFixtures(project(":core")))

View File

@ -11,7 +11,7 @@
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.pocket.PocketUpgradeDataProvider;
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.Metrics;
import dan200.computercraft.shared.ModRegistry;
@ -272,8 +272,8 @@ private Stream<String> getExpectedKeys() {
Registries.ITEMS.stream()
.filter(x -> Registries.ITEMS.getKey(x).getNamespace().equals(ComputerCraftAPI.MOD_ID))
.map(Item::getDescriptionId),
turtleUpgrades.getGeneratedUpgrades().stream().map(IUpgradeBase::getUnlocalisedAdjective),
pocketUpgrades.getGeneratedUpgrades().stream().map(IUpgradeBase::getUnlocalisedAdjective),
turtleUpgrades.getGeneratedUpgrades().stream().map(UpgradeBase::getUnlocalisedAdjective),
pocketUpgrades.getGeneratedUpgrades().stream().map(UpgradeBase::getUnlocalisedAdjective),
Metric.metrics().values().stream().map(x -> AggregatedMetric.TRANSLATION_PREFIX + x.name() + ".name"),
getConfigKeys(ConfigSpec.serverSpec),
getConfigKeys(ConfigSpec.clientSpec)

View File

@ -7,21 +7,20 @@
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.DetailRegistry;
import dan200.computercraft.api.detail.IDetailProvider;
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.filesystem.WritableMount;
import dan200.computercraft.api.lua.GenericSource;
import dan200.computercraft.api.lua.ILuaAPIFactory;
import dan200.computercraft.api.media.IMediaProvider;
import dan200.computercraft.api.network.IPacketNetwork;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.api.media.MediaProvider;
import dan200.computercraft.api.network.PacketNetwork;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
import dan200.computercraft.core.apis.ApiFactories;
import dan200.computercraft.core.asm.GenericMethod;
import dan200.computercraft.core.filesystem.FileMount;
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.details.BlockDetails;
import dan200.computercraft.shared.details.ItemDetails;
@ -54,19 +53,15 @@ public abstract class AbstractComputerCraftAPI implements ComputerCraftAPIServic
}
@Override
public final int createUniqueNumberedSaveDir(Level world, String parentSubPath) {
var server = world.getServer();
if (server == null) throw new IllegalArgumentException("Cannot find server from provided level");
public final int createUniqueNumberedSaveDir(MinecraftServer server, String parentSubPath) {
return ServerContext.get(server).getNextId(parentSubPath);
}
@Override
public final @Nullable IWritableMount createSaveDirMount(Level world, String subPath, long capacity) {
var server = world.getServer();
if (server == null) throw new IllegalArgumentException("Cannot find server from provided level");
public final @Nullable WritableMount createSaveDirMount(MinecraftServer server, String subPath, long capacity) {
var root = ServerContext.get(server).storageDir().toFile();
try {
return new FileMount(new File(ServerContext.get(server).storageDir().toFile(), subPath), capacity);
return new FileMount(new File(root, subPath), capacity);
} catch (Exception e) {
return null;
}
@ -78,7 +73,7 @@ public final void registerGenericSource(GenericSource source) {
}
@Override
public final void registerBundledRedstoneProvider(IBundledRedstoneProvider provider) {
public final void registerBundledRedstoneProvider(BundledRedstoneProvider provider) {
BundledRedstone.register(provider);
}
@ -88,12 +83,12 @@ public final int getBundledRedstoneOutput(Level world, BlockPos pos, Direction s
}
@Override
public final void registerMediaProvider(IMediaProvider provider) {
public final void registerMediaProvider(MediaProvider provider) {
MediaProviders.register(provider);
}
@Override
public final IPacketNetwork getWirelessNetwork() {
public final PacketNetwork getWirelessNetwork(MinecraftServer server) {
return WirelessNetwork.getUniversal();
}
@ -102,13 +97,11 @@ public final void registerAPIFactory(ILuaAPIFactory factory) {
ApiFactories.register(factory);
}
@Override
public final IWiredNode createWiredNodeForElement(IWiredElement element) {
return new WiredNode(element);
public final WiredNode createWiredNodeForElement(WiredElement element) {
return new WiredNodeImpl(element);
}
@Override
public void registerRefuelHandler(TurtleRefuelHandler handler) {
TurtleRefuelHandlers.register(handler);
@ -123,17 +116,4 @@ public final DetailRegistry<ItemStack> getItemStackDetailRegistry() {
public final DetailRegistry<BlockReference> getBlockInWorldDetailRegistry() {
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);
}
}
}

View File

@ -5,7 +5,7 @@
*/
package dan200.computercraft.impl;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@ -19,12 +19,12 @@
public final class BundledRedstone {
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() {
}
public static synchronized void register(IBundledRedstoneProvider provider) {
public static synchronized void register(BundledRedstoneProvider provider) {
Objects.requireNonNull(provider, "provider cannot be null");
if (!providers.contains(provider)) providers.add(provider);
}

View File

@ -6,7 +6,7 @@
package dan200.computercraft.impl;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -19,12 +19,12 @@
public final class MediaProviders {
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() {
}
public static synchronized void register(IMediaProvider provider) {
public static synchronized void register(MediaProvider provider) {
Objects.requireNonNull(provider, "provider cannot be null");
providers.add(provider);
}

View File

@ -7,7 +7,7 @@
import com.google.gson.*;
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.shared.platform.PlatformHelper;
import net.minecraft.core.Registry;
@ -36,11 +36,11 @@
* @see TurtleUpgrades
* @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 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
) {
}

View File

@ -5,8 +5,8 @@
*/
package dan200.computercraft.impl.detail;
import dan200.computercraft.api.detail.DetailProvider;
import dan200.computercraft.api.detail.DetailRegistry;
import dan200.computercraft.api.detail.IDetailProvider;
import java.util.*;
@ -16,16 +16,16 @@
* @param <T> The type of object that this registry provides details for.
*/
public class DetailRegistryImpl<T> implements DetailRegistry<T> {
private final Collection<IDetailProvider<T>> providers = new ArrayList<>();
private final IDetailProvider<T> basic;
private final Collection<DetailProvider<T>> providers = new ArrayList<>();
private final DetailProvider<T> basic;
public DetailRegistryImpl(IDetailProvider<T> basic) {
public DetailRegistryImpl(DetailProvider<T> basic) {
this.basic = basic;
providers.add(basic);
}
@Override
public synchronized void addProvider(IDetailProvider<T> provider) {
public synchronized void addProvider(DetailProvider<T> provider) {
Objects.requireNonNull(provider, "provider cannot be null");
if (!providers.contains(provider)) providers.add(provider);
}

View File

@ -21,7 +21,7 @@ public final class InvariantChecker {
private InvariantChecker() {
}
public static void checkNode(WiredNode node) {
public static void checkNode(WiredNodeImpl node) {
if (!ENABLED) return;
var network = node.network;
@ -41,7 +41,7 @@ public static void checkNode(WiredNode node) {
}
}
public static void checkNetwork(WiredNetwork network) {
public static void checkNetwork(WiredNetworkImpl network) {
if (!ENABLED) return;
for (var node : network.nodes) checkNode(node);

View File

@ -5,44 +5,44 @@
*/
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 java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public final class WiredNetworkChange implements IWiredNetworkChange {
private static final WiredNetworkChange EMPTY = new WiredNetworkChange(Collections.emptyMap(), Collections.emptyMap());
final class WiredNetworkChangeImpl implements WiredNetworkChange {
private static final WiredNetworkChangeImpl EMPTY = new WiredNetworkChangeImpl(Collections.emptyMap(), Collections.emptyMap());
private final Map<String, IPeripheral> removed;
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.added = added;
}
public static WiredNetworkChange changed(Map<String, IPeripheral> removed, Map<String, IPeripheral> added) {
return new WiredNetworkChange(Collections.unmodifiableMap(removed), Collections.unmodifiableMap(added));
static WiredNetworkChangeImpl changed(Map<String, IPeripheral> removed, Map<String, IPeripheral> added) {
return new WiredNetworkChangeImpl(Collections.unmodifiableMap(removed), Collections.unmodifiableMap(added));
}
public static WiredNetworkChange added(Map<String, IPeripheral> added) {
return added.isEmpty() ? EMPTY : new WiredNetworkChange(Collections.emptyMap(), Collections.unmodifiableMap(added));
static WiredNetworkChangeImpl added(Map<String, IPeripheral> added) {
return added.isEmpty() ? EMPTY : new WiredNetworkChangeImpl(Collections.emptyMap(), Collections.unmodifiableMap(added));
}
public static WiredNetworkChange removed(Map<String, IPeripheral> removed) {
return removed.isEmpty() ? EMPTY : new WiredNetworkChange(Collections.unmodifiableMap(removed), Collections.emptyMap());
static WiredNetworkChangeImpl removed(Map<String, IPeripheral> removed) {
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.
if (oldPeripherals.isEmpty() && newPeripherals.isEmpty()) {
return EMPTY;
} else if (oldPeripherals.isEmpty()) {
return new WiredNetworkChange(Collections.emptyMap(), newPeripherals);
return new WiredNetworkChangeImpl(Collections.emptyMap(), newPeripherals);
} else if (newPeripherals.isEmpty()) {
return new WiredNetworkChange(oldPeripherals, Collections.emptyMap());
return new WiredNetworkChangeImpl(oldPeripherals, Collections.emptyMap());
}
Map<String, IPeripheral> added = new HashMap<>(newPeripherals);
@ -80,13 +80,13 @@ public boolean isEmpty() {
return added.isEmpty() && removed.isEmpty();
}
void broadcast(Iterable<WiredNode> nodes) {
void broadcast(Iterable<WiredNodeImpl> nodes) {
if (!isEmpty()) {
for (var node : nodes) node.element.networkChanged(this);
}
}
void broadcast(WiredNode node) {
void broadcast(WiredNodeImpl node) {
if (!isEmpty()) {
node.element.networkChanged(this);
}

View File

@ -7,30 +7,30 @@
import com.google.common.collect.ImmutableMap;
import dan200.computercraft.api.network.Packet;
import dan200.computercraft.api.network.wired.IWiredNetwork;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.network.wired.WiredNetwork;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.peripheral.IPeripheral;
import java.util.*;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public final class WiredNetwork implements IWiredNetwork {
final class WiredNetworkImpl implements WiredNetwork {
final ReadWriteLock lock = new ReentrantReadWriteLock();
Set<WiredNode> nodes;
Set<WiredNodeImpl> nodes;
private Map<String, IPeripheral> peripherals = new HashMap<>();
WiredNetwork(WiredNode node) {
WiredNetworkImpl(WiredNodeImpl node) {
nodes = new HashSet<>(1);
nodes.add(node);
}
private WiredNetwork(HashSet<WiredNode> nodes) {
private WiredNetworkImpl(HashSet<WiredNodeImpl> nodes) {
this.nodes = nodes;
}
@Override
public boolean connect(IWiredNode nodeU, IWiredNode nodeV) {
public boolean connect(WiredNode nodeU, WiredNode nodeV) {
var wiredU = checkNode(nodeU);
var wiredV = checkNode(nodeV);
if (nodeU == nodeV) throw new IllegalArgumentException("Cannot add a connection to oneself.");
@ -65,11 +65,11 @@ public boolean connect(IWiredNode nodeU, IWiredNode nodeV) {
peripherals.putAll(otherPeripherals);
if (!thisPeripherals.isEmpty()) {
WiredNetworkChange.added(thisPeripherals).broadcast(otherNodes);
WiredNetworkChangeImpl.added(thisPeripherals).broadcast(otherNodes);
}
if (!otherPeripherals.isEmpty()) {
WiredNetworkChange.added(otherPeripherals).broadcast(thisNodes);
WiredNetworkChangeImpl.added(otherPeripherals).broadcast(thisNodes);
}
} finally {
other.lock.writeLock().unlock();
@ -90,7 +90,7 @@ public boolean connect(IWiredNode nodeU, IWiredNode nodeV) {
}
@Override
public boolean disconnect(IWiredNode nodeU, IWiredNode nodeV) {
public boolean disconnect(WiredNode nodeU, WiredNode nodeV) {
var wiredU = checkNode(nodeU);
var wiredV = checkNode(nodeV);
if (nodeU == nodeV) throw new IllegalArgumentException("Cannot remove a connection to oneself.");
@ -108,8 +108,8 @@ public boolean disconnect(IWiredNode nodeU, IWiredNode nodeV) {
// Determine if there is still some connection from u to v.
// Note this is an inlining of reachableNodes which short-circuits
// if all nodes are reachable.
Queue<WiredNode> enqueued = new ArrayDeque<>();
var reachableU = new HashSet<WiredNode>();
Queue<WiredNodeImpl> enqueued = new ArrayDeque<>();
var reachableU = new HashSet<WiredNodeImpl>();
reachableU.add(wiredU);
enqueued.add(wiredU);
@ -127,7 +127,7 @@ public boolean disconnect(IWiredNode nodeU, IWiredNode nodeV) {
// Create a new network with all U-reachable nodes/edges and remove them
// from the existing graph.
var networkU = new WiredNetwork(reachableU);
var networkU = new WiredNetworkImpl(reachableU);
networkU.lock.writeLock().lock();
try {
// Remove nodes from this network
@ -141,9 +141,9 @@ public boolean disconnect(IWiredNode nodeU, IWiredNode nodeV) {
}
// Broadcast changes
if (!peripherals.isEmpty()) WiredNetworkChange.removed(peripherals).broadcast(networkU.nodes);
if (!peripherals.isEmpty()) WiredNetworkChangeImpl.removed(peripherals).broadcast(networkU.nodes);
if (!networkU.peripherals.isEmpty()) {
WiredNetworkChange.removed(networkU.peripherals).broadcast(nodes);
WiredNetworkChangeImpl.removed(networkU.peripherals).broadcast(nodes);
}
InvariantChecker.checkNetwork(this);
@ -161,7 +161,7 @@ public boolean disconnect(IWiredNode nodeU, IWiredNode nodeV) {
}
@Override
public boolean remove(IWiredNode node) {
public boolean remove(WiredNode node) {
var wired = checkNode(node);
lock.writeLock().lock();
@ -177,7 +177,7 @@ public boolean remove(IWiredNode node) {
nodes.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
// check for network splitting
@ -203,14 +203,14 @@ public boolean remove(IWiredNode node) {
// A split may cause 2..neighbours.size() separate networks, so we
// iterate through our neighbour list, generating child networks.
neighbours.removeAll(reachable);
var maximals = new ArrayList<WiredNetwork>(neighbours.size() + 1);
var maximals = new ArrayList<WiredNetworkImpl>(neighbours.size() + 1);
maximals.add(wiredNetwork);
maximals.add(new WiredNetwork(reachable));
maximals.add(new WiredNetworkImpl(reachable));
while (!neighbours.isEmpty()) {
reachable = reachableNodes(neighbours.iterator().next());
neighbours.removeAll(reachable);
maximals.add(new WiredNetwork(reachable));
maximals.add(new WiredNetworkImpl(reachable));
}
for (var network : maximals) network.lock.writeLock().lock();
@ -233,7 +233,7 @@ public boolean remove(IWiredNode node) {
// Then broadcast network changes once all nodes are finalised
for (var network : maximals) {
WiredNetworkChange.changeOf(peripherals, network.peripherals).broadcast(network.nodes);
WiredNetworkChangeImpl.changeOf(peripherals, network.peripherals).broadcast(network.nodes);
}
} finally {
for (var network : maximals) network.lock.writeLock().unlock();
@ -249,7 +249,7 @@ public boolean remove(IWiredNode node) {
}
@Override
public void updatePeripherals(IWiredNode node, Map<String, IPeripheral> newPeripherals) {
public void updatePeripherals(WiredNode node, Map<String, IPeripheral> newPeripherals) {
var wired = checkNode(node);
Objects.requireNonNull(peripherals, "peripherals cannot be null");
@ -258,7 +258,7 @@ public void updatePeripherals(IWiredNode node, Map<String, IPeripheral> newPerip
if (wired.network != this) throw new IllegalStateException("Node is not on this network");
var oldPeripherals = wired.peripherals;
var change = WiredNetworkChange.changeOf(oldPeripherals, newPeripherals);
var change = WiredNetworkChangeImpl.changeOf(oldPeripherals, newPeripherals);
if (change.isEmpty()) return;
wired.peripherals = ImmutableMap.copyOf(newPeripherals);
@ -275,8 +275,8 @@ public void updatePeripherals(IWiredNode node, Map<String, IPeripheral> newPerip
}
}
static void transmitPacket(WiredNode start, Packet packet, double range, boolean interdimensional) {
Map<WiredNode, TransmitPoint> points = new HashMap<>();
static void transmitPacket(WiredNodeImpl start, Packet packet, double range, boolean interdimensional) {
Map<WiredNodeImpl, TransmitPoint> points = new HashMap<>();
var transmitTo = new TreeSet<TransmitPoint>();
{
@ -324,7 +324,7 @@ static void transmitPacket(WiredNode start, Packet packet, double range, boolean
}
}
private void removeSingleNode(WiredNode wired, WiredNetwork wiredNetwork) {
private void removeSingleNode(WiredNodeImpl wired, WiredNetworkImpl wiredNetwork) {
wiredNetwork.lock.writeLock().lock();
try {
// Cache all the old nodes.
@ -337,11 +337,11 @@ private void removeSingleNode(WiredNode wired, WiredNetwork wiredNetwork) {
wired.peripherals = Collections.emptyMap();
// 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.
peripherals.keySet().removeAll(wiredPeripherals.keySet());
if (!wiredPeripherals.isEmpty()) WiredNetworkChange.removed(wiredPeripherals).broadcast(nodes);
if (!wiredPeripherals.isEmpty()) WiredNetworkChangeImpl.removed(wiredPeripherals).broadcast(nodes);
} finally {
wiredNetwork.lock.writeLock().unlock();
@ -349,11 +349,11 @@ private void removeSingleNode(WiredNode wired, WiredNetwork wiredNetwork) {
}
private static class TransmitPoint implements Comparable<TransmitPoint> {
final WiredNode node;
final WiredNodeImpl node;
double distance;
boolean interdimensional;
TransmitPoint(WiredNode node, double distance, boolean interdimensional) {
TransmitPoint(WiredNodeImpl node, double distance, boolean interdimensional) {
this.node = node;
this.distance = distance;
this.interdimensional = interdimensional;
@ -368,22 +368,22 @@ public int compareTo(TransmitPoint o) {
}
}
private static WiredNode checkNode(IWiredNode node) {
if (node instanceof WiredNode) {
return (WiredNode) node;
private static WiredNodeImpl checkNode(WiredNode node) {
if (node instanceof WiredNodeImpl) {
return (WiredNodeImpl) node;
} else {
throw new IllegalArgumentException("Unknown implementation of IWiredNode: " + node);
}
}
private static HashSet<WiredNode> reachableNodes(WiredNode start) {
Queue<WiredNode> enqueued = new ArrayDeque<>();
var reachable = new HashSet<WiredNode>();
private static HashSet<WiredNodeImpl> reachableNodes(WiredNodeImpl start) {
Queue<WiredNodeImpl> enqueued = new ArrayDeque<>();
var reachable = new HashSet<WiredNodeImpl>();
reachable.add(start);
enqueued.add(start);
WiredNode node;
WiredNodeImpl node;
while ((node = enqueued.poll()) != null) {
for (var neighbour : node.neighbours) {
// Otherwise attempt to enqueue this neighbour as well.

View File

@ -5,39 +5,39 @@
*/
package dan200.computercraft.impl.network.wired;
import dan200.computercraft.api.network.IPacketReceiver;
import dan200.computercraft.api.network.Packet;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.IWiredNetwork;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.network.wired.IWiredSender;
import dan200.computercraft.api.network.PacketReceiver;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.network.wired.WiredNetwork;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.network.wired.WiredSender;
import dan200.computercraft.api.peripheral.IPeripheral;
import javax.annotation.Nullable;
import java.util.*;
public final class WiredNode implements IWiredNode {
private @Nullable Set<IPacketReceiver> receivers;
public final class WiredNodeImpl implements WiredNode {
private @Nullable Set<PacketReceiver> receivers;
final IWiredElement element;
final WiredElement element;
Map<String, IPeripheral> peripherals = Collections.emptyMap();
final HashSet<WiredNode> neighbours = new HashSet<>();
volatile WiredNetwork network;
final HashSet<WiredNodeImpl> neighbours = new HashSet<>();
volatile WiredNetworkImpl network;
public WiredNode(IWiredElement element) {
public WiredNodeImpl(WiredElement element) {
this.element = element;
network = new WiredNetwork(this);
network = new WiredNetworkImpl(this);
}
@Override
public synchronized void addReceiver(IPacketReceiver receiver) {
public synchronized void addReceiver(PacketReceiver receiver) {
if (receivers == null) receivers = new HashSet<>();
receivers.add(receiver);
}
@Override
public synchronized void removeReceiver(IPacketReceiver receiver) {
public synchronized void removeReceiver(PacketReceiver receiver) {
if (receivers != null) receivers.remove(receiver);
}
@ -66,13 +66,13 @@ public boolean isWireless() {
@Override
public void transmitSameDimension(Packet packet, double range) {
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");
}
acquireReadLock();
try {
WiredNetwork.transmitPacket(this, packet, range, false);
WiredNetworkImpl.transmitPacket(this, packet, range, false);
} finally {
network.lock.readLock().unlock();
}
@ -81,25 +81,25 @@ public void transmitSameDimension(Packet packet, double range) {
@Override
public void transmitInterdimensional(Packet packet) {
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");
}
acquireReadLock();
try {
WiredNetwork.transmitPacket(this, packet, 0, true);
WiredNetworkImpl.transmitPacket(this, packet, 0, true);
} finally {
network.lock.readLock().unlock();
}
}
@Override
public IWiredElement getElement() {
public WiredElement getElement() {
return element;
}
@Override
public IWiredNetwork getNetwork() {
public WiredNetwork getNetwork() {
return network;
}

View File

@ -7,7 +7,7 @@
import com.mojang.brigadier.arguments.ArgumentType;
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.media.IMedia;
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
@ -98,7 +98,7 @@
/**
* Registers ComputerCraft's registry entries and additional objects, such as {@link CauldronInteraction}s and
* {@link IDetailProvider}s
* {@link DetailProvider}s
* <p>
* The functions in this class should be called from a loader-specific class.
*/

View File

@ -5,13 +5,13 @@
*/
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.Direction;
import net.minecraft.world.level.Level;
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider {
public class DefaultBundledRedstoneProvider implements BundledRedstoneProvider {
@Override
public int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side) {
return getDefaultBundledRedstoneOutput(world, pos, side);

View File

@ -314,7 +314,7 @@ public final ServerComputer createServerComputer() {
var computer = ServerContext.get(server).registry().get(instanceID);
if (computer == null) {
if (computerID < 0) {
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level, IDAssigner.COMPUTER);
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(server, IDAssigner.COMPUTER);
BlockEntityHelpers.updateBlock(this);
}

View File

@ -8,7 +8,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
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.filesystem.FileSystem;
import dan200.computercraft.core.util.IoUtil;
@ -29,7 +29,7 @@
import java.util.Map;
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);
/**

View File

@ -6,7 +6,7 @@
package dan200.computercraft.shared.computer.core;
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.peripheral.IPeripheral;
import dan200.computercraft.core.apis.IAPIEnvironment;
@ -245,7 +245,7 @@ public MetricsObserver getMetrics() {
}
@Override
public @Nullable IWritableMount createRootMount() {
return ComputerCraftAPI.createSaveDirMount(level, "computer/" + computer.getID(), Config.computerSpaceLimit);
public @Nullable WritableMount createRootMount() {
return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + computer.getID(), Config.computerSpaceLimit);
}
}

View File

@ -7,7 +7,7 @@
import com.google.common.annotations.VisibleForTesting;
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.computer.ComputerThread;
import dan200.computercraft.core.computer.GlobalEnvironment;
@ -21,7 +21,6 @@
import dan200.computercraft.shared.util.IDAssigner;
import net.minecraft.SharedConstants;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.LevelResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -156,7 +155,7 @@ public ServerComputerRegistry registry() {
*
* @param kind The kind we're assigning an ID for, for instance {@code "computer"} or {@code "peripheral.monitor"}.
* @return The next available ID.
* @see ComputerCraftAPI#createUniqueNumberedSaveDir(Level, String)
* @see ComputerCraftAPI#createUniqueNumberedSaveDir(MinecraftServer, String)
*/
public int getNextId(String kind) {
return idAssigner.getNextId(kind);
@ -183,8 +182,8 @@ public GlobalMetrics metrics() {
private record Environment(MinecraftServer server) implements GlobalEnvironment {
@Override
public @Nullable IMount createResourceMount(String domain, String subPath) {
return ComputerCraftAPI.createResourceMount(domain, subPath);
public @Nullable Mount createResourceMount(String domain, String subPath) {
return ComputerCraftAPI.createResourceMount(server, domain, subPath);
}
@Override

View File

@ -6,13 +6,14 @@
package dan200.computercraft.shared.computer.items;
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.shared.computer.blocks.AbstractComputerBlock;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.config.Config;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
@ -63,12 +64,12 @@ public boolean setLabel(ItemStack stack, @Nullable String label) {
}
@Override
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) {
var family = getFamily();
if (family != ComputerFamily.COMMAND) {
var id = getComputerID(stack);
if (id >= 0) {
return ComputerCraftAPI.createSaveDirMount(world, "computer/" + id, Config.computerSpaceLimit);
return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + id, Config.computerSpaceLimit);
}
}
return null;

View File

@ -9,7 +9,7 @@
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
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.TurtleUpgrades;
import dan200.computercraft.shared.pocket.items.PocketComputerItem;
@ -245,7 +245,7 @@ private class UpgradeInfo {
final Ingredient ingredient;
final @Nullable ITurtleUpgrade turtle;
final @Nullable IPocketUpgrade pocket;
final IUpgradeBase upgrade;
final UpgradeBase upgrade;
private @Nullable ArrayList<T> recipes;
UpgradeInfo(ItemStack stack, ITurtleUpgrade turtle) {

View File

@ -7,7 +7,7 @@
import dan200.computercraft.annotations.ForgeOverride;
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.core.util.Colour;
import dan200.computercraft.shared.ModRegistry;
@ -17,6 +17,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
@ -83,13 +84,13 @@ public boolean setLabel(ItemStack stack, @Nullable String label) {
}
@Override
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) {
var diskID = getDiskID(stack);
if (diskID < 0) {
diskID = ComputerCraftAPI.createUniqueNumberedSaveDir(world, "disk");
diskID = ComputerCraftAPI.createUniqueNumberedSaveDir(level.getServer(), "disk");
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) {

View File

@ -7,7 +7,7 @@
import dan200.computercraft.annotations.ForgeOverride;
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.core.filesystem.SubMount;
import dan200.computercraft.core.util.Colour;
@ -15,6 +15,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
@ -57,8 +58,8 @@ public String getLabel(ItemStack stack) {
}
@Override
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
var rootTreasure = getTreasureMount();
public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) {
var rootTreasure = ComputerCraftAPI.createResourceMount(level.getServer(), "computercraft", "lua/treasure");
if (rootTreasure == null) return null;
var subPath = getSubPath(stack);
@ -93,10 +94,6 @@ public static ItemStack create(String subPath, int colourIndex) {
return result;
}
private static @Nullable IMount getTreasureMount() {
return ComputerCraftAPI.createResourceMount("computercraft", "lua/treasure");
}
private static String getTitle(ItemStack stack) {
var nbt = stack.getTag();
return nbt != null && nbt.contains(NBT_TITLE) ? nbt.getString(NBT_TITLE) : "'missingno' by how did you get this anyway?";

View File

@ -9,7 +9,7 @@
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
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.impl.PocketUpgrades;
import dan200.computercraft.impl.TurtleUpgrades;
@ -42,7 +42,7 @@ public UpgradesLoadedMessage(FriendlyByteBuf buf) {
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
) {
var registry = PlatformHelper.get().wrap(registryKey);
@ -71,7 +71,7 @@ public void toBytes(FriendlyByteBuf buf) {
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
) {
var registry = PlatformHelper.get().wrap(registryKey);

View File

@ -6,7 +6,7 @@
package dan200.computercraft.shared.peripheral.diskdrive;
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.IPeripheral;
import dan200.computercraft.shared.common.AbstractContainerBlockEntity;
@ -205,7 +205,7 @@ void ejectDisk() {
private void mountDisk(IComputerAccess computer, MountInfo info, MediaStack disk) {
var mount = disk.getMount((ServerLevel) getLevel());
if (mount != null) {
if (mount instanceof IWritableMount writable) {
if (mount instanceof WritableMount writable) {
// Try mounting at the lowest numbered "disk" name we can
var n = 1;
while (info.mountPath == null) {

View File

@ -5,7 +5,7 @@
*/
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.impl.MediaProviders;
import net.minecraft.server.level.ServerLevel;
@ -24,7 +24,7 @@ class MediaStack {
final @Nullable IMedia media;
@Nullable
private IMount mount;
private Mount mount;
MediaStack(ItemStack stack) {
this.stack = stack;
@ -42,7 +42,7 @@ String getAudioTitle() {
}
@Nullable
public IMount getMount(ServerLevel level) {
public Mount getMount(ServerLevel level) {
if (media == null) return null;
if (mount == null) mount = media.createDataMount(stack, level);

View File

@ -7,10 +7,10 @@
import dan200.computercraft.api.lua.LuaException;
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.PacketNetwork;
import dan200.computercraft.api.network.PacketReceiver;
import dan200.computercraft.api.network.PacketSender;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
@ -83,8 +83,8 @@
* <mc-recipe recipe="computercraft:wired_modem_full_from"></mc-recipe>
* </div>
*/
public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPacketReceiver {
private @Nullable IPacketNetwork network;
public abstract class ModemPeripheral implements IPeripheral, PacketSender, PacketReceiver {
private @Nullable PacketNetwork network;
private final Set<IComputerAccess> computers = new HashSet<>(1);
private final ModemState state;
@ -96,7 +96,7 @@ public ModemState getModemState() {
return state;
}
private synchronized void setNetwork(@Nullable IPacketNetwork network) {
private synchronized void setNetwork(@Nullable PacketNetwork network) {
if (this.network == network) return;
// Leave old network
@ -137,7 +137,7 @@ public void receiveDifferentDimension(Packet packet) {
}
}
protected abstract IPacketNetwork getNetwork();
protected abstract PacketNetwork getNetwork();
@Override
public String getType() {

View File

@ -6,8 +6,8 @@
package dan200.computercraft.shared.peripheral.modem.wired;
import com.google.common.base.Objects;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.command.text.ChatHelpers;
@ -67,7 +67,7 @@ protected void detachPeripheral(String name) {
private boolean connectionsFormed = false;
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 WiredModemPeripheral modem = new WiredModemPeripheral(
new ModemState(() -> TickScheduler.schedule(tickToken)),
@ -89,7 +89,7 @@ public Object getTarget() {
}
};
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) {
super(type, pos, state);
@ -309,7 +309,7 @@ private void updateConnectedPeripherals() {
}
@Nullable
public IWiredElement getWiredElement(@Nullable Direction direction) {
public WiredElement getWiredElement(@Nullable Direction direction) {
return direction == null || CableBlock.canConnectIn(getBlockState(), direction) ? cable : null;
}

View File

@ -6,20 +6,20 @@
package dan200.computercraft.shared.peripheral.modem.wired;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.IWiredNetworkChange;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.network.wired.WiredNetworkChange;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.peripheral.IPeripheral;
import java.util.HashMap;
import java.util.Map;
public abstract class WiredModemElement implements IWiredElement {
private final IWiredNode node = ComputerCraftAPI.createWiredNodeForElement(this);
public abstract class WiredModemElement implements WiredElement {
private final WiredNode node = ComputerCraftAPI.createWiredNodeForElement(this);
private final Map<String, IPeripheral> remotePeripherals = new HashMap<>();
@Override
public IWiredNode getNode() {
public WiredNode getNode() {
return node;
}
@ -29,7 +29,7 @@ public String getSenderID() {
}
@Override
public void networkChanged(IWiredNetworkChange change) {
public void networkChanged(WiredNetworkChange change) {
synchronized (remotePeripherals) {
remotePeripherals.keySet().removeAll(change.peripheralsRemoved().keySet());
for (var name : change.peripheralsRemoved().keySet()) {

View File

@ -6,8 +6,8 @@
package dan200.computercraft.shared.peripheral.modem.wired;
import com.google.common.base.Objects;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.command.text.ChatHelpers;
import dan200.computercraft.shared.peripheral.modem.ModemState;
@ -81,9 +81,9 @@ public Vec3 getPosition() {
private final TickScheduler.Token tickToken = new TickScheduler.Token(this);
private final ModemState modemState = new ModemState(() -> TickScheduler.schedule(tickToken));
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;
@ -278,7 +278,7 @@ private void updateConnectedPeripherals() {
node.updatePeripherals(peripherals);
}
public IWiredElement getElement() {
public WiredElement getElement() {
return element;
}

View File

@ -6,16 +6,16 @@
package dan200.computercraft.shared.peripheral.modem.wired;
import com.google.common.collect.ImmutableMap;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.filesystem.Mount;
import dan200.computercraft.api.filesystem.WritableMount;
import dan200.computercraft.api.lua.*;
import dan200.computercraft.api.network.IPacketNetwork;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.network.wired.IWiredSender;
import dan200.computercraft.api.network.PacketNetwork;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.network.wired.WiredSender;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IWorkMonitor;
import dan200.computercraft.api.peripheral.NotAttachedException;
import dan200.computercraft.api.peripheral.WorkMonitor;
import dan200.computercraft.core.apis.PeripheralAPI;
import dan200.computercraft.core.asm.PeripheralMethod;
import dan200.computercraft.core.util.LuaUtil;
@ -30,7 +30,7 @@
import java.util.concurrent.ConcurrentHashMap;
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 final WiredModemElement modem;
@ -54,7 +54,7 @@ public double getRange() {
}
@Override
protected IPacketNetwork getNetwork() {
protected PacketNetwork getNetwork() {
return modem.getNode();
}
@ -261,7 +261,7 @@ public boolean equals(@Nullable IPeripheral other) {
//endregion
@Override
public IWiredNode getNode() {
public WiredNode getNode() {
return modem.getNode();
}
@ -368,7 +368,7 @@ public MethodResult callMethod(ILuaContext context, String methodName, IArgument
// IComputerAccess implementation
@Override
public synchronized @Nullable String mount(String desiredLocation, IMount mount) {
public synchronized @Nullable String mount(String desiredLocation, Mount mount) {
if (!attached) throw new NotAttachedException();
var mounted = computer.mount(desiredLocation, mount, name);
mounts.add(mounted);
@ -376,7 +376,7 @@ public MethodResult callMethod(ILuaContext context, String methodName, IArgument
}
@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();
var mounted = computer.mount(desiredLocation, mount, driveName);
mounts.add(mounted);
@ -384,7 +384,7 @@ public MethodResult callMethod(ILuaContext context, String methodName, IArgument
}
@Override
public synchronized @Nullable String mountWritable(String desiredLocation, IWritableMount mount) {
public synchronized @Nullable String mountWritable(String desiredLocation, WritableMount mount) {
if (!attached) throw new NotAttachedException();
var mounted = computer.mountWritable(desiredLocation, mount, name);
mounts.add(mounted);
@ -392,7 +392,7 @@ public MethodResult callMethod(ILuaContext context, String methodName, IArgument
}
@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();
var mounted = computer.mountWritable(desiredLocation, mount, driveName);
mounts.add(mounted);
@ -419,7 +419,7 @@ public void queueEvent(String event, @Nullable Object... arguments) {
}
@Override
public IWorkMonitor getMainThreadMonitor() {
public WorkMonitor getMainThreadMonitor() {
if (!attached) throw new NotAttachedException();
return computer.getMainThreadMonitor();
}

View File

@ -6,7 +6,8 @@
package dan200.computercraft.shared.peripheral.modem.wireless;
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.peripheral.modem.ModemPeripheral;
import dan200.computercraft.shared.peripheral.modem.ModemState;
@ -51,7 +52,7 @@ public double getRange() {
}
@Override
protected IPacketNetwork getNetwork() {
return ComputerCraftAPI.getWirelessNetwork();
protected PacketNetwork getNetwork() {
return ComputerCraftAPI.getWirelessNetwork(Nullability.assertNonNull(getLevel().getServer()));
}
}

View File

@ -5,9 +5,9 @@
*/
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.PacketNetwork;
import dan200.computercraft.api.network.PacketReceiver;
import javax.annotation.Nullable;
import java.util.Collections;
@ -15,7 +15,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class WirelessNetwork implements IPacketNetwork {
public class WirelessNetwork implements PacketNetwork {
// TODO: Move this to ServerContext.
private static @Nullable WirelessNetwork universalNetwork = null;
@ -28,16 +28,16 @@ public static void resetNetworks() {
universalNetwork = null;
}
private final Set<IPacketReceiver> receivers = Collections.newSetFromMap(new ConcurrentHashMap<>());
private final Set<PacketReceiver> receivers = Collections.newSetFromMap(new ConcurrentHashMap<>());
@Override
public void addReceiver(IPacketReceiver receiver) {
public void addReceiver(PacketReceiver receiver) {
Objects.requireNonNull(receiver, "device cannot be null");
receivers.add(receiver);
}
@Override
public void removeReceiver(IPacketReceiver receiver) {
public void removeReceiver(PacketReceiver receiver) {
Objects.requireNonNull(receiver, "device cannot be null");
receivers.remove(receiver);
}
@ -54,7 +54,7 @@ public void transmitInterdimensional(Packet packet) {
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();
if (receiver.getLevel() == sender.getLevel()) {
var receiveRange = Math.max(range, receiver.getRange()); // Ensure range is symmetrical

View File

@ -7,7 +7,7 @@
import com.mojang.authlib.GameProfile;
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.shared.network.NetworkMessage;
import dan200.computercraft.shared.network.client.ClientNetworkContext;
@ -45,7 +45,6 @@
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nullable;
import java.util.Collection;
@ -204,7 +203,7 @@ static PlatformHelper get() {
* include all changes, and so block updates should still be listened to.
* @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
@ -239,18 +238,6 @@ static PlatformHelper get() {
@Nullable
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.
*

View File

@ -8,7 +8,7 @@
import com.google.common.base.Objects;
import dan200.computercraft.annotations.ForgeOverride;
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.pocket.IPocketUpgrade;
import dan200.computercraft.core.computer.ComputerSide;
@ -192,21 +192,19 @@ public String getCreatorModId(ItemStack stack) {
return ComputerCraftAPI.MOD_ID;
}
public PocketServerComputer createServerComputer(ServerLevel world, Entity entity, @Nullable Container inventory, ItemStack stack) {
if (world.isClientSide) throw new IllegalStateException("Cannot call createServerComputer on the client");
public PocketServerComputer createServerComputer(ServerLevel level, Entity entity, @Nullable Container inventory, ItemStack 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));
if (computer == null) {
var computerID = getComputerID(stack);
if (computerID < 0) {
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(world, IDAssigner.COMPUTER);
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level.getServer(), IDAssigner.COMPUTER);
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());
setSessionID(stack, registry.getSessionID());
@ -219,7 +217,7 @@ public PocketServerComputer createServerComputer(ServerLevel world, Entity entit
if (inventory != null) inventory.setChanged();
}
computer.setLevel(world);
computer.setLevel(level);
return computer;
}
@ -265,10 +263,10 @@ public boolean setLabel(ItemStack stack, @Nullable String label) {
}
@Override
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
public @Nullable Mount createDataMount(ItemStack stack, ServerLevel level) {
var id = getComputerID(stack);
if (id >= 0) {
return ComputerCraftAPI.createSaveDirMount(world, "computer/" + id, Config.computerSpaceLimit);
return ComputerCraftAPI.createSaveDirMount(level.getServer(), "computer/" + id, Config.computerSpaceLimit);
}
return null;
}

View File

@ -8,7 +8,7 @@
import dan200.computercraft.api.detail.VanillaDetailRegistries;
import dan200.computercraft.api.lua.*;
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.TurtleSide;
import dan200.computercraft.core.apis.IAPIEnvironment;
@ -82,7 +82,7 @@ public String[] getNames() {
return new String[]{ "turtle" };
}
private MethodResult trackCommand(ITurtleCommand command) {
private MethodResult trackCommand(TurtleCommand command) {
environment.observe(Metrics.TURTLE_OPS);
return turtle.executeCommand(command);
}

View File

@ -18,7 +18,6 @@
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.config.Config;
import dan200.computercraft.shared.container.InventoryDelegate;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity;
import dan200.computercraft.shared.util.BlockEntityHelpers;
import dan200.computercraft.shared.util.Holiday;
@ -39,7 +38,6 @@
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nullable;
import java.util.*;
@ -382,12 +380,6 @@ public Container getInventory() {
return inventory;
}
@Override
@Deprecated(forRemoval = true)
public IItemHandlerModifiable getItemHandler() {
return PlatformHelper.get().wrapContainerToItemHandler(inventory);
}
@Override
public boolean isFuelNeeded() {
return Config.turtlesNeedFuel;
@ -436,7 +428,7 @@ public void addFuel(int fuel) {
}
@Override
public MethodResult executeCommand(ITurtleCommand command) {
public MethodResult executeCommand(TurtleCommand command) {
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");

View File

@ -5,7 +5,7 @@
*/
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) {
}

View File

@ -6,13 +6,13 @@
package dan200.computercraft.shared.turtle.core;
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 net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
public class TurtleCompareCommand implements ITurtleCommand {
public class TurtleCompareCommand implements TurtleCommand {
private final InteractDirection direction;
public TurtleCompareCommand(InteractDirection direction) {

View File

@ -6,11 +6,11 @@
package dan200.computercraft.shared.turtle.core;
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 net.minecraft.world.item.ItemStack;
public class TurtleCompareToCommand implements ITurtleCommand {
public class TurtleCompareToCommand implements TurtleCommand {
private final int slot;
public TurtleCompareToCommand(int slot) {

View File

@ -6,13 +6,13 @@
package dan200.computercraft.shared.turtle.core;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.turtle.TurtleUtil;
import dan200.computercraft.shared.turtle.upgrades.TurtleInventoryCrafting;
public class TurtleCraftCommand implements ITurtleCommand {
public class TurtleCraftCommand implements TurtleCommand {
private final int limit;
public TurtleCraftCommand(int limit) {

View File

@ -6,11 +6,11 @@
package dan200.computercraft.shared.turtle.core;
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.shared.util.WorldUtil;
public class TurtleDetectCommand implements ITurtleCommand {
public class TurtleDetectCommand implements TurtleCommand {
private final InteractDirection direction;
public TurtleDetectCommand(InteractDirection direction) {

View File

@ -6,8 +6,8 @@
package dan200.computercraft.shared.turtle.core;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.platform.ContainerTransfer;
import dan200.computercraft.shared.platform.PlatformHelper;
@ -16,7 +16,7 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.LevelEvent;
public class TurtleDropCommand implements ITurtleCommand {
public class TurtleDropCommand implements TurtleCommand {
private final InteractDirection direction;
private final int quantity;

View File

@ -10,7 +10,7 @@
import dan200.computercraft.shared.turtle.TurtleUtil;
import net.minecraft.world.item.ItemStack;
public class TurtleEquipCommand implements ITurtleCommand {
public class TurtleEquipCommand implements TurtleCommand {
private final TurtleSide side;
public TurtleEquipCommand(TurtleSide side) {

View File

@ -8,10 +8,10 @@
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.VanillaDetailRegistries;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
public class TurtleInspectCommand implements ITurtleCommand {
public class TurtleInspectCommand implements TurtleCommand {
private final InteractDirection direction;
public TurtleInspectCommand(InteractDirection direction) {

View File

@ -6,8 +6,8 @@
package dan200.computercraft.shared.turtle.core;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.config.Config;
import dan200.computercraft.shared.util.WorldUtil;
@ -18,7 +18,7 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
public class TurtleMoveCommand implements ITurtleCommand {
public class TurtleMoveCommand implements TurtleCommand {
private final MoveDirection direction;
public TurtleMoveCommand(MoveDirection direction) {

View File

@ -7,8 +7,8 @@
import com.google.common.base.Splitter;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.turtle.TurtleUtil;
@ -36,7 +36,7 @@
import javax.annotation.Nullable;
public class TurtlePlaceCommand implements ITurtleCommand {
public class TurtlePlaceCommand implements TurtleCommand {
private final InteractDirection direction;
private final Object[] extraArguments;

View File

@ -6,12 +6,12 @@
package dan200.computercraft.shared.turtle.core;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.impl.TurtleRefuelHandlers;
public class TurtleRefuelCommand implements ITurtleCommand {
public class TurtleRefuelCommand implements TurtleCommand {
private final int limit;
public TurtleRefuelCommand(int limit) {

View File

@ -6,8 +6,8 @@
package dan200.computercraft.shared.turtle.core;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.platform.ContainerTransfer;
import dan200.computercraft.shared.platform.PlatformHelper;
@ -20,7 +20,7 @@
import net.minecraft.world.level.block.LevelEvent;
import net.minecraft.world.phys.AABB;
public class TurtleSuckCommand implements ITurtleCommand {
public class TurtleSuckCommand implements TurtleCommand {
private final InteractDirection direction;
private final int quantity;

View File

@ -10,7 +10,7 @@
import javax.annotation.Nullable;
import java.util.Locale;
public class TurtleToolCommand implements ITurtleCommand {
public class TurtleToolCommand implements TurtleCommand {
private final TurtleVerb verb;
private final InteractDirection direction;
private final @Nullable TurtleSide side;

View File

@ -6,12 +6,12 @@
package dan200.computercraft.shared.turtle.core;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.util.InventoryUtil;
public class TurtleTransferToCommand implements ITurtleCommand {
public class TurtleTransferToCommand implements TurtleCommand {
private final int slot;
private final int quantity;

View File

@ -6,11 +6,11 @@
package dan200.computercraft.shared.turtle.core;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
public class TurtleTurnCommand implements ITurtleCommand {
public class TurtleTurnCommand implements TurtleCommand {
private final TurnDirection direction;
public TurtleTurnCommand(TurnDirection direction) {

View File

@ -7,7 +7,7 @@
import com.google.gson.JsonObject;
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 net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
@ -25,7 +25,7 @@ private TurtleToolSerialiser() {
@Override
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 craftingItem = GsonHelper.getAsItem(object, "craftingItem", toolItem);
var damageMultiplier = GsonHelper.getAsFloat(object, "damageMultiplier", 3.0f);

View File

@ -8,8 +8,8 @@
import com.google.auto.service.AutoService;
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.arguments.ArgumentType;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.filesystem.Mount;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.impl.AbstractComputerCraftAPI;
import dan200.computercraft.impl.ComputerCraftAPIService;
@ -139,7 +139,7 @@ public ComponentAccess<IPeripheral> createPeripheralAccess(Consumer<Direction> i
}
@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");
}
@ -226,7 +226,7 @@ public String getInstalledVersion() {
@Nullable
@Override
public IMount createResourceMount(String domain, String subPath) {
public Mount createResourceMount(MinecraftServer server, String domain, String subPath) {
throw new UnsupportedOperationException("Cannot create resource mount");
}

View File

@ -8,10 +8,10 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.IWiredNetwork;
import dan200.computercraft.api.network.wired.IWiredNetworkChange;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.network.wired.WiredNetwork;
import dan200.computercraft.api.network.wired.WiredNetworkChange;
import dan200.computercraft.api.network.wired.WiredNode;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.core.BlockPos;
@ -36,7 +36,7 @@ public void testConnect() {
bE = new NetworkElement(null, null, "b"),
cE = new NetworkElement(null, null, "c");
IWiredNode
WiredNode
aN = aE.getNode(),
bN = bE.getNode(),
cN = cE.getNode();
@ -76,7 +76,7 @@ public void testDisconnectNoChange() {
bE = new NetworkElement(null, null, "b"),
cE = new NetworkElement(null, null, "c");
IWiredNode
WiredNode
aN = aE.getNode(),
bN = bE.getNode(),
cN = cE.getNode();
@ -103,7 +103,7 @@ public void testDisconnectLeaf() {
bE = new NetworkElement(null, null, "b"),
cE = new NetworkElement(null, null, "c");
IWiredNode
WiredNode
aN = aE.getNode(),
bN = bE.getNode(),
cN = cE.getNode();
@ -131,7 +131,7 @@ public void testDisconnectSplit() {
bE = new NetworkElement(null, null, "b"),
bbE = new NetworkElement(null, null, "b_");
IWiredNode
WiredNode
aN = aE.getNode(),
aaN = aaE.getNode(),
bN = bE.getNode(),
@ -172,7 +172,7 @@ public void testRemoveLeaf() {
bE = new NetworkElement(null, null, "b"),
cE = new NetworkElement(null, null, "c");
IWiredNode
WiredNode
aN = aE.getNode(),
bN = bE.getNode(),
cN = cE.getNode();
@ -203,7 +203,7 @@ public void testRemoveSplit() {
bbE = new NetworkElement(null, null, "b_"),
cE = new NetworkElement(null, null, "c");
IWiredNode
WiredNode
aN = aE.getNode(),
aaN = aaE.getNode(),
bN = bE.getNode(),
@ -238,7 +238,7 @@ public void testRemoveSplit() {
@Test
@Disabled("Takes a long time to run, mostly for stress testing")
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());
// Test connecting
@ -297,11 +297,11 @@ public void testLarge() {
}
}
private static final class NetworkElement implements IWiredElement {
private static final class NetworkElement implements WiredElement {
private final Level world;
private final Vec3 position;
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> remotePeripherals = Maps.newHashMap();
@ -334,12 +334,12 @@ public String toString() {
}
@Override
public IWiredNode getNode() {
public WiredNode getNode() {
return node;
}
@Override
public void networkChanged(IWiredNetworkChange change) {
public void networkChanged(WiredNetworkChange change) {
remotePeripherals.keySet().removeAll(change.peripheralsRemoved().keySet());
remotePeripherals.putAll(change.peripheralsAdded());
}
@ -406,11 +406,11 @@ public void map(BiFunction<T, BlockPos, T> transform) {
}
}
private static Set<WiredNode> nodes(IWiredNetwork network) {
return ((WiredNetwork) network).nodes;
private static Set<WiredNodeImpl> nodes(WiredNetwork network) {
return ((WiredNetworkImpl) network).nodes;
}
private static Set<WiredNode> neighbours(IWiredNode node) {
return ((WiredNode) node).neighbours;
private static Set<WiredNodeImpl> neighbours(WiredNode node) {
return ((WiredNodeImpl) node).neighbours;
}
}

View File

@ -5,7 +5,7 @@
*/
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.server.packs.FolderPackResources;
import net.minecraft.server.packs.PackType;
@ -25,7 +25,7 @@
import static org.junit.jupiter.api.Assertions.*;
public class ResourceMountTest {
private IMount mount;
private Mount mount;
@BeforeEach
public void before() {

View File

@ -14,7 +14,6 @@ val docApi by configurations.registering {
}
dependencies {
compileOnly(project(":mc-stubs"))
compileOnlyApi(libs.jsr305)
compileOnlyApi(libs.checkerFramework)
compileOnlyApi(libs.jetbrainsAnnotations)

View File

@ -11,7 +11,7 @@
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 size The size of the file.

View File

@ -13,7 +13,7 @@
/**
* An {@link IOException} which occurred on a specific file.
* <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 {
@Serial

View File

@ -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;
}

View File

@ -14,15 +14,15 @@
/**
* 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>
* 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}.
*
* @see IComputerAccess#mount(String, IMount)
* @see IWritableMount
* @see IComputerAccess#mount(String, Mount)
* @see WritableMount
*/
public interface IMount {
public interface Mount {
/**
* Returns whether a file with a given path exists or not.
*

View File

@ -13,17 +13,17 @@
import java.util.OptionalLong;
/**
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}
* or {@link IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
* 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, WritableMount)}, that can also be written to.
* <p>
* 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}.
*
* @see IComputerAccess#mount(String, IMount)
* @see IComputerAccess#mountWritable(String, IWritableMount)
* @see IMount
* @see IComputerAccess#mount(String, Mount)
* @see IComputerAccess#mountWritable(String, WritableMount)
* @see Mount
*/
public interface IWritableMount extends IMount {
public interface WritableMount extends Mount {
/**
* Creates a directory at a given path inside the virtual file system.
*

View File

@ -7,7 +7,6 @@
import dan200.computercraft.api.peripheral.GenericPeripheral;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.resources.ResourceLocation;
/**
* A generic source of {@link LuaFunction} functions.
@ -44,10 +43,10 @@ public interface GenericSource {
/**
* A unique identifier for this generic source.
* <p>
* This is currently unused, but may be used in the future to allow disabling specific sources. It is recommended
* to return an identifier using your mod's ID.
* While this can return an arbitrary string, it's recommended that this is formatted the same was as Minecraft's
* resource locations/identifiers, so is of the form {@code "mod_id:source_id"}.
*
* @return This source's identifier.
*/
ResourceLocation id();
String id();
}

View File

@ -5,7 +5,6 @@
*/
package dan200.computercraft.api.lua;
import dan200.computercraft.api.filesystem.IFileSystem;
import dan200.computercraft.api.peripheral.IComputerAccess;
import javax.annotation.Nullable;
@ -15,14 +14,6 @@
* about a computer.
*/
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.
*

View File

@ -23,7 +23,7 @@ public interface ILuaContext {
* @throws LuaException If the task could not be queued.
* @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.
@ -36,7 +36,7 @@ public interface ILuaContext {
* @return The objects returned by {@code task}.
* @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);
}
}

View File

@ -51,7 +51,7 @@
* Minecraft in a thread-unsafe manner.
*
* @return Whether this function should be run on the main thread.
* @see ILuaContext#issueMainThreadTask(ILuaTask)
* @see ILuaContext#issueMainThreadTask(LuaTask)
*/
boolean mainThread() default false;

View File

@ -8,14 +8,14 @@
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
* next tick.
*
* @see ILuaContext#issueMainThreadTask(ILuaTask)
* @see ILuaContext#issueMainThreadTask(LuaTask)
*/
@FunctionalInterface
public interface ILuaTask {
public interface LuaTask {
/**
* Execute this task.
*

View File

@ -34,7 +34,7 @@ public MethodResult resume(Object[] response) throws LuaException {
}
}
static MethodResult make(ILuaContext context, ILuaTask func) throws LuaException {
static MethodResult make(ILuaContext context, LuaTask func) throws LuaException {
var task = context.issueMainThreadTask(func);
return new TaskCallback(task).pull;
}

View File

@ -5,11 +5,11 @@
*/
package dan200.computercraft.api.peripheral;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.filesystem.Mount;
import dan200.computercraft.api.filesystem.WritableMount;
import dan200.computercraft.api.lua.ILuaCallback;
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 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
* file in the desired location. Store this value if you wish to unmount the mount later.
* @throws NotAttachedException If the peripheral has been detached.
* @see #mount(String, IMount, String)
* @see #mountWritable(String, IWritableMount)
* @see #mount(String, Mount, String)
* @see #mountWritable(String, WritableMount)
* @see #unmount(String)
* @see IMount
* @see Mount
*/
@Nullable
default String mount(String desiredLocation, IMount mount) {
default String mount(String desiredLocation, Mount mount) {
return mount(desiredLocation, mount, getAttachmentName());
}
@ -48,13 +48,13 @@ default String mount(String desiredLocation, IMount mount) {
* @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.
* @throws NotAttachedException If the peripheral has been detached.
* @see #mount(String, IMount)
* @see #mountWritable(String, IWritableMount)
* @see #mount(String, Mount)
* @see #mountWritable(String, WritableMount)
* @see #unmount(String)
* @see IMount
* @see Mount
*/
@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.
@ -64,12 +64,12 @@ default String mount(String desiredLocation, IMount mount) {
* @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.
* @throws NotAttachedException If the peripheral has been detached.
* @see #mount(String, IMount)
* @see #mount(String, Mount)
* @see #unmount(String)
* @see IMount
* @see Mount
*/
@Nullable
default String mountWritable(String desiredLocation, IWritableMount mount) {
default String mountWritable(String desiredLocation, WritableMount mount) {
return mountWritable(desiredLocation, mount, getAttachmentName());
}
@ -82,16 +82,16 @@ default String mountWritable(String desiredLocation, IWritableMount mount) {
* @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.
* @throws NotAttachedException If the peripheral has been detached.
* @see #mount(String, IMount)
* @see #mount(String, Mount)
* @see #unmount(String)
* @see IMount
* @see Mount
*/
@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)}
* or {@link #mountWritable(String, IWritableMount)}.
* Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, Mount)}
* or {@link #mountWritable(String, WritableMount)}.
* <p>
* 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
@ -100,12 +100,12 @@ default String mountWritable(String desiredLocation, IWritableMount mount) {
* Note that you cannot unmount another peripheral's mounts.
*
* @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
* {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
* This must be the location of a directory previously mounted by {@link #mount(String, Mount)} or
* {@link #mountWritable(String, WritableMount)}, as indicated by their return value.
* @throws NotAttachedException If the peripheral has been detached.
* @throws IllegalStateException If the mount does not exist, or was mounted by another peripheral.
* @see #mount(String, IMount)
* @see #mountWritable(String, IWritableMount)
* @see #mount(String, Mount)
* @see #mountWritable(String, WritableMount)
*/
void unmount(@Nullable String location);
@ -175,11 +175,11 @@ default String mountWritable(String desiredLocation, IWritableMount mount) {
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>
* 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
* {@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.
* <p>
* Please note that the returned implementation is <em>not</em> thread-safe, and should only be used from the main
@ -188,5 +188,5 @@ default String mountWritable(String desiredLocation, IWritableMount mount) {
* @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.
*/
IWorkMonitor getMainThreadMonitor();
WorkMonitor getMainThreadMonitor();
}

View File

@ -23,7 +23,7 @@
*
* @see IComputerAccess#getMainThreadMonitor()
*/
public interface IWorkMonitor {
public interface WorkMonitor {
/**
* 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