-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fea28f1
commit 2b2829c
Showing
5 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../java/com/github/tartaricacid/touhoulittlemaid/network/message/SetMaidSoundIdMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.github.tartaricacid.touhoulittlemaid.network.message; | ||
|
||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraftforge.network.NetworkEvent; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class SetMaidSoundIdMessage { | ||
private final int entityId; | ||
private final String soundId; | ||
|
||
public SetMaidSoundIdMessage(int entityId, String soundId) { | ||
this.entityId = entityId; | ||
this.soundId = soundId; | ||
} | ||
|
||
public static void encode(SetMaidSoundIdMessage message, FriendlyByteBuf buf) { | ||
buf.writeInt(message.entityId); | ||
buf.writeUtf(message.soundId); | ||
} | ||
|
||
public static SetMaidSoundIdMessage decode(FriendlyByteBuf buf) { | ||
return new SetMaidSoundIdMessage(buf.readInt(), buf.readUtf()); | ||
} | ||
|
||
public static void handle(SetMaidSoundIdMessage message, Supplier<NetworkEvent.Context> contextSupplier) { | ||
NetworkEvent.Context context = contextSupplier.get(); | ||
if (context.getDirection().getReceptionSide().isServer()) { | ||
context.enqueueWork(() -> { | ||
ServerPlayer sender = context.getSender(); | ||
if (sender == null) { | ||
return; | ||
} | ||
Entity entity = sender.level.getEntity(message.entityId); | ||
if (entity instanceof EntityMaid maid && maid.isOwnedBy(sender)) { | ||
maid.setSoundPackId(message.soundId); | ||
} | ||
}); | ||
} | ||
context.setPacketHandled(true); | ||
} | ||
} |