mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-24 02:17:39 +00:00
Clean up how we enumerate Lua/peripheral methods
- Move several interfaces out of `d00.computercraft.core.asm` into a new `aethods` package. It may make sense to expose this to the public API in a future commit (possibly part of #1462). - Add a new MethodSupplier<T> interface, which provides methods to iterate over all methods exported by an object (either directly, or including those from ObjectSources). This interface's concrete implementation (asm.MethodSupplierImpl), uses Generators and IntCaches as before - we can now make that all package-private though, which is nice! - Make the LuaMethod and PeripheralMethod MethodSupplier local to the ComputerContext. This currently has no effect (the underlying Generator is still global), but eventually we'll make GenericMethods non-global, which unlocks the door for #1382. - Update everything to use this new interface. This is mostly pretty sensible, but is a little uglier on the MC side (especially in generic peripherals), as we need to access the global ServerContext.
This commit is contained in:
@@ -11,12 +11,16 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.NonNullConsumer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
public class GenericPeripheralProvider {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GenericPeripheralProvider.class);
|
||||
|
||||
private static final ArrayList<Capability<?>> capabilities = new ArrayList<>();
|
||||
|
||||
public static synchronized void addCapability(Capability<?> capability) {
|
||||
@@ -29,7 +33,13 @@ public class GenericPeripheralProvider {
|
||||
var blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity == null) return null;
|
||||
|
||||
var builder = new GenericPeripheralBuilder();
|
||||
var server = level.getServer();
|
||||
if (server == null) {
|
||||
LOG.warn("Fetching peripherals on a non-server level {}.", level, new IllegalStateException("Fetching peripherals on a non-server level."));
|
||||
return null;
|
||||
}
|
||||
|
||||
var builder = new GenericPeripheralBuilder(server);
|
||||
builder.addMethods(blockEntity);
|
||||
|
||||
for (var capability : capabilities) {
|
||||
|
||||
Reference in New Issue
Block a user