Jump boost now have particles
This commit is contained in:
parent
1902912a3b
commit
86a8011f29
@ -4,11 +4,17 @@ import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.network.FriendlyByteBuf
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.util.RandomSource
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import net.minecraftforge.network.NetworkEvent
|
||||
import net.minecraftforge.network.PacketDistributor
|
||||
import net.minecraftforge.network.PacketDistributor.TargetPoint
|
||||
import ru.dbotthepony.mc.otm.config.ClientConfig
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.config.AndroidConfig
|
||||
@ -18,8 +24,12 @@ import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
||||
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
|
||||
import ru.dbotthepony.mc.otm.capability.matteryPlayer
|
||||
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
|
||||
import ru.dbotthepony.mc.otm.client.minecraft
|
||||
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
|
||||
import ru.dbotthepony.mc.otm.core.math.Vector
|
||||
import ru.dbotthepony.mc.otm.core.math.component1
|
||||
import ru.dbotthepony.mc.otm.core.math.component2
|
||||
import ru.dbotthepony.mc.otm.core.math.component3
|
||||
import ru.dbotthepony.mc.otm.core.util.formatPower
|
||||
import ru.dbotthepony.mc.otm.core.math.plus
|
||||
import ru.dbotthepony.mc.otm.network.MatteryPacket
|
||||
@ -32,6 +42,11 @@ import ru.dbotthepony.mc.otm.registry.MNames
|
||||
import ru.dbotthepony.mc.otm.registry.MSoundEvents
|
||||
import java.util.function.Supplier
|
||||
|
||||
private fun makeSmoke(x: Double, y: Double, z: Double, random: RandomSource, level: Level) {
|
||||
for (i in 0 .. random.nextInt(4, 8))
|
||||
level.addParticle(ParticleTypes.POOF, x + random.nextDouble() * 0.5 - 0.25, y + random.nextDouble() * 0.5 - 0.25, z + random.nextDouble() * 0.5 - 0.25, random.nextGaussian() * 0.02, random.nextGaussian() * 0.02, random.nextGaussian() * 0.02)
|
||||
}
|
||||
|
||||
object TriggerJumpBoostPacket : MatteryPacket {
|
||||
override fun write(buff: FriendlyByteBuf) {
|
||||
// no op
|
||||
@ -46,26 +61,48 @@ object TriggerJumpBoostPacket : MatteryPacket {
|
||||
if (!mattery.isAndroid)
|
||||
return@enqueueWork
|
||||
|
||||
val feature = mattery.getFeature(AndroidFeatures.JUMP_BOOST) as JumpBoostFeature? ?: return@enqueueWork
|
||||
val feature = mattery.getFeature(AndroidFeatures.JUMP_BOOST) ?: return@enqueueWork
|
||||
|
||||
if (feature.isActive && feature.cooldown <= 4 && mattery.androidEnergy.extractEnergyExact(AndroidConfig.JumpBoost.ENERGY_COST, false)) {
|
||||
feature.putOnCooldown()
|
||||
|
||||
context.sender?.let {
|
||||
it.level().playSound(
|
||||
it,
|
||||
it,
|
||||
MSoundEvents.ANDROID_JUMP_BOOST,
|
||||
SoundSource.PLAYERS,
|
||||
1f,
|
||||
1f
|
||||
it, it,
|
||||
MSoundEvents.ANDROID_JUMP_BOOST, SoundSource.PLAYERS,
|
||||
1f, 1f
|
||||
)
|
||||
|
||||
MatteryPlayerNetworkChannel.send(PacketDistributor.NEAR.with { TargetPoint(it, it.x, it.y, it.z, 64.0, it.level().dimension()) }, JumpBoostParticlesPacket(it.x, it.y, it.z))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JumpBoostParticlesPacket(val x: Double, val y: Double, val z: Double) : MatteryPacket {
|
||||
override fun write(buff: FriendlyByteBuf) {
|
||||
buff.writeDouble(x)
|
||||
buff.writeDouble(y)
|
||||
buff.writeDouble(z)
|
||||
}
|
||||
|
||||
override fun play(context: Supplier<NetworkEvent.Context>) {
|
||||
context.packetHandled = true
|
||||
context.enqueueWork {
|
||||
minecraft.player?.level()?.let {
|
||||
makeSmoke(x, y, z, it.random, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(buff: FriendlyByteBuf): JumpBoostParticlesPacket {
|
||||
return JumpBoostParticlesPacket(buff.readDouble(), buff.readDouble(), buff.readDouble())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JumpBoostFeature(capability: MatteryPlayerCapability) : AndroidSwitchableFeature(AndroidFeatures.JUMP_BOOST, capability) {
|
||||
private var tickCooldownClient = false
|
||||
|
||||
@ -78,7 +115,7 @@ class JumpBoostFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
|
||||
if (setByRemote) {
|
||||
tickCooldownClient = false
|
||||
}
|
||||
})
|
||||
}).property
|
||||
|
||||
private var lastGround = false
|
||||
|
||||
@ -98,13 +135,12 @@ class JumpBoostFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
|
||||
MatteryPlayerNetworkChannel.sendToServer(TriggerJumpBoostPacket)
|
||||
|
||||
ply.level().playSound(
|
||||
ply,
|
||||
ply,
|
||||
MSoundEvents.ANDROID_JUMP_BOOST,
|
||||
SoundSource.PLAYERS,
|
||||
1f,
|
||||
1f
|
||||
ply, ply,
|
||||
MSoundEvents.ANDROID_JUMP_BOOST, SoundSource.PLAYERS,
|
||||
1f, 1f
|
||||
)
|
||||
|
||||
makeSmoke(ply.x, ply.y, ply.z, ply.random, ply.level())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import ru.dbotthepony.mc.otm.android.AndroidFeatureType
|
||||
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
|
||||
import ru.dbotthepony.mc.otm.android.AndroidResearchType
|
||||
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
|
||||
import ru.dbotthepony.mc.otm.android.feature.JumpBoostParticlesPacket
|
||||
import ru.dbotthepony.mc.otm.android.feature.TriggerJumpBoostPacket
|
||||
import ru.dbotthepony.mc.otm.android.feature.TriggerShockwavePacket
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
||||
@ -582,6 +583,7 @@ object MatteryPlayerNetworkChannel : MatteryNetworkChannel(
|
||||
|
||||
add(TriggerShockwavePacket::class, { TriggerShockwavePacket }, PLAY_TO_SERVER)
|
||||
add(TriggerJumpBoostPacket::class, { TriggerJumpBoostPacket }, PLAY_TO_SERVER)
|
||||
add(JumpBoostParticlesPacket::class, JumpBoostParticlesPacket.Companion::read, PLAY_TO_CLIENT)
|
||||
|
||||
add(PickItemFromInventoryPacket::class, PickItemFromInventoryPacket.Companion::read, PLAY_TO_SERVER)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user