More backporting

This commit is contained in:
DBotThePony 2023-12-31 21:14:32 +07:00
parent 422ae92303
commit 98fcacc9a8
Signed by: DBot
GPG Key ID: DCC23B5715498507
7 changed files with 53 additions and 24 deletions

View File

@ -25,6 +25,7 @@ import ru.dbotthepony.mc.otm.core.collect.filterIsInstance
import ru.dbotthepony.mc.otm.core.collect.filterNotNull
import ru.dbotthepony.mc.otm.core.collect.map
import ru.dbotthepony.mc.otm.core.collect.toList
import ru.dbotthepony.mc.otm.core.value
import ru.dbotthepony.mc.otm.menu.decorative.PainterMenu
import ru.dbotthepony.mc.otm.menu.matter.MatterEntanglerMenu
import ru.dbotthepony.mc.otm.menu.tech.PlatePressMenu

View File

@ -30,10 +30,8 @@ import ru.dbotthepony.mc.otm.capability.energy.getBarColor
import ru.dbotthepony.mc.otm.capability.energy.getBarWidth
import ru.dbotthepony.mc.otm.capability.matteryEnergy
import ru.dbotthepony.mc.otm.config.EnergyBalanceValues
import ru.dbotthepony.mc.otm.core.Factory
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.collect.filter
import ru.dbotthepony.mc.otm.core.computeIfAbsent
import ru.dbotthepony.mc.otm.core.getID
import ru.dbotthepony.mc.otm.core.getValue
import ru.dbotthepony.mc.otm.core.isNotEmpty

View File

