Added Speedometer and Stressometer as peripherals

- Speedometer can get current speed
- Stressometer can get current stress level as well as network stress capacity
- Made GaugeTileEntity abstract
This commit is contained in:
caelwarner 2022-10-03 16:38:12 -07:00
parent 47b8619d07
commit 1420406ab7
No known key found for this signature in database
GPG key ID: 514BEF5EADE889FF
5 changed files with 126 additions and 1 deletions

View file

@ -0,0 +1,35 @@
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 SpeedGaugePeripheral(SpeedGaugeTileEntity tile) {
this.tile = tile;
}
@LuaFunction
public float getSpeed() {
return this.tile.getSpeed();
}
@NotNull
@Override
public String getType() {
return "Create_Speedometer";
}
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other;
}
}

View file

@ -0,0 +1,40 @@
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 StressGaugePeripheral(StressGaugeTileEntity tile) {
this.tile = tile;
}
@LuaFunction
public float getStress() {
return this.tile.getNetworkStress();
}
@LuaFunction
public float getStressCapacity() {
return this.tile.getNetworkCapacity();
}
@NotNull
@Override
public String getType() {
return "Create_Stressometer";
}
@Override
public boolean equals(@Nullable IPeripheral other) {
return this == other;
}
}

View file

@ -2,23 +2,33 @@ package com.simibubi.create.content.contraptions.relays.gauge;
import java.util.List; import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.compat.computercraft.ComputerControllable;
import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
public class GaugeTileEntity extends KineticTileEntity implements IHaveGoggleInformation { public abstract class GaugeTileEntity extends KineticTileEntity implements IHaveGoggleInformation, ComputerControllable {
public float dialTarget; public float dialTarget;
public float dialState; public float dialState;
public float prevDialState; public float prevDialState;
public int color; public int color;
private LazyOptional<IPeripheral> peripheral;
public GaugeTileEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) { public GaugeTileEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) {
super(typeIn, pos, state); super(typeIn, pos, state);
} }
@ -52,4 +62,29 @@ public class GaugeTileEntity extends KineticTileEntity implements IHaveGoggleInf
return true; return true;
} }
@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
LazyOptional<T> peripheralCap = getPeripheralCapability(cap);
return peripheralCap.isPresent() ? peripheralCap : super.getCapability(cap, side);
}
@Override
public void setRemoved() {
super.setRemoved();
removePeripheral();
}
@Override
public void setPeripheral(LazyOptional<IPeripheral> peripheral) {
this.peripheral = peripheral;
}
@Override
public LazyOptional<IPeripheral> getPeripheral() {
return this.peripheral;
}
} }

View file

@ -2,11 +2,13 @@ package com.simibubi.create.content.contraptions.relays.gauge;
import java.util.List; import java.util.List;
import com.simibubi.create.compat.computercraft.SpeedGaugePeripheral;
import com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel; import com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.Color; import com.simibubi.create.foundation.utility.Color;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -62,4 +64,10 @@ public class SpeedGaugeTileEntity extends GaugeTileEntity {
.forGoggles(tooltip); .forGoggles(tooltip);
return true; return true;
} }
@Override
public IPeripheral createPeripheral() {
return new SpeedGaugePeripheral(this);
}
} }

View file

@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.relays.gauge;
import java.util.List; import java.util.List;
import com.simibubi.create.compat.computercraft.StressGaugePeripheral;
import com.simibubi.create.content.contraptions.base.IRotate.StressImpact; import com.simibubi.create.content.contraptions.base.IRotate.StressImpact;
import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.advancement.AllAdvancements;
import com.simibubi.create.foundation.item.ItemDescription; import com.simibubi.create.foundation.item.ItemDescription;
@ -11,6 +12,7 @@ import com.simibubi.create.foundation.utility.Color;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.LangBuilder; import com.simibubi.create.foundation.utility.LangBuilder;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -141,4 +143,9 @@ public class StressGaugeTileEntity extends GaugeTileEntity {
award(AllAdvancements.STRESSOMETER_MAXED); award(AllAdvancements.STRESSOMETER_MAXED);
} }
@Override
public IPeripheral createPeripheral() {
return new StressGaugePeripheral(this);
}
} }