net.minecraftforge.fml.network.NetworkDirection Java Examples

The following examples show how to use net.minecraftforge.fml.network.NetworkDirection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemBreakingTracker.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void onItemBroken(PlayerEntity player, ItemStack stack)
{
    int scrappingLevel = EnchantmentHelper.getEnchantmentLevel(SurvivalistMod.SCRAPING.get(), stack);

    if (player.getClass().getName().equals("com.rwtema.extrautils2.fakeplayer.XUFakePlayer"))
        return;

    boolean fortune = rnd.nextDouble() > 0.9 / (1 + scrappingLevel);

    ItemStack ret = null;

    for (Triple<ItemStack, ItemStack, ItemStack> scraping : scrapingRegistry)
    {
        ItemStack source = scraping.getLeft();

        if (source.getItem() != stack.getItem())
            continue;

        ItemStack good = scraping.getMiddle();
        ItemStack bad = scraping.getRight();

        ret = fortune ? good.copy() : bad.copy();

        break;
    }

    if (ret != null)
    {
        SurvivalistMod.LOGGER.debug("Item broke (" + stack + ") and the player got " + ret + " in return!");

        SurvivalistMod.channel.sendTo(new ScrapingMessage(stack, ret), ((ServerPlayerEntity) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT);

        ItemHandlerHelper.giveItemToPlayer(player, ret);
    }
}
 
Example #2
Source File: PacketHandler.java    From MiningGadgets with MIT License 5 votes vote down vote up
public static void sendToAll(Object msg, World world) {
    //Todo Maybe only send to nearby players?
    for (PlayerEntity player : world.getPlayers()) {
        if (!(player instanceof FakePlayer))
            HANDLER.sendTo(msg, ((ServerPlayerEntity) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT);
    }
}
 
Example #3
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public IPacket<?> toPacket(NetworkDirection direction, int index) {
    if (incoming()) {
        throw new IllegalStateException("Tried to write an incoming packet");
    }
    return direction.buildPacket(Pair.of(toPacketBuffer(), index), channel).getThis();
}
 
Example #4
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public void sendToServer() {
    sendToServer(toPacket(NetworkDirection.PLAY_TO_SERVER));
}
 
Example #5
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendToOps() {
    sendToOps(toPacket(NetworkDirection.PLAY_TO_CLIENT));
}
 
Example #6
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendToChunk(World world, ChunkPos pos) {
    sendToChunk(toPacket(NetworkDirection.PLAY_TO_CLIENT), world, pos);
}
 
Example #7
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendToChunk(World world, int chunkX, int chunkZ) {
    sendToChunk(toPacket(NetworkDirection.PLAY_TO_CLIENT), world, chunkX, chunkZ);
}
 
Example #8
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendToChunk(World world, BlockPos blockPos) {
    sendToChunk(toPacket(NetworkDirection.PLAY_TO_CLIENT), world, blockPos);
}
 
Example #9
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendToDimension(DimensionType dim) {
    sendToDimension(toPacket(NetworkDirection.PLAY_TO_CLIENT), dim);
}
 
Example #10
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendPacketToAllAround(double x, double y, double z, double range, DimensionType dim) {
    sendToAllAround(toPacket(NetworkDirection.PLAY_TO_CLIENT), x, y, z, range, dim);
}
 
Example #11
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendToClients() {
    sendToClients(toPacket(NetworkDirection.PLAY_TO_CLIENT));
}
 
Example #12
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void sendToPlayer(ServerPlayerEntity player) {
    sendToPlayer(toPacket(NetworkDirection.PLAY_TO_CLIENT), player);
}
 
Example #13
Source File: SimpleChannel.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public <M> void sendToServer(M message) {
	sendTo(message, MinecraftClient.getInstance().getNetworkHandler().getConnection(), NetworkDirection.PLAY_TO_SERVER);
}
 
Example #14
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public IPacket<?> toPacket(NetworkDirection direction) {
    return toPacket(direction, 0);
}
 
Example #15
Source File: PacketHandler.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static void sendTo(Object msg, ServerPlayerEntity player) {
    if (!(player instanceof FakePlayer))
        HANDLER.sendTo(msg, player.connection.netManager, NetworkDirection.PLAY_TO_CLIENT);
}
 
Example #16
Source File: MixinCustomPayloadC2SPacket.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public NetworkDirection getDirection() {
	return NetworkDirection.PLAY_TO_SERVER;
}
 
Example #17
Source File: MixinLoginQueryRequestS2CPacket.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public NetworkDirection getDirection() {
	return NetworkDirection.LOGIN_TO_CLIENT;
}
 
Example #18
Source File: MixinCustomPayloadS2CPacket.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public NetworkDirection getDirection() {
	return NetworkDirection.PLAY_TO_CLIENT;
}
 
Example #19
Source File: MixinLoginQueryResponseC2SPacket.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public NetworkDirection getDirection() {
	return NetworkDirection.LOGIN_TO_SERVER;
}
 
Example #20
Source File: SimpleChannel.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public <M> Packet<?> toVanillaPacket(M message, NetworkDirection direction) {
	return direction.buildPacket(toBuffer(message), channelName).getThis();
}
 
Example #21
Source File: SimpleChannel.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public <M> void sendTo(M message, ClientConnection connection, NetworkDirection direction) {
	connection.send(toVanillaPacket(message, direction));
}