-
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.
fix: sync issue between screen and hidden explosive
- Loading branch information
Showing
8 changed files
with
84 additions
and
10 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
15 changes: 15 additions & 0 deletions
15
src/main/java/fenn7/grenadesandgadgets/commonside/item/network/GrenadesModC2SPackets.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,15 @@ | ||
package fenn7.grenadesandgadgets.commonside.item.network; | ||
|
||
import fenn7.grenadesandgadgets.commonside.GrenadesMod; | ||
import fenn7.grenadesandgadgets.commonside.item.network.packets.SyncHiddenExplosiveC2SPacket; | ||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class GrenadesModC2SPackets { | ||
public static Identifier SYNC_HIDDEN_EXPLOSIVE_C2S = new Identifier(GrenadesMod.MOD_ID, "hidden_explosive_c2s"); | ||
|
||
public static void registerC2SPackets() { | ||
GrenadesMod.LOGGER.warn("Initialising Grenades And Gadgets S2C Packets..."); | ||
ServerPlayNetworking.registerGlobalReceiver(SYNC_HIDDEN_EXPLOSIVE_C2S, SyncHiddenExplosiveC2SPacket::receive); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...enn7/grenadesandgadgets/commonside/item/network/packets/SyncHiddenExplosiveC2SPacket.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,27 @@ | ||
package fenn7.grenadesandgadgets.commonside.item.network.packets; | ||
|
||
import fenn7.grenadesandgadgets.client.screen.HiddenExplosiveScreenHandler; | ||
import fenn7.grenadesandgadgets.commonside.block.GrenadesModBlockEntities; | ||
import fenn7.grenadesandgadgets.commonside.block.entity.HiddenExplosiveBlockEntity; | ||
import net.fabricmc.fabric.api.networking.v1.PacketSender; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.network.ServerPlayNetworkHandler; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class SyncHiddenExplosiveC2SPacket { | ||
public static void receive(MinecraftServer server, ServerPlayerEntity serverPlayerEntity, | ||
ServerPlayNetworkHandler serverPlayNetworkHandler, PacketByteBuf buf, PacketSender packetSender) { | ||
BlockPos pos = buf.readBlockPos(); | ||
if (pos != null) { | ||
var optional = serverPlayerEntity.getWorld().getBlockEntity(pos, GrenadesModBlockEntities.HIDDEN_EXPLOSIVE_BLOCK_ENTITY); | ||
var handler = serverPlayerEntity.currentScreenHandler; | ||
if (optional.isPresent()) { | ||
optional.get().getDelegate().set(1, 1); | ||
} else if (handler instanceof HiddenExplosiveScreenHandler hiddenHandler) { | ||
hiddenHandler.setDelegateValue(1, 1); | ||
} | ||
} | ||
} | ||
} |
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