Update plate press recipe
This commit is contained in:
parent
adc2ce0017
commit
7f927d5f05
@ -1,11 +1,13 @@
|
|||||||
package ru.dbotthepony.mc.otm.network
|
package ru.dbotthepony.mc.otm.network
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
import io.netty.buffer.ByteBufAllocator
|
import io.netty.buffer.ByteBufAllocator
|
||||||
import it.unimi.dsi.fastutil.bytes.ByteArrayList
|
import it.unimi.dsi.fastutil.bytes.ByteArrayList
|
||||||
import net.minecraft.core.RegistryAccess
|
import net.minecraft.core.RegistryAccess
|
||||||
import net.minecraft.network.FriendlyByteBuf
|
import net.minecraft.network.FriendlyByteBuf
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs
|
||||||
import net.minecraft.network.codec.StreamCodec
|
import net.minecraft.network.codec.StreamCodec
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload
|
||||||
import net.neoforged.neoforge.network.connection.ConnectionType
|
import net.neoforged.neoforge.network.connection.ConnectionType
|
||||||
@ -84,3 +86,7 @@ fun <V> StreamCodec<in RegistryFriendlyByteBuf, V>.decode(registry: RegistryAcce
|
|||||||
decode(it)
|
decode(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> Codec<T>.streamCodec(): MatteryStreamCodec<RegistryFriendlyByteBuf, T> {
|
||||||
|
return ByteBufCodecs.fromCodecWithRegistries(this).wrap()
|
||||||
|
}
|
||||||
|
@ -4,27 +4,29 @@ import io.netty.buffer.ByteBuf
|
|||||||
import net.minecraft.core.UUIDUtil
|
import net.minecraft.core.UUIDUtil
|
||||||
import net.minecraft.network.FriendlyByteBuf
|
import net.minecraft.network.FriendlyByteBuf
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs
|
||||||
import net.minecraft.network.codec.StreamCodec
|
import net.minecraft.network.codec.StreamCodec
|
||||||
|
import net.minecraft.util.valueproviders.FloatProvider
|
||||||
import ru.dbotthepony.kommons.math.RGBAColor
|
import ru.dbotthepony.kommons.math.RGBAColor
|
||||||
import ru.dbotthepony.mc.otm.core.math.readDecimal
|
import ru.dbotthepony.mc.otm.core.math.readDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.writeDecimal
|
import ru.dbotthepony.mc.otm.core.math.writeDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.readItemType
|
import ru.dbotthepony.mc.otm.core.readItemType
|
||||||
import ru.dbotthepony.mc.otm.core.writeItemType
|
import ru.dbotthepony.mc.otm.core.writeItemType
|
||||||
|
import kotlin.reflect.KMutableProperty1
|
||||||
|
|
||||||
// because mojang didn't bother
|
|
||||||
object StreamCodecs {
|
object StreamCodecs {
|
||||||
val NOTHING: MatteryStreamCodec<ByteBuf, Nothing?> = StreamCodec.of<ByteBuf, Nothing?>({ _, _ -> }, { null }).wrap()
|
val NOTHING: MatteryStreamCodec<ByteBuf, Nothing?> = StreamCodec.of<ByteBuf, Nothing?>({ _, _ -> }, { null }).wrap()
|
||||||
|
|
||||||
val BYTE: MatteryStreamCodec<ByteBuf, Byte> = StreamCodec.of({ s, v -> s.writeByte(v.toInt()) }, ByteBuf::readByte).wrap()
|
val BYTE: MatteryStreamCodec<ByteBuf, Byte> = StreamCodec.of({ s, v -> s.writeByte(v.toInt()) }, ByteBuf::readByte).wrap()
|
||||||
val SHORT = StreamCodec.of({ s, v -> s.writeShort(v.toInt()) }, ByteBuf::readShort).wrap()
|
val SHORT = ByteBufCodecs.SHORT.wrap()
|
||||||
val INT = StreamCodec.of(ByteBuf::writeInt, ByteBuf::readInt).wrap()
|
val INT = ByteBufCodecs.INT.wrap()
|
||||||
val VAR_INT = StreamCodec.of(FriendlyByteBuf::writeVarInt, FriendlyByteBuf::readVarInt).wrap()
|
val VAR_INT = ByteBufCodecs.VAR_INT.wrap()
|
||||||
val LONG = StreamCodec.of(ByteBuf::writeLong, ByteBuf::readLong).wrap()
|
val LONG = StreamCodec.of(ByteBuf::writeLong, ByteBuf::readLong).wrap()
|
||||||
val VAR_LONG = StreamCodec.of(FriendlyByteBuf::writeVarLong, FriendlyByteBuf::readVarLong).wrap()
|
val VAR_LONG = ByteBufCodecs.VAR_LONG.wrap()
|
||||||
val DOUBLE = StreamCodec.of(ByteBuf::writeDouble, ByteBuf::readDouble).wrap()
|
val DOUBLE = ByteBufCodecs.DOUBLE.wrap()
|
||||||
val FLOAT = StreamCodec.of(ByteBuf::writeFloat, ByteBuf::readFloat).wrap()
|
val FLOAT = ByteBufCodecs.FLOAT.wrap()
|
||||||
val BOOLEAN = StreamCodec.of(ByteBuf::writeBoolean, ByteBuf::readBoolean).wrap()
|
val BOOLEAN = ByteBufCodecs.BOOL.wrap()
|
||||||
val STRING = StreamCodec.of(FriendlyByteBuf::writeUtf, FriendlyByteBuf::readUtf).wrap()
|
val STRING = ByteBufCodecs.STRING_UTF8.wrap()
|
||||||
val UUID = UUIDUtil.STREAM_CODEC.wrap()
|
val UUID = UUIDUtil.STREAM_CODEC.wrap()
|
||||||
|
|
||||||
val RGBA: MatteryStreamCodec<ByteBuf, RGBAColor> = StreamCodec.of<ByteBuf, RGBAColor>(
|
val RGBA: MatteryStreamCodec<ByteBuf, RGBAColor> = StreamCodec.of<ByteBuf, RGBAColor>(
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
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 net.minecraft.core.HolderLookup
|
import net.minecraft.core.HolderLookup
|
||||||
import net.minecraft.core.NonNullList
|
import net.minecraft.core.NonNullList
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs
|
||||||
|
import net.minecraft.network.codec.StreamCodec
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
import net.minecraft.util.valueproviders.ConstantFloat
|
import net.minecraft.util.valueproviders.ConstantFloat
|
||||||
import net.minecraft.util.valueproviders.FloatProvider
|
import net.minecraft.util.valueproviders.FloatProvider
|
||||||
@ -21,6 +25,8 @@ import ru.dbotthepony.mc.otm.core.get
|
|||||||
import ru.dbotthepony.mc.otm.registry.MRecipes
|
import ru.dbotthepony.mc.otm.registry.MRecipes
|
||||||
import ru.dbotthepony.mc.otm.core.registryName
|
import ru.dbotthepony.mc.otm.core.registryName
|
||||||
import ru.dbotthepony.mc.otm.data.minRange
|
import ru.dbotthepony.mc.otm.data.minRange
|
||||||
|
import ru.dbotthepony.mc.otm.network.StreamCodecs
|
||||||
|
import ru.dbotthepony.mc.otm.network.streamCodec
|
||||||
import ru.dbotthepony.mc.otm.registry.MItems
|
import ru.dbotthepony.mc.otm.registry.MItems
|
||||||
|
|
||||||
class PlatePressRecipe(
|
class PlatePressRecipe(
|
||||||
@ -70,7 +76,7 @@ class PlatePressRecipe(
|
|||||||
override fun getResultItem(registry: HolderLookup.Provider): ItemStack = outputStack
|
override fun getResultItem(registry: HolderLookup.Provider): ItemStack = outputStack
|
||||||
|
|
||||||
override fun getSerializer(): RecipeSerializer<*> {
|
override fun getSerializer(): RecipeSerializer<*> {
|
||||||
return SERIALIZER
|
return Companion
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getType(): RecipeType<PlatePressRecipe> = MRecipes.PLATE_PRESS
|
override fun getType(): RecipeType<PlatePressRecipe> = MRecipes.PLATE_PRESS
|
||||||
@ -79,19 +85,32 @@ class PlatePressRecipe(
|
|||||||
return ItemStack(MItems.TWIN_PLATE_PRESS[null]!!)
|
return ItemStack(MItems.TWIN_PLATE_PRESS[null]!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toFinished(id: ResourceLocation) = SERIALIZER.toFinished(this, id)
|
companion object : RecipeSerializer<PlatePressRecipe> {
|
||||||
|
private val codec = RecordCodecBuilder.mapCodec {
|
||||||
|
it.group(
|
||||||
|
Ingredient.CODEC_NONEMPTY.fieldOf("input").forGetter(PlatePressRecipe::input),
|
||||||
|
Ingredient.CODEC_NONEMPTY.fieldOf("output").forGetter(PlatePressRecipe::output),
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
private val streamCodec = StreamCodec.composite(
|
||||||
val SERIALIZER = Codec2RecipeSerializer<PlatePressRecipe> { context ->
|
Ingredient.CONTENTS_STREAM_CODEC, PlatePressRecipe::input,
|
||||||
RecordCodecBuilder.create {
|
Ingredient.CONTENTS_STREAM_CODEC, PlatePressRecipe::output,
|
||||||
it.group(
|
ByteBufCodecs.INT, PlatePressRecipe::count,
|
||||||
context.ingredients.fieldOf("input").forGetter(PlatePressRecipe::input),
|
ByteBufCodecs.INT, PlatePressRecipe::workTime,
|
||||||
context.ingredients.fieldOf("output").forGetter(PlatePressRecipe::output),
|
FloatProvider.CODEC.streamCodec(), PlatePressRecipe::experience,
|
||||||
Codec.INT.minRange(1).optionalFieldOf("count", 1).forGetter(PlatePressRecipe::count),
|
::PlatePressRecipe
|
||||||
Codec.INT.minRange(0).optionalFieldOf("workTime", 200).forGetter(PlatePressRecipe::workTime),
|
)
|
||||||
FloatProvider.CODEC.optionalFieldOf("experience", ConstantFloat.ZERO).forGetter(PlatePressRecipe::experience)
|
|
||||||
).apply(it, ::PlatePressRecipe)
|
override fun codec(): MapCodec<PlatePressRecipe> {
|
||||||
}
|
return codec
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun streamCodec(): StreamCodec<RegistryFriendlyByteBuf, PlatePressRecipe> {
|
||||||
|
return streamCodec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user