-
Notifications
You must be signed in to change notification settings - Fork 21
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
3c6c377
commit 8b88baf
Showing
6 changed files
with
124 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
src/main/java/net/gigabit101/rebornstorage/packet/PacketMultiblockUpdate.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,52 @@ | ||
package net.gigabit101.rebornstorage.packet; | ||
|
||
import net.gigabit101.rebornstorage.blockentities.BlockEntityMultiCrafter; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraftforge.network.NetworkEvent; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class PacketMultiblockUpdate | ||
{ | ||
private final BlockPos blockPos; | ||
private final boolean assembled; | ||
|
||
public PacketMultiblockUpdate(BlockPos blockPos, boolean assembled) | ||
{ | ||
this.blockPos = blockPos; | ||
this.assembled = assembled; | ||
} | ||
|
||
public static void encode(PacketMultiblockUpdate packetGui, FriendlyByteBuf buf) | ||
{ | ||
buf.writeBlockPos(packetGui.blockPos); | ||
buf.writeBoolean(packetGui.assembled); | ||
} | ||
|
||
public static PacketMultiblockUpdate decode(FriendlyByteBuf buf) | ||
{ | ||
return new PacketMultiblockUpdate(buf.readBlockPos(), buf.readBoolean()); | ||
} | ||
|
||
public static class Handler | ||
{ | ||
public static void handle(final PacketMultiblockUpdate message, Supplier<NetworkEvent.Context> ctx) | ||
{ | ||
ctx.get().enqueueWork(() -> | ||
{ | ||
ServerPlayer player = ctx.get().getSender(); | ||
if (player == null) return; | ||
|
||
BlockEntity blockEntity = player.level().getBlockEntity(message.blockPos); | ||
if(blockEntity != null && blockEntity instanceof BlockEntityMultiCrafter blockEntityMultiCrafter) | ||
{ | ||
blockEntityMultiCrafter.getMultiBlock().setAssembled(message.assembled); | ||
} | ||
}); | ||
ctx.get().setPacketHandled(true); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/net/gigabit101/rebornstorage/packet/PacketRequestMultiblockUpdate.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,50 @@ | ||
package net.gigabit101.rebornstorage.packet; | ||
|
||
import net.gigabit101.rebornstorage.blockentities.BlockEntityMultiCrafter; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraftforge.network.NetworkEvent; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class PacketRequestMultiblockUpdate | ||
{ | ||
private final BlockPos blockPos; | ||
|
||
public PacketRequestMultiblockUpdate(BlockPos blockPos) | ||
{ | ||
this.blockPos = blockPos; | ||
} | ||
|
||
public static void encode(PacketRequestMultiblockUpdate packetGui, FriendlyByteBuf buf) | ||
{ | ||
buf.writeBlockPos(packetGui.blockPos); | ||
} | ||
|
||
public static PacketRequestMultiblockUpdate decode(FriendlyByteBuf buf) | ||
{ | ||
return new PacketRequestMultiblockUpdate(buf.readBlockPos()); | ||
} | ||
|
||
public static class Handler | ||
{ | ||
public static void handle(final PacketRequestMultiblockUpdate message, Supplier<NetworkEvent.Context> ctx) | ||
{ | ||
ctx.get().enqueueWork(() -> | ||
{ | ||
ServerPlayer player = ctx.get().getSender(); | ||
if (player == null) return; | ||
|
||
BlockEntity blockEntity = player.level().getBlockEntity(message.blockPos); | ||
if(blockEntity != null && blockEntity instanceof BlockEntityMultiCrafter blockEntityMultiCrafter) | ||
{ | ||
boolean assembled = blockEntityMultiCrafter.getMultiBlock().isAssembled(); | ||
PacketHandler.sendTo(new PacketMultiblockUpdate(message.blockPos, assembled), player); | ||
} | ||
}); | ||
ctx.get().setPacketHandled(true); | ||
} | ||
} | ||
} |