Add physical models to chemical generator and matter bottler
This commit is contained in:
parent
a8349b70d5
commit
90a2d4f9ca
@ -8,6 +8,9 @@ const models = [
|
||||
['matter_replicator', 'matter_replicator_working'],
|
||||
// 'matter_panel',
|
||||
['matter_decomposer', 'matter_decomposer_working'],
|
||||
|
||||
['chemical_generator', 'chemical_generator_idle'],
|
||||
['matter_bottler', 'matter_bottler_idle'],
|
||||
];
|
||||
|
||||
const fs = require('fs')
|
||||
|
@ -1,7 +1,9 @@
|
||||
package ru.dbotthepony.mc.otm.block
|
||||
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.world.level.BlockGetter
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.EntityBlock
|
||||
@ -10,10 +12,13 @@ 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.StateDefinition
|
||||
import net.minecraft.world.phys.shapes.CollisionContext
|
||||
import net.minecraft.world.phys.shapes.VoxelShape
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.Registry
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityChemicalGenerator
|
||||
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState
|
||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes
|
||||
|
||||
class BlockChemicalGenerator : BlockMatteryRotatable(), EntityBlock {
|
||||
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
|
||||
@ -56,4 +61,26 @@ class BlockChemicalGenerator : BlockMatteryRotatable(), EntityBlock {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getShape(
|
||||
p_60555_: BlockState,
|
||||
p_60556_: BlockGetter,
|
||||
p_60557_: BlockPos,
|
||||
p_60558_: CollisionContext
|
||||
): VoxelShape {
|
||||
return SHAPES[p_60555_.getValue(FACING).ordinal]
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val def = BlockShapes.CHEMICAL_GENERATOR.computeShape()
|
||||
|
||||
private val SHAPES: List<VoxelShape> = listOf(
|
||||
def,
|
||||
def,
|
||||
def,
|
||||
BlockShapes.CHEMICAL_GENERATOR.rotate(Direction.NORTH).computeShape(),
|
||||
BlockShapes.CHEMICAL_GENERATOR.rotate(Direction.WEST).computeShape(),
|
||||
BlockShapes.CHEMICAL_GENERATOR.rotate(Direction.EAST).computeShape()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import javax.annotation.ParametersAreNonnullByDefault
|
||||
import ru.dbotthepony.mc.otm.block.BlockMatteryRotatable
|
||||
import net.minecraft.world.level.block.EntityBlock
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.world.level.BlockGetter
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
@ -13,8 +15,11 @@ import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterBottler
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker
|
||||
import net.minecraft.world.level.block.state.StateDefinition
|
||||
import net.minecraft.world.phys.shapes.CollisionContext
|
||||
import net.minecraft.world.phys.shapes.VoxelShape
|
||||
import ru.dbotthepony.mc.otm.Registry
|
||||
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState
|
||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes
|
||||
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
@ -38,4 +43,26 @@ class BlockMatterBottler : BlockMatteryRotatable(), EntityBlock {
|
||||
super.createBlockStateDefinition(builder)
|
||||
builder.add(WorkerState.SEMI_WORKER_STATE)
|
||||
}
|
||||
|
||||
override fun getShape(
|
||||
p_60555_: BlockState,
|
||||
p_60556_: BlockGetter,
|
||||
p_60557_: BlockPos,
|
||||
p_60558_: CollisionContext
|
||||
): VoxelShape {
|
||||
return SHAPES[p_60555_.getValue(FACING).ordinal]
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val def = BlockShapes.MATTER_BOTTLER.computeShape()
|
||||
|
||||
private val SHAPES: List<VoxelShape> = listOf(
|
||||
def,
|
||||
def,
|
||||
def,
|
||||
BlockShapes.MATTER_BOTTLER.rotate(Direction.NORTH).computeShape(),
|
||||
BlockShapes.MATTER_BOTTLER.rotate(Direction.WEST).computeShape(),
|
||||
BlockShapes.MATTER_BOTTLER.rotate(Direction.EAST).computeShape()
|
||||
)
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package ru.dbotthepony.mc.otm.block.entity
|
||||
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.core.Vec3i
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.IntTag
|
||||
import net.minecraft.network.chat.Component
|
||||
@ -12,6 +11,7 @@ import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.entity.player.Player
|
||||
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.state.BlockState
|
||||
import net.minecraftforge.common.ForgeHooks
|
||||
import net.minecraftforge.common.capabilities.Capability
|
||||
@ -28,6 +28,7 @@ import ru.dbotthepony.mc.otm.core.Fraction
|
||||
import ru.dbotthepony.mc.otm.menu.ChemicalGeneratorMenu
|
||||
import ru.dbotthepony.mc.otm.*
|
||||
import ru.dbotthepony.mc.otm.block.BlockMatteryRotatable
|
||||
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState
|
||||
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
@ -36,7 +37,7 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
return NAME
|
||||
}
|
||||
|
||||
override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu? {
|
||||
override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu {
|
||||
return ChemicalGeneratorMenu(containerID, inventory, this)
|
||||
}
|
||||
|
||||
@ -48,21 +49,21 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
return resolver.cast()
|
||||
|
||||
if (valid && cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
return container_handler.get().cast()
|
||||
return itemHandler.get().cast()
|
||||
|
||||
return super.getCapability(cap, side)
|
||||
}
|
||||
|
||||
override fun invalidateCaps() {
|
||||
super.invalidateCaps()
|
||||
container_handler.invalidate()
|
||||
itemHandler.invalidate()
|
||||
valid = false
|
||||
resolver.invalidate()
|
||||
}
|
||||
|
||||
override fun reviveCaps() {
|
||||
super.reviveCaps()
|
||||
container_handler.revive()
|
||||
itemHandler.revive()
|
||||
valid = true
|
||||
resolver = LazyOptional.of {energy}
|
||||
}
|
||||
@ -77,7 +78,7 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
|
||||
companion object {
|
||||
private val THROUGHPUT = Fraction(160)
|
||||
private val THROUGHPUT_INT = 160
|
||||
private const val THROUGHPUT_INT = 160
|
||||
private val GENERATION_SPEED = Fraction(40)
|
||||
private val MAX_ENERGY = Fraction(24_000)
|
||||
private val NAME = TranslatableComponent("block.overdrive_that_matters.chemical_generator")
|
||||
@ -150,7 +151,7 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
check = true
|
||||
}, 2)
|
||||
|
||||
val container_handler = container.handler(fun (slot, stack): Boolean {
|
||||
val itemHandler = container.handler(fun (slot, stack): Boolean {
|
||||
if (slot == 0)
|
||||
return ForgeHooks.getBurnTime(stack, null) > 0
|
||||
|
||||
@ -192,11 +193,11 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
}
|
||||
|
||||
override fun receiveEnergyInner(howMuch: Fraction, simulate: Boolean): Fraction {
|
||||
val new_energy = (howMuch + power).min(MAX_ENERGY)
|
||||
val diff = new_energy - power
|
||||
val new = (howMuch + power).min(MAX_ENERGY)
|
||||
val diff = new - power
|
||||
|
||||
if (!simulate) {
|
||||
power = new_energy
|
||||
power = new
|
||||
setChangedLight()
|
||||
}
|
||||
|
||||
@ -216,7 +217,7 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
|
||||
private var check = false
|
||||
|
||||
fun workWithPower(it: IEnergyStorage) {
|
||||
private fun workWithPower(it: IEnergyStorage) {
|
||||
if (it is IMatteryEnergyStorage) {
|
||||
val demand = it.missingPower
|
||||
val extracted = energy.extractEnergyInner(demand, true)
|
||||
@ -245,6 +246,12 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
working_ticks_total = 0
|
||||
check = true
|
||||
}
|
||||
|
||||
if (blockState.getValue(WorkerState.WORKER_STATE) != WorkerState.WORKING) {
|
||||
level?.setBlock(blockPos, blockState.setValue(WorkerState.WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS)
|
||||
}
|
||||
} else if (blockState.getValue(WorkerState.WORKER_STATE) != WorkerState.IDLE) {
|
||||
level?.setBlock(blockPos, blockState.setValue(WorkerState.WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS)
|
||||
}
|
||||
|
||||
if (working_ticks == 0 && !isBlockedByRedstone && check) {
|
||||
|
Loading…
Reference in New Issue
Block a user