-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add range support to expulsion pylon
- Loading branch information
1 parent
d211c64
commit 50b2885
Showing
13 changed files
with
258 additions
and
68 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
25 changes: 25 additions & 0 deletions
25
src/main/java/net/permutated/pylons/network/NetworkDispatcher.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,25 @@ | ||
package net.permutated.pylons.network; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.network.NetworkRegistry; | ||
import net.minecraftforge.network.simple.SimpleChannel; | ||
import net.permutated.pylons.Pylons; | ||
|
||
|
||
public class NetworkDispatcher { | ||
private NetworkDispatcher() { | ||
// nothing to do | ||
} | ||
|
||
private static final String PROTOCOL_VERSION = "1"; | ||
|
||
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(Pylons.MODID, "main"), | ||
() -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); | ||
|
||
public static void register() { | ||
int packetIndex = 0; | ||
INSTANCE.registerMessage(packetIndex++, PacketButtonClicked.class, PacketButtonClicked::toBytes, PacketButtonClicked::new, PacketButtonClicked::handle); | ||
|
||
Pylons.LOGGER.info("Registered {} network packets", packetIndex); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/net/permutated/pylons/network/PacketButtonClicked.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.permutated.pylons.network; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraftforge.network.NetworkEvent; | ||
import net.permutated.pylons.tile.AbstractPylonTile; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
public class PacketButtonClicked { | ||
private final BlockPos blockPos; | ||
|
||
public PacketButtonClicked(BlockPos blockPos) { | ||
this.blockPos = blockPos; | ||
} | ||
|
||
public PacketButtonClicked(FriendlyByteBuf buffer) { | ||
blockPos = buffer.readBlockPos(); | ||
} | ||
|
||
public void toBytes(FriendlyByteBuf buffer) { | ||
buffer.writeBlockPos(this.blockPos); | ||
} | ||
|
||
@SuppressWarnings("java:S1172") | ||
public static void handle(PacketButtonClicked event, Supplier<NetworkEvent.Context> ctx) { | ||
ctx.get().enqueueWork(() -> { | ||
Optional<Player> player = Optional.ofNullable(ctx.get().getSender()); | ||
Optional<Level> world = player.map(Player::getCommandSenderWorld); | ||
|
||
if (player.isPresent() && world.get() instanceof ServerLevel serverLevel && serverLevel.isLoaded(event.blockPos)) { | ||
var be = serverLevel.getBlockEntity(event.blockPos); | ||
if (be instanceof AbstractPylonTile pylonTile) { | ||
pylonTile.handleRangePacket(); | ||
} | ||
} | ||
}); | ||
ctx.get().setPacketHandled(true); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/net/permutated/pylons/network/package-info.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,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
package net.permutated.pylons.network; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
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.