Painter Recipes updates
This commit is contained in:
parent
6d21760621
commit
b26f109f56
@ -1,6 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.recipe
|
package ru.dbotthepony.mc.otm.recipe
|
||||||
|
|
||||||
import com.mojang.serialization.Codec
|
import com.mojang.serialization.Codec
|
||||||
|
import com.mojang.serialization.MapCodec
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap
|
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntMap
|
import it.unimi.dsi.fastutil.objects.Object2IntMap
|
||||||
@ -31,7 +32,7 @@ import java.util.function.Predicate
|
|||||||
|
|
||||||
abstract class AbstractPainterRecipe(
|
abstract class AbstractPainterRecipe(
|
||||||
dyes: Map<out DyeColor?, Int>
|
dyes: Map<out DyeColor?, Int>
|
||||||
) : Recipe<Container> {
|
) : IMatteryRecipe<Container> {
|
||||||
val dyes: Object2IntMap<DyeColor?> = Object2IntMaps.unmodifiable(Object2IntArrayMap(dyes))
|
val dyes: Object2IntMap<DyeColor?> = Object2IntMaps.unmodifiable(Object2IntArrayMap(dyes))
|
||||||
|
|
||||||
override fun getToastSymbol(): ItemStack = ItemStack(MItems.PAINTER)
|
override fun getToastSymbol(): ItemStack = ItemStack(MItems.PAINTER)
|
||||||
@ -85,6 +86,17 @@ abstract class AbstractPainterRecipe(
|
|||||||
return refName
|
return refName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val wrapperCodec: Codec<DyeColorWrapper> = StringRepresentable.fromEnum(DyeColorWrapper::values)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
protected val dyesFieldCodec: MapCodec<Map<DyeColor?, Int>> = PredicatedCodecList<Map<DyeColorWrapper, Int>>(
|
||||||
|
wrapperCodec.xmap({ mapOf(it to 1) }, { it.keys.first() }) to Predicate { it.keys.size == 1 && it.values.first() == 1 },
|
||||||
|
Codec.list(wrapperCodec).xmap({ it.associateWith { 1 } }, { ArrayList(it.keys) }) to Predicate { it.values.all { it == 1 } },
|
||||||
|
Codec.unboundedMap(wrapperCodec, Codec.INT.minRange(1)) to Predicate { true }
|
||||||
|
).fieldOf("dyes").xmap({ it.mapKeys { it.key.key } }, { it.mapKeys { k -> DyeColorWrapper.entries.first { k.key == it.key } } })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PainterRecipe(
|
class PainterRecipe(
|
||||||
@ -142,22 +154,16 @@ class PainterRecipe(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getOutput(container: Container): ItemStack {
|
override fun getOutput(container: Container): ItemStack {
|
||||||
return this.output
|
return output.copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val wrapperCodec = StringRepresentable.fromEnum(DyeColorWrapper::values)
|
|
||||||
|
|
||||||
val SERIALIZER = Codec2RecipeSerializer<PainterRecipe> { context ->
|
val SERIALIZER = Codec2RecipeSerializer<PainterRecipe> { context ->
|
||||||
RecordCodecBuilder.create {
|
RecordCodecBuilder.create {
|
||||||
it.group(
|
it.group(
|
||||||
context.ingredients.fieldOf("input").forGetter(PainterRecipe::input),
|
context.ingredients.fieldOf("input").forGetter(PainterRecipe::input),
|
||||||
ItemStack.CODEC.fieldOf("output").forGetter(PainterRecipe::output),
|
ItemStack.CODEC.fieldOf("output").forGetter(PainterRecipe::output),
|
||||||
PredicatedCodecList<Map<DyeColorWrapper, Int>>(
|
dyesFieldCodec.forGetter(AbstractPainterRecipe::dyes),
|
||||||
wrapperCodec.xmap({ mapOf(it to 1) }, { it.keys.first() }) to Predicate { it.keys.size == 1 && it.values.first() == 1 },
|
|
||||||
Codec.list(wrapperCodec).xmap({ it.associateWith { 1 } }, { ArrayList(it.keys) }) to Predicate { it.values.all { it == 1 } },
|
|
||||||
Codec.unboundedMap(wrapperCodec, Codec.INT.minRange(1)) to Predicate { true }
|
|
||||||
).fieldOf("dyes").xmap({ it.mapKeys { it.key.key } }, { it.mapKeys { k -> DyeColorWrapper.entries.first { k.key == it.key } } }).forGetter(PainterRecipe::dyes),
|
|
||||||
).apply(it, ::PainterRecipe)
|
).apply(it, ::PainterRecipe)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +218,7 @@ class PainterArmorDyeRecipe(
|
|||||||
if (entry.key == null) {
|
if (entry.key == null) {
|
||||||
(output.item as DyeableLeatherItem).clearColor(output)
|
(output.item as DyeableLeatherItem).clearColor(output)
|
||||||
} else {
|
} else {
|
||||||
output = DyeableLeatherItem.dyeArmor(output.copy(), listOf(DyeItem.byColor(entry.key!!)))
|
output = DyeableLeatherItem.dyeArmor(output, listOf(DyeItem.byColor(entry.key!!)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,16 +226,10 @@ class PainterArmorDyeRecipe(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val wrapperCodec = StringRepresentable.fromEnum(DyeColorWrapper::values)
|
|
||||||
|
|
||||||
val SERIALIZER = Codec2RecipeSerializer<PainterArmorDyeRecipe> { _ ->
|
val SERIALIZER = Codec2RecipeSerializer<PainterArmorDyeRecipe> { _ ->
|
||||||
RecordCodecBuilder.create {
|
RecordCodecBuilder.create {
|
||||||
it.group(
|
it.group(
|
||||||
PredicatedCodecList<Map<DyeColorWrapper, Int>>(
|
dyesFieldCodec.forGetter(AbstractPainterRecipe::dyes),
|
||||||
wrapperCodec.xmap({ mapOf(it to 1) }, { it.keys.first() }) to Predicate { it.keys.size == 1 && it.values.first() == 1 },
|
|
||||||
Codec.list(wrapperCodec).xmap({ it.associateWith { 1 } }, { ArrayList(it.keys) }) to Predicate { it.values.all { it == 1 } },
|
|
||||||
Codec.unboundedMap(wrapperCodec, Codec.INT.minRange(1)) to Predicate { true }
|
|
||||||
).fieldOf("dyes").xmap({ it.mapKeys { it.key.key } }, { it.mapKeys { k -> DyeColorWrapper.entries.first { k.key == it.key } } }).forGetter(PainterArmorDyeRecipe::dyes),
|
|
||||||
).apply(it, ::PainterArmorDyeRecipe)
|
).apply(it, ::PainterArmorDyeRecipe)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user