Make exosuit inventory contents appear in LivingDropsEvent when possible
This commit is contained in:
parent
705eaaf993
commit
2e7e676739
@ -107,6 +107,7 @@ public final class OverdriveThatMatters {
|
|||||||
EVENT_BUS.addListener(EventPriority.LOWEST, MatteryPlayerCapability.Companion::onPlayerDeath);
|
EVENT_BUS.addListener(EventPriority.LOWEST, MatteryPlayerCapability.Companion::onPlayerDeath);
|
||||||
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onPlayerCloneEvent);
|
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onPlayerCloneEvent);
|
||||||
EVENT_BUS.addListener(EventPriority.LOW, MatteryPlayerCapability.Companion::onPickupEvent);
|
EVENT_BUS.addListener(EventPriority.LOW, MatteryPlayerCapability.Companion::onPickupEvent);
|
||||||
|
EVENT_BUS.addListener(EventPriority.HIGHEST, MatteryPlayerCapability.Companion::onLivingDrops);
|
||||||
|
|
||||||
EVENT_BUS.addListener(EventPriority.LOW, MatterDataKt::serverStartData);
|
EVENT_BUS.addListener(EventPriority.LOW, MatterDataKt::serverStartData);
|
||||||
EVENT_BUS.addListener(EventPriority.NORMAL, MatterRegistryKt::onPlayerJoin);
|
EVENT_BUS.addListener(EventPriority.NORMAL, MatterRegistryKt::onPlayerJoin);
|
||||||
|
@ -13,6 +13,7 @@ import net.minecraft.server.level.ServerPlayer
|
|||||||
import net.minecraft.world.effect.MobEffect
|
import net.minecraft.world.effect.MobEffect
|
||||||
import net.minecraft.world.effect.MobEffects
|
import net.minecraft.world.effect.MobEffects
|
||||||
import net.minecraft.world.entity.Entity
|
import net.minecraft.world.entity.Entity
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
import net.minecraft.world.entity.item.ItemEntity
|
import net.minecraft.world.entity.item.ItemEntity
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
@ -25,6 +26,7 @@ import net.minecraftforge.common.util.INBTSerializable
|
|||||||
import net.minecraftforge.common.util.LazyOptional
|
import net.minecraftforge.common.util.LazyOptional
|
||||||
import net.minecraftforge.event.AttachCapabilitiesEvent
|
import net.minecraftforge.event.AttachCapabilitiesEvent
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent
|
import net.minecraftforge.event.entity.living.LivingDeathEvent
|
||||||
|
import net.minecraftforge.event.entity.living.LivingDropsEvent
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent
|
||||||
import net.minecraftforge.event.entity.living.LivingHurtEvent
|
import net.minecraftforge.event.entity.living.LivingHurtEvent
|
||||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent
|
import net.minecraftforge.event.entity.player.EntityItemPickupEvent
|
||||||
@ -33,6 +35,7 @@ import net.minecraftforge.eventbus.api.EventPriority
|
|||||||
import net.minecraftforge.eventbus.api.SubscribeEvent
|
import net.minecraftforge.eventbus.api.SubscribeEvent
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
|
||||||
import org.apache.commons.lang3.mutable.MutableInt
|
import org.apache.commons.lang3.mutable.MutableInt
|
||||||
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.mc.otm.*
|
import ru.dbotthepony.mc.otm.*
|
||||||
import ru.dbotthepony.mc.otm.android.AndroidFeature
|
import ru.dbotthepony.mc.otm.android.AndroidFeature
|
||||||
import ru.dbotthepony.mc.otm.android.AndroidFeatureType
|
import ru.dbotthepony.mc.otm.android.AndroidFeatureType
|
||||||
@ -47,6 +50,7 @@ import ru.dbotthepony.mc.otm.registry.MRegistry
|
|||||||
import ru.dbotthepony.mc.otm.registry.StatNames
|
import ru.dbotthepony.mc.otm.registry.StatNames
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayDeque
|
import kotlin.collections.ArrayDeque
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEnergyStorage, INBTSerializable<CompoundTag> {
|
class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEnergyStorage, INBTSerializable<CompoundTag> {
|
||||||
@ -96,18 +100,24 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dropExoSuitInventory() {
|
fun dropExoSuitInventory(): List<ItemEntity> {
|
||||||
val iterator = exoSuitContainer.iterator()
|
val result = ArrayList<ItemEntity>()
|
||||||
|
val oldCaptureDrops = ply.captureDrops(result) as MutableCollection<ItemEntity>?
|
||||||
|
|
||||||
|
val iterator = exoSuitContainer.iterator().nonEmpty()
|
||||||
|
|
||||||
for (item in iterator) {
|
for (item in iterator) {
|
||||||
if (!item.isEmpty) {
|
|
||||||
if (!hasVanishingCurse(item)) {
|
if (!hasVanishingCurse(item)) {
|
||||||
ply.drop(item, true, false)
|
ply.drop(item, true, false)?.also(result::add)
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator.remove()
|
iterator.remove()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
ply.captureDrops(oldCaptureDrops)
|
||||||
|
oldCaptureDrops?.addAll(result)
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
var isExoSuitCraftingUpgraded by synchronizer.bool(setter = setter@{ value, access, _ ->
|
var isExoSuitCraftingUpgraded by synchronizer.bool(setter = setter@{ value, access, _ ->
|
||||||
@ -822,6 +832,23 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
.ifPresentK { it.invalidateNetworkState() }
|
.ifPresentK { it.invalidateNetworkState() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val waitingToDie = ArrayList<Pair<LivingEntity, MatteryPlayerCapability>>()
|
||||||
|
|
||||||
|
fun onLivingDrops(event: LivingDropsEvent) {
|
||||||
|
val indexOf = waitingToDie.indexOfFirst { event.entity == it.first }
|
||||||
|
|
||||||
|
if (indexOf == -1)
|
||||||
|
return
|
||||||
|
|
||||||
|
val drops = waitingToDie[indexOf].second.dropExoSuitInventory()
|
||||||
|
|
||||||
|
if (event.entity.captureDrops() == null) {
|
||||||
|
event.drops.addAll(drops)
|
||||||
|
}
|
||||||
|
|
||||||
|
waitingToDie.removeAt(indexOf)
|
||||||
|
}
|
||||||
|
|
||||||
fun onPlayerDeath(event: LivingDeathEvent) {
|
fun onPlayerDeath(event: LivingDeathEvent) {
|
||||||
val ply = event.entity as? Player ?: return
|
val ply = event.entity as? Player ?: return
|
||||||
val mattery = ply.matteryPlayer ?: return
|
val mattery = ply.matteryPlayer ?: return
|
||||||
@ -833,7 +860,18 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mattery.hasExoSuit && !ply.level.gameRules.getBoolean(GameRules.RULE_KEEPINVENTORY)) {
|
if (mattery.hasExoSuit && !ply.level.gameRules.getBoolean(GameRules.RULE_KEEPINVENTORY)) {
|
||||||
mattery.dropExoSuitInventory()
|
waitingToDie.add(ply to mattery)
|
||||||
|
|
||||||
|
addPostServerTickerOnce {
|
||||||
|
val index = waitingToDie.indexOfFirst { it.first == ply }
|
||||||
|
|
||||||
|
if (index != -1) {
|
||||||
|
waitingToDie.removeAt(index)
|
||||||
|
mattery.dropExoSuitInventory().forEach { ply.level.addFreshEntity(it) }
|
||||||
|
LOGGER.warn("Unable to 'properly' drop $ply's ExoSuit inventory contents")
|
||||||
|
LOGGER.warn("I blame Forge.")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mattery.isAndroid) {
|
if (!mattery.isAndroid) {
|
||||||
@ -881,6 +919,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
|
|
||||||
private val itemPickupTicks = WeakHashMap<Player, WeakHashMap<ItemEntity, MutableInt>>()
|
private val itemPickupTicks = WeakHashMap<Player, WeakHashMap<ItemEntity, MutableInt>>()
|
||||||
|
|
||||||
|
private val LOGGER = LogManager.getLogger()
|
||||||
|
|
||||||
fun onPickupEvent(event: EntityItemPickupEvent) {
|
fun onPickupEvent(event: EntityItemPickupEvent) {
|
||||||
if (event.item.owner != null && event.item.owner != event.entity.uuid && event.item.age < 200 || event.item.item.isEmpty) {
|
if (event.item.owner != null && event.item.owner != event.entity.uuid && event.item.age < 200 || event.item.item.isEmpty) {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user