Becoming android sound
This commit is contained in:
parent
f016e10dd2
commit
99340baf30
@ -2,15 +2,17 @@ package ru.dbotthepony.mc.otm.network.android;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.capability.android.AndroidCapabilityPlayer;
|
||||
import ru.dbotthepony.mc.otm.registry.MSoundEvents;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public record AndroidStatusPacket(Type type, boolean status) {
|
||||
public record AndroidStatusPacket(Type type, boolean status, boolean playSound) {
|
||||
public enum Type {
|
||||
IS_ANDROID,
|
||||
WILL_BECOME_ANDROID,
|
||||
@ -19,6 +21,7 @@ public record AndroidStatusPacket(Type type, boolean status) {
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
buffer.writeByte(type.ordinal());
|
||||
buffer.writeBoolean(status);
|
||||
buffer.writeBoolean(playSound);
|
||||
}
|
||||
|
||||
public void play(Supplier<NetworkEvent.Context> context) {
|
||||
@ -39,11 +42,15 @@ public record AndroidStatusPacket(Type type, boolean status) {
|
||||
else if (type == Type.WILL_BECOME_ANDROID)
|
||||
pcap.willBecomeAndroid = status;
|
||||
}
|
||||
|
||||
if (playSound) {
|
||||
ply.level.playSound(ply, ply, MSoundEvents.INSTANCE.getPLAYER_BECOME_ANDROID(), SoundSource.PLAYERS, 1f, 1f);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static AndroidStatusPacket read(FriendlyByteBuf buffer) {
|
||||
return new AndroidStatusPacket(Type.values()[buffer.readByte()], buffer.readBoolean());
|
||||
return new AndroidStatusPacket(Type.values()[buffer.readByte()], buffer.readBoolean(), buffer.readBoolean());
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class AndroidCapabilityPlayer(@JvmField val ply: Player) : AndroidCapability(ply
|
||||
@JvmField
|
||||
var willBecomeAndroid = false
|
||||
private var willBecomeAndroidNetwork = false
|
||||
private var shouldPlaySound = false
|
||||
private val research = ArrayList<AndroidResearch>()
|
||||
|
||||
override fun invalidateNetworkState() {
|
||||
@ -60,6 +61,7 @@ class AndroidCapabilityPlayer(@JvmField val ply: Player) : AndroidCapability(ply
|
||||
|
||||
isAndroid = true
|
||||
willBecomeAndroid = false
|
||||
shouldPlaySound = false
|
||||
battery = ImpreciseFraction(60000)
|
||||
maxBattery = ImpreciseFraction(60000)
|
||||
}
|
||||
@ -76,6 +78,7 @@ class AndroidCapabilityPlayer(@JvmField val ply: Player) : AndroidCapability(ply
|
||||
if (!isAndroid) return
|
||||
|
||||
isAndroid = false
|
||||
shouldPlaySound = false
|
||||
battery = ImpreciseFraction(0)
|
||||
maxBattery = ImpreciseFraction(60000)
|
||||
dropBattery()
|
||||
@ -167,12 +170,13 @@ class AndroidCapabilityPlayer(@JvmField val ply: Player) : AndroidCapability(ply
|
||||
super.tickNetwork()
|
||||
if (isAndroid != isAndroidNetwork) {
|
||||
isAndroidNetwork = isAndroid
|
||||
sendNetwork(AndroidStatusPacket(AndroidStatusPacket.Type.IS_ANDROID, isAndroid))
|
||||
sendNetwork(AndroidStatusPacket(AndroidStatusPacket.Type.IS_ANDROID, isAndroid, shouldPlaySound))
|
||||
shouldPlaySound = false
|
||||
}
|
||||
|
||||
if (willBecomeAndroid != willBecomeAndroidNetwork) {
|
||||
willBecomeAndroidNetwork = willBecomeAndroid
|
||||
sendNetwork(AndroidStatusPacket(AndroidStatusPacket.Type.WILL_BECOME_ANDROID, willBecomeAndroid))
|
||||
sendNetwork(AndroidStatusPacket(AndroidStatusPacket.Type.WILL_BECOME_ANDROID, willBecomeAndroid, false))
|
||||
}
|
||||
|
||||
for (instance in research) {
|
||||
@ -207,6 +211,7 @@ class AndroidCapabilityPlayer(@JvmField val ply: Player) : AndroidCapability(ply
|
||||
|
||||
if (sleep_ticks > SLEEP_TICKS_LIMIT) {
|
||||
becomeAndroid()
|
||||
shouldPlaySound = true
|
||||
sleep_ticks = 0
|
||||
|
||||
(ply as? ServerPlayer)?.displayClientMessage(TranslatableComponent("otm.pill.message_finish").withStyle(ChatFormatting.DARK_RED), false)
|
||||
|
@ -16,6 +16,7 @@ object MSoundEvents {
|
||||
|
||||
val RIFLE_SHOT: SoundEvent by make("item.rifle_shot")
|
||||
val PLASMA_WEAPON_OVERHEAT: SoundEvent by make("item.plasma_weapon_overheat")
|
||||
val PLAYER_BECOME_ANDROID: SoundEvent by make("player_become_android")
|
||||
|
||||
internal fun register() {
|
||||
registry.register(FMLJavaModLoadingContext.get().modEventBus)
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"otm.sound.rifle_shoot": "Plasma rifle fires",
|
||||
"otm.sound.plasma_weapon_overheat": "Plasma weapon overheats",
|
||||
"otm.sound.player_become_android": "Player became android",
|
||||
|
||||
"itemGroup.otm": "Overdrive That Matters",
|
||||
|
||||
|
@ -10,6 +10,17 @@
|
||||
]
|
||||
},
|
||||
|
||||
"player_become_android": {
|
||||
"subtitle": "otm.sound.player_become_android",
|
||||
"sounds": [
|
||||
{
|
||||
"name": "overdrive_that_matters:player_become_android",
|
||||
"volume": 1.0,
|
||||
"weight": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"item.plasma_weapon_overheat": {
|
||||
"subtitle": "otm.sound.plasma_weapon_overheat",
|
||||
"sounds": [
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user