Java Code Examples for com.nukkitx.protocol.bedrock.data.ItemData#getId()
The following examples show how to use
com.nukkitx.protocol.bedrock.data.ItemData#getId() .
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: DownstreamPacketHandler.java From ProxyPass with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean handle(InventoryContentPacket packet) { if (packet.getContainerId() == ContainerId.CREATIVE) { List<CreativeItemEntry> entries = new ArrayList<>(); for (ItemData data : packet.getContents()) { int id = data.getId(); Integer damage = data.getDamage() == 0 ? null : (int) data.getDamage(); CompoundTag tag = data.getTag(); String tagData = null; if (tag != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (NBTOutputStream stream = new NBTOutputStream(new LittleEndianDataOutputStream(byteArrayOutputStream))) { stream.write(tag); } catch (IOException e) { throw new RuntimeException(e); } tagData = Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()); } entries.add(new CreativeItemEntry(id, damage, tagData)); } CreativeItems items = new CreativeItems(entries); proxy.saveJson("creative_items.json", items); } return false; }
Example 2
Source File: JavaSpawnParticleTranslator.java From Geyser with MIT License | 4 votes |
@Override public void translate(ServerSpawnParticlePacket packet, GeyserSession session) { LevelEventPacket particle = new LevelEventPacket(); switch (packet.getParticle().getType()) { case BLOCK: particle.setType(LevelEventType.DESTROY); particle.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())); particle.setData(BlockTranslator.getBedrockBlockId(((BlockParticleData) packet.getParticle().getData()).getBlockState())); session.sendUpstreamPacket(particle); break; case FALLING_DUST: //In fact, FallingDustParticle should have data like DustParticle, //but in MCProtocol, its data is BlockState(1). particle.setType(LevelEventType.PARTICLE_FALLING_DUST); particle.setData(BlockTranslator.getBedrockBlockId(((FallingDustParticleData)packet.getParticle().getData()).getBlockState())); particle.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())); session.sendUpstreamPacket(particle); break; case ITEM: ItemStack javaItem = ((ItemParticleData)packet.getParticle().getData()).getItemStack(); ItemData bedrockItem = ItemTranslator.translateToBedrock(session, javaItem); int id = bedrockItem.getId(); short damage = bedrockItem.getDamage(); particle.setType(LevelEventType.PARTICLE_ITEM_BREAK); particle.setData(id << 16 | damage); particle.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())); session.sendUpstreamPacket(particle); break; case DUST: DustParticleData data = (DustParticleData)packet.getParticle().getData(); int r = (int) (data.getRed()*255); int g = (int) (data.getGreen()*255); int b = (int) (data.getBlue()*255); particle.setType(LevelEventType.PARTICLE_FALLING_DUST); particle.setData(((0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)); particle.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())); session.sendUpstreamPacket(particle); break; default: LevelEventType typeParticle = EffectRegistry.getParticleLevelEventType(packet.getParticle().getType()); if (typeParticle != null) { particle.setType(typeParticle); particle.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())); session.sendUpstreamPacket(particle); } else { String stringParticle = EffectRegistry.getParticleString(packet.getParticle().getType()); if (stringParticle != null) { SpawnParticleEffectPacket stringPacket = new SpawnParticleEffectPacket(); stringPacket.setIdentifier(stringParticle); stringPacket.setDimensionId(session.getPlayerEntity().getDimension()); stringPacket.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())); session.sendUpstreamPacket(stringPacket); } } break; } }