Some renaming and cleanup.
This commit is contained in:
@@ -18,21 +18,25 @@ import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
* must be created. For example, if the implementation's registry name is
|
||||
* {@code my_mod:my_block_device}:
|
||||
* <pre>
|
||||
* /give ? oc2:hard_drive{oc2:{base:"my_mod:my_block_device"}}
|
||||
* /give ? oc2:hard_drive{oc2:{data:"my_mod:my_block_device"}}
|
||||
* </pre>
|
||||
* The drive can be made readonly by also specifying the {@code readonly} tag:
|
||||
* <pre>
|
||||
* /give ? oc2:hard_drive{oc2:{data:"my_mod:my_block_device",readonly:true}}
|
||||
* </pre>
|
||||
*/
|
||||
public interface BaseBlockDevice extends IForgeRegistryEntry<BaseBlockDevice> {
|
||||
public interface BlockDeviceData extends IForgeRegistryEntry<BlockDeviceData> {
|
||||
/**
|
||||
* The registry name of the registry holding block device bases.
|
||||
*/
|
||||
ResourceLocation REGISTRY = new ResourceLocation(API.MOD_ID, "base_block_device");
|
||||
ResourceLocation REGISTRY = new ResourceLocation(API.MOD_ID, "block_device_data");
|
||||
|
||||
/**
|
||||
* Gets the read-only base block device this implementation describes.
|
||||
*
|
||||
* @return the block device.
|
||||
*/
|
||||
BlockDevice get();
|
||||
BlockDevice getBlockDevice();
|
||||
|
||||
/**
|
||||
* The display name of this block device base. May be shown in the tooltip
|
||||
@@ -40,5 +44,5 @@ public interface BaseBlockDevice extends IForgeRegistryEntry<BaseBlockDevice> {
|
||||
*
|
||||
* @return the display name of this block device.
|
||||
*/
|
||||
ITextComponent getName();
|
||||
ITextComponent getDisplayName();
|
||||
}
|
||||
@@ -45,5 +45,5 @@ public interface Firmware extends IForgeRegistryEntry<Firmware> {
|
||||
*
|
||||
* @return the display name of this firmware.
|
||||
*/
|
||||
ITextComponent getName();
|
||||
ITextComponent getDisplayName();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package li.cil.oc2.api.bus.device.data;
|
||||
|
||||
import li.cil.oc2.api.bus.device.vm.VMDevice;
|
||||
package li.cil.oc2.api.bus.device.vm;
|
||||
|
||||
/**
|
||||
* This interface serves as a marker for devices that load firmware.
|
||||
@@ -41,6 +41,8 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void render(final ComputerTileEntity tileEntity, final float partialTicks, final MatrixStack matrixStack, final IRenderTypeBuffer buffer, final int light, final int overlay) {
|
||||
final Direction blockFacing = tileEntity.getBlockState().get(ComputerBlock.HORIZONTAL_FACING);
|
||||
|
||||
@@ -5,7 +5,7 @@ import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.client.ClientSetup;
|
||||
import li.cil.oc2.common.block.Blocks;
|
||||
import li.cil.oc2.common.bus.device.DeviceTypes;
|
||||
import li.cil.oc2.common.bus.device.data.BaseBlockDevices;
|
||||
import li.cil.oc2.common.bus.device.data.BlockDeviceDataRegistration;
|
||||
import li.cil.oc2.common.bus.device.data.Firmwares;
|
||||
import li.cil.oc2.common.bus.device.provider.Providers;
|
||||
import li.cil.oc2.common.container.Containers;
|
||||
@@ -40,7 +40,7 @@ public final class Main {
|
||||
|
||||
Providers.initialize();
|
||||
DeviceTypes.initialize();
|
||||
BaseBlockDevices.initialize();
|
||||
BlockDeviceDataRegistration.initialize();
|
||||
Firmwares.initialize();
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(CommonSetup.class);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package li.cil.oc2.common.bus.device.data;
|
||||
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.api.bus.device.data.BaseBlockDevice;
|
||||
import li.cil.oc2.api.bus.device.data.BlockDeviceData;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
@@ -10,16 +10,16 @@ import net.minecraftforge.registries.RegistryBuilder;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class BaseBlockDevices {
|
||||
private static final DeferredRegister<BaseBlockDevice> INITIALIZER = DeferredRegister.create(BaseBlockDevice.class, API.MOD_ID);
|
||||
public final class BlockDeviceDataRegistration {
|
||||
private static final DeferredRegister<BlockDeviceData> INITIALIZER = DeferredRegister.create(BlockDeviceData.class, API.MOD_ID);
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final Supplier<IForgeRegistry<BaseBlockDevice>> REGISTRY = INITIALIZER.makeRegistry(BaseBlockDevice.REGISTRY.getPath(), RegistryBuilder::new);
|
||||
public static final Supplier<IForgeRegistry<BlockDeviceData>> REGISTRY = INITIALIZER.makeRegistry(BlockDeviceData.REGISTRY.getPath(), RegistryBuilder::new);
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final RegistryObject<BaseBlockDevice> BUILDROOT = INITIALIZER.register("buildroot", BuildrootRootFileSystem::new);
|
||||
public static final RegistryObject<BlockDeviceData> BUILDROOT = INITIALIZER.register("buildroot", BuildrootBlockDeviceData::new);
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package li.cil.oc2.common.bus.device.data;
|
||||
|
||||
import li.cil.oc2.api.bus.device.data.BaseBlockDevice;
|
||||
import li.cil.oc2.api.bus.device.data.BlockDeviceData;
|
||||
import li.cil.sedna.api.device.BlockDevice;
|
||||
import li.cil.sedna.buildroot.Buildroot;
|
||||
import li.cil.sedna.device.block.ByteBufferBlockDevice;
|
||||
@@ -12,29 +12,33 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class BuildrootRootFileSystem extends ForgeRegistryEntry<BaseBlockDevice> implements BaseBlockDevice {
|
||||
public final class BuildrootBlockDeviceData extends ForgeRegistryEntry<BlockDeviceData> implements BlockDeviceData {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static final ByteBufferBlockDevice ROOT_FS;
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static final ByteBufferBlockDevice INSTANCE;
|
||||
|
||||
static {
|
||||
ByteBufferBlockDevice rootfs;
|
||||
ByteBufferBlockDevice instance;
|
||||
try {
|
||||
rootfs = ByteBufferBlockDevice.createFromStream(Buildroot.getRootFilesystem(), true);
|
||||
instance = ByteBufferBlockDevice.createFromStream(Buildroot.getRootFilesystem(), true);
|
||||
} catch (final IOException e) {
|
||||
LOGGER.error(e);
|
||||
rootfs = ByteBufferBlockDevice.create(0, true);
|
||||
instance = ByteBufferBlockDevice.create(0, true);
|
||||
}
|
||||
ROOT_FS = rootfs;
|
||||
INSTANCE = instance;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public BlockDevice getBlockDevice() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockDevice get() {
|
||||
return ROOT_FS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getName() {
|
||||
public ITextComponent getDisplayName() {
|
||||
return new StringTextComponent("Linux");
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public final class BuildrootFirmware extends ForgeRegistryEntry<Firmware> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getName() {
|
||||
return new StringTextComponent("OpenSBI+Linux");
|
||||
public ITextComponent getDisplayName() {
|
||||
return new StringTextComponent("Linux");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package li.cil.oc2.common.bus.device.item;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import li.cil.oc2.api.bus.device.ItemDevice;
|
||||
import li.cil.oc2.api.bus.device.data.FirmwareLoader;
|
||||
import li.cil.oc2.api.bus.device.vm.FirmwareLoader;
|
||||
import li.cil.oc2.api.bus.device.vm.VMContext;
|
||||
import li.cil.oc2.api.bus.device.vm.VMDevice;
|
||||
import li.cil.oc2.api.bus.device.vm.VMDeviceLoadResult;
|
||||
|
||||
@@ -3,7 +3,7 @@ package li.cil.oc2.common.bus.device.item;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import li.cil.oc2.api.bus.device.ItemDevice;
|
||||
import li.cil.oc2.api.bus.device.data.Firmware;
|
||||
import li.cil.oc2.api.bus.device.data.FirmwareLoader;
|
||||
import li.cil.oc2.api.bus.device.vm.FirmwareLoader;
|
||||
import li.cil.oc2.api.bus.device.vm.VMContext;
|
||||
import li.cil.oc2.api.bus.device.vm.VMDevice;
|
||||
import li.cil.oc2.api.bus.device.vm.VMDeviceLoadResult;
|
||||
|
||||
@@ -3,13 +3,13 @@ package li.cil.oc2.common.bus.device.provider.item;
|
||||
import li.cil.oc2.api.bus.device.DeviceType;
|
||||
import li.cil.oc2.api.bus.device.DeviceTypes;
|
||||
import li.cil.oc2.api.bus.device.ItemDevice;
|
||||
import li.cil.oc2.api.bus.device.data.BaseBlockDevice;
|
||||
import li.cil.oc2.api.bus.device.data.BlockDeviceData;
|
||||
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
|
||||
import li.cil.oc2.common.Config;
|
||||
import li.cil.oc2.common.bus.device.item.HardDriveVMDevice;
|
||||
import li.cil.oc2.common.bus.device.item.SparseHardDriveVMDevice;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
|
||||
import li.cil.oc2.common.item.HardDriveItem;
|
||||
import li.cil.oc2.common.item.BlockDeviceItem;
|
||||
import li.cil.oc2.common.item.Items;
|
||||
import li.cil.sedna.api.device.BlockDevice;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -28,14 +28,14 @@ public final class HardDriveItemDeviceProvider extends AbstractItemDeviceProvide
|
||||
protected Optional<ItemDevice> getItemDevice(final ItemDeviceQuery query) {
|
||||
final ItemStack stack = query.getItemStack();
|
||||
|
||||
final boolean readonly = HardDriveItem.isReadonly(stack);
|
||||
final BaseBlockDevice baseBlockDevice = HardDriveItem.getBaseBlockDevice(stack);
|
||||
if (baseBlockDevice != null) {
|
||||
final BlockDevice base = baseBlockDevice.get();
|
||||
final boolean readonly = BlockDeviceItem.isReadonly(stack);
|
||||
final BlockDeviceData handler = BlockDeviceItem.getData(stack);
|
||||
if (handler != null) {
|
||||
final BlockDevice base = handler.getBlockDevice();
|
||||
return Optional.of(new SparseHardDriveVMDevice(stack, base, readonly));
|
||||
}
|
||||
|
||||
final int size = MathHelper.clamp(HardDriveItem.getCapacity(stack), 0, Config.maxHardDriveSize);
|
||||
final int size = MathHelper.clamp(BlockDeviceItem.getCapacity(stack), 0, Config.maxHardDriveSize);
|
||||
return Optional.of(new HardDriveVMDevice(stack, size, readonly));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,15 @@ import java.util.function.Function;
|
||||
public class TypedDeviceItemStackHandler extends DeviceItemStackHandler {
|
||||
private final DeviceType deviceType;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public TypedDeviceItemStackHandler(final int size, final Function<ItemStack, List<ItemDeviceInfo>> deviceLookup, final DeviceType deviceType) {
|
||||
super(size, deviceLookup);
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(final int slot, final ItemStack stack) {
|
||||
return super.isItemValid(slot, stack) && Devices.getDeviceTypes(stack).contains(deviceType);
|
||||
|
||||
@@ -89,7 +89,7 @@ public final class FlashMemoryItem extends AbstractStorageItem {
|
||||
protected ITextComponent getDisplayNameSuffix(final ItemStack stack) {
|
||||
final Firmware firmware = getFirmware(stack);
|
||||
if (firmware != null) {
|
||||
return firmware.getName();
|
||||
return firmware.getDisplayName();
|
||||
} else {
|
||||
return super.getDisplayNameSuffix(stack);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class BlobStorage {
|
||||
private static final HashMultimap<UUID, Future<Void>> WRITE_HANDLES = HashMultimap.create();
|
||||
private static final HashMultimap<UUID, Future<Void>> READ_HANDLES = HashMultimap.create();
|
||||
private static final ExecutorService WORKERS = Executors.newCachedThreadPool(r -> {
|
||||
final Thread thread = new Thread(r, "OC2 BlobStorage Thread");
|
||||
final Thread thread = new Thread(r, "Blob Storage I/O");
|
||||
thread.setDaemon(false);
|
||||
return thread;
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package li.cil.oc2.common.vm;
|
||||
|
||||
import li.cil.oc2.api.bus.device.data.FirmwareLoader;
|
||||
import li.cil.oc2.api.bus.device.vm.FirmwareLoader;
|
||||
import li.cil.oc2.api.bus.device.vm.VMDeviceLoadResult;
|
||||
import li.cil.oc2.api.bus.device.vm.event.VMPausingEvent;
|
||||
import li.cil.oc2.common.Constants;
|
||||
|
||||
@@ -10,10 +10,14 @@ public final class ManagedEventBus implements VMLifecycleEventBus {
|
||||
private final EventBus eventBus;
|
||||
private final ArrayList<Object> subscribers = new ArrayList<>();
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public ManagedEventBus(final EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public void invalidate() {
|
||||
for (final Object subscriber : subscribers) {
|
||||
eventBus.unregister(subscriber);
|
||||
|
||||
@@ -18,6 +18,7 @@ public class VirtualMachineRunner implements Runnable {
|
||||
private static final ExecutorService VM_RUNNERS = Executors.newCachedThreadPool(r -> {
|
||||
final Thread thread = new Thread(r);
|
||||
thread.setDaemon(true);
|
||||
thread.setName("VirtualMachine Runner");
|
||||
return thread;
|
||||
});
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface VirtualMachineState {
|
||||
boolean isRunning();
|
||||
|
||||
AbstractDeviceBusController.BusState getBusState();
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@@ -26,11 +24,13 @@ public interface VirtualMachineState {
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
void setBootErrorClient(ITextComponent value);
|
||||
|
||||
boolean isRunning();
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
public enum RunState {
|
||||
enum RunState {
|
||||
STOPPED,
|
||||
LOADING_DEVICES,
|
||||
RUNNING,
|
||||
|
||||
Reference in New Issue
Block a user