Added PeripheralBase

This commit is contained in:
caelwarner 2022-10-04 19:36:08 -07:00
parent d404f07319
commit 9a80781401
No known key found for this signature in database
GPG key ID: 514BEF5EADE889FF
7 changed files with 34 additions and 54 deletions

View file

@ -5,26 +5,22 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.content.logistics.block.display.DisplayLinkTileEntity; import com.simibubi.create.content.logistics.block.display.DisplayLinkTileEntity;
import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.IArguments;
import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag; import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
public class DisplayLinkPeripheral implements IPeripheral { public class DisplayLinkPeripheral extends PeripheralBase<DisplayLinkTileEntity> {
public static final String TAG_KEY = "ComputerSourceList"; public static final String TAG_KEY = "ComputerSourceList";
private final DisplayLinkTileEntity tile;
public DisplayLinkPeripheral(DisplayLinkTileEntity tile) { public DisplayLinkPeripheral(DisplayLinkTileEntity tile) {
this.tile = tile; super(tile);
} }
@LuaFunction @LuaFunction
@ -127,9 +123,4 @@ public class DisplayLinkPeripheral implements IPeripheral {
return "Create_DisplayLink"; return "Create_DisplayLink";
} }
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other;
}
} }

View file

@ -0,0 +1,21 @@
package com.simibubi.create.compat.computercraft;
import org.jetbrains.annotations.Nullable;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.world.level.block.entity.BlockEntity;
public abstract class PeripheralBase<T extends BlockEntity & ComputerControllable> implements IPeripheral {
protected T tile;
public PeripheralBase(T tile) {
this.tile = tile;
}
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other;
}
}

View file

@ -1,7 +1,6 @@
package com.simibubi.create.compat.computercraft; package com.simibubi.create.compat.computercraft;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.content.contraptions.relays.advanced.sequencer.Instruction; import com.simibubi.create.content.contraptions.relays.advanced.sequencer.Instruction;
import com.simibubi.create.content.contraptions.relays.advanced.sequencer.InstructionSpeedModifiers; import com.simibubi.create.content.contraptions.relays.advanced.sequencer.InstructionSpeedModifiers;
@ -11,14 +10,11 @@ import com.simibubi.create.content.contraptions.relays.advanced.sequencer.Sequen
import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.IArguments;
import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.IPeripheral;
public class SequencedGearshiftPeripheral implements IPeripheral { public class SequencedGearshiftPeripheral extends PeripheralBase<SequencedGearshiftTileEntity> {
private final SequencedGearshiftTileEntity tile;
public SequencedGearshiftPeripheral(SequencedGearshiftTileEntity tile) { public SequencedGearshiftPeripheral(SequencedGearshiftTileEntity tile) {
this.tile = tile; super(tile);
} }
@LuaFunction(mainThread = true) @LuaFunction(mainThread = true)
@ -55,9 +51,4 @@ public class SequencedGearshiftPeripheral implements IPeripheral {
return "Create_SequencedGearshift"; return "Create_SequencedGearshift";
} }
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other;
}
} }

View file

@ -1,18 +1,18 @@
package com.simibubi.create.compat.computercraft; package com.simibubi.create.compat.computercraft;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerTileEntity;
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour;
import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.IPeripheral;
public class SpeedControllerPeripheral implements IPeripheral { public class SpeedControllerPeripheral extends PeripheralBase<SpeedControllerTileEntity> {
private final ScrollValueBehaviour targetSpeed; private final ScrollValueBehaviour targetSpeed;
public SpeedControllerPeripheral(ScrollValueBehaviour targetSpeed) { public SpeedControllerPeripheral(SpeedControllerTileEntity tile, ScrollValueBehaviour targetSpeed) {
super(tile);
this.targetSpeed = targetSpeed; this.targetSpeed = targetSpeed;
} }
@ -32,9 +32,4 @@ public class SpeedControllerPeripheral implements IPeripheral {
return "Create_RotationSpeedController"; return "Create_RotationSpeedController";
} }
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other;
}
} }

View file

@ -1,19 +1,15 @@
package com.simibubi.create.compat.computercraft; package com.simibubi.create.compat.computercraft;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.content.contraptions.relays.gauge.SpeedGaugeTileEntity; import com.simibubi.create.content.contraptions.relays.gauge.SpeedGaugeTileEntity;
import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.IPeripheral;
public class SpeedGaugePeripheral implements IPeripheral { public class SpeedGaugePeripheral extends PeripheralBase<SpeedGaugeTileEntity> {
private final SpeedGaugeTileEntity tile;
public SpeedGaugePeripheral(SpeedGaugeTileEntity tile) { public SpeedGaugePeripheral(SpeedGaugeTileEntity tile) {
this.tile = tile; super(tile);
} }
@LuaFunction @LuaFunction
@ -27,9 +23,4 @@ public class SpeedGaugePeripheral implements IPeripheral {
return "Create_Speedometer"; return "Create_Speedometer";
} }
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other;
}
} }

View file

@ -1,19 +1,15 @@
package com.simibubi.create.compat.computercraft; package com.simibubi.create.compat.computercraft;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.content.contraptions.relays.gauge.StressGaugeTileEntity; import com.simibubi.create.content.contraptions.relays.gauge.StressGaugeTileEntity;
import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.IPeripheral;
public class StressGaugePeripheral implements IPeripheral { public class StressGaugePeripheral extends PeripheralBase<StressGaugeTileEntity> {
private final StressGaugeTileEntity tile;
public StressGaugePeripheral(StressGaugeTileEntity tile) { public StressGaugePeripheral(StressGaugeTileEntity tile) {
this.tile = tile; super(tile);
} }
@LuaFunction @LuaFunction
@ -32,9 +28,4 @@ public class StressGaugePeripheral implements IPeripheral {
return "Create_Stressometer"; return "Create_Stressometer";
} }
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other;
}
} }

View file

@ -153,7 +153,7 @@ public class SpeedControllerTileEntity extends KineticTileEntity implements Comp
@Override @Override
public IPeripheral createPeripheral() { public IPeripheral createPeripheral() {
return new SpeedControllerPeripheral(targetSpeed); return new SpeedControllerPeripheral(this, targetSpeed);
} }
@Override @Override