Drive viewer working state and power consumption
This commit is contained in:
parent
c101edaee4
commit
387111ee64
@ -253,10 +253,12 @@ const facings = [
|
|||||||
fs.writeFileSync(_root + 'blockstates/pattern_storage.json', JSON.stringify(blockstate, null, '\t'))
|
fs.writeFileSync(_root + 'blockstates/pattern_storage.json', JSON.stringify(blockstate, null, '\t'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matter scanner
|
// Машины с WorkerState
|
||||||
{
|
{
|
||||||
const to_generate = ['matter_scanner', 'matter_replicator', 'matter_decomposer', 'matter_bottler']
|
const to_generate = ['matter_scanner', 'matter_replicator', 'matter_decomposer']
|
||||||
|
const to_generate_semi = ['matter_bottler', 'drive_viewer']
|
||||||
const states = ['idle', 'working', 'error']
|
const states = ['idle', 'working', 'error']
|
||||||
|
const states_semi = ['idle', 'working']
|
||||||
|
|
||||||
for (const machine of to_generate) {
|
for (const machine of to_generate) {
|
||||||
const blockstate = {
|
const blockstate = {
|
||||||
@ -281,6 +283,30 @@ const facings = [
|
|||||||
|
|
||||||
fs.writeFileSync(_root + 'blockstates/' + machine + '.json', JSON.stringify(blockstate, null, '\t'))
|
fs.writeFileSync(_root + 'blockstates/' + machine + '.json', JSON.stringify(blockstate, null, '\t'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const machine of to_generate_semi) {
|
||||||
|
const blockstate = {
|
||||||
|
multipart: []
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const face of facings) {
|
||||||
|
for (const state of states) {
|
||||||
|
blockstate.multipart.push({
|
||||||
|
when: {
|
||||||
|
facing: face.facing,
|
||||||
|
worker: states_semi
|
||||||
|
},
|
||||||
|
|
||||||
|
apply: {
|
||||||
|
model: 'overdrive_that_matters:block/' + machine + '_' + state,
|
||||||
|
y: face.y ? face.y : undefined
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(_root + 'blockstates/' + machine + '.json', JSON.stringify(blockstate, null, '\t'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// просто дропы блоков
|
// просто дропы блоков
|
||||||
|
@ -1,17 +1,37 @@
|
|||||||
package ru.dbotthepony.mc.otm.block;
|
package ru.dbotthepony.mc.otm.block;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.EntityBlock;
|
import net.minecraft.world.level.block.EntityBlock;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
|
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.minecraft.world.level.block.state.StateDefinition;
|
||||||
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityDriveViewer;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityDriveViewer;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static ru.dbotthepony.mc.otm.block.entity.worker.WorkerState.SEMI_WORKER_STATE;
|
||||||
|
|
||||||
public class BlockDriveViewer extends BlockMatteryRotatable implements EntityBlock {
|
public class BlockDriveViewer extends BlockMatteryRotatable implements EntityBlock {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||||
return new BlockEntityDriveViewer(blockPos, blockState);
|
return new BlockEntityDriveViewer(blockPos, blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) {
|
||||||
|
return p_153212_.isClientSide || p_153214_ != Registry.BlockEntities.DRIVE_VIEWER ? null : BlockEntityDriveViewer::ticker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
|
super.createBlockStateDefinition(builder);
|
||||||
|
builder.add(SEMI_WORKER_STATE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||||||
import net.minecraft.world.level.block.state.StateDefinition;
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import ru.dbotthepony.mc.otm.Registry;
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterBottler;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterBottler;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -31,6 +31,6 @@ public class BlockMatterBottler extends BlockMatteryRotatable implements EntityB
|
|||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
super.createBlockStateDefinition(builder);
|
super.createBlockStateDefinition(builder);
|
||||||
builder.add(BlockEntityMatteryWorker.WORKER_STATE);
|
builder.add(WorkerState.SEMI_WORKER_STATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import net.minecraft.world.phys.shapes.CollisionContext;
|
|||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
import ru.dbotthepony.mc.otm.Registry;
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterDecomposer;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterDecomposer;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState;
|
||||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -37,7 +37,7 @@ public class BlockMatterDecomposer extends BlockMatteryRotatable implements Enti
|
|||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
super.createBlockStateDefinition(builder);
|
super.createBlockStateDefinition(builder);
|
||||||
builder.add(BlockEntityMatteryWorker.WORKER_STATE);
|
builder.add(WorkerState.WORKER_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<VoxelShape> SHAPES;
|
private static final List<VoxelShape> SHAPES;
|
||||||
|
@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
|
|||||||
import ru.dbotthepony.mc.otm.Registry;
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterReplicator;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterReplicator;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState;
|
||||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -37,7 +38,7 @@ public class BlockMatterReplicator extends BlockMatteryRotatable implements Enti
|
|||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
super.createBlockStateDefinition(builder);
|
super.createBlockStateDefinition(builder);
|
||||||
builder.add(BlockEntityMatteryWorker.WORKER_STATE);
|
builder.add(WorkerState.WORKER_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<VoxelShape> SHAPES;
|
private static final List<VoxelShape> SHAPES;
|
||||||
|
@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
|
|||||||
import ru.dbotthepony.mc.otm.Registry;
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterScanner;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterScanner;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState;
|
||||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -37,7 +38,7 @@ public class BlockMatterScanner extends BlockMatteryRotatable implements EntityB
|
|||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
super.createBlockStateDefinition(builder);
|
super.createBlockStateDefinition(builder);
|
||||||
builder.add(BlockEntityMatteryWorker.WORKER_STATE);
|
builder.add(WorkerState.WORKER_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<VoxelShape> SHAPES;
|
private static final List<VoxelShape> SHAPES;
|
||||||
|
@ -7,9 +7,14 @@ import net.minecraft.network.chat.TranslatableComponent;
|
|||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
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 ru.dbotthepony.mc.otm.Registry;
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState;
|
||||||
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryMachineEnergyStorage;
|
import ru.dbotthepony.mc.otm.capability.MatteryMachineEnergyStorage;
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
||||||
import ru.dbotthepony.mc.otm.menu.DriveViewerMenu;
|
import ru.dbotthepony.mc.otm.menu.DriveViewerMenu;
|
||||||
@ -18,6 +23,44 @@ import javax.annotation.Nullable;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class BlockEntityDriveViewer extends BlockEntityMatteryPowered {
|
public class BlockEntityDriveViewer extends BlockEntityMatteryPowered {
|
||||||
|
public static final BigDecimal MTE_PER_OPERATION = new BigDecimal("3.125");
|
||||||
|
|
||||||
|
public boolean canIOItems() {
|
||||||
|
return energy.getBatteryLevel().compareTo(MTE_PER_OPERATION) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setChanged() {
|
||||||
|
super.setChanged();
|
||||||
|
|
||||||
|
if (level != null) {
|
||||||
|
if (drive_slot.getItem(0).getCapability(MatteryCapability.DRIVE).isPresent() && canIOItems()) {
|
||||||
|
if (getBlockState().getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.WORKING) {
|
||||||
|
level.setBlock(getBlockPos(), getBlockState().setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (getBlockState().getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.IDLE) {
|
||||||
|
level.setBlock(getBlockPos(), getBlockState().setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIOItemCount(int desired, boolean simulate) {
|
||||||
|
if (!canIOItems())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
var extracted = energy.extractEnergyInner(MTE_PER_OPERATION.multiply(new BigDecimal(desired)), true);
|
||||||
|
var modulo = extracted.divideToIntegralValue(MTE_PER_OPERATION);
|
||||||
|
|
||||||
|
if (simulate)
|
||||||
|
return modulo.intValue();
|
||||||
|
|
||||||
|
energy.extractEnergyInner(modulo.multiply(MTE_PER_OPERATION), false);
|
||||||
|
|
||||||
|
return modulo.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
public BlockEntityDriveViewer(BlockPos p_155229_, BlockState p_155230_) {
|
public BlockEntityDriveViewer(BlockPos p_155229_, BlockState p_155230_) {
|
||||||
super(Registry.BlockEntities.DRIVE_VIEWER, p_155229_, p_155230_);
|
super(Registry.BlockEntities.DRIVE_VIEWER, p_155229_, p_155230_);
|
||||||
energy = new MatteryMachineEnergyStorage(this, MatteryMachineEnergyStorage.MachineType.WORKER, new BigDecimal(30_000));
|
energy = new MatteryMachineEnergyStorage(this, MatteryMachineEnergyStorage.MachineType.WORKER, new BigDecimal(30_000));
|
||||||
@ -49,4 +92,10 @@ public class BlockEntityDriveViewer extends BlockEntityMatteryPowered {
|
|||||||
super.load(nbt);
|
super.load(nbt);
|
||||||
drive_slot.deserializeNBT(nbt.get("drive_slot"));
|
drive_slot.deserializeNBT(nbt.get("drive_slot"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T extends BlockEntity> void ticker(Level level, BlockPos blockPos, BlockState blockState, T t) {
|
||||||
|
if (t instanceof BlockEntityDriveViewer tile) {
|
||||||
|
tile.batteryChargeLoop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import net.minecraftforge.common.util.LazyOptional;
|
|||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import ru.dbotthepony.mc.otm.Registry;
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
|
||||||
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState;
|
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState;
|
||||||
import ru.dbotthepony.mc.otm.capability.*;
|
import ru.dbotthepony.mc.otm.capability.*;
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
||||||
@ -255,8 +254,8 @@ public class BlockEntityMatterBottler extends BlockEntityMatteryPowered implemen
|
|||||||
|
|
||||||
if (tile.work_flow) {
|
if (tile.work_flow) {
|
||||||
if (capability != null) {
|
if (capability != null) {
|
||||||
if (tile.getBlockState().getValue(BlockEntityMatteryWorker.WORKER_STATE) != WorkerState.WORKING) {
|
if (tile.getBlockState().getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.WORKING) {
|
||||||
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryWorker.WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS);
|
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile.matter.getStoredMatter().compareTo(MATTER_EXCHANGE_RATE) < 0) {
|
if (tile.matter.getStoredMatter().compareTo(MATTER_EXCHANGE_RATE) < 0) {
|
||||||
@ -298,14 +297,14 @@ public class BlockEntityMatterBottler extends BlockEntityMatteryPowered implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tile.getBlockState().getValue(BlockEntityMatteryWorker.WORKER_STATE) != WorkerState.IDLE) {
|
if (tile.getBlockState().getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.IDLE) {
|
||||||
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryWorker.WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (capability != null) {
|
if (capability != null) {
|
||||||
if (tile.getBlockState().getValue(BlockEntityMatteryWorker.WORKER_STATE) != WorkerState.WORKING) {
|
if (tile.getBlockState().getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.WORKING) {
|
||||||
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryWorker.WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS);
|
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
var energy = tile.energy.extractEnergyInner(ENERGY_CONSUMPTION, true);
|
var energy = tile.energy.extractEnergyInner(ENERGY_CONSUMPTION, true);
|
||||||
@ -330,8 +329,8 @@ public class BlockEntityMatterBottler extends BlockEntityMatteryPowered implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tile.getBlockState().getValue(BlockEntityMatteryWorker.WORKER_STATE) != WorkerState.IDLE) {
|
if (tile.getBlockState().getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.IDLE) {
|
||||||
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryWorker.WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import net.minecraft.world.level.block.Block;
|
|||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
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.minecraft.world.level.block.state.properties.EnumProperty;
|
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPowered;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPowered;
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||||
|
|
||||||
@ -91,15 +90,13 @@ abstract public class BlockEntityMatteryWorker extends BlockEntityMatteryPowered
|
|||||||
return new MachineJobStatus();
|
return new MachineJobStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final EnumProperty<WorkerState> WORKER_STATE = EnumProperty.create("worker", WorkerState.class);
|
|
||||||
|
|
||||||
private int idle_ticks_anim = 0;
|
private int idle_ticks_anim = 0;
|
||||||
private int working_ticks_anim = 0;
|
private int working_ticks_anim = 0;
|
||||||
private int error_ticks_anim = 0;
|
private int error_ticks_anim = 0;
|
||||||
|
|
||||||
protected void workerLoop() {
|
protected void workerLoop() {
|
||||||
if (level != null && error_ticks_anim > 20 && getBlockState().hasProperty(WORKER_STATE) && getBlockState().getValue(WORKER_STATE) != WorkerState.ERROR) {
|
if (level != null && error_ticks_anim > 20 && getBlockState().hasProperty(WorkerState.WORKER_STATE) && getBlockState().getValue(WorkerState.WORKER_STATE) != WorkerState.ERROR) {
|
||||||
level.setBlock(getBlockPos(), getBlockState().setValue(WORKER_STATE, WorkerState.ERROR), Block.UPDATE_CLIENTS);
|
level.setBlock(getBlockPos(), getBlockState().setValue(WorkerState.WORKER_STATE, WorkerState.ERROR), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (throttle_ticks > 0) {
|
if (throttle_ticks > 0) {
|
||||||
@ -117,8 +114,8 @@ abstract public class BlockEntityMatteryWorker extends BlockEntityMatteryPowered
|
|||||||
error_ticks_anim = 0;
|
error_ticks_anim = 0;
|
||||||
idle_ticks_anim++;
|
idle_ticks_anim++;
|
||||||
|
|
||||||
if (level != null && idle_ticks_anim > 20 && getBlockState().hasProperty(WORKER_STATE) && getBlockState().getValue(WORKER_STATE) != WorkerState.IDLE) {
|
if (level != null && idle_ticks_anim > 20 && getBlockState().hasProperty(WorkerState.WORKER_STATE) && getBlockState().getValue(WorkerState.WORKER_STATE) != WorkerState.IDLE) {
|
||||||
level.setBlock(getBlockPos(), getBlockState().setValue(WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
level.setBlock(getBlockPos(), getBlockState().setValue(WorkerState.WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -139,8 +136,8 @@ abstract public class BlockEntityMatteryWorker extends BlockEntityMatteryPowered
|
|||||||
if (current_job.power_consumption_multiplier().compareTo(BigDecimal.ZERO) != 0 && energy.getBatteryLevel().compareTo(BigDecimal.ZERO) == 0) {
|
if (current_job.power_consumption_multiplier().compareTo(BigDecimal.ZERO) != 0 && energy.getBatteryLevel().compareTo(BigDecimal.ZERO) == 0) {
|
||||||
idle_ticks_anim++;
|
idle_ticks_anim++;
|
||||||
|
|
||||||
if (level != null && idle_ticks_anim > 20 && getBlockState().hasProperty(WORKER_STATE) && getBlockState().getValue(WORKER_STATE) != WorkerState.IDLE) {
|
if (level != null && idle_ticks_anim > 20 && getBlockState().hasProperty(WorkerState.WORKER_STATE) && getBlockState().getValue(WorkerState.WORKER_STATE) != WorkerState.IDLE) {
|
||||||
level.setBlock(getBlockPos(), getBlockState().setValue(WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
level.setBlock(getBlockPos(), getBlockState().setValue(WorkerState.WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -221,8 +218,8 @@ abstract public class BlockEntityMatteryWorker extends BlockEntityMatteryPowered
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level != null && (working_ticks_anim > 20 && error_ticks_anim == 0) && getBlockState().hasProperty(WORKER_STATE) && getBlockState().getValue(WORKER_STATE) != WorkerState.WORKING) {
|
if (level != null && (working_ticks_anim > 20 && error_ticks_anim == 0) && getBlockState().hasProperty(WorkerState.WORKER_STATE) && getBlockState().getValue(WorkerState.WORKER_STATE) != WorkerState.WORKING) {
|
||||||
level.setBlock(getBlockPos(), getBlockState().setValue(WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS);
|
level.setBlock(getBlockPos(), getBlockState().setValue(WorkerState.WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.worker;
|
package ru.dbotthepony.mc.otm.block.entity.worker;
|
||||||
|
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ public enum WorkerState implements StringRepresentable {
|
|||||||
WORKING,
|
WORKING,
|
||||||
ERROR;
|
ERROR;
|
||||||
|
|
||||||
|
public static final EnumProperty<WorkerState> WORKER_STATE = EnumProperty.create("worker", WorkerState.class);
|
||||||
|
public static final EnumProperty<WorkerState> SEMI_WORKER_STATE = EnumProperty.create("worker", WorkerState.class, IDLE, WORKING);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getSerializedName() {
|
public String getSerializedName() {
|
||||||
|
@ -230,22 +230,47 @@ public class DriveViewerMenu extends PoweredMatteryMenu {
|
|||||||
if (item.isEmpty() || item.getCapability(MatteryCapability.DRIVE).isPresent() || item.getCapability(CapabilityEnergy.ENERGY).isPresent())
|
if (item.isEmpty() || item.getCapability(MatteryCapability.DRIVE).isPresent() || item.getCapability(CapabilityEnergy.ENERGY).isPresent())
|
||||||
return super.quickMoveStack(ply, slot_index);
|
return super.quickMoveStack(ply, slot_index);
|
||||||
|
|
||||||
if (last_drive == null)
|
if (last_drive == null || tile == null)
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
|
|
||||||
var remaining = last_drive.insertItem(item, false);
|
var tile = (BlockEntityDriveViewer) this.tile;
|
||||||
|
int amount = tile.getIOItemCount(item.getCount(), true);
|
||||||
|
|
||||||
if (remaining.getCount() == item.getCount())
|
if (amount == 0)
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
|
|
||||||
if (remaining.isEmpty()) {
|
if (amount == item.getCount()) {
|
||||||
|
var remaining = last_drive.insertItem(item, false);
|
||||||
|
|
||||||
|
if (remaining.getCount() == item.getCount())
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
|
||||||
|
if (remaining.isEmpty()) {
|
||||||
|
var copy = item.copy();
|
||||||
|
slot.set(ItemStack.EMPTY);
|
||||||
|
tile.getIOItemCount(item.getCount(), false);
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
var copy = item.copy();
|
var copy = item.copy();
|
||||||
slot.set(ItemStack.EMPTY);
|
tile.getIOItemCount(item.getCount() - remaining.getCount(), false);
|
||||||
|
item.shrink(remaining.getCount());
|
||||||
|
slot.setChanged();
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var copy_insert = item.copy();
|
||||||
|
copy_insert.setCount(amount);
|
||||||
|
|
||||||
|
var remaining = last_drive.insertItem(copy_insert, false);
|
||||||
|
|
||||||
|
if (remaining.getCount() == copy_insert.getCount())
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
|
||||||
var copy = item.copy();
|
var copy = item.copy();
|
||||||
item.setCount(item.getCount() - remaining.getCount());
|
tile.getIOItemCount(amount - remaining.getCount(), false);
|
||||||
|
item.shrink(amount - remaining.getCount());
|
||||||
slot.setChanged();
|
slot.setChanged();
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
@ -284,20 +309,27 @@ public class DriveViewerMenu extends PoweredMatteryMenu {
|
|||||||
if (menu.last_drive == null)
|
if (menu.last_drive == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var tile = (BlockEntityDriveViewer) menu.tile;
|
||||||
|
|
||||||
if (click == ClickType.QUICK_MOVE && stack_id > -1) {
|
if (click == ClickType.QUICK_MOVE && stack_id > -1) {
|
||||||
|
if (!tile.canIOItems())
|
||||||
|
return;
|
||||||
|
|
||||||
var get_state = view.state.get(stack_id);
|
var get_state = view.state.get(stack_id);
|
||||||
|
|
||||||
if (get_state == null) {
|
if (get_state == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var extracted = menu.last_drive.extractItem(get_state.id_upstream, action == ClickAction.PRIMARY ? get_state.stack.getMaxStackSize() : Math.max(1, get_state.stack.getMaxStackSize() / 2), true);
|
int amount = tile.getIOItemCount(action == ClickAction.PRIMARY ? get_state.stack.getMaxStackSize() : Math.max(1, get_state.stack.getMaxStackSize() / 2), true);
|
||||||
|
var extracted = menu.last_drive.extractItem(get_state.id_upstream, amount, true);
|
||||||
|
|
||||||
if (!extracted.isEmpty()) {
|
if (!extracted.isEmpty()) {
|
||||||
var move = menu.quickMoveToInventory(extracted, false);
|
var move = menu.quickMoveToInventory(extracted, false);
|
||||||
|
|
||||||
if (move.remaining().getCount() != extracted.getCount()) {
|
if (move.remaining().getCount() != extracted.getCount()) {
|
||||||
menu.last_drive.extractItem(get_state.id_upstream, extracted.getCount() - move.remaining().getCount(), false);
|
menu.last_drive.extractItem(get_state.id_upstream, extracted.getCount() - move.remaining().getCount(), false);
|
||||||
|
tile.getIOItemCount(extracted.getCount() - move.remaining().getCount(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,18 +355,42 @@ public class DriveViewerMenu extends PoweredMatteryMenu {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!tile.canIOItems())
|
||||||
|
return;
|
||||||
|
|
||||||
if (!menu.getCarried().isEmpty() && click != ClickType.QUICK_MOVE) {
|
if (!menu.getCarried().isEmpty() && click != ClickType.QUICK_MOVE) {
|
||||||
// try to put
|
// try to put
|
||||||
if (action == ClickAction.PRIMARY) {
|
if (action == ClickAction.PRIMARY) {
|
||||||
menu.setCarried(menu.last_drive.insertItem(menu.getCarried(), false));
|
var carried = menu.getCarried();
|
||||||
MatteryNetworking.send(ply, new SetCarriedPacket(menu.getCarried()));
|
int amount = tile.getIOItemCount(carried.getCount(), true);
|
||||||
menu.setRemoteCarried(menu.getCarried().copy());
|
|
||||||
|
if (amount == carried.getCount()) {
|
||||||
|
var leftover = menu.last_drive.insertItem(menu.getCarried(), false);
|
||||||
|
menu.setCarried(leftover);
|
||||||
|
tile.getIOItemCount(amount - leftover.getCount(), false);
|
||||||
|
|
||||||
|
MatteryNetworking.send(ply, new SetCarriedPacket(menu.getCarried()));
|
||||||
|
menu.setRemoteCarried(menu.getCarried().copy());
|
||||||
|
} else if (amount != 0) {
|
||||||
|
var copy = carried.copy();
|
||||||
|
copy.setCount(amount);
|
||||||
|
|
||||||
|
var leftover = menu.last_drive.insertItem(copy, false);
|
||||||
|
tile.getIOItemCount(amount - leftover.getCount(), false);
|
||||||
|
|
||||||
|
leftover.setCount(carried.getCount() - amount + leftover.getCount());
|
||||||
|
menu.setCarried(leftover);
|
||||||
|
|
||||||
|
MatteryNetworking.send(ply, new SetCarriedPacket(menu.getCarried()));
|
||||||
|
menu.setRemoteCarried(menu.getCarried().copy());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var copy = menu.getCarried().copy();
|
var copy = menu.getCarried().copy();
|
||||||
copy.setCount(1);
|
copy.setCount(1);
|
||||||
|
|
||||||
if (menu.last_drive.insertItem(copy, false).isEmpty()) {
|
if (tile.getIOItemCount(1, true) == 1 && menu.last_drive.insertItem(copy, false).isEmpty()) {
|
||||||
menu.getCarried().shrink(1);
|
menu.getCarried().shrink(1);
|
||||||
|
tile.getIOItemCount(1, false);
|
||||||
MatteryNetworking.send(ply, new SetCarriedPacket(menu.getCarried()));
|
MatteryNetworking.send(ply, new SetCarriedPacket(menu.getCarried()));
|
||||||
menu.setRemoteCarried(menu.getCarried().copy());
|
menu.setRemoteCarried(menu.getCarried().copy());
|
||||||
}
|
}
|
||||||
@ -346,7 +402,12 @@ public class DriveViewerMenu extends PoweredMatteryMenu {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.setCarried(menu.last_drive.extractItem(get_state.id_upstream, action == ClickAction.PRIMARY ? get_state.stack.getMaxStackSize() : Math.max(1, get_state.stack.getMaxStackSize() / 2), false));
|
int amount = tile.getIOItemCount(action == ClickAction.PRIMARY ? get_state.stack.getMaxStackSize() : Math.max(1, get_state.stack.getMaxStackSize() / 2), true);
|
||||||
|
|
||||||
|
var extracted = menu.last_drive.extractItem(get_state.id_upstream, amount, false);
|
||||||
|
|
||||||
|
tile.getIOItemCount(extracted.getCount(), false);
|
||||||
|
menu.setCarried(extracted);
|
||||||
MatteryNetworking.send(ply, new SetCarriedPacket(menu.getCarried()));
|
MatteryNetworking.send(ply, new SetCarriedPacket(menu.getCarried()));
|
||||||
menu.setRemoteCarried(menu.getCarried().copy());
|
menu.setRemoteCarried(menu.getCarried().copy());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user