1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-21 23:54:48 +00:00

Expose peripherals as a capability

This registers IPeripheral as a capability. As a result, all (Minecraft
facing) functionality operates using LazyOptional<_>s instead.

Peripheral providers should now return a LazyOptional<IPeripheral> too.
Hopefully this will allow custom peripherals to mark themselves as
invalid (say, because a dependency has changed).

While peripheral providers are somewhat redundant, they still have their
usages. If a peripheral is applied to a large number of blocks (for
instance, all inventories) then using capabilities does incur some
memory overhead.

We also make the following changes based on the above:
 - Remove the default implementation for IWiredElement, migrating the
   definition to a common "Capabilities" class.

 - Remove IPeripheralTile - we'll exclusively use capabilities now.
   Absurdly this is the most complex change, as all TEs needed to be
   migrated too.

   I'm not 100% sure of the correctness of this changes so far - I've
   tested it pretty well, but blocks with more complex peripheral logic
   (wired/wireless modems and turtles) are still a little messy.

 - Remove the "command block" peripheral provider, attaching a
   capability instead.
This commit is contained in:
SquidDev
2020-05-15 17:09:12 +01:00
parent d5f82fa458
commit 5409d441b5
29 changed files with 567 additions and 407 deletions

View File

@@ -0,0 +1,25 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
public final class Capabilities
{
@CapabilityInject( IPeripheral.class )
public static Capability<IPeripheral> CAPABILITY_PERIPHERAL = null;
@CapabilityInject( IWiredElement.class )
public static Capability<IWiredElement> CAPABILITY_WIRED_ELEMENT = null;
private Capabilities()
{
}
}