@ -297,9 +297,10 @@ abstract class MatteryMenu(
open inner class EquipmentSlot(container: Container, index: Int, val type: net.minecraft.world.entity.EquipmentSlot) : InventorySlot(container, index) {
constructor(type: net.minecraft.world.entity.EquipmentSlot) : this(inventory, 34 + type.ordinal, type)
override fun setByPlayer(newItem: ItemStack, oldItem: ItemStack) {
override fun setByPlayer(newItem: ItemStack) {
val oldItem = item
inventory.player.onEquipItem(type, oldItem, newItem)
super.setByPlayer(newItem, oldItem)
super.setByPlayer(newItem)
}
override fun mayPlace(itemStack: ItemStack): Boolean {
@ -326,9 +327,10 @@ abstract class MatteryMenu(
autoCreateInventoryFrame = autoFrame
offhandSlot = object : InventorySlot(inventory, 40) {
override fun setByPlayer(newItem: ItemStack, oldItem: ItemStack) {
override fun setByPlayer(newItem: ItemStack) {
val oldItem = this.item
inventory.player.onEquipItem(net.minecraft.world.entity.EquipmentSlot.OFFHAND, oldItem, newItem)
super.setByPlayer(newItem, oldItem)
super.setByPlayer(newItem)
}
override fun getNoItemIcon(): Pair<ResourceLocation, ResourceLocation> {

View File

@ -31,8 +31,13 @@ import ru.dbotthepony.mc.otm.registry.MRecipes
import java.util.function.Predicate
abstract class AbstractPainterRecipe(
val id: ResourceLocation,
dyes: Map<out DyeColor?, Int>
) : IMatteryRecipe<Container> {
override fun getId(): ResourceLocation {
return id
}
val dyes: Object2IntMap<DyeColor?> = Object2IntMaps.unmodifiable(Object2IntArrayMap(dyes))
abstract fun matches(value: ItemStack): Boolean
@ -106,15 +111,17 @@ abstract class AbstractPainterRecipe(
}
class PainterRecipe(
id: ResourceLocation,
val input: Ingredient,
val output: ItemStack,
dyes: Map<out DyeColor?, Int>
) : AbstractPainterRecipe(dyes) {
) : AbstractPainterRecipe(id, dyes) {
constructor(
id: ResourceLocation,
input: Ingredient,
output: ItemStack,
dyes: Set<DyeColor?>
) : this(input, output, Object2IntArrayMap<DyeColor?>().also { map -> dyes.forEach { map[it] = 1 } })
) : this(id, input, output, Object2IntArrayMap<DyeColor?>().also { map -> dyes.forEach { map[it] = 1 } })
override fun matches(value: ItemStack): Boolean {
return !isIncomplete && input.test(value)
@ -154,8 +161,8 @@ class PainterRecipe(
return MRecipes.PAINTER
}
fun toFinished(id: ResourceLocation): FinishedRecipe {
return SERIALIZER.toFinished(this, id)
fun toFinished(): FinishedRecipe {
return SERIALIZER.toFinished(this)
}
override fun getOutput(container: Container): ItemStack {
@ -169,17 +176,19 @@ class PainterRecipe(
context.ingredients.fieldOf("input").forGetter(PainterRecipe::input),
ItemStack.CODEC.fieldOf("output").forGetter(PainterRecipe::output),
dyesFieldCodec.forGetter(AbstractPainterRecipe::dyes),
).apply(it, ::PainterRecipe)
).apply(it) { a, b, c -> PainterRecipe(context.id, a, b, c) }
}
}
}
}
class PainterArmorDyeRecipe(
id: ResourceLocation,
dyes: Map<out DyeColor?, Int>
) : AbstractPainterRecipe(dyes) {
) : AbstractPainterRecipe(id, dyes) {
constructor(
id: ResourceLocation,
dyes: Set<DyeColor?>
) : this(Object2IntArrayMap<DyeColor?>().also { map -> dyes.forEach { map[it] = 1 } })
) : this(id, Object2IntArrayMap<DyeColor?>().also { map -> dyes.forEach { map[it] = 1 } })
override fun matches(value: ItemStack): Boolean {
return !isIncomplete && value.item is DyeableArmorItem
@ -207,8 +216,8 @@ class PainterArmorDyeRecipe(
override fun isIncomplete(): Boolean = dyes.isEmpty()
fun toFinished(id: ResourceLocation): FinishedRecipe {
return SERIALIZER.toFinished(this, id)
fun toFinished(): FinishedRecipe {
return SERIALIZER.toFinished(this)
}
override fun getOutput(container: Container): ItemStack {
@ -228,11 +237,11 @@ class PainterArmorDyeRecipe(
}
companion object {
val SERIALIZER = Codec2RecipeSerializer<PainterArmorDyeRecipe> { _ ->
val SERIALIZER = Codec2RecipeSerializer<PainterArmorDyeRecipe> { context ->
RecordCodecBuilder.create {
it.group(
dyesFieldCodec.forGetter(AbstractPainterRecipe::dyes),
).apply(it, ::PainterArmorDyeRecipe)
).apply(it) { a -> PainterArmorDyeRecipe(context.id, a) }
}
}
}

View File

@ -24,12 +24,17 @@ import ru.dbotthepony.mc.otm.data.minRange
import ru.dbotthepony.mc.otm.registry.MItems
class PlatePressRecipe(
val id: ResourceLocation,
val input: Ingredient,
val output: Ingredient,
val count: Int = 1,
val workTime: Int = 200,
val experience: FloatProvider = ConstantFloat.ZERO
) : Recipe<Container> {
override fun getId(): ResourceLocation {
return id
}
override fun matches(container: Container, p_44003_: Level): Boolean {
if (isIncomplete)
return false
@ -79,7 +84,7 @@ class PlatePressRecipe(
return ItemStack(MItems.PLATE_PRESS)
}
fun toFinished(id: ResourceLocation) = SERIALIZER.toFinished(this, id)
fun toFinished() = SERIALIZER.toFinished(this)
companion object {
val SERIALIZER = Codec2RecipeSerializer<PlatePressRecipe> { context ->
@ -90,7 +95,7 @@ class PlatePressRecipe(
Codec.INT.minRange(1).optionalFieldOf("count", 1).forGetter(PlatePressRecipe::count),
Codec.INT.minRange(0).optionalFieldOf("workTime", 200).forGetter(PlatePressRecipe::workTime),
FloatProvider.CODEC.optionalFieldOf("experience", ConstantFloat.ZERO).forGetter(PlatePressRecipe::experience)
).apply(it, ::PlatePressRecipe)
).apply(it) { a, b, c, d, e -> PlatePressRecipe(context.id, a, b, c, d, e) }
}
}
}

View File

@ -14,6 +14,7 @@ import net.minecraft.advancements.CriterionTrigger
import net.minecraft.advancements.critereon.DeserializationContext
import net.minecraft.advancements.critereon.InventoryChangeTrigger
import net.minecraft.advancements.critereon.MinMaxBounds
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.PlayerAdvancements
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.Container
@ -83,13 +84,13 @@ object MatteryInventoryChangeTrigger : CriterionTrigger<InventoryChangeTrigger.T
nodes.add(Node(
DefaultStrategy,
{ predicates.iterator().flatMap { (it.items.map { it.map { it.value() } }.orElse(listOf(null))).iterator() }.toList() },
{ predicates.iterator().flatMap { (it.items ?: listOf(null)).iterator() }.toList() },
{ v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v == null || item.item == v },
{ inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> mutableListOf(item.item) }))
nodes.add(Node(
DefaultStrategy,
{ predicates.map { it.tag.orElse(null) } },
{ predicates.map { it.tag } },
{ v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v == null || item.`is`(v) },
{ inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> item.tags.collect(Collectors.toCollection(::ArrayList)) }))
@ -133,13 +134,13 @@ object MatteryInventoryChangeTrigger : CriterionTrigger<InventoryChangeTrigger.T
fun add(listener: CriterionTrigger.Listener<InventoryChangeTrigger.TriggerInstance>) {
if (set.add(listener)) {
search(listener.trigger, tree, 0).forEach { it.add(listener) }
search(listener.triggerInstance, tree, 0).forEach { it.add(listener) }
}
}
fun remove(listener: CriterionTrigger.Listener<InventoryChangeTrigger.TriggerInstance>) {
if (set.remove(listener)) {
search(listener.trigger, tree, 0).forEach { it.remove(listener) }
search(listener.triggerInstance, tree, 0).forEach { it.remove(listener) }
}
}
@ -165,7 +166,7 @@ object MatteryInventoryChangeTrigger : CriterionTrigger<InventoryChangeTrigger.T
if (nodeId + 1 == nodes.size) {
for (l in v as Set<CriterionTrigger.Listener<InventoryChangeTrigger.TriggerInstance>>) {
// переделываем matches у InventoryTriggerInstance
with (l.trigger) {
with (l.triggerInstance) {
if (
this.slotsFull.matches(slotsFull) &&
this.slotsEmpty.matches(slotsEmpty) &&
@ -217,6 +218,10 @@ object MatteryInventoryChangeTrigger : CriterionTrigger<InventoryChangeTrigger.T
listeners[advancements]?.remove(instance)
}
override fun getId(): ResourceLocation {
return CriteriaTriggers.INVENTORY_CHANGED.id
}
override fun removePlayerListeners(advancements: PlayerAdvancements) {
listeners.remove(advancements)
}

View File

@ -170,3 +170,12 @@ public net.minecraft.advancements.critereon.InventoryChangeTrigger$TriggerInstan
#public-f net.minecraft.advancements.critereon.SimpleCriterionTrigger m_6467_(Lnet/minecraft/server/PlayerAdvancements;Lnet/minecraft/advancements/CriterionTrigger$Listener;)V # addPlayerListener
#public-f net.minecraft.advancements.critereon.SimpleCriterionTrigger m_6468_(Lnet/minecraft/server/PlayerAdvancements;Lnet/minecraft/advancements/CriterionTrigger$Listener;)V # removePlayerListener
#public-f net.minecraft.advancements.critereon.SimpleCriterionTrigger m_5656_(Lnet/minecraft/server/PlayerAdvancements;)V # removePlayerListeners
public net.minecraft.advancements.critereon.ItemPredicate f_45031_
public net.minecraft.advancements.critereon.ItemPredicate f_45032_
public net.minecraft.advancements.critereon.ItemPredicate f_45033_
public net.minecraft.advancements.critereon.ItemPredicate f_151427_
public net.minecraft.advancements.critereon.ItemPredicate f_45036_
public net.minecraft.advancements.critereon.ItemPredicate f_45035_
public net.minecraft.advancements.critereon.ItemPredicate f_45034_
public net.minecraft.advancements.critereon.ItemPredicate f_45029_