Javadoc fixes and small cleanup.

This commit is contained in:
Florian Nücke
2021-06-06 13:40:09 +02:00
parent 55bb6bc40c
commit 9fae40bdc7
24 changed files with 91 additions and 34 deletions

View File

@@ -11,14 +11,20 @@ import java.util.UUID;
* {@link DeviceBusElement#addController(DeviceBusController)}.
* <p>
* This interface is usually provided by VM containers and used to collect connected
* {@link Device}s by aggregating the devices that were added to the device bus elements
* via {@link DeviceBus#addDevice(Device)}.
* {@link Device}s by aggregating the devices made available by {@link DeviceBusElement}s
* via {@link DeviceBusElement#getLocalDevices()}.
* <p>
* The only way for {@link DeviceBusElement}s to be added to a bus is for a
* {@link DeviceBusController} to detect them during a scan.
* <p>
* This interface is only of relevance when implementing a VM container or a bus element,
* i.e. something that acts as a "cable" or otherwise extends the bus itself.
* This interface is only of relevance when implementing
* <ul>
* <li>a VM container, in which case an implementation
* of this interface must be used to control the bus for that container, or</li>
* <li>a bus element, which <em>must</em> call {@link #scheduleBusScan()} when the observable structure
* of the bus has changed (neighbors connected/disconnected) and <em>must</em> call {@link #scanDevices()}
* when the local list of devices has changed.</li>
* </ul>
*
* @see DeviceBusElement
*/

View File

@@ -17,8 +17,13 @@ import java.util.UUID;
* When discovered during a scan, the controller will then use the devices
* connected to this element.
* <p>
* This interface is only relevant when implementing it, e.g. to provide a custom
* "cable" or other means to extend a bus.
* This interface is relevant when implementing means to extend the bus, e.g.
* to provide a custom cable implementation or some kind of a device container.
* <p>
* Implementations <em>must</em> call {@link #scheduleScan()} when they become
* invalid, e.g. due to being in a chunk that is being unloaded or the block
* they are defined by being destroyed or the block face they were available
* through no longer offering the element.
*/
public interface DeviceBusElement extends DeviceBus {
/**
@@ -26,7 +31,8 @@ public interface DeviceBusElement extends DeviceBus {
* <p>
* This will be called by {@link DeviceBusController}s when scanning.
* <p>
* Bus elements can be have multiple controllers at the same time.
* Bus elements can be have multiple controllers at the same time. This is used
* by controllers to detect each other on the bus.
* <p>
* When {@link #scheduleScan()} is called, {@link DeviceBusController#scheduleBusScan()}
* <em>must</em> be called for each registered controller.
@@ -104,7 +110,7 @@ public interface DeviceBusElement extends DeviceBus {
* any connected item devices.
* <p>
* Block devices that require a running amount of energy should use regular means of having
* energy injected into them. The device bus is not intended nor communicated as something
* energy injected into them. The device bus is not intended for nor communicated as something
* that transfers power.
*
* @return the complexity of this bus element.

View File

@@ -47,6 +47,14 @@ public interface ItemDeviceProvider extends IForgeRegistryEntry<ItemDeviceProvid
*/
Optional<ItemDevice> getDevice(ItemDeviceQuery query);
/**
* Get the type of a device that would be obtained from {@link #getDevice(ItemDeviceQuery)}
* if called with the same query. The device type controls which slot devices may be
* inserted in in item device containers.
*
* @param query the query describing the object to get the {@link DeviceType} for.
* @return the device type for the specified type, if available.
*/
default Optional<DeviceType> getDeviceType(final ItemDeviceQuery query) {
return Optional.of(DeviceTypes.CARD);
}

View File

@@ -9,8 +9,8 @@ import java.util.Optional;
/**
* Represents a single method that can be exposed by a {@link RPCDevice}.
* <p>
* The easiest and hence recommended way of implementing this interface is to use
* the {@link ObjectDevice} class.
* The easiest and hence recommended way of generating an implementation of this
* interface is to use the {@link ObjectDevice} class.
* <p>
* Method parameters are serialized and deserialized using Gson. When using custom
* parameter types it may be necessary to register a custom type adapter for them

View File

@@ -4,9 +4,14 @@ import net.minecraft.util.text.ITextComponent;
import java.util.Optional;
/**
* May be fired by devices while handling {@link VMInitializingEvent} to indicate that initialization failed.
*/
public final class VMInitializationException extends RuntimeException {
private final ITextComponent message;
///////////////////////////////////////////////////////////////
public VMInitializationException(final ITextComponent message) {
this.message = message;
}
@@ -15,6 +20,15 @@ public final class VMInitializationException extends RuntimeException {
this.message = null;
}
///////////////////////////////////////////////////////////////
/**
* The error message indicating why initialization failed.
* <p>
* This should be a human readable message, as it may be displayed to the user.
*
* @return the error message.
*/
public Optional<ITextComponent> getErrorMessage() {
return Optional.ofNullable(message);
}

View File

@@ -19,7 +19,7 @@ import li.cil.oc2.api.bus.device.vm.context.VMContext;
* <p>
* <em>This is invoked from the worker thread running the VM.</em>
*/
public final class VMInitializingEvent extends VMLifecycleEvent {
public final class VMInitializingEvent {
private final long programStartAddress;
///////////////////////////////////////////////////////////////

View File

@@ -1,4 +0,0 @@
package li.cil.oc2.api.bus.device.vm.event;
public class VMLifecycleEvent {
}

View File

@@ -8,5 +8,5 @@ package li.cil.oc2.api.bus.device.vm.event;
* if such interactions may modify VM state, to prevent corrupting data being
* serialized asynchronously.
*/
public final class VMPausingEvent extends VMLifecycleEvent {
public final class VMPausingEvent {
}

View File

@@ -10,5 +10,5 @@ package li.cil.oc2.api.bus.device.vm.event;
* Typically this is used in combination with {@link VMPausingEvent}, to re-enable external
* interactions after VM state is guaranteed to be safe to modify again.
*/
public final class VMResumedRunningEvent extends VMLifecycleEvent {
public final class VMResumedRunningEvent {
}

View File

@@ -12,5 +12,5 @@ import li.cil.oc2.api.bus.device.vm.context.VMContext;
* from a saved state as well as when continuing to run after being paused for
* a save. It is intended for awaiting asynchronous load and store operations.
*/
public final class VMResumingRunningEvent extends VMLifecycleEvent {
public final class VMResumingRunningEvent {
}

View File

@@ -21,6 +21,8 @@ public final class GuiUtils {
private static final int DEVICE_INFO_ICON_SIZE = 28;
private static final int RELATIVE_ICON_POSITION = (SLOT_SIZE - DEVICE_INFO_ICON_SIZE) / 2;
///////////////////////////////////////////////////////////////////
public static <TContainer extends Container> void renderMissingDeviceInfoIcon(final MatrixStack matrixStack, final ContainerScreen<TContainer> screen, final DeviceType type, final ResourceLocation icon) {
findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getMenu(), type).ifPresent(slot -> {
screen.getMinecraft().getTextureManager().bind(icon);
@@ -55,6 +57,8 @@ public final class GuiUtils {
});
}
///////////////////////////////////////////////////////////////////
private static Optional<TypedSlotItemHandler> findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(final Container container, final DeviceType type) {
TypedSlotItemHandler firstSlot = null;
for (final Slot slot : container.slots) {

View File

@@ -19,6 +19,8 @@ public abstract class ImageButton extends AbstractButton {
private static final long PRESS_DURATION = 200;
private static final long TOOLTIP_DELAY = 250;
///////////////////////////////////////////////////////////////////
private final Screen parent;
private final List<? extends ITextComponent> tooltip;
private final Sprite baseImage;
@@ -26,6 +28,8 @@ public abstract class ImageButton extends AbstractButton {
private long lastPressedAt;
private long hoveringStartedAt;
///////////////////////////////////////////////////////////////////
public ImageButton(final Screen parent,
final int x, final int y,
final int width, final int height,
@@ -44,6 +48,8 @@ public abstract class ImageButton extends AbstractButton {
this.pressedImage = pressedImage;
}
///////////////////////////////////////////////////////////////////
@Override
public void onPress() {
lastPressedAt = System.currentTimeMillis();

View File

@@ -11,6 +11,8 @@ public final class Sprite extends AbstractGui {
public final int width, height;
public final int u0, v0;
///////////////////////////////////////////////////////////////////
public Sprite(final ResourceLocation atlas, final int textureSize, final int width, final int height, final int u0, final int v0) {
this.image = atlas;
this.textureSize = textureSize;
@@ -20,6 +22,8 @@ public final class Sprite extends AbstractGui {
this.v0 = v0;
}
///////////////////////////////////////////////////////////////////
public void draw(final MatrixStack stack, final int x, final int y) {
Minecraft.getInstance().getTextureManager().bind(image);
blit(stack, x, y, u0, v0, width, height, textureSize, textureSize);

View File

@@ -19,6 +19,8 @@ public abstract class ToggleImageButton extends AbstractButton {
private static final long PRESS_DURATION = 200;
private static final long TOOLTIP_DELAY = 250;
///////////////////////////////////////////////////////////////////
private final Screen parent;
private final List<? extends ITextComponent> tooltip;
private final Sprite baseImage;
@@ -28,6 +30,8 @@ public abstract class ToggleImageButton extends AbstractButton {
private long lastPressedAt;
private long hoveringStartedAt;
///////////////////////////////////////////////////////////////////
public ToggleImageButton(
final Screen parent,
final int x, final int y,
@@ -49,6 +53,8 @@ public abstract class ToggleImageButton extends AbstractButton {
this.activeImage = activeImage;
}
///////////////////////////////////////////////////////////////////
@Override
public void onPress() {
lastPressedAt = System.currentTimeMillis();

View File

@@ -22,17 +22,20 @@ import java.util.List;
import java.util.Random;
public final class BusCableBakedModel implements IDynamicBakedModel {
private final IBakedModel proxy;
private final IBakedModel[] straightModelByAxis;
private final IBakedModel[] supportModelByFace;
///////////////////////////////////////////////////////////////////
public BusCableBakedModel(final IBakedModel proxy, final IBakedModel[] straightModelByAxis, final IBakedModel[] supportModelByFace) {
this.proxy = proxy;
this.straightModelByAxis = straightModelByAxis;
this.supportModelByFace = supportModelByFace;
}
///////////////////////////////////////////////////////////////////
@Override
public List<BakedQuad> getQuads(@Nullable final BlockState state, @Nullable final Direction side, final Random rand, final IModelData extraData) {
if (state == null || !state.getValue(BusCableBlock.HAS_CABLE)) {

View File

@@ -21,12 +21,18 @@ public final class BusCableModel implements IModelGeometry<BusCableModel> {
private static final ResourceLocation BUS_CABLE_STRAIGHT_MODEL = new ResourceLocation(API.MOD_ID, "block/cable_straight");
private static final ResourceLocation BUS_CABLE_SUPPORT_MODEL = new ResourceLocation(API.MOD_ID, "block/cable_support");
///////////////////////////////////////////////////////////////////
private final ModelLoaderRegistry.VanillaProxy proxy;
///////////////////////////////////////////////////////////////////
public BusCableModel(final ModelLoaderRegistry.VanillaProxy proxy) {
this.proxy = proxy;
}
///////////////////////////////////////////////////////////////////
@Override
public IBakedModel bake(final IModelConfiguration owner, final ModelBakery bakery, final Function<RenderMaterial, TextureAtlasSprite> spriteGetter, final IModelTransform modelTransform, final ItemOverrideList overrides, final ResourceLocation modelLocation) {
final IBakedModel bakedBaseModel = proxy.bake(owner, bakery, spriteGetter, modelTransform, overrides, modelLocation);

View File

@@ -48,10 +48,5 @@ public final class RobotEntityRenderer extends EntityRenderer<RobotEntity> {
model.renderToBuffer(matrixStack, builder, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
matrixStack.popPose();
// final RayTraceResult hit = Minecraft.getInstance().objectMouseOver;
// if (hit instanceof EntityRayTraceResult && entity == ((EntityRayTraceResult) hit).getEntity()) {
// super.renderName(entity, new StringTextComponent("hi"), matrixStack, buffer, packedLight);
// }
}
}

View File

@@ -1,7 +0,0 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package li.cil.oc2.common.bus.device.block;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -22,6 +22,7 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@SuppressWarnings("UnstableApiUsage")
@@ -48,6 +49,7 @@ public final class NetworkInterfaceCardItemDevice extends IdentityProxy<ItemStac
///////////////////////////////////////////////////////////////
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(final Capability<T> cap, @Nullable final Direction side) {
if (cap == Capabilities.NETWORK_INTERFACE && side != null) {

View File

@@ -9,6 +9,7 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.IEnergyStorage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class EnergyStorageItemStack implements IEnergyStorage, ICapabilityProvider {
@@ -61,6 +62,7 @@ public final class EnergyStorageItemStack implements IEnergyStorage, ICapability
return true;
}
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(final Capability<T> capability, @Nullable final Direction side) {
if (Capabilities.ENERGY_STORAGE != null && capability != null) {

View File

@@ -73,6 +73,7 @@ import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.ItemStackHandler;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.nio.ByteBuffer;
import java.util.*;
@@ -165,6 +166,7 @@ public final class RobotEntity extends Entity implements Robot {
getEntityData().set(SELECTED_SLOT, (byte) MathHelper.clamp(value, 0, INVENTORY_SIZE - 1));
}
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(final Capability<T> capability, @Nullable final Direction side) {
if (capability == Capabilities.ITEM_HANDLER) {
@@ -311,7 +313,7 @@ public final class RobotEntity extends Entity implements Robot {
}
@Override
public IPacket<?> getAddEntityPacket() {
public IPacket<?> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}

View File

@@ -11,5 +11,4 @@ public final class MemoryItem extends AbstractStorageItem {
protected String getOrCreateDescriptionId() {
return "item.oc2.memory";
}
}

View File

@@ -8,6 +8,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -26,6 +27,7 @@ public abstract class AbstractTileEntity extends TileEntity {
///////////////////////////////////////////////////////////////////
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(final Capability<T> capability, @Nullable final Direction side) {
if (isRemoved()) {

View File

@@ -41,12 +41,12 @@ import net.minecraft.util.Direction;
import net.minecraft.util.IIntArray;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fml.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.nio.ByteBuffer;
@@ -186,6 +186,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
virtualMachine.busController.scheduleBusScan();
}
@NotNull
@Override
public <T> LazyOptional<T> getCapability(final Capability<T> capability, @Nullable final Direction side) {
if (isRemoved()) {
@@ -371,6 +372,8 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
@Override
public Optional<Collection<LazyOptional<DeviceBusElement>>> getNeighbors() {
return super.getNeighbors().map(neighbors -> {
// If we have valid neighbors (complete bus) also add a connection to the bus
// element hosting our item devices.
final ArrayList<LazyOptional<DeviceBusElement>> list = new ArrayList<>(neighbors);
list.add(LazyOptional.of(() -> deviceItems.busElement));
return list;