Inspiring stuff.

This commit is contained in:
DBotThePony 2022-08-29 12:56:16 +07:00
parent e395ffa2b5
commit c3a969a16a
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 39 additions and 4 deletions

View File

@ -23,6 +23,7 @@ import net.minecraftforge.common.util.LazyOptional
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.entity.player.Player
import net.minecraftforge.common.capabilities.Capability
import net.minecraftforge.common.capabilities.ForgeCapabilities
@ -30,11 +31,14 @@ import net.minecraftforge.event.AttachCapabilitiesEvent
import net.minecraftforge.event.entity.living.LivingDeathEvent
import net.minecraftforge.eventbus.api.SubscribeEvent
import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent
import net.minecraftforge.event.entity.player.EntityItemPickupEvent
import net.minecraftforge.event.entity.player.PlayerEvent
import net.minecraftforge.eventbus.api.EventPriority
import org.apache.commons.lang3.mutable.MutableInt
import ru.dbotthepony.mc.otm.*
import ru.dbotthepony.mc.otm.android.AndroidResearch
import ru.dbotthepony.mc.otm.android.AndroidResearchType
import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
import ru.dbotthepony.mc.otm.network.*
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
@ -46,6 +50,8 @@ import kotlin.collections.ArrayDeque
@Suppress("unused")
class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEnergyStorage, INBTSerializable<CompoundTag> {
var exoSuitItems = MatteryContainer(20)
private var shouldSendIteration = false
var iteration = 0
private set
@ -292,6 +298,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
}
}
tag["exo_suit_inventory"] = exoSuitItems.serializeNBT()
return tag
}
@ -360,6 +368,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
}
}
}
exoSuitItems.deserializeNBT(compound["exo_suit_inventory"])
}
fun dropBattery() {
@ -803,6 +813,29 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
val ENERGY_FOR_HUNGER_POINT = ImpreciseFraction(1000)
const val SLEEP_TICKS_LIMIT = 80
/*
private val itemPickupTicks = WeakHashMap<Player, WeakHashMap<ItemEntity, MutableInt>>()
@SubscribeEvent(priority = EventPriority.LOW)
fun onPickupEvent(event: EntityItemPickupEvent) {
if (event.item.owner != null && event.item.owner != event.entity.uuid && event.item.age < 200 || event.item.item.isEmpty) {
return
}
val it = event.entity.matteryPlayer ?: return
val ticks = itemPickupTicks.computeIfAbsent(event.entity) { WeakHashMap() }.computeIfAbsent(event.item) { MutableInt() }
ticks.increment()
if (ticks.value < 10) {
return
}
val leftover = it.exoSuitItems.addItem(event.item.item, false)
event.item.item.count = leftover.count
}
*/
}
}

View File

@ -329,9 +329,10 @@ open class MatteryContainer(val watcher: Runnable, private val size: Int) : Cont
}
}
@JvmOverloads
fun Container.addItem(stack: ItemStack, range: IntRange, simulate: Boolean = false): ItemStack {
check(this !is MatteryContainer) { "call MatteryContainer#addItem instead" }
if (this is MatteryContainer) {
return this.addItem(stack, range, simulate)
}
if (range.last >= containerSize || range.first < 0)
throw IllegalArgumentException("Invalid range: $range")

View File

@ -20,6 +20,7 @@ import net.minecraftforge.common.capabilities.Capability
import net.minecraftforge.event.ForgeEventFactory
import net.minecraftforge.eventbus.api.SubscribeEvent
import net.minecraftforge.event.entity.player.EntityItemPickupEvent
import net.minecraftforge.eventbus.api.EventPriority
import ru.dbotthepony.mc.otm.TextComponent
import ru.dbotthepony.mc.otm.capability.drive.DrivePool
import ru.dbotthepony.mc.otm.container.ItemFilter
@ -101,9 +102,9 @@ class PortableCondensationDriveItem(capacity: Int) :
const val MAX_FILTERS = 4 * 3
const val FILTER_PATH = "filter"
@SubscribeEvent
@SubscribeEvent(priority = EventPriority.LOWEST)
fun onPickupEvent(event: EntityItemPickupEvent) {
if (event.item.owner != null && event.item.owner != event.entity.uuid && event.item.age < 200) {
if (event.item.owner != null && event.item.owner != event.entity.uuid && event.item.age < 200 || event.item.item.isEmpty) {
return
}