Machine redstone controls
This commit is contained in:
parent
e74ce49694
commit
65ee43fd11
@ -54,4 +54,14 @@ public abstract class BlockMattery extends Block {
|
||||
|
||||
return super.use(p_60503_, level, pos, ply, p_60507_, p_60508_);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block sender, BlockPos sender_pos, boolean flag) {
|
||||
super.neighborChanged(state, level, pos, sender, sender_pos, flag);
|
||||
|
||||
if (this instanceof EntityBlock && !level.isClientSide && level.getBlockEntity(pos) instanceof BlockEntityMattery tile) {
|
||||
tile.setRedstoneSignal(level.getBestNeighborSignal(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,9 @@ public class BlockEntityAndroidStation extends BlockEntityMatteryPowered impleme
|
||||
if (t instanceof BlockEntityAndroidStation tile) {
|
||||
tile.batteryChargeLoop();
|
||||
|
||||
if (tile.isBlockedByRedstone())
|
||||
return;
|
||||
|
||||
BlockPos pos = tile.getBlockPos();
|
||||
List<LivingEntity> entities = tile.getLevel().getEntitiesOfClass(LivingEntity.class, new AABB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 2, pos.getZ() + 1));
|
||||
|
||||
|
@ -317,6 +317,9 @@ public class BlockEntityBatteryBank extends BlockEntityMattery {
|
||||
|
||||
public static <T extends BlockEntity> void tick(Level level, BlockPos blockPos, BlockState blockState, T t) {
|
||||
if (t instanceof BlockEntityBatteryBank tile) {
|
||||
if (tile.isBlockedByRedstone())
|
||||
return;
|
||||
|
||||
BlockEntity get_entity = level.getBlockEntity(blockPos.offset(tile.getBlockState().getValue(BlockMatteryRotatable.FACING).getNormal()));
|
||||
|
||||
if (get_entity != null) {
|
||||
|
@ -231,6 +231,14 @@ public class BlockEntityMatterBottler extends BlockEntityMatteryPowered implemen
|
||||
if (t instanceof BlockEntityMatterBottler tile) {
|
||||
tile.batteryChargeLoop();
|
||||
|
||||
if (tile.isBlockedByRedstone()) {
|
||||
if (tile.getBlockState().getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.IDLE) {
|
||||
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack work_stack = null;
|
||||
IMatterHandler capability = null;
|
||||
int align = tile.work_flow ? 0 : 3;
|
||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.block.entity;
|
||||
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@ -24,6 +25,8 @@ import java.util.UUID;
|
||||
@ParametersAreNonnullByDefault
|
||||
public abstract class BlockEntityMattery extends BlockEntity implements MenuProvider {
|
||||
protected Component display_name;
|
||||
protected RedstoneSetting redstone_setting = RedstoneSetting.LOW;
|
||||
protected int redstone_signal = 0;
|
||||
|
||||
public BlockEntityMattery(BlockEntityType<?> p_155228_, BlockPos p_155229_, BlockState p_155230_) {
|
||||
super(p_155228_, p_155229_, p_155230_);
|
||||
@ -44,7 +47,45 @@ public abstract class BlockEntityMattery extends BlockEntity implements MenuProv
|
||||
@Override
|
||||
abstract public AbstractContainerMenu createMenu(int containerID, Inventory inventory, Player ply);
|
||||
|
||||
public boolean canOpenMachine(Player ply) {
|
||||
protected void redstoneStatusUpdated(boolean new_blocked, boolean old_blocked) {
|
||||
|
||||
}
|
||||
|
||||
public void setRedstoneSignal(int level) {
|
||||
final var old = isBlockedByRedstone();
|
||||
redstone_signal = level;
|
||||
final var state = isBlockedByRedstone();
|
||||
|
||||
if (old != state) {
|
||||
redstoneStatusUpdated(state, old);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRedstoneSetting(RedstoneSetting setting) {
|
||||
final var old = isBlockedByRedstone();
|
||||
redstone_setting = setting;
|
||||
final var state = isBlockedByRedstone();
|
||||
|
||||
if (old != state) {
|
||||
redstoneStatusUpdated(state, old);
|
||||
}
|
||||
}
|
||||
|
||||
public RedstoneSetting getRedstoneSetting() {
|
||||
return redstone_setting;
|
||||
}
|
||||
|
||||
protected boolean isBlockedByRedstone() {
|
||||
switch (redstone_setting) {
|
||||
case LOW -> {
|
||||
return redstone_signal > 0;
|
||||
}
|
||||
|
||||
case HIGH -> {
|
||||
return redstone_signal <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -53,13 +94,18 @@ public abstract class BlockEntityMattery extends BlockEntity implements MenuProv
|
||||
if (display_name != null)
|
||||
nbt.putString("Name", Component.Serializer.toJson(display_name));
|
||||
|
||||
nbt.putByte("redstone", (byte) redstone_setting.ordinal());
|
||||
|
||||
return super.save(nbt);
|
||||
}
|
||||
|
||||
public void load(CompoundTag nbt) {
|
||||
super.load(nbt);
|
||||
|
||||
if (nbt.contains("Name") && nbt.get("Name") instanceof StringTag tag)
|
||||
if (nbt.get("Name") instanceof StringTag tag)
|
||||
display_name = Component.Serializer.fromJson(tag.getAsString());
|
||||
|
||||
if (nbt.get("redstone") instanceof ByteTag tag)
|
||||
redstone_setting = RedstoneSetting.get(tag.getAsByte());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package ru.dbotthepony.mc.otm.block.entity;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
|
||||
public enum RedstoneSetting {
|
||||
IGNORED(new TranslatableComponent("otm.gui.redstone.ignored"), new TranslatableComponent("otm.gui.redstone.ignored.description")),
|
||||
LOW(new TranslatableComponent("otm.gui.redstone.low"), new TranslatableComponent("otm.gui.redstone.low.description")),
|
||||
HIGH(new TranslatableComponent("otm.gui.redstone.high"), new TranslatableComponent("otm.gui.redstone.high.description"));
|
||||
|
||||
public final Component name;
|
||||
public final Component description;
|
||||
private static final RedstoneSetting[] values = RedstoneSetting.values();
|
||||
|
||||
RedstoneSetting(TranslatableComponent name, TranslatableComponent description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public RedstoneSetting next() {
|
||||
return values[(ordinal() + 1) % values.length];
|
||||
}
|
||||
|
||||
public static RedstoneSetting get(int index) {
|
||||
if (index < 0 || index > 2) {
|
||||
return LOW;
|
||||
}
|
||||
|
||||
return values[index];
|
||||
}
|
||||
}
|
@ -95,6 +95,12 @@ abstract public class BlockEntityMatteryWorker extends BlockEntityMatteryPowered
|
||||
private int working_ticks_anim = 0;
|
||||
private int error_ticks_anim = 0;
|
||||
|
||||
@Override
|
||||
protected void redstoneStatusUpdated(boolean new_blocked, boolean old_blocked) {
|
||||
super.redstoneStatusUpdated(new_blocked, old_blocked);
|
||||
is_idling = new_blocked;
|
||||
}
|
||||
|
||||
protected void workerLoop() {
|
||||
if (level != null && error_ticks_anim > 20 && getBlockState().hasProperty(WorkerState.WORKER_STATE) && getBlockState().getValue(WorkerState.WORKER_STATE) != WorkerState.ERROR) {
|
||||
level.setBlock(getBlockPos(), getBlockState().setValue(WorkerState.WORKER_STATE, WorkerState.ERROR), Block.UPDATE_CLIENTS);
|
||||
@ -123,6 +129,11 @@ abstract public class BlockEntityMatteryWorker extends BlockEntityMatteryPowered
|
||||
}
|
||||
|
||||
if (current_job == null) {
|
||||
if (isBlockedByRedstone()) {
|
||||
is_idling = true;
|
||||
return;
|
||||
}
|
||||
|
||||
MachineJob input = getNextJob();
|
||||
|
||||
if (input == null) {
|
||||
@ -134,6 +145,11 @@ abstract public class BlockEntityMatteryWorker extends BlockEntityMatteryPowered
|
||||
current_job = input;
|
||||
}
|
||||
|
||||
if (isBlockedByRedstone()) {
|
||||
is_idling = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (current_job.power_consumption_multiplier().compareTo(BigDecimal.ZERO) != 0 && energy.getBatteryLevel().compareTo(BigDecimal.ZERO) == 0) {
|
||||
idle_ticks_anim++;
|
||||
|
||||
|
@ -20,6 +20,14 @@
|
||||
"otm.gui.pattern.percentage_level": "Fill level: %s%%",
|
||||
"otm.gui.pattern.format": "Stored patterns: %s / %s",
|
||||
|
||||
"otm.gui.redstone.ignored": "Redstone mode: Ignored",
|
||||
"otm.gui.redstone.low": "Redstone mode: Low",
|
||||
"otm.gui.redstone.high": "Redstone mode: High",
|
||||
|
||||
"otm.gui.redstone.ignored.description": "Redstone signal does not affect machine's function",
|
||||
"otm.gui.redstone.low.description": "Machine work if no redstone signal is present",
|
||||
"otm.gui.redstone.high.description": "Machine work only if any redstone signal is present",
|
||||
|
||||
"otm.death_reason": "Decommissioned!",
|
||||
|
||||
"otm.item.power.infinite.storage": "Stored energy: Infinity / Infinity",
|
||||
|
Loading…
Reference in New Issue
Block a user