net.minecraft.network.PacketByteBuf Java Examples
The following examples show how to use
net.minecraft.network.PacketByteBuf.
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: MixinClientChunkManager.java From multiconnect with MIT License | 6 votes |
@Inject(method = "loadChunkFromPacket", at = @At("RETURN")) private void onLoadChunkFromPacket(int x, int z, BiomeArray biomes, PacketByteBuf buf, CompoundTag heightmaps, int verticalStripBitmask, boolean bl, CallbackInfoReturnable<WorldChunk> ci) { if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) { if (ci.getReturnValue() != null) { synchronized (LOCK) { UpgradeData upgradeData = ChunkUpgrader.fixChunk(ci.getReturnValue()); ((IUpgradableChunk) ci.getReturnValue()).multiconnect_setClientUpgradeData(upgradeData); for (int dx = -1; dx <= 1; dx++) { for (int dz = -1; dz <= 1; dz++) { WorldChunk chunk = getChunk(x + dx, z + dz, ChunkStatus.FULL, false); if (chunk != null) ((IUpgradableChunk) chunk).multiconnect_onNeighborLoaded(); } } } } } }
Example #2
Source File: MachineHandledScreen.java From Galacticraft-Rewoven with MIT License | 5 votes |
private void sendRedstoneUpdate(ConfigurableElectricMachineBlockEntity entity) { MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CustomPayloadC2SPacket(new Identifier(Constants.MOD_ID, "redstone_update"), new PacketByteBuf(Unpooled.buffer()) .writeBlockPos(pos) .writeEnumConstant(entity.getRedstoneState()) )); }
Example #3
Source File: MixinCustomPayload_NetworkHandler.java From Galaxy with GNU Affero General Public License v3.0 | 5 votes |
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true) private void onCustomPayload(CustomPayloadC2SPacket packet, CallbackInfo info) { Main main = Main.Companion.getMain(); if (main == null) return; Identifier channel = ((CustomPayloadC2SPacketAccessor) packet).getChannel(); PacketByteBuf buff = ((CustomPayloadC2SPacketAccessor) packet).getData(); main.getEventManager().emit(new PacketReceiveEvent(channel, buff, player)); }
Example #4
Source File: MixinPacketInflater.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
@Inject(at = @At("HEAD"), method = "decode(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;Ljava/util/List;)V", cancellable = true) protected void decode(ChannelHandlerContext channelHandlerContext_1, ByteBuf byteBuf_1, List<Object> list_1, CallbackInfo info) throws Exception { if (!ModuleManager.getModule(AntiChunkBan.class).isToggled()) return; info.cancel(); if (byteBuf_1.readableBytes() != 0) { PacketByteBuf packetByteBuf_1 = new PacketByteBuf(byteBuf_1); int int_1 = packetByteBuf_1.readVarInt(); if (int_1 == 0) { list_1.add(packetByteBuf_1.readBytes(packetByteBuf_1.readableBytes())); } else { if (int_1 > 51200000) { throw new DecoderException("Badly compressed packet - size of " + (int_1 / 1000000) + "MB is larger than protocol maximum of 50 MB"); } byte[] bytes_1 = new byte[packetByteBuf_1.readableBytes()]; packetByteBuf_1.readBytes(bytes_1); this.inflater.setInput(bytes_1); byte[] bytes_2 = new byte[int_1]; this.inflater.inflate(bytes_2); list_1.add(Unpooled.wrappedBuffer(bytes_2)); this.inflater.reset(); } } }
Example #5
Source File: ChunkData.java From multiconnect with MIT License | 5 votes |
public static int skipPalette(PacketByteBuf buf) { int paletteSize = buf.readByte(); if (paletteSize <= 8) { // array and bimap palette data look the same enough to use the same code here int size = buf.readVarInt(); for (int i = 0; i < size; i++) buf.readVarInt(); // state id } return paletteSize; }
Example #6
Source File: MixinDecoderHandler.java From multiconnect with MIT License | 5 votes |
@ModifyVariable(method = "decode", ordinal = 0, at = @At(value = "STORE", ordinal = 0)) private PacketByteBuf transformPacketByteBuf(PacketByteBuf buf) { if (side == NetworkSide.CLIENTBOUND) buf = new TransformerByteBuf(buf, context.get()); context.set(null); return buf; }
Example #7
Source File: MixinEncoderHandler.java From multiconnect with MIT License | 5 votes |
@ModifyVariable(method = "encode", ordinal = 0, at = @At(value = "STORE", ordinal = 0)) private PacketByteBuf transformPacketByteBuf(PacketByteBuf buf) { if (side == NetworkSide.SERVERBOUND) buf = new TransformerByteBuf(buf, context.get()); context.set(null); this.buf.set(buf); return buf; }
Example #8
Source File: Protocol_1_12_2.java From multiconnect with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Override public <T> T readTrackedData(TrackedDataHandler<T> handler, PacketByteBuf buf) { if (handler == TrackedDataHandlerRegistry.OPTIONAL_BLOCK_STATE) { int stateId = buf.readVarInt(); if (stateId == 0) return (T) Optional.empty(); return (T) Optional.ofNullable(Block.STATE_IDS.get(Blocks_1_12_2.convertToStateRegistryId(stateId))); } return super.readTrackedData(handler, buf); }
Example #9
Source File: MixinClientChunkManager.java From multiconnect with MIT License | 5 votes |
@Inject(method = "loadChunkFromPacket", at = @At("RETURN")) private void onLoadChunkFromPacket(int x, int z, BiomeArray biomeArray, PacketByteBuf buf, CompoundTag heightmaps, int verticalStripMask, boolean bl, CallbackInfoReturnable<WorldChunk> ci) { if (ConnectionInfo.protocolVersion <= Protocols.V1_14_4) { if (ci.getReturnValue() != null) { Biome[] biomeData = PendingBiomeData.getPendingBiomeData(x, z); if (biomeData != null) { ((IBiomeStorage_1_14_4) ci.getReturnValue()).multiconnect_setBiomeArray_1_14_4(biomeData); PendingBiomeData.setPendingBiomeData(x, z, null); } } } }
Example #10
Source File: MixinClientPlayNetworkHandler.java From multiconnect with MIT License | 5 votes |
@Inject(method = "onCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER), cancellable = true) private void onOnCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) { if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2) { Identifier channel = packet.getChannel(); if (Protocol_1_13_2.CUSTOM_PAYLOAD_TRADE_LIST.equals(channel)) { PacketByteBuf buf = packet.getData(); int syncId = buf.readInt(); TraderOfferList trades = new TraderOfferList(); int tradeCount = buf.readUnsignedByte(); for (int i = 0; i < tradeCount; i++) { ItemStack buy = buf.readItemStack(); ItemStack sell = buf.readItemStack(); boolean hasSecondItem = buf.readBoolean(); ItemStack secondBuy = hasSecondItem ? buf.readItemStack() : ItemStack.EMPTY; boolean locked = buf.readBoolean(); int tradeUses = buf.readInt(); int maxTradeUses = buf.readInt(); TradeOffer trade = new TradeOffer(buy, secondBuy, sell, tradeUses, maxTradeUses, 0, 1); if (locked) trade.clearUses(); trades.add(trade); } onSetTradeOffers(new SetTradeOffersS2CPacket(syncId, trades, 5, 0, false, false)); ci.cancel(); } else if (Protocol_1_13_2.CUSTOM_PAYLOAD_OPEN_BOOK.equals(channel)) { OpenWrittenBookS2CPacket openBookPacket = new OpenWrittenBookS2CPacket(); try { openBookPacket.read(packet.getData()); } catch (IOException e) { LOGGER.error("Failed to read open book packet", e); } onOpenWrittenBook(openBookPacket); ci.cancel(); } } }
Example #11
Source File: MixinClientChunkManager.java From multiconnect with MIT License | 5 votes |
@Inject(method = "loadChunkFromPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/WorldChunk;getSectionArray()[Lnet/minecraft/world/chunk/ChunkSection;")) private void recalculateHeightmaps(int x, int z, BiomeArray biomeArray, PacketByteBuf buf, CompoundTag tag, int verticalStripMask, boolean bl, CallbackInfoReturnable<WorldChunk> ci) { if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2) { WorldChunk chunk = this.chunk.get(); for (ChunkSection section : chunk.getSectionArray()) { if (section != null) { section.calculateCounts(); } } Heightmap.populateHeightmaps(chunk, CLIENT_HEIGHTMAPS); } this.chunk.set(null); }
Example #12
Source File: GuiOpenS2CPacket_1_13_2.java From multiconnect with MIT License | 5 votes |
@Override public void read(PacketByteBuf buf) { syncId = buf.readUnsignedByte(); type = buf.readString(32); title = buf.readText(); slotCount = buf.readUnsignedByte(); if (type.equals("EntityHorse")) horseId = buf.readInt(); }
Example #13
Source File: PlaceRecipeC2SPacket_1_12.java From multiconnect with MIT License | 5 votes |
private void writeTransactions(PacketByteBuf buf, List<Transaction> transactions) { buf.writeShort(transactions.size()); for (Transaction transaction : transactions) { buf.writeItemStack(transaction.stack); buf.writeByte(transaction.craftingSlot); buf.writeByte(transaction.invSlot); } }
Example #14
Source File: PlaceRecipeC2SPacket_1_12.java From multiconnect with MIT License | 5 votes |
@Override public void write(PacketByteBuf buf) { buf.writeByte(syncId); buf.writeShort(transactionId); writeTransactions(buf, transactionsFromMatrix); writeTransactions(buf, transactionsToMatrix); }
Example #15
Source File: MixinTradeOfferList.java From multiconnect with MIT License | 5 votes |
@Redirect(method = "fromPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;readInt()I", ordinal = 4)) private static int redirectReadDemandBonus(PacketByteBuf buf) { if (ConnectionInfo.protocolVersion <= Protocols.V1_14_3) return 0; else return buf.readInt(); }
Example #16
Source File: EntitySpawnGlobalS2CPacket_1_15_2.java From multiconnect with MIT License | 5 votes |
@Override public void read(PacketByteBuf buf) { buf.readVarInt(); // id entityTypeId = buf.readByte(); x = buf.readDouble(); y = buf.readDouble(); z = buf.readDouble(); }
Example #17
Source File: MachineHandledScreen.java From Galacticraft-Rewoven with MIT License | 5 votes |
private void sendSecurityUpdate(ConfigurableElectricMachineBlockEntity entity) { if (this.playerInventory.player.getUuid().equals(entity.getSecurity().getOwner()) || !entity.getSecurity().hasOwner()) { MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CustomPayloadC2SPacket(new Identifier(Constants.MOD_ID, "security_update"), new PacketByteBuf(Unpooled.buffer()) .writeBlockPos(pos) .writeEnumConstant(entity.getSecurity().getPublicity()) )); } else { Galacticraft.logger.error("Tried to send security update when not the owner!"); } }
Example #18
Source File: PlayerInventoryScreenMixin.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true) public void mouseClicked(double mouseX, double mouseY, int button, CallbackInfoReturnable<Boolean> ci) { if (PlayerInventoryGCScreen.isCoordinateBetween((int) Math.floor(mouseX), x + 30, x + 59) && PlayerInventoryGCScreen.isCoordinateBetween((int) Math.floor(mouseY), y - 26, y)) { this.client.getNetworkHandler().sendPacket(new CustomPayloadC2SPacket(new Identifier(Constants.MOD_ID, "open_gc_inv"), new PacketByteBuf(Unpooled.buffer(0)))); } }
Example #19
Source File: FabricationRecipeSerializer.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public T read(Identifier id, PacketByteBuf packet) { String string_1 = packet.readString(32767); Ingredient ingredient_1 = Ingredient.fromPacket(packet); ItemStack itemStack_1 = packet.readItemStack(); return this.recipeFactory.create(id, string_1, ingredient_1, itemStack_1); }
Example #20
Source File: ShapelessCompressingRecipeSerializer.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public T read(Identifier id, PacketByteBuf packet) { // String group = packet.readString(32767); int ingredientCount = packet.readVarInt(); DefaultedList<Ingredient> ingredients = DefaultedList.ofSize(ingredientCount, Ingredient.EMPTY); for (int index = 0; index < ingredients.size(); ++index) { ingredients.set(index, Ingredient.fromPacket(packet)); } ItemStack result = packet.readItemStack(); return factory.create(id, /*group, */result, ingredients); }
Example #21
Source File: ShapelessCompressingRecipeSerializer.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public void write(PacketByteBuf packet, ShapelessCompressingRecipe recipe) { // packet.writeString(recipe.group); packet.writeVarInt(recipe.getInput().size()); for (Ingredient ingredient : recipe.getInput()) { ingredient.write(packet); } packet.writeItemStack(recipe.getOutput()); }
Example #22
Source File: ShapedCompressingRecipeSerializer.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public void write(PacketByteBuf packet, T recipe) { packet.writeVarInt(recipe.getWidth()); packet.writeVarInt(recipe.getHeight()); packet.writeString(recipe.group); for (Ingredient ingredient_1 : recipe.getIngredients()) { ingredient_1.write(packet); } packet.writeItemStack(recipe.getOutput()); }
Example #23
Source File: ShapedCompressingRecipeSerializer.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public T read(Identifier identifier_1, PacketByteBuf packet) { int int_1 = packet.readVarInt(); int int_2 = packet.readVarInt(); String group = packet.readString(32767); DefaultedList<Ingredient> defaultedList_1 = DefaultedList.ofSize(int_1 * int_2, Ingredient.EMPTY); for (int int_3 = 0; int_3 < defaultedList_1.size(); ++int_3) { defaultedList_1.set(int_3, Ingredient.fromPacket(packet)); } ItemStack itemStack_1 = packet.readItemStack(); return factory.create(identifier_1, group, int_1, int_2, defaultedList_1, itemStack_1); }
Example #24
Source File: MixinChunkDataS2C.java From multiconnect with MIT License | 4 votes |
@Inject(method = "getReadBuffer", at = @At("RETURN"), cancellable = true) private void onGetReadBuffer(CallbackInfoReturnable<PacketByteBuf> ci) { TransformerByteBuf transformerByteBuf = new TransformerByteBuf(ci.getReturnValue(), null); transformerByteBuf.readTopLevelType(ChunkData.class); ci.setReturnValue(transformerByteBuf); }
Example #25
Source File: MixinDecoderHandler.java From multiconnect with MIT License | 4 votes |
@Inject(method = "decode", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Packet;read(Lnet/minecraft/network/PacketByteBuf;)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD) private void postDecode(ChannelHandlerContext context, ByteBuf buf, List<Object> output, CallbackInfo ci, PacketByteBuf packetBuf, int packetId, Packet<?> packet) { if (!((TransformerByteBuf) packetBuf).canDecodeAsync(packet.getClass())) { ConnectionInfo.resourceReloadLock.readLock().unlock(); } }
Example #26
Source File: MixinDataTracker.java From multiconnect with MIT License | 4 votes |
@Redirect(method = "entryFromPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/data/TrackedDataHandler;read(Lnet/minecraft/network/PacketByteBuf;)Ljava/lang/Object;")) private static <T> T read(TrackedDataHandler<T> handler, PacketByteBuf buf) { return ConnectionInfo.protocol.readTrackedData(handler, buf); }
Example #27
Source File: MixinDataTracker.java From multiconnect with MIT License | 4 votes |
@Inject(method = "writeEntryToPacket", at = @At("HEAD"), cancellable = true) private static <T> void onWriteEntryToPacket(PacketByteBuf buf, DataTracker.Entry<T> entry, CallbackInfo ci) { if (entry.getData().getId() < 0) ci.cancel(); }
Example #28
Source File: MixinCustomPayloadS2C.java From multiconnect with MIT License | 4 votes |
@Inject(method = "getData", at = @At("RETURN"), cancellable = true) private void onRead(CallbackInfoReturnable<PacketByteBuf> ci) { ci.setReturnValue(new TransformerByteBuf(ci.getReturnValue(), null).readTopLevelType(CustomPayload.class)); }
Example #29
Source File: CustomPayloadC2SPacket_1_12_2.java From multiconnect with MIT License | 4 votes |
@Override public void write(PacketByteBuf buf) { buf.writeString(channel); buf.writeBytes(data); }
Example #30
Source File: CustomPayloadC2SPacket_1_12_2.java From multiconnect with MIT License | 4 votes |
@Override public void read(PacketByteBuf buf) { throw new UnsupportedOperationException(); }