mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-10 07:48:29 -04:00
optimize entity attribute calculation
Armor stands (living entities) need that to weather it is possible to target them. Reduces memory usage (enum map, only on demand, skip empty map).
This commit is contained in:
parent
9555ff19ea
commit
c2b7890b2f
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2024 Moritz Zwerger
|
* Copyright (C) 2020-2025 Moritz Zwerger
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
@ -48,7 +48,7 @@ class ArmorStand(session: PlaySession, entityType: EntityType, data: EntityData,
|
|||||||
return flags.isBitMask(bitMask)
|
return flags.isBitMask(bitMask)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val canRaycast: Boolean get() = super.canRaycast && !isMarker
|
override val canRaycast: Boolean get() = !isMarker && super.canRaycast
|
||||||
override val hitboxColor: RGBColor? get() = if (isMarker) null else super.hitboxColor
|
override val hitboxColor: RGBColor? get() = if (isMarker) null else super.hitboxColor
|
||||||
override var defaultAABB: AABB = AABB.EMPTY
|
override var defaultAABB: AABB = AABB.EMPTY
|
||||||
override var dimensions: Vec2 = DIMENSIONS
|
override var dimensions: Vec2 = DIMENSIONS
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
* Copyright (C) 2020-2025 Moritz Zwerger
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
@ -64,9 +64,9 @@ class EntityAttributes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
operator fun get(type: AttributeType, fallback: Double = this.fallback[type] ?: type.fallback): Double {
|
operator fun get(type: AttributeType, fallback: Double = this.fallback[type] ?: type.fallback): Double {
|
||||||
val attributes = this.attributes[type]
|
val attributes = this.attributes[type] ?: return fallback
|
||||||
val base = attributes?.base ?: fallback
|
val modifiers = attributes.process()
|
||||||
val modifiers = process(attributes)
|
val base = attributes.base
|
||||||
|
|
||||||
var added = base
|
var added = base
|
||||||
for (modifier in modifiers[AttributeOperations.ADD] ?: emptySet()) {
|
for (modifier in modifiers[AttributeOperations.ADD] ?: emptySet()) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
* Copyright (C) 2020-2025 Moritz Zwerger
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.data.registries.effects.attributes.container
|
package de.bixilon.minosoft.data.registries.effects.attributes.container
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.registries.effects.attributes.AttributeOperations
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class AttributeContainer(
|
class AttributeContainer(
|
||||||
@ -42,6 +43,19 @@ class AttributeContainer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun process(): Map<AttributeOperations, Set<AttributeModifier>> {
|
||||||
|
// ToDo: Deduplicate uuids?
|
||||||
|
if (modifier.isEmpty()) return emptyMap()
|
||||||
|
val result: MutableMap<AttributeOperations, MutableSet<AttributeModifier>> = EnumMap(AttributeOperations::class.java)
|
||||||
|
|
||||||
|
for (modifier in this) {
|
||||||
|
result.getOrPut(modifier.operation) { mutableSetOf() } += modifier
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
operator fun contains(uuid: UUID) = uuid in modifier
|
operator fun contains(uuid: UUID) = uuid in modifier
|
||||||
|
|
||||||
override fun iterator(): Iterator<AttributeModifier> {
|
override fun iterator(): Iterator<AttributeModifier> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user