Compare commits
2 Commits
c18fa330a6
...
b116ae7f91
Author | SHA1 | Date | |
---|---|---|---|
b116ae7f91 | |||
e55b1da9cb |
@ -6,9 +6,9 @@ import ru.dbotthepony.mc.otm.data.FlywheelMaterialDataProvider
|
||||
import ru.dbotthepony.mc.otm.registry.MBlockTags
|
||||
|
||||
fun addFlywheelMaterials(provider: FlywheelMaterialDataProvider) {
|
||||
provider.add(Tags.Blocks.STORAGE_BLOCKS_DIAMOND, Decimal(1_000_000))
|
||||
provider.add(Tags.Blocks.STORAGE_BLOCKS_COPPER, Decimal(3_500_000))
|
||||
provider.add(Tags.Blocks.STORAGE_BLOCKS_IRON, Decimal(3_000_000))
|
||||
provider.add(Tags.Blocks.STORAGE_BLOCKS_GOLD, Decimal(18_000_000))
|
||||
provider.add(MBlockTags.TRITANIUM_BLOCKS, Decimal(9_000_000))
|
||||
provider.add(Tags.Blocks.STORAGE_BLOCKS_DIAMOND, Decimal(25_000_000))
|
||||
provider.add(Tags.Blocks.STORAGE_BLOCKS_COPPER, Decimal(60_000_000))
|
||||
provider.add(Tags.Blocks.STORAGE_BLOCKS_IRON, Decimal(50_000_000))
|
||||
provider.add(Tags.Blocks.STORAGE_BLOCKS_GOLD, Decimal(300_000_000))
|
||||
provider.add(MBlockTags.TRITANIUM_BLOCKS, Decimal(225_000_000))
|
||||
}
|
||||
|
@ -409,6 +409,11 @@ private fun misc(provider: MatteryLanguageProvider) {
|
||||
gui("matter.format_and_complexity2", "%s (%s) / Complexity: %s (%s)")
|
||||
gui("matter.name", "MtU")
|
||||
|
||||
gui("flywheel.top", "When used as flywheel core:")
|
||||
gui("flywheel.storage", "* Storage: %s")
|
||||
gui("flywheel.receive_efficiency", "* Wind up efficiency: %s")
|
||||
gui("flywheel.momentum_loss_speed", "* Momentum loss speed factor: %s")
|
||||
|
||||
gui("filter.is_whitelist", "Is Whitelist")
|
||||
gui("filter.match_nbt", "Match NBT")
|
||||
gui("filter.match_tag", "Match Tag")
|
||||
|
@ -406,6 +406,11 @@ private fun misc(provider: MatteryLanguageProvider) {
|
||||
gui("matter.format_and_complexity2", "%s (%s) / Сложность: %s (%s)")
|
||||
gui("matter.name", "МтЕд")
|
||||
|
||||
gui("flywheel.top", "Как материал сердечника маховой батареи:")
|
||||
gui("flywheel.storage", "* Хранилище: %s")
|
||||
gui("flywheel.receive_efficiency", "* КПД раскрутки: %s")
|
||||
gui("flywheel.momentum_loss_speed", "* Фактор потери накопленной скорости: %s")
|
||||
|
||||
gui("filter.is_whitelist", "Белый список")
|
||||
gui("filter.match_nbt", "Сравнивать NBT")
|
||||
gui("filter.match_tag", "Сравнить Теги")
|
||||
|
@ -206,6 +206,7 @@ object OverdriveThatMatters {
|
||||
FORGE_BUS.addListener(EventPriority.NORMAL, AndroidResearchManager::syncEvent)
|
||||
|
||||
FORGE_BUS.addListener(EventPriority.NORMAL, FlywheelMaterials::reloadEvent)
|
||||
FORGE_BUS.addListener(EventPriority.NORMAL, FlywheelMaterials::onDataPackSync)
|
||||
|
||||
FORGE_BUS.addListener(EventPriority.NORMAL, MatterManager::reloadEvent)
|
||||
FORGE_BUS.addListener(EventPriority.NORMAL, MatterManager::onServerStarted)
|
||||
@ -243,6 +244,7 @@ object OverdriveThatMatters {
|
||||
|
||||
private fun setupClient(event: FMLClientSetupEvent) {
|
||||
FORGE_BUS.addListener(EventPriority.NORMAL, MatterManager::tooltipEvent)
|
||||
FORGE_BUS.addListener(EventPriority.NORMAL, FlywheelMaterials::tooltipEvent)
|
||||
|
||||
FORGE_BUS.addListener(EventPriority.NORMAL, MatteryGUI::onScreenRender)
|
||||
FORGE_BUS.addListener(EventPriority.LOWEST, MatteryGUI::onOpenGUIEvent)
|
||||
|
@ -15,6 +15,7 @@ import net.minecraft.Util
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Holder
|
||||
import net.minecraft.core.HolderLookup
|
||||
import net.minecraft.core.IdMap
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.SectionPos
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
@ -264,8 +265,16 @@ inline fun itemAttributes(builder: ItemAttributeModifiers.Builder.() -> Unit): I
|
||||
return value.build()
|
||||
}
|
||||
|
||||
fun <T : Any> FriendlyByteBuf.writeType(registry: IdMap<T>, value: T) {
|
||||
writeInt(registry.getId(value))
|
||||
}
|
||||
|
||||
fun FriendlyByteBuf.writeBlockType(value: Block) {
|
||||
writeType(BuiltInRegistries.BLOCK, value)
|
||||
}
|
||||
|
||||
fun FriendlyByteBuf.writeItemType(value: Item) {
|
||||
writeInt(BuiltInRegistries.ITEM.getId(value))
|
||||
writeType(BuiltInRegistries.ITEM, value)
|
||||
}
|
||||
|
||||
fun RegistryFriendlyByteBuf.writeItem(value: ItemStack) {
|
||||
@ -280,8 +289,17 @@ fun OutputStream.writeItemType(value: Item) {
|
||||
writeVarIntLE(BuiltInRegistries.ITEM.getId(value))
|
||||
}
|
||||
|
||||
fun <T : Any> FriendlyByteBuf.readType(registry: IdMap<T>): T {
|
||||
val id = readInt()
|
||||
return registry.byId(id) ?: throw NoSuchElementException("No such entry with ID $id")
|
||||
}
|
||||
|
||||
fun FriendlyByteBuf.readBlockType(): Block {
|
||||
return readType(BuiltInRegistries.BLOCK)
|
||||
}
|
||||
|
||||
fun FriendlyByteBuf.readItemType(): Item {
|
||||
return BuiltInRegistries.ITEM.byId(readInt())
|
||||
return readType(BuiltInRegistries.ITEM)
|
||||
}
|
||||
|
||||
fun RegistryFriendlyByteBuf.readItem(): ItemStack {
|
||||
|
@ -8,19 +8,42 @@ import com.mojang.datafixers.util.Either
|
||||
import com.mojang.serialization.Codec
|
||||
import com.mojang.serialization.JsonOps
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.network.FriendlyByteBuf
|
||||
import net.minecraft.network.codec.StreamCodec
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.server.packs.resources.ResourceManager
|
||||
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener
|
||||
import net.minecraft.tags.BlockTags
|
||||
import net.minecraft.tags.TagKey
|
||||
import net.minecraft.util.profiling.ProfilerFiller
|
||||
import net.minecraft.world.item.BlockItem
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
import net.neoforged.neoforge.event.AddReloadListenerEvent
|
||||
import net.neoforged.neoforge.event.OnDatapackSyncEvent
|
||||
import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent
|
||||
import net.neoforged.neoforge.network.PacketDistributor
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.SERVER_IS_LIVE
|
||||
import ru.dbotthepony.mc.otm.client.isShiftDown
|
||||
import ru.dbotthepony.mc.otm.client.minecraft
|
||||
import ru.dbotthepony.mc.otm.core.ResourceLocation
|
||||
import ru.dbotthepony.mc.otm.core.TextComponent
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||
import ru.dbotthepony.mc.otm.core.math.readDecimal
|
||||
import ru.dbotthepony.mc.otm.core.math.writeDecimal
|
||||
import ru.dbotthepony.mc.otm.core.readBlockType
|
||||
import ru.dbotthepony.mc.otm.core.registryName
|
||||
import ru.dbotthepony.mc.otm.core.util.formatPower
|
||||
import ru.dbotthepony.mc.otm.core.writeBlockType
|
||||
import ru.dbotthepony.mc.otm.data.codec.DecimalCodec
|
||||
import ru.dbotthepony.mc.otm.data.codec.minRange
|
||||
|
||||
@ -57,6 +80,36 @@ object FlywheelMaterials : SimpleJsonResourceReloadListener(GsonBuilder().setPre
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
fun write(stream: FriendlyByteBuf) {
|
||||
stream.writeBoolean(id.left().isPresent)
|
||||
|
||||
id
|
||||
.ifLeft { stream.writeResourceLocation(it.location) }
|
||||
.ifRight { stream.writeBlockType(it) }
|
||||
|
||||
stream.writeDecimal(storage)
|
||||
stream.writeVarInt(priority)
|
||||
stream.writeBoolean(receiveEfficiency != Decimal.ONE)
|
||||
if (receiveEfficiency != Decimal.ONE) stream.writeDecimal(receiveEfficiency)
|
||||
stream.writeBoolean(momentumLossSpeed != Decimal.ONE)
|
||||
if (momentumLossSpeed != Decimal.ONE) stream.writeDecimal(momentumLossSpeed)
|
||||
}
|
||||
}
|
||||
|
||||
private fun readEntry(stream: FriendlyByteBuf): Entry {
|
||||
val id: Either<TagKey<Block>, Block> = if (stream.readBoolean()) {
|
||||
Either.left(BlockTags.create(stream.readResourceLocation()))
|
||||
} else {
|
||||
Either.right(stream.readBlockType())
|
||||
}
|
||||
|
||||
val storage = stream.readDecimal()
|
||||
val priority = stream.readVarInt()
|
||||
val receiveEfficiency = if (stream.readBoolean()) stream.readDecimal() else Decimal.ONE
|
||||
val momentumLossSpeed = if (stream.readBoolean()) stream.readDecimal() else Decimal.ONE
|
||||
|
||||
return Entry(id, storage, priority, receiveEfficiency, momentumLossSpeed)
|
||||
}
|
||||
|
||||
private var elements = ArrayList<Entry>()
|
||||
@ -149,5 +202,62 @@ object FlywheelMaterials : SimpleJsonResourceReloadListener(GsonBuilder().setPre
|
||||
event.addListener(this)
|
||||
}
|
||||
|
||||
val SYNC_TYPE = CustomPacketPayload.Type<SyncPacket>(ResourceLocation(OverdriveThatMatters.MOD_ID, "flywheel_materials_sync"))
|
||||
val SYNC_CODEC: StreamCodec<FriendlyByteBuf, SyncPacket> = StreamCodec.ofMember(SyncPacket::write, ::readSyncPacket)
|
||||
|
||||
private fun readSyncPacket(buff: FriendlyByteBuf): SyncPacket {
|
||||
return SyncPacket(buff.readList { readEntry(it) })
|
||||
}
|
||||
|
||||
class SyncPacket(val elements: List<Entry>) : CustomPacketPayload {
|
||||
override fun type(): CustomPacketPayload.Type<out CustomPacketPayload> {
|
||||
return SYNC_TYPE
|
||||
}
|
||||
|
||||
fun write(stream: FriendlyByteBuf) {
|
||||
stream.writeCollection(elements) { s, entry -> entry.write(s) }
|
||||
}
|
||||
|
||||
fun play(context: IPayloadContext) {
|
||||
if (SERVER_IS_LIVE)
|
||||
return // singleplayer or LAN host
|
||||
|
||||
FlywheelMaterials.elements = ArrayList(elements)
|
||||
mappingChanged = true
|
||||
}
|
||||
}
|
||||
|
||||
fun onDataPackSync(event: OnDatapackSyncEvent) {
|
||||
if (event.player == null) {
|
||||
PacketDistributor.sendToAllPlayers(SyncPacket(elements))
|
||||
} else {
|
||||
PacketDistributor.sendToPlayer(event.player as ServerPlayer, SyncPacket(elements))
|
||||
}
|
||||
}
|
||||
|
||||
fun tooltipEvent(event: ItemTooltipEvent) {
|
||||
if (minecraft.window.isShiftDown) {
|
||||
val item = event.itemStack.item
|
||||
|
||||
if (item is BlockItem) {
|
||||
val entry = this[item.block]
|
||||
|
||||
if (entry != null) {
|
||||
event.toolTip.add(TextComponent(""))
|
||||
event.toolTip.add(TranslatableComponent("otm.gui.flywheel.top").withStyle(ChatFormatting.GRAY))
|
||||
event.toolTip.add(TranslatableComponent("otm.gui.flywheel.storage", entry.storage.formatPower()).withStyle(ChatFormatting.GRAY))
|
||||
|
||||
if (entry.receiveEfficiency != Decimal.ONE) {
|
||||
event.toolTip.add(TranslatableComponent("otm.gui.flywheel.receive_efficiency", entry.receiveEfficiency.toString(1)).withStyle(ChatFormatting.GRAY))
|
||||
}
|
||||
|
||||
if (entry.momentumLossSpeed != Decimal.ONE) {
|
||||
event.toolTip.add(TranslatableComponent("otm.gui.flywheel.momentum_loss_speed", entry.momentumLossSpeed.toString(1)).withStyle(ChatFormatting.GRAY))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val LOGGER = LogManager.getLogger()
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import net.neoforged.neoforge.network.registration.HandlerThread
|
||||
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
||||
import ru.dbotthepony.mc.otm.android.feature.ItemEntityDataPacket
|
||||
import ru.dbotthepony.mc.otm.compat.vanilla.InventoryScrollPacket
|
||||
import ru.dbotthepony.mc.otm.data.FlywheelMaterials
|
||||
import ru.dbotthepony.mc.otm.item.QuantumBatteryItem
|
||||
import ru.dbotthepony.mc.otm.matter.MatterManager
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
@ -35,6 +36,7 @@ fun registerNetworkPackets(event: RegisterPayloadHandlersEvent) {
|
||||
r.executesOn(HandlerThread.NETWORK)
|
||||
.playToClient(AndroidResearchManager.SYNC_TYPE, AndroidResearchManager.SYNC_CODEC, AndroidResearchManager.SyncPacket::play)
|
||||
.playToClient(MatterManager.SYNC_TYPE, MatterManager.SYNC_CODEC, MatterManager.SyncPacket::play)
|
||||
.playToClient(FlywheelMaterials.SYNC_TYPE, FlywheelMaterials.SYNC_CODEC, FlywheelMaterials.SyncPacket::play)
|
||||
|
||||
// exopack
|
||||
r
|
||||
|
Loading…
Reference in New Issue
Block a user