1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2025-04-11 03:15:44 +02:00

Work on Tables (supporting item, Pedestal logic & color tweaks)

This commit is contained in:
chylex 2020-02-26 14:43:16 +01:00
parent 412ed53da3
commit 7de1d6cba9
9 changed files with 131 additions and 11 deletions

View File

@ -3,6 +3,7 @@ import chylex.hee.client.render.util.NO_TINT
import chylex.hee.game.block.entity.TileEntityTablePedestal
import chylex.hee.game.block.info.BlockBuilder
import chylex.hee.game.block.util.Property
import chylex.hee.game.mechanics.table.PedestalStatusIndicator
import chylex.hee.init.ModItems
import chylex.hee.system.migration.forge.Side
import chylex.hee.system.migration.forge.Sided
@ -155,6 +156,9 @@ class BlockTablePedestal(builder: BlockBuilder) : BlockSimpleShaped(builder, COM
tile.dropAllItems()
}
}
else if (tile.isDedicatedOutput){
tile.dropAllItems()
}
else if (!isItemAreaBlocked(world, pos)){
tile.addToInput(heldItem.copyIf { player.isCreative })
}
@ -211,7 +215,7 @@ class BlockTablePedestal(builder: BlockBuilder) : BlockSimpleShaped(builder, COM
return when(tintIndex){
1 -> pos.getTile<TileEntityTablePedestal>(world)?.tableIndicatorColor?.i ?: NO_TINT
2 -> pos.getTile<TileEntityTablePedestal>(world)?.statusIndicatorColorClient ?: NO_TINT
2 -> pos.getTile<TileEntityTablePedestal>(world)?.statusIndicatorColorClient ?: PedestalStatusIndicator.Contents.NONE.color.i
else -> NO_TINT
}
}

View File

