mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-06-17 02:40:06 +00:00
367773e173
- Separate FileMount into separate FileMount and WritableFileMount classes. This separates the (relatively simple) read-only code from the (soon to be even more complex) read/write code. It also allows you to create read-only mounts which don't bother with filesystem accounting, which is nice. - Make openForWrite/openForAppend always return a SeekableFileHandle. Appendable files still cannot be seeked within, but that check is now done on the FS side. - Refactor the various mount tests to live in test contract interfaces, allowing us to reuse them between mounts. - Clean up our error handling a little better. (Most) file-specific code has been moved to FileMount, and ArchiveMount-derived classes now throw correct path-localised exceptions.
63 lines
2.4 KiB
Java
63 lines
2.4 KiB
Java
/*
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
*/
|
|
package dan200.computercraft.impl;
|
|
|
|
import com.google.auto.service.AutoService;
|
|
import dan200.computercraft.api.ComputerCraftAPI;
|
|
import dan200.computercraft.api.detail.DetailRegistry;
|
|
import dan200.computercraft.api.network.wired.WiredElement;
|
|
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
|
import dan200.computercraft.impl.detail.DetailRegistryImpl;
|
|
import dan200.computercraft.shared.details.FluidData;
|
|
import dan200.computercraft.shared.peripheral.generic.GenericPeripheralProvider;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
import net.minecraftforge.common.util.LazyOptional;
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
import net.minecraftforge.fml.ModList;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import static dan200.computercraft.shared.Capabilities.CAPABILITY_WIRED_ELEMENT;
|
|
|
|
@AutoService(ComputerCraftAPIService.class)
|
|
public final class ComputerCraftAPIImpl extends AbstractComputerCraftAPI implements ComputerCraftAPIForgeService {
|
|
private final DetailRegistry<FluidStack> fluidStackDetails = new DetailRegistryImpl<>(FluidData::fillBasic);
|
|
|
|
private @Nullable String version;
|
|
|
|
@Override
|
|
public String getInstalledVersion() {
|
|
if (version != null) return version;
|
|
return version = ModList.get().getModContainerById(ComputerCraftAPI.MOD_ID)
|
|
.map(x -> x.getModInfo().getVersion().toString())
|
|
.orElse("unknown");
|
|
}
|
|
|
|
@Override
|
|
public void registerPeripheralProvider(IPeripheralProvider provider) {
|
|
Peripherals.register(provider);
|
|
}
|
|
|
|
@Override
|
|
public void registerGenericCapability(Capability<?> capability) {
|
|
GenericPeripheralProvider.addCapability(capability);
|
|
}
|
|
|
|
@Override
|
|
public LazyOptional<WiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side) {
|
|
var tile = world.getBlockEntity(pos);
|
|
return tile == null ? LazyOptional.empty() : tile.getCapability(CAPABILITY_WIRED_ELEMENT, side);
|
|
}
|
|
|
|
@Override
|
|
public DetailRegistry<FluidStack> getFluidStackDetailRegistry() {
|
|
return fluidStackDetails;
|
|
}
|
|
}
|