-
Notifications
You must be signed in to change notification settings - Fork 3
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
50cef6a
commit 70c135a
Showing
15 changed files
with
187 additions
and
67 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
6 changes: 6 additions & 0 deletions
6
...n/java/io/github/mattidragon/advancednetworking/block/AdventureModeAccessBlockEntity.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,6 @@ | ||
package io.github.mattidragon.advancednetworking.block; | ||
|
||
public interface AdventureModeAccessBlockEntity { | ||
boolean isAdventureModeAccessAllowed(); | ||
void setAdventureModeAccessAllowed(boolean allowed); | ||
} |
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
44 changes: 23 additions & 21 deletions
44
src/main/java/io/github/mattidragon/advancednetworking/misc/ScreenPosSyncPacket.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 |
---|---|---|
@@ -1,40 +1,42 @@ | ||
package io.github.mattidragon.advancednetworking.misc; | ||
|
||
import io.github.mattidragon.advancednetworking.screen.ControllerScreenHandler; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; | ||
import net.fabricmc.fabric.api.networking.v1.FabricPacket; | ||
import net.fabricmc.fabric.api.networking.v1.PacketType; | ||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.util.Identifier; | ||
|
||
import static io.github.mattidragon.advancednetworking.AdvancedNetworking.id; | ||
|
||
public class ScreenPosSyncPacket { | ||
public record ScreenPosSyncPacket(int syncId, double x, double y, int zoom) implements FabricPacket { | ||
private static final Identifier ID = id("pos_sync"); | ||
private static final PacketType<ScreenPosSyncPacket> TYPE = PacketType.create(ID, ScreenPosSyncPacket::new); | ||
|
||
public static void register() { | ||
ServerPlayNetworking.registerGlobalReceiver(ID, ((server, player, handler, buf, responseSender) -> { | ||
var x = buf.readDouble(); | ||
var y = buf.readDouble(); | ||
var zoom = buf.readInt(); | ||
var syncId = buf.readByte(); | ||
public ScreenPosSyncPacket(PacketByteBuf buf) { | ||
this(buf.readByte(), buf.readDouble(), buf.readDouble(), buf.readInt()); | ||
} | ||
|
||
server.execute(() -> { | ||
if (player.currentScreenHandler.syncId == syncId && player.currentScreenHandler instanceof ControllerScreenHandler networking) { | ||
networking.viewX = x; | ||
networking.viewY = y; | ||
networking.zoom = zoom; | ||
} | ||
}); | ||
})); | ||
public static void register() { | ||
ServerPlayNetworking.registerGlobalReceiver(TYPE, (packet, player, responseSender) -> { | ||
if (player.currentScreenHandler.syncId == packet.syncId && player.currentScreenHandler instanceof ControllerScreenHandler networking) { | ||
networking.viewX = packet.x; | ||
networking.viewY = packet.y; | ||
networking.zoom = packet.zoom; | ||
} | ||
}); | ||
} | ||
|
||
public static void send(int syncId, double x, double y, int zoom) { | ||
var buf = PacketByteBufs.create(); | ||
@Override | ||
public void write(PacketByteBuf buf) { | ||
buf.writeByte(syncId); | ||
buf.writeDouble(x); | ||
buf.writeDouble(y); | ||
buf.writeInt(zoom); | ||
buf.writeByte(syncId); | ||
} | ||
|
||
ClientPlayNetworking.send(ID, buf); | ||
@Override | ||
public PacketType<?> getType() { | ||
return TYPE; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...main/java/io/github/mattidragon/advancednetworking/misc/SetAdventureModeAccessPacket.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,41 @@ | ||
package io.github.mattidragon.advancednetworking.misc; | ||
|
||
import io.github.mattidragon.advancednetworking.block.AdventureModeAccessBlockEntity; | ||
import net.fabricmc.fabric.api.networking.v1.FabricPacket; | ||
import net.fabricmc.fabric.api.networking.v1.PacketType; | ||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
import static io.github.mattidragon.advancednetworking.AdvancedNetworking.id; | ||
|
||
public record SetAdventureModeAccessPacket(BlockPos pos, boolean allowAccess) implements FabricPacket { | ||
private static final Identifier ID = id("set_adventure_mode_access"); | ||
private static final PacketType<SetAdventureModeAccessPacket> TYPE = PacketType.create(ID, SetAdventureModeAccessPacket::new); | ||
|
||
public SetAdventureModeAccessPacket(PacketByteBuf buf) { | ||
this(buf.readBlockPos(), buf.readBoolean()); | ||
} | ||
|
||
public static void register() { | ||
ServerPlayNetworking.registerGlobalReceiver(TYPE, (packet, player, responseSender) -> { | ||
if (!player.isCreativeLevelTwoOp()) return; | ||
var world = player.getWorld(); | ||
if (world.getBlockEntity(packet.pos) instanceof AdventureModeAccessBlockEntity blockEntity) { | ||
blockEntity.setAdventureModeAccessAllowed(packet.allowAccess); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void write(PacketByteBuf buf) { | ||
buf.writeBlockPos(pos); | ||
buf.writeBoolean(allowAccess); | ||
} | ||
|
||
@Override | ||
public PacketType<?> getType() { | ||
return TYPE; | ||
} | ||
} |
Oops, something went wrong.