mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-11 04:22:00 +01:00
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:
parent
47b8619d07
commit
1420406ab7
5 changed files with 126 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,23 +2,33 @@ package com.simibubi.create.content.contraptions.relays.gauge;
|
|||
|
||||
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.goggles.IHaveGoggleInformation;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
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 dialState;
|
||||
public float prevDialState;
|
||||
public int color;
|
||||
|
||||
private LazyOptional<IPeripheral> peripheral;
|
||||
|
||||
public GaugeTileEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) {
|
||||
super(typeIn, pos, state);
|
||||
}
|
||||
|
@ -52,4 +62,29 @@ public class GaugeTileEntity extends KineticTileEntity implements IHaveGoggleInf
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@ package com.simibubi.create.content.contraptions.relays.gauge;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.compat.computercraft.SpeedGaugePeripheral;
|
||||
import com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel;
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.utility.Color;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -62,4 +64,10 @@ public class SpeedGaugeTileEntity extends GaugeTileEntity {
|
|||
.forGoggles(tooltip);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPeripheral createPeripheral() {
|
||||
return new SpeedGaugePeripheral(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.relays.gauge;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.compat.computercraft.StressGaugePeripheral;
|
||||
import com.simibubi.create.content.contraptions.base.IRotate.StressImpact;
|
||||
import com.simibubi.create.foundation.advancement.AllAdvancements;
|
||||
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.LangBuilder;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -141,4 +143,9 @@ public class StressGaugeTileEntity extends GaugeTileEntity {
|
|||
award(AllAdvancements.STRESSOMETER_MAXED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPeripheral createPeripheral() {
|
||||
return new StressGaugePeripheral(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue