Refactored peripheralHandler to peripheral

- peripheralHandler was the wrong name. It's just a peripheral.
- Changed peripheral type from "cdl" to "Create_DisplayLink"
- Added equals function to DisplayLinkPeripheral
This commit is contained in:
caelwarner 2022-10-03 16:17:05 -07:00
parent 6591c2d46e
commit 47b8619d07
No known key found for this signature in database
GPG key ID: 514BEF5EADE889FF
3 changed files with 14 additions and 14 deletions

View file

@ -14,24 +14,24 @@ public interface ComputerControllable {
IPeripheral createPeripheral();
void setPeripheralHandler(LazyOptional<IPeripheral> peripheralHandler);
void setPeripheral(LazyOptional<IPeripheral> peripheral);
LazyOptional<IPeripheral> getPeripheralHandler();
LazyOptional<IPeripheral> getPeripheral();
default <T> LazyOptional<T> getPeripheralCapability(@NotNull Capability<T> cap) {
if (cap == PERIPHERAL_CAPABILITY) {
if (getPeripheralHandler() == null || !getPeripheralHandler().isPresent())
setPeripheralHandler(LazyOptional.of(this::createPeripheral));
if (getPeripheral() == null || !getPeripheral().isPresent())
setPeripheral(LazyOptional.of(this::createPeripheral));
return getPeripheralHandler().cast();
return getPeripheral().cast();
}
return LazyOptional.empty();
}
default void removePeripheral() {
if (getPeripheralHandler() != null)
getPeripheralHandler().invalidate();
if (getPeripheral() != null)
getPeripheral().invalidate();
}
}

View file

@ -124,12 +124,12 @@ public class DisplayLinkPeripheral implements IPeripheral {
@NotNull
@Override
public String getType() {
return "cdl";
return "Create_DisplayLink";
}
@Override
public boolean equals(@Nullable IPeripheral other) {
return false;
return this == other;
}
}

View file

@ -42,7 +42,7 @@ public class DisplayLinkTileEntity extends SmartTileEntity implements ComputerCo
public int refreshTicks;
private LazyOptional<IPeripheral> peripheralHandler;
private LazyOptional<IPeripheral> peripheral;
public DisplayLinkTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
@ -203,13 +203,13 @@ public class DisplayLinkTileEntity extends SmartTileEntity implements ComputerCo
}
@Override
public void setPeripheralHandler(LazyOptional<IPeripheral> peripheralHandler) {
this.peripheralHandler = peripheralHandler;
public void setPeripheral(LazyOptional<IPeripheral> peripheral) {
this.peripheral = peripheral;
}
@Override
public LazyOptional<IPeripheral> getPeripheralHandler() {
return this.peripheralHandler;
public LazyOptional<IPeripheral> getPeripheral() {
return this.peripheral;
}
public void target(BlockPos targetPosition) {