generated from NeoForgeMDKs/MDK-1.21.1-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dedicated Server is broken, add fast scrolls to GUI
Can't figure out where the packet ID desync happens
- Loading branch information
Showing
15 changed files
with
201 additions
and
54 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
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
src/main/java/net/nayrus/noteblockmaster/network/NetworkUtil.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 net.nayrus.noteblockmaster.network; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.nayrus.noteblockmaster.network.payload.ScheduleCoreSound; | ||
import net.neoforged.neoforge.network.PacketDistributor; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
public class NetworkUtil { | ||
|
||
public static void broadcastPayload( | ||
List<ServerPlayer> players, | ||
@Nullable Player except, | ||
double x, | ||
double y, | ||
double z, | ||
double radius, | ||
ResourceKey<Level> dimension, | ||
CustomPacketPayload payload | ||
) { | ||
for (ServerPlayer serverplayer : players) { | ||
if (serverplayer != except && serverplayer.level().dimension() == dimension) { | ||
double d0 = x - serverplayer.getX(); | ||
double d1 = y - serverplayer.getY(); | ||
double d2 = z - serverplayer.getZ(); | ||
if (d0 * d0 + d1 * d1 + d2 * d2 < radius * radius) { | ||
PacketDistributor.sendToPlayer(serverplayer, payload); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void broadcastCoreSound(ServerLevel level, ScheduleCoreSound payload){ | ||
BlockPos pos = payload.pos(); | ||
broadcastPayload(level.players(), null, pos.getX(), pos.getY(), pos.getZ(), 64, level.dimension(), payload); | ||
} | ||
|
||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/net/nayrus/noteblockmaster/network/payload/ScheduleCoreSound.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,44 @@ | ||
package net.nayrus.noteblockmaster.network.payload; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.nayrus.noteblockmaster.NoteBlockMaster; | ||
import net.nayrus.noteblockmaster.sound.AdvancedInstrument; | ||
|
||
public record ScheduleCoreSound(BlockPos pos, float volume, int data) implements CustomPacketPayload { | ||
|
||
public static final Type<ScheduleCoreSound> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(NoteBlockMaster.MOD_ID, "schedulecoresound")); | ||
|
||
@Override | ||
public Type<ScheduleCoreSound> type() { | ||
return TYPE; | ||
} | ||
|
||
public static final StreamCodec<RegistryFriendlyByteBuf, ScheduleCoreSound> STREAM_CODEC = StreamCodec.composite( | ||
BlockPos.STREAM_CODEC, ScheduleCoreSound::pos, | ||
ByteBufCodecs.FLOAT, ScheduleCoreSound::volume, | ||
ByteBufCodecs.INT, ScheduleCoreSound::data, | ||
ScheduleCoreSound::new | ||
); | ||
|
||
public static ScheduleCoreSound of( | ||
BlockPos pos, | ||
int sustainIndex, // 8 Bit | ||
int noteVal, // 8 Bit | ||
float volume, | ||
AdvancedInstrument instrument, // 5 Bit | ||
boolean noDecay, // 1 Bit | ||
int delay // 5 Bit | ||
){ | ||
int data = (sustainIndex & 0xFF) | ||
| ((noteVal & 0xFF) << 8) | ||
| ((instrument.ordinal() & 0x1F) << 16) | ||
| ((noDecay ? 1 : 0) << 24) | ||
| ((delay & 0x1F) << 25); | ||
return new ScheduleCoreSound(pos, volume, data); | ||
} | ||
} |
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
Oops, something went wrong.