@ -23,12 +23,13 @@ import chylex.hee.system.util.getTile
import chylex.hee.system.util.use
import net.minecraft.item.Item
import net.minecraft.tileentity.TileEntityType
import net.minecraft.util.math.BlockPos
import org.apache.commons.lang3.math.Fraction
abstract class TileEntityBaseTable(type: TileEntityType<out TileEntityBaseTable>) : TileEntityBaseSpecialFirstTick(type){
private companion object{
private const val MAX_CLUSTER_DISTANCE = 12
private const val MAX_PEDESTAL_DISTANCE = 6
private const val MAX_PEDESTAL_DISTANCE = 4.5
private const val PROCESS_REFRESH_RATE = 10
@ -48,6 +49,12 @@ abstract class TileEntityBaseTable(type: TileEntityType<out TileEntityBaseTable>
protected abstract val processSerializer: ITableProcessSerializer
protected abstract val processTickRate: Int
val hasSupportingItem
get() = currentProcesses.any { it is ProcessSupportingItemHolder }
val totalFreePedestals
get() = pedestalHandler.inputPedestalTiles.count { !isPedestalBusy(it) }
private var tickCounterRefresh = 0
private var tickCounterProcessing = 0
@ -193,11 +200,17 @@ abstract class TileEntityBaseTable(type: TileEntityType<out TileEntityBaseTable>
return false
}
override fun requestUseSupportingItem(item: Item, amount: Int): Boolean{
return currentProcesses.firstOrNull { it is ProcessSupportingItemHolder && it.useItem(item, amount) } != null
override fun requestUseSupportingItem(item: Item, amount: Int): BlockPos?{
for(foundProcess in currentProcesses){
if (foundProcess is ProcessSupportingItemHolder && foundProcess.useItem(item, amount)){
return foundProcess.pedestalPos
}
}
return null
}
override fun getOutputPedestal(candidate: TileEntityTablePedestal): TileEntityTablePedestal {
override fun getOutputPedestal(candidate: TileEntityTablePedestal): TileEntityTablePedestal{
return pedestalHandler.dedicatedOutputPedestalTile ?: candidate
}

View File

@ -0,0 +1,47 @@
package chylex.hee.game.block.entity.base
import chylex.hee.game.block.entity.TileEntityTablePedestal
import chylex.hee.game.mechanics.table.interfaces.ITableProcess
import chylex.hee.game.mechanics.table.process.ProcessSupportingItemBlocker
import chylex.hee.game.mechanics.table.process.ProcessSupportingItemHolder
import chylex.hee.game.mechanics.table.process.serializer.MultiProcessSerializer.Companion.Mapping
import net.minecraft.item.ItemStack
import net.minecraft.tileentity.TileEntityType
import net.minecraft.util.math.BlockPos
abstract class TileEntityBaseTableWithSupportingItem(type: TileEntityType<out TileEntityBaseTableWithSupportingItem>) : TileEntityBaseTable(type){
protected companion object{
val SUPPORTING_ITEM_MAPPINGS = arrayOf(
Mapping("Supporting", ::ProcessSupportingItemHolder),
Mapping("Blocking", ::ProcessSupportingItemBlocker)
)
}
protected abstract fun isSupportingItem(stack: ItemStack): Boolean
protected abstract fun getProcessFor(pedestalPos: BlockPos, stack: ItemStack): ITableProcess?
final override fun createNewProcesses(unassignedPedestals: List<TileEntityTablePedestal>): List<ITableProcess>{
val newProcesses = ArrayList<ITableProcess>(1)
var hasSupportingItem = hasSupportingItem
for(pedestal in unassignedPedestals){
if (isSupportingItem(pedestal.itemInputCopy)){
newProcesses.add(ProcessSupportingItemHolder(this, pedestal.pos))
hasSupportingItem = true
}
else{
val process = getProcessFor(pedestal.pos, pedestal.itemInputCopy)
if (process != null){
if (totalFreePedestals - newProcesses.size <= 1 && !hasSupportingItem){
newProcesses.add(ProcessSupportingItemBlocker(this, pedestal.pos))
}
else{
newProcesses.add(process)
}
}
}
}
return newProcesses
}
}

View File

@ -25,11 +25,11 @@ class PedestalStatusIndicator(private val pedestal: TileEntityTablePedestal) : I
enum class Contents(override val color: IntColor) : IIndicatorColor{
NONE(RGB(161, 151, 145)),
WITH_INPUT(HCL(70.0, 100F, 85F)),
OUTPUTTED(HCL(230.0, 100F, 72F))
OUTPUTTED(HCL(114.0, 100F, 76F))
}
enum class Process(override val color: IntColor) : IIndicatorColor{
WORKING(HCL(114.0, 100F, 76F)),
WORKING(HCL(230.0, 100F, 72F)),
PAUSED(HCL(70.0, 100F, 85F)),
BLOCKED(HCL(15.0, 100F, 64F)),
DEDICATED_OUTPUT(HCL(286.0, 100F, 82F)),

View File

@ -12,7 +12,7 @@ import chylex.hee.system.util.use
import net.minecraft.util.math.BlockPos
import net.minecraftforge.common.util.INBTSerializable
class TableLinkedPedestalHandler(private val table: TileEntityBaseTable, maxDistance: Int) : INBTSerializable<TagCompound>{
class TableLinkedPedestalHandler(private val table: TileEntityBaseTable, maxDistance: Double) : INBTSerializable<TagCompound>{
private companion object{
private const val POS_TAG = "Pos"
private const val OUTPUT_TAG = "Output"

View File

@ -1,13 +1,14 @@
package chylex.hee.game.mechanics.table.interfaces
import chylex.hee.game.block.entity.TileEntityTablePedestal
import net.minecraft.item.Item
import net.minecraft.util.math.BlockPos
import org.apache.commons.lang3.math.Fraction
interface ITableContext{
val isPaused: Boolean
fun ensureDustAvailable(amount: Fraction): Boolean
fun requestUseResources(): Boolean
fun requestUseSupportingItem(item: Item, amount: Int): Boolean
fun requestUseSupportingItem(item: Item, amount: Int): BlockPos?
fun getOutputPedestal(candidate: TileEntityTablePedestal) : TileEntityTablePedestal
fun triggerWorkParticle()
fun markProcessFinished()

View File

@ -96,9 +96,12 @@ abstract class ProcessManyPedestals(private val table: TileEntityBaseTable, pos:
is Work -> {
val currentTime = table.wrld.totalTime
if (context.isPaused || tiles.any { currentTime - it.inputModTime < 20L } || !context.ensureDustAvailable(dustPerTick)){
if (context.isPaused || tiles.any { currentTime - it.inputModTime < 20L }){
setStatusIndicator(tiles, PAUSED)
}
else if (!context.ensureDustAvailable(dustPerTick)){
setStatusIndicator(tiles, BLOCKED)
}
else{
val inputs = Array(tiles.size){ tiles[it].itemInputCopy }
val newState = onWorkTick(context, inputs)
@ -125,7 +128,7 @@ abstract class ProcessManyPedestals(private val table: TileEntityBaseTable, pos:
if (context.isPaused){
setStatusIndicator(tiles, PAUSED)
}
else if (tiles.find { it.pos == state.pedestal }?.let(context::getOutputPedestal)?.addToOutput(state.stacks) == true){
else if (state.pedestal.getTile<TileEntityTablePedestal>(table.wrld)?.let(context::getOutputPedestal)?.addToOutput(state.stacks) == true){
for(tile in tiles){
tile.replaceInput(tile.itemInputCopy.apply(whenFinished::transform), silent = false)
}

View File

@ -0,0 +1,49 @@
package chylex.hee.game.mechanics.table.process
import chylex.hee.game.block.entity.TileEntityTablePedestal
import chylex.hee.game.block.entity.base.TileEntityBaseTable
import chylex.hee.game.mechanics.energy.IEnergyQuantity.Units
import chylex.hee.game.mechanics.table.PedestalStatusIndicator.Process.BLOCKED
import chylex.hee.game.mechanics.table.interfaces.ITableContext
import chylex.hee.game.mechanics.table.interfaces.ITableProcess
import chylex.hee.game.mechanics.table.interfaces.ITableProcess.Companion.NO_DUST
import chylex.hee.system.util.TagCompound
import chylex.hee.system.util.getPos
import chylex.hee.system.util.getTile
import chylex.hee.system.util.putPos
import net.minecraft.util.math.BlockPos
class ProcessSupportingItemBlocker(private val table: TileEntityBaseTable, pos: BlockPos) : ITableProcess{
constructor(table: TileEntityBaseTable, nbt: TagCompound) : this(table, nbt.getPos("PedestalPos"))
override val pedestals = arrayOf(pos)
override val energyPerTick = Units(0)
override val dustPerTick = NO_DUST
private val pedestalTile
get() = pedestals[0].getTile<TileEntityTablePedestal>(table.wrld)
// Handling
override fun initialize(){
pedestalTile!!.updateProcessStatus(BLOCKED)
}
override fun revalidate(): Boolean{
return pedestalTile?.hasInputItem == true && table.totalFreePedestals == 0
}
override fun tick(context: ITableContext){}
override fun dispose(){
pedestalTile?.updateProcessStatus(null)
}
// Serialization
override fun serializeNBT() = TagCompound().apply {
putPos("PedestalPos", pedestals[0])
}
override fun deserializeNBT(nbt: TagCompound){}
}

View File

@ -26,6 +26,9 @@ class ProcessSupportingItemHolder(private val table: TileEntityBaseTable, pos: B
override val energyPerTick = Units(0)
override val dustPerTick = NO_DUST
val pedestalPos
get() = pedestals[0]
private val pedestalTile
get() = pedestals[0].getTile<TileEntityTablePedestal>(table.wrld)