Split worker class
This commit is contained in:
parent
651ba41da7
commit
300c27d366
@ -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.BlockEntityMatteryPoweredWorker;
|
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
||||||
|
|
||||||
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(BlockEntityMatteryPoweredWorker.WORKER_STATE);
|
builder.add(BlockEntityMatteryWorker.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.BlockEntityMatteryPoweredWorker;
|
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
||||||
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(BlockEntityMatteryPoweredWorker.WORKER_STATE);
|
builder.add(BlockEntityMatteryWorker.WORKER_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<VoxelShape> SHAPES;
|
private static final List<VoxelShape> SHAPES;
|
||||||
|
@ -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.BlockEntityMatterReplicator;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterReplicator;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPoweredWorker;
|
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
||||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -31,13 +31,13 @@ public class BlockMatterReplicator extends BlockMatteryRotatable implements Enti
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) {
|
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.MATTER_REPLICATOR ? null : BlockEntityMatteryPoweredWorker::basicTicker;
|
return p_153212_.isClientSide || p_153214_ != Registry.BlockEntities.MATTER_REPLICATOR ? null : BlockEntityMatteryWorker::basicTicker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(BlockEntityMatteryPoweredWorker.WORKER_STATE);
|
builder.add(BlockEntityMatteryWorker.WORKER_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<VoxelShape> SHAPES;
|
private static final List<VoxelShape> SHAPES;
|
||||||
|
@ -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.BlockEntityMatterScanner;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterScanner;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPoweredWorker;
|
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
||||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -31,13 +31,13 @@ public class BlockMatterScanner extends BlockMatteryRotatable implements EntityB
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) {
|
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.MATTER_SCANNER ? null : BlockEntityMatteryPoweredWorker::basicTicker;
|
return p_153212_.isClientSide || p_153214_ != Registry.BlockEntities.MATTER_SCANNER ? null : BlockEntityMatteryWorker::basicTicker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(BlockEntityMatteryPoweredWorker.WORKER_STATE);
|
builder.add(BlockEntityMatteryWorker.WORKER_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<VoxelShape> SHAPES;
|
private static final List<VoxelShape> SHAPES;
|
||||||
|
@ -8,7 +8,6 @@ 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.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
@ -18,8 +17,9 @@ import net.minecraftforge.common.capabilities.Capability;
|
|||||||
import net.minecraftforge.common.util.LazyOptional;
|
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.OverdriveThatMatters;
|
|
||||||
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.capability.*;
|
import ru.dbotthepony.mc.otm.capability.*;
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
||||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||||
@ -255,8 +255,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(BlockEntityMatteryPoweredWorker.WORKER_STATE) != BlockEntityMatteryPoweredWorker.WorkerState.WORKING) {
|
if (tile.getBlockState().getValue(BlockEntityMatteryWorker.WORKER_STATE) != WorkerState.WORKING) {
|
||||||
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryPoweredWorker.WORKER_STATE, BlockEntityMatteryPoweredWorker.WorkerState.WORKING), Block.UPDATE_CLIENTS);
|
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryWorker.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 +298,14 @@ public class BlockEntityMatterBottler extends BlockEntityMatteryPowered implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tile.getBlockState().getValue(BlockEntityMatteryPoweredWorker.WORKER_STATE) != BlockEntityMatteryPoweredWorker.WorkerState.IDLE) {
|
if (tile.getBlockState().getValue(BlockEntityMatteryWorker.WORKER_STATE) != WorkerState.IDLE) {
|
||||||
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryPoweredWorker.WORKER_STATE, BlockEntityMatteryPoweredWorker.WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryWorker.WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (capability != null) {
|
if (capability != null) {
|
||||||
if (tile.getBlockState().getValue(BlockEntityMatteryPoweredWorker.WORKER_STATE) != BlockEntityMatteryPoweredWorker.WorkerState.WORKING) {
|
if (tile.getBlockState().getValue(BlockEntityMatteryWorker.WORKER_STATE) != WorkerState.WORKING) {
|
||||||
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryPoweredWorker.WORKER_STATE, BlockEntityMatteryPoweredWorker.WorkerState.WORKING), Block.UPDATE_CLIENTS);
|
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryWorker.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 +330,8 @@ public class BlockEntityMatterBottler extends BlockEntityMatteryPowered implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tile.getBlockState().getValue(BlockEntityMatteryPoweredWorker.WORKER_STATE) != BlockEntityMatteryPoweredWorker.WorkerState.IDLE) {
|
if (tile.getBlockState().getValue(BlockEntityMatteryWorker.WORKER_STATE) != WorkerState.IDLE) {
|
||||||
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryPoweredWorker.WORKER_STATE, BlockEntityMatteryPoweredWorker.WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
level.setBlock(tile.getBlockPos(), tile.getBlockState().setValue(BlockEntityMatteryWorker.WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@ 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.*;
|
import ru.dbotthepony.mc.otm.*;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.BlockEntityMatteryWorker;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.MachineJob;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.MachineJobStatus;
|
||||||
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;
|
||||||
import ru.dbotthepony.mc.otm.capability.IMatterGridCell;
|
import ru.dbotthepony.mc.otm.capability.IMatterGridCell;
|
||||||
@ -28,7 +31,7 @@ import javax.annotation.Nonnull;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class BlockEntityMatterDecomposer extends BlockEntityMatteryPoweredWorker implements IMatterGridCell {
|
public class BlockEntityMatterDecomposer extends BlockEntityMatteryWorker implements IMatterGridCell {
|
||||||
private static final TranslatableComponent MACHINE_NAME = new TranslatableComponent("block.overdrive_that_matters.matter_decomposer");
|
private static final TranslatableComponent MACHINE_NAME = new TranslatableComponent("block.overdrive_that_matters.matter_decomposer");
|
||||||
private boolean valid = true;
|
private boolean valid = true;
|
||||||
public final MatterHandlerCapability matter = new MatterHandlerCapability(this::setChanged, IMatterHandler.MatterDirection.EXTRACT, new BigDecimal("20"));
|
public final MatterHandlerCapability matter = new MatterHandlerCapability(this::setChanged, IMatterHandler.MatterDirection.EXTRACT, new BigDecimal("20"));
|
||||||
|
@ -16,6 +16,10 @@ 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.MachineJob;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.MachineJobStatus;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.WorkTickContext;
|
||||||
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;
|
||||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||||
@ -26,7 +30,7 @@ import javax.annotation.Nonnull;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class BlockEntityMatterReplicator extends BlockEntityMatteryPoweredWorker implements IMatterGridCell {
|
public class BlockEntityMatterReplicator extends BlockEntityMatteryWorker implements IMatterGridCell {
|
||||||
public BlockEntityMatterReplicator(BlockPos p_155229_, BlockState p_155230_) {
|
public BlockEntityMatterReplicator(BlockPos p_155229_, BlockState p_155230_) {
|
||||||
super(Registry.BlockEntities.MATTER_REPLICATOR, p_155229_, p_155230_);
|
super(Registry.BlockEntities.MATTER_REPLICATOR, p_155229_, p_155230_);
|
||||||
energy = new MatteryMachineEnergyStorage(this, MatteryMachineEnergyStorage.MachineType.WORKER, new BigDecimal(200_000), new BigDecimal(4000), new BigDecimal(4000));
|
energy = new MatteryMachineEnergyStorage(this, MatteryMachineEnergyStorage.MachineType.WORKER, new BigDecimal(200_000), new BigDecimal(4000), new BigDecimal(4000));
|
||||||
|
@ -15,6 +15,9 @@ import net.minecraftforge.common.capabilities.Capability;
|
|||||||
import net.minecraftforge.common.util.LazyOptional;
|
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.block.entity.worker.BlockEntityMatteryWorker;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.MachineJob;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.MachineJobStatus;
|
||||||
import ru.dbotthepony.mc.otm.capability.*;
|
import ru.dbotthepony.mc.otm.capability.*;
|
||||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||||
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
||||||
@ -28,7 +31,7 @@ import java.math.BigDecimal;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BlockEntityMatterScanner extends BlockEntityMatteryPoweredWorker implements IMatterGridCell {
|
public class BlockEntityMatterScanner extends BlockEntityMatteryWorker implements IMatterGridCell {
|
||||||
private static final TranslatableComponent NAME = new TranslatableComponent("block.overdrive_that_matters.matter_scanner");
|
private static final TranslatableComponent NAME = new TranslatableComponent("block.overdrive_that_matters.matter_scanner");
|
||||||
|
|
||||||
public final MatteryContainer input_slot = new MatteryContainer(this::setChanged, 1);
|
public final MatteryContainer input_slot = new MatteryContainer(this::setChanged, 1);
|
||||||
|
@ -1,92 +1,29 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity;
|
package ru.dbotthepony.mc.otm.block.entity.worker;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.DoubleTag;
|
import net.minecraft.nbt.DoubleTag;
|
||||||
import net.minecraft.nbt.StringTag;
|
|
||||||
import net.minecraft.nbt.Tag;
|
|
||||||
import net.minecraft.util.StringRepresentable;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
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 net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPowered;
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
abstract public class BlockEntityMatteryPoweredWorker extends BlockEntityMatteryPowered {
|
abstract public class BlockEntityMatteryWorker extends BlockEntityMatteryPowered {
|
||||||
public BlockEntityMatteryPoweredWorker(BlockEntityType<?> p_155228_, BlockPos p_155229_, BlockState p_155230_) {
|
public BlockEntityMatteryWorker(BlockEntityType<?> p_155228_, BlockPos p_155229_, BlockState p_155230_) {
|
||||||
super(p_155228_, p_155229_, p_155230_);
|
super(p_155228_, p_155229_, p_155230_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
protected abstract BigDecimal getBaseConsumption();
|
protected abstract BigDecimal getBaseConsumption();
|
||||||
|
|
||||||
public record WorkTickContext(MachineJob job, BigDecimal required_power, BigDecimal extracted_power, BigDecimal work_speed) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public record MachineJobStatus(boolean valid, int throttle) {
|
|
||||||
public MachineJobStatus() {
|
|
||||||
this(true, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MachineJobStatus(boolean finished) {
|
|
||||||
this(finished, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public record MachineJob(ItemStack stack, double ticks_processing_time, BigDecimal power_consumption_multiplier, CompoundTag data) {
|
|
||||||
public MachineJob(ItemStack stack, double ticks_processing_time, BigDecimal power_consumption_multiplier, CompoundTag data) {
|
|
||||||
this.stack = stack;
|
|
||||||
this.ticks_processing_time = ticks_processing_time;
|
|
||||||
this.power_consumption_multiplier = power_consumption_multiplier;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MachineJob(ItemStack stack, double ticks_processing_time, BigDecimal power_consumption_multiplier) {
|
|
||||||
this(stack, ticks_processing_time, power_consumption_multiplier, new CompoundTag());
|
|
||||||
}
|
|
||||||
|
|
||||||
public MachineJob(ItemStack stack, double ticks_processing_time) {
|
|
||||||
this(stack, ticks_processing_time, BigDecimal.ONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompoundTag serializeNBT() {
|
|
||||||
CompoundTag store_job = new CompoundTag();
|
|
||||||
|
|
||||||
store_job.put("data", data);
|
|
||||||
store_job.put("stack", stack.serializeNBT());
|
|
||||||
store_job.putDouble("ticks_processing_time", ticks_processing_time);
|
|
||||||
store_job.putString("power_consumption_multiplier", power_consumption_multiplier.toString());
|
|
||||||
|
|
||||||
return store_job;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static MachineJob deserializeNBT(@Nullable Tag nbt) {
|
|
||||||
if (nbt == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (nbt instanceof CompoundTag tag) {
|
|
||||||
if (tag.get("stack") instanceof CompoundTag stack_tag && tag.get("ticks_processing_time") instanceof DoubleTag ticks_processing_time && tag.get("power_consumption_multiplier") instanceof StringTag power_consumption_multiplier) {
|
|
||||||
ItemStack stack = ItemStack.of(stack_tag);
|
|
||||||
|
|
||||||
if (!stack.isEmpty()) {
|
|
||||||
return new MachineJob(stack, ticks_processing_time.getAsDouble(), new BigDecimal(power_consumption_multiplier.getAsString()), tag.getCompound("data"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
protected BigDecimal consumptionPerWork() {
|
protected BigDecimal consumptionPerWork() {
|
||||||
return getBaseConsumption();
|
return getBaseConsumption();
|
||||||
@ -154,18 +91,6 @@ abstract public class BlockEntityMatteryPoweredWorker extends BlockEntityMattery
|
|||||||
return new MachineJobStatus();
|
return new MachineJobStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum WorkerState implements StringRepresentable {
|
|
||||||
IDLE,
|
|
||||||
WORKING,
|
|
||||||
ERROR;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nonnull
|
|
||||||
public String getSerializedName() {
|
|
||||||
return this == IDLE ? "idle" : this == WORKING ? "working" : "error";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final EnumProperty<WorkerState> WORKER_STATE = EnumProperty.create("worker", WorkerState.class);
|
public static final EnumProperty<WorkerState> WORKER_STATE = EnumProperty.create("worker", WorkerState.class);
|
||||||
|
|
||||||
private int idle_ticks_anim = 0;
|
private int idle_ticks_anim = 0;
|
||||||
@ -211,7 +136,7 @@ abstract public class BlockEntityMatteryPoweredWorker extends BlockEntityMattery
|
|||||||
current_job = input;
|
current_job = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
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(WORKER_STATE) && getBlockState().getValue(WORKER_STATE) != WorkerState.IDLE) {
|
||||||
@ -223,17 +148,17 @@ abstract public class BlockEntityMatteryPoweredWorker extends BlockEntityMattery
|
|||||||
|
|
||||||
idle_ticks_anim = 0;
|
idle_ticks_anim = 0;
|
||||||
|
|
||||||
if (work_ticks < current_job.ticks_processing_time) {
|
if (work_ticks < current_job.ticks_processing_time()) {
|
||||||
if (current_job.power_consumption_multiplier.compareTo(BigDecimal.ZERO) != 0) {
|
if (current_job.power_consumption_multiplier().compareTo(BigDecimal.ZERO) != 0) {
|
||||||
BigDecimal required_power = consumptionPerWork().multiply(current_job.power_consumption_multiplier);
|
BigDecimal required_power = consumptionPerWork().multiply(current_job.power_consumption_multiplier());
|
||||||
BigDecimal extracted_power = energy.extractEnergyInner(required_power, true);
|
BigDecimal extracted_power = energy.extractEnergyInner(required_power, true);
|
||||||
|
|
||||||
BigDecimal work_speed = extracted_power.divide(required_power, MatteryCapability.ROUND_RULES);
|
BigDecimal work_speed = extracted_power.divide(required_power, MatteryCapability.ROUND_RULES);
|
||||||
|
|
||||||
MachineJobStatus status = onWorkTick(new WorkTickContext(current_job, required_power, extracted_power, work_speed));
|
MachineJobStatus status = onWorkTick(new WorkTickContext(current_job, required_power, extracted_power, work_speed));
|
||||||
|
|
||||||
if (!status.valid) {
|
if (!status.valid()) {
|
||||||
throttle_ticks += status.throttle;
|
throttle_ticks += status.throttle();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,29 +167,29 @@ abstract public class BlockEntityMatteryPoweredWorker extends BlockEntityMattery
|
|||||||
|
|
||||||
double new_work_ticks = work_speed.doubleValue() + work_ticks;
|
double new_work_ticks = work_speed.doubleValue() + work_ticks;
|
||||||
|
|
||||||
if (new_work_ticks > current_job.ticks_processing_time) {
|
if (new_work_ticks > current_job.ticks_processing_time()) {
|
||||||
work_ticks = current_job.ticks_processing_time;
|
work_ticks = current_job.ticks_processing_time();
|
||||||
energy.extractEnergyInner(extracted_power.multiply(new BigDecimal(1d - (new_work_ticks - current_job.ticks_processing_time), MatteryCapability.ROUND_RULES)), false);
|
energy.extractEnergyInner(extracted_power.multiply(new BigDecimal(1d - (new_work_ticks - current_job.ticks_processing_time()), MatteryCapability.ROUND_RULES)), false);
|
||||||
} else {
|
} else {
|
||||||
work_ticks = new_work_ticks;
|
work_ticks = new_work_ticks;
|
||||||
energy.extractEnergyInner(extracted_power, false);
|
energy.extractEnergyInner(extracted_power, false);
|
||||||
|
|
||||||
if (work_ticks >= current_job.ticks_processing_time) {
|
if (work_ticks >= current_job.ticks_processing_time()) {
|
||||||
MachineJobStatus finish = onJobFinish(current_job);
|
MachineJobStatus finish = onJobFinish(current_job);
|
||||||
|
|
||||||
if (finish.valid) {
|
if (finish.valid()) {
|
||||||
current_job = null;
|
current_job = null;
|
||||||
work_ticks = 0d;
|
work_ticks = 0d;
|
||||||
} else {
|
} else {
|
||||||
throttle_ticks += finish.throttle;
|
throttle_ticks += finish.throttle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MachineJobStatus status = onWorkTick(new WorkTickContext(current_job, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ONE));
|
MachineJobStatus status = onWorkTick(new WorkTickContext(current_job, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ONE));
|
||||||
|
|
||||||
if (!status.valid) {
|
if (!status.valid()) {
|
||||||
throttle_ticks += status.throttle;
|
throttle_ticks += status.throttle();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,26 +197,26 @@ abstract public class BlockEntityMatteryPoweredWorker extends BlockEntityMattery
|
|||||||
error_ticks_anim = 0;
|
error_ticks_anim = 0;
|
||||||
work_ticks += 1d;
|
work_ticks += 1d;
|
||||||
|
|
||||||
if (work_ticks >= current_job.ticks_processing_time) {
|
if (work_ticks >= current_job.ticks_processing_time()) {
|
||||||
MachineJobStatus finish = onJobFinish(current_job);
|
MachineJobStatus finish = onJobFinish(current_job);
|
||||||
|
|
||||||
if (finish.valid) {
|
if (finish.valid()) {
|
||||||
current_job = null;
|
current_job = null;
|
||||||
work_ticks = 0d;
|
work_ticks = 0d;
|
||||||
} else {
|
} else {
|
||||||
throttle_ticks += finish.throttle;
|
throttle_ticks += finish.throttle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MachineJobStatus finish = onJobFinish(current_job);
|
MachineJobStatus finish = onJobFinish(current_job);
|
||||||
|
|
||||||
if (finish.valid) {
|
if (finish.valid()) {
|
||||||
current_job = null;
|
current_job = null;
|
||||||
work_ticks = 0d;
|
work_ticks = 0d;
|
||||||
error_ticks_anim = 0;
|
error_ticks_anim = 0;
|
||||||
} else {
|
} else {
|
||||||
throttle_ticks += finish.throttle;
|
throttle_ticks += finish.throttle();
|
||||||
error_ticks_anim++;
|
error_ticks_anim++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,7 +234,7 @@ abstract public class BlockEntityMatteryPoweredWorker extends BlockEntityMattery
|
|||||||
if (current_job == null)
|
if (current_job == null)
|
||||||
return 0d;
|
return 0d;
|
||||||
|
|
||||||
return Math.min(1d, work_ticks / current_job.ticks_processing_time);
|
return Math.min(1d, work_ticks / current_job.ticks_processing_time());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -320,7 +245,7 @@ abstract public class BlockEntityMatteryPoweredWorker extends BlockEntityMattery
|
|||||||
protected abstract MachineJob getNextJob();
|
protected abstract MachineJob getNextJob();
|
||||||
|
|
||||||
public static <T extends BlockEntity> void basicTicker(Level level, BlockPos blockPos, BlockState blockState, T t) {
|
public static <T extends BlockEntity> void basicTicker(Level level, BlockPos blockPos, BlockState blockState, T t) {
|
||||||
if (t instanceof BlockEntityMatteryPoweredWorker tile) {
|
if (t instanceof BlockEntityMatteryWorker tile) {
|
||||||
tile.batteryChargeLoop();
|
tile.batteryChargeLoop();
|
||||||
tile.workerLoop();
|
tile.workerLoop();
|
||||||
}
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.block.entity.worker;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.DoubleTag;
|
||||||
|
import net.minecraft.nbt.StringTag;
|
||||||
|
import net.minecraft.nbt.Tag;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public record MachineJob(ItemStack stack, double ticks_processing_time, BigDecimal power_consumption_multiplier,
|
||||||
|
CompoundTag data) {
|
||||||
|
public MachineJob(ItemStack stack, double ticks_processing_time, BigDecimal power_consumption_multiplier, CompoundTag data) {
|
||||||
|
this.stack = stack;
|
||||||
|
this.ticks_processing_time = ticks_processing_time;
|
||||||
|
this.power_consumption_multiplier = power_consumption_multiplier;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MachineJob(ItemStack stack, double ticks_processing_time, BigDecimal power_consumption_multiplier) {
|
||||||
|
this(stack, ticks_processing_time, power_consumption_multiplier, new CompoundTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MachineJob(ItemStack stack, double ticks_processing_time) {
|
||||||
|
this(stack, ticks_processing_time, BigDecimal.ONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag serializeNBT() {
|
||||||
|
CompoundTag store_job = new CompoundTag();
|
||||||
|
|
||||||
|
store_job.put("data", data);
|
||||||
|
store_job.put("stack", stack.serializeNBT());
|
||||||
|
store_job.putDouble("ticks_processing_time", ticks_processing_time);
|
||||||
|
store_job.putString("power_consumption_multiplier", power_consumption_multiplier.toString());
|
||||||
|
|
||||||
|
return store_job;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static MachineJob deserializeNBT(@Nullable Tag nbt) {
|
||||||
|
if (nbt == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (nbt instanceof CompoundTag tag) {
|
||||||
|
if (tag.get("stack") instanceof CompoundTag stack_tag && tag.get("ticks_processing_time") instanceof DoubleTag ticks_processing_time && tag.get("power_consumption_multiplier") instanceof StringTag power_consumption_multiplier) {
|
||||||
|
ItemStack stack = ItemStack.of(stack_tag);
|
||||||
|
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
return new MachineJob(stack, ticks_processing_time.getAsDouble(), new BigDecimal(power_consumption_multiplier.getAsString()), tag.getCompound("data"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.block.entity.worker;
|
||||||
|
|
||||||
|
public record MachineJobStatus(boolean valid, int throttle) {
|
||||||
|
public MachineJobStatus() {
|
||||||
|
this(true, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MachineJobStatus(boolean finished) {
|
||||||
|
this(finished, 0);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.block.entity.worker;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public record WorkTickContext(MachineJob job, BigDecimal required_power, BigDecimal extracted_power,
|
||||||
|
BigDecimal work_speed) {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.block.entity.worker;
|
||||||
|
|
||||||
|
import net.minecraft.util.StringRepresentable;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public enum WorkerState implements StringRepresentable {
|
||||||
|
IDLE,
|
||||||
|
WORKING,
|
||||||
|
ERROR;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nonnull
|
||||||
|
public String getSerializedName() {
|
||||||
|
return this == IDLE ? "idle" : this == WORKING ? "working" : "error";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user