use of com.nukkitx.math.vector.Vector3i in project Geyser by GeyserMC.
the class BlockInventoryHolder method prepareInventory.
@Override
public void prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
// (This could be a virtual inventory that the player is opening)
if (checkInteractionPosition(session)) {
// Then, check to see if the interacted block is valid for this inventory by ensuring the block state identifier is valid
int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
if (isValidBlock(javaBlockString)) {
// We can safely use this block
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
setCustomName(session, session.getLastInteractionBlockPosition(), inventory, javaBlockId);
return;
}
}
// Otherwise, time to conjure up a fake block!
Vector3i position = session.getPlayerEntity().getPosition().toInt();
position = position.add(Vector3i.UP);
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(position);
blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState));
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket);
inventory.setHolderPosition(position);
setCustomName(session, position, inventory, defaultJavaBlockState);
}
use of com.nukkitx.math.vector.Vector3i in project Geyser by GeyserMC.
the class BedrockBlockPickRequestTranslator method translate.
@Override
public void translate(GeyserSession session, BlockPickRequestPacket packet) {
Vector3i vector = packet.getBlockPosition();
int blockToPick = session.getGeyser().getWorldManager().getBlockAt(session, vector.getX(), vector.getY(), vector.getZ());
// Block is air - chunk caching is probably off
if (blockToPick == BlockStateValues.JAVA_AIR_ID) {
// Check for an item frame since the client thinks that's a block when it's an entity in Java
ItemFrameEntity entity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
if (entity != null) {
// Check to see if the item frame has an item in it first
if (entity.getHeldItem() != null && entity.getHeldItem().getId() != 0) {
// Grab the item in the frame
InventoryUtils.findOrCreateItem(session, entity.getHeldItem());
} else {
// Grab the frame as the item
InventoryUtils.findOrCreateItem(session, entity.getDefinition() == EntityDefinitions.GLOW_ITEM_FRAME ? "minecraft:glow_item_frame" : "minecraft:item_frame");
}
}
return;
}
InventoryUtils.findOrCreateItem(session, BlockRegistries.JAVA_BLOCKS.get(blockToPick).getPickItem());
}
use of com.nukkitx.math.vector.Vector3i in project Protocol by CloudburstMC.
the class StructureBlockUpdateSerializer_v340 method serialize.
@Override
public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StructureBlockUpdatePacket packet) {
StructureEditorData editorData = packet.getEditorData();
StructureSettings settings = editorData.getSettings();
helper.writeBlockPosition(buffer, packet.getBlockPosition());
VarInts.writeUnsignedInt(buffer, editorData.getType().ordinal());
// Structure Editor Data start
helper.writeString(buffer, editorData.getName());
helper.writeString(buffer, editorData.getName());
helper.writeBlockPosition(buffer, settings.getOffset());
helper.writeBlockPosition(buffer, settings.getSize());
buffer.writeBoolean(!settings.isIgnoringEntities());
buffer.writeBoolean(settings.isIgnoringBlocks());
buffer.writeBoolean(editorData.isIncludingPlayers());
// show air
buffer.writeBoolean(false);
// Structure Settings start
buffer.writeFloatLE(settings.getIntegrityValue());
VarInts.writeUnsignedInt(buffer, settings.getIntegritySeed());
VarInts.writeUnsignedInt(buffer, settings.getMirror().ordinal());
VarInts.writeUnsignedInt(buffer, settings.getRotation().ordinal());
buffer.writeBoolean(settings.isIgnoringEntities());
// ignore structure blocks
buffer.writeBoolean(true);
Vector3i min = packet.getBlockPosition().add(settings.getOffset());
helper.writeVector3i(buffer, min);
Vector3i max = min.add(settings.getSize());
helper.writeVector3i(buffer, max);
// Structure Settings end
// Structure Editor Data end
buffer.writeBoolean(editorData.isBoundingBoxVisible());
buffer.writeBoolean(packet.isPowered());
}
use of com.nukkitx.math.vector.Vector3i in project Protocol by CloudburstMC.
the class BedrockPacketHelper_v440 method readStructureSettings.
@Override
public StructureSettings readStructureSettings(ByteBuf buffer) {
String paletteName = this.readString(buffer);
boolean ignoringEntities = buffer.readBoolean();
boolean ignoringBlocks = buffer.readBoolean();
Vector3i size = this.readBlockPosition(buffer);
Vector3i offset = this.readBlockPosition(buffer);
long lastEditedByEntityId = VarInts.readLong(buffer);
StructureRotation rotation = StructureRotation.from(buffer.readByte());
StructureMirror mirror = StructureMirror.from(buffer.readByte());
StructureAnimationMode animationMode = StructureAnimationMode.from(buffer.readUnsignedByte());
float animationSeconds = buffer.readFloatLE();
float integrityValue = buffer.readFloatLE();
int integritySeed = buffer.readIntLE();
Vector3f pivot = this.readVector3f(buffer);
return new StructureSettings(paletteName, ignoringEntities, ignoringBlocks, size, offset, lastEditedByEntityId, rotation, mirror, animationMode, animationSeconds, integrityValue, integritySeed, pivot);
}
use of com.nukkitx.math.vector.Vector3i in project Protocol by CloudburstMC.
the class BedrockPacketHelper_v388 method readStructureSettings.
@Override
public StructureSettings readStructureSettings(ByteBuf buffer) {
String paletteName = this.readString(buffer);
boolean ignoringEntities = buffer.readBoolean();
boolean ignoringBlocks = buffer.readBoolean();
Vector3i size = this.readBlockPosition(buffer);
Vector3i offset = this.readBlockPosition(buffer);
long lastEditedByEntityId = VarInts.readLong(buffer);
StructureRotation rotation = StructureRotation.from(buffer.readByte());
StructureMirror mirror = StructureMirror.from(buffer.readByte());
float integrityValue = buffer.readFloatLE();
int integritySeed = buffer.readIntLE();
Vector3f pivot = this.readVector3f(buffer);
return new StructureSettings(paletteName, ignoringEntities, ignoringBlocks, size, offset, lastEditedByEntityId, rotation, mirror, StructureAnimationMode.NONE, 0, integrityValue, integritySeed, pivot);
}
Aggregations