From 9a807814013e54f59230d7f57f4c212164311e64 Mon Sep 17 00:00:00 2001 From: caelwarner Date: Tue, 4 Oct 2022 19:36:08 -0700 Subject: [PATCH] Added PeripheralBase --- .../computercraft/DisplayLinkPeripheral.java | 13 ++---------- .../compat/computercraft/PeripheralBase.java | 21 +++++++++++++++++++ .../SequencedGearshiftPeripheral.java | 13 ++---------- .../SpeedControllerPeripheral.java | 13 ++++-------- .../computercraft/SpeedGaugePeripheral.java | 13 ++---------- .../computercraft/StressGaugePeripheral.java | 13 ++---------- .../advanced/SpeedControllerTileEntity.java | 2 +- 7 files changed, 34 insertions(+), 54 deletions(-) create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/PeripheralBase.java diff --git a/src/main/java/com/simibubi/create/compat/computercraft/DisplayLinkPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/DisplayLinkPeripheral.java index 097b5d2f9..4c093c152 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/DisplayLinkPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/DisplayLinkPeripheral.java @@ -5,26 +5,22 @@ import java.util.List; import java.util.Map; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import com.simibubi.create.content.logistics.block.display.DisplayLinkTileEntity; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; -public class DisplayLinkPeripheral implements IPeripheral { +public class DisplayLinkPeripheral extends PeripheralBase { public static final String TAG_KEY = "ComputerSourceList"; - private final DisplayLinkTileEntity tile; - public DisplayLinkPeripheral(DisplayLinkTileEntity tile) { - this.tile = tile; + super(tile); } @LuaFunction @@ -127,9 +123,4 @@ public class DisplayLinkPeripheral implements IPeripheral { return "Create_DisplayLink"; } - @Override - public boolean equals(@Nullable IPeripheral other) { - return this == other; - } - } diff --git a/src/main/java/com/simibubi/create/compat/computercraft/PeripheralBase.java b/src/main/java/com/simibubi/create/compat/computercraft/PeripheralBase.java new file mode 100644 index 000000000..6ede16801 --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/PeripheralBase.java @@ -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 implements IPeripheral { + + protected T tile; + + public PeripheralBase(T tile) { + this.tile = tile; + } + + @Override + public boolean equals(@Nullable IPeripheral other) { + return this == other; + } + +} diff --git a/src/main/java/com/simibubi/create/compat/computercraft/SequencedGearshiftPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/SequencedGearshiftPeripheral.java index 4d00c3652..165b9afaa 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/SequencedGearshiftPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/SequencedGearshiftPeripheral.java @@ -1,7 +1,6 @@ package com.simibubi.create.compat.computercraft; 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.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.LuaException; import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.peripheral.IPeripheral; -public class SequencedGearshiftPeripheral implements IPeripheral { - - private final SequencedGearshiftTileEntity tile; +public class SequencedGearshiftPeripheral extends PeripheralBase { public SequencedGearshiftPeripheral(SequencedGearshiftTileEntity tile) { - this.tile = tile; + super(tile); } @LuaFunction(mainThread = true) @@ -55,9 +51,4 @@ public class SequencedGearshiftPeripheral implements IPeripheral { return "Create_SequencedGearshift"; } - @Override - public boolean equals(@Nullable IPeripheral other) { - return this == other; - } - } diff --git a/src/main/java/com/simibubi/create/compat/computercraft/SpeedControllerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/SpeedControllerPeripheral.java index 5a3955d95..57ed3617c 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/SpeedControllerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/SpeedControllerPeripheral.java @@ -1,18 +1,18 @@ package com.simibubi.create.compat.computercraft; 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 dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.peripheral.IPeripheral; -public class SpeedControllerPeripheral implements IPeripheral { +public class SpeedControllerPeripheral extends PeripheralBase { private final ScrollValueBehaviour targetSpeed; - public SpeedControllerPeripheral(ScrollValueBehaviour targetSpeed) { + public SpeedControllerPeripheral(SpeedControllerTileEntity tile, ScrollValueBehaviour targetSpeed) { + super(tile); this.targetSpeed = targetSpeed; } @@ -32,9 +32,4 @@ public class SpeedControllerPeripheral implements IPeripheral { return "Create_RotationSpeedController"; } - @Override - public boolean equals(@Nullable IPeripheral other) { - return this == other; - } - } diff --git a/src/main/java/com/simibubi/create/compat/computercraft/SpeedGaugePeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/SpeedGaugePeripheral.java index 1994cad85..077d1ccd2 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/SpeedGaugePeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/SpeedGaugePeripheral.java @@ -1,19 +1,15 @@ package com.simibubi.create.compat.computercraft; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import com.simibubi.create.content.contraptions.relays.gauge.SpeedGaugeTileEntity; import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.peripheral.IPeripheral; -public class SpeedGaugePeripheral implements IPeripheral { - - private final SpeedGaugeTileEntity tile; +public class SpeedGaugePeripheral extends PeripheralBase { public SpeedGaugePeripheral(SpeedGaugeTileEntity tile) { - this.tile = tile; + super(tile); } @LuaFunction @@ -27,9 +23,4 @@ public class SpeedGaugePeripheral implements IPeripheral { return "Create_Speedometer"; } - @Override - public boolean equals(@Nullable IPeripheral other) { - return this == other; - } - } diff --git a/src/main/java/com/simibubi/create/compat/computercraft/StressGaugePeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/StressGaugePeripheral.java index d967244a9..7e9d47c23 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/StressGaugePeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/StressGaugePeripheral.java @@ -1,19 +1,15 @@ package com.simibubi.create.compat.computercraft; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import com.simibubi.create.content.contraptions.relays.gauge.StressGaugeTileEntity; import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.peripheral.IPeripheral; -public class StressGaugePeripheral implements IPeripheral { - - private final StressGaugeTileEntity tile; +public class StressGaugePeripheral extends PeripheralBase { public StressGaugePeripheral(StressGaugeTileEntity tile) { - this.tile = tile; + super(tile); } @LuaFunction @@ -32,9 +28,4 @@ public class StressGaugePeripheral implements IPeripheral { return "Create_Stressometer"; } - @Override - public boolean equals(@Nullable IPeripheral other) { - return this == other; - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerTileEntity.java index 675ac42f3..2a38ebb6c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerTileEntity.java @@ -153,7 +153,7 @@ public class SpeedControllerTileEntity extends KineticTileEntity implements Comp @Override public IPeripheral createPeripheral() { - return new SpeedControllerPeripheral(targetSpeed); + return new SpeedControllerPeripheral(this, targetSpeed); } @Override