Search in sources :

Example 11 with BlockStorage

use of com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage in project Geyser by GeyserMC.

the class GeyserSpigot1_12WorldManager method getBlockNetworkId.

@Override
@SuppressWarnings("deprecation")
public int getBlockNetworkId(Player player, Block block, int x, int y, int z) {
    // Get block entity storage
    BlockStorage storage = Via.getManager().getConnectionManager().getConnectedClient(player.getUniqueId()).get(BlockStorage.class);
    // Black magic that gets the old block state ID
    int oldBlockId = (block.getType().getId() << 4) | (block.getData() & 0xF);
    return getLegacyBlock(storage, oldBlockId, x, y, z);
}
Also used : BlockStorage(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage)

Example 12 with BlockStorage

use of com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage in project ViaVersion by ViaVersion.

the class BannerHandler method transform.

@Override
public int transform(UserConnection user, CompoundTag tag) {
    BlockStorage storage = user.get(BlockStorage.class);
    Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z")));
    if (!storage.contains(position)) {
        Via.getPlatform().getLogger().warning("Received an banner color update packet, but there is no banner! O_o " + tag);
        return -1;
    }
    int blockId = storage.get(position).getOriginal();
    Tag base = tag.get("Base");
    int color = 0;
    if (base != null) {
        color = ((NumberTag) tag.get("Base")).asInt();
    }
    // Standing banner
    if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
        blockId += ((15 - color) * 16);
    // Wall banner
    } else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) {
        blockId += ((15 - color) * 4);
    } else {
        Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
    }
    if (tag.get("Patterns") instanceof ListTag) {
        for (Tag pattern : (ListTag) tag.get("Patterns")) {
            if (pattern instanceof CompoundTag) {
                Tag c = ((CompoundTag) pattern).get("Color");
                if (c instanceof IntTag) {
                    // Invert color id
                    ((IntTag) c).setValue(15 - (int) c.getValue());
                }
            }
        }
    }
    Tag name = tag.get("CustomName");
    if (name instanceof StringTag) {
        ((StringTag) name).setValue(ChatRewriter.legacyTextToJsonString(((StringTag) name).getValue()));
    }
    return blockId;
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) BlockStorage(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage) Position(com.viaversion.viaversion.api.minecraft.Position) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag)

Example 13 with BlockStorage

use of com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage in project ViaVersion by ViaVersion.

the class SkullHandler method transform.

@Override
public int transform(UserConnection user, CompoundTag tag) {
    BlockStorage storage = user.get(BlockStorage.class);
    Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z")));
    if (!storage.contains(position)) {
        Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag);
        return -1;
    }
    int id = storage.get(position).getOriginal();
    if (id >= SKULL_WALL_START && id <= SKULL_END) {
        Tag skullType = tag.get("SkullType");
        if (skullType != null) {
            id += ((NumberTag) tag.get("SkullType")).asInt() * 20;
        }
        if (tag.contains("Rot")) {
            id += ((NumberTag) tag.get("Rot")).asInt();
        }
    } else {
        Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag);
        return -1;
    }
    return id;
}
Also used : BlockStorage(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage) Position(com.viaversion.viaversion.api.minecraft.Position) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag)

Example 14 with BlockStorage

use of com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage in project DirtMultiversion by DirtPowered.

the class ProtocolBeta17to14 method onConnect.

@Override
public void onConnect(ServerSession session) {
    ProtocolStorage storage = session.getStorage();
    storage.set(BlockStorage.class, new BlockStorage(MinecraftVersion.B1_7_3));
    storage.set(PlayerTabListCache.class, new PlayerTabListCache());
    storage.set(KeepAliveTask.class, new KeepAliveTask(session));
    storage.set(PlayerHealthTracker.class, new PlayerHealthTracker());
    session.broadcastPacket(createTabEntryPacket(session.getUserData().getUsername(), true), getFrom());
}
Also used : BlockStorage(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage) ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) KeepAliveTask(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.other.KeepAliveTask) PlayerHealthTracker(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.other.PlayerHealthTracker)

Example 15 with BlockStorage

use of com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage in project DirtMultiversion by DirtPowered.

the class RotationUtil method fixBlockRotation.

public static byte fixBlockRotation(ServerSession session, int startX, int startY, int startZ) {
    BlockStorage blockStorage = session.getUserData().getProtocolStorage().get(BlockStorage.class);
    byte blockData = 3;
    if (blockStorage == null) {
        return blockData;
    }
    int rot1 = blockStorage.getBlockAt(startX, startY, startZ - 1);
    int rot2 = blockStorage.getBlockAt(startX, startY, startZ + 1);
    int rot3 = blockStorage.getBlockAt(startX - 1, startY, startZ);
    int rot4 = blockStorage.getBlockAt(startX + 1, startY, startZ);
    int rot5;
    if (rot3 == CHEST_BLOCK) {
        rot5 = blockStorage.getBlockAt(startX - 1, startY, startZ - 1);
    } else {
        rot5 = blockStorage.getBlockAt(startX + 1, startY, startZ - 1);
    }
    int rot6;
    if (rot3 == CHEST_BLOCK) {
        rot6 = blockStorage.getBlockAt(startX - 1, startY, startZ + 1);
    } else {
        rot6 = blockStorage.getBlockAt(startX + 1, startY, startZ + 1);
    }
    if (rot1 != CHEST_BLOCK && rot2 != CHEST_BLOCK) {
        if (rot3 != CHEST_BLOCK && rot4 != CHEST_BLOCK) {
            if (SolidBlockList.isSolid(rot2) && !SolidBlockList.isSolid(rot1)) {
                blockData = 2;
            }
            if (SolidBlockList.isSolid(rot3) && !SolidBlockList.isSolid(rot4)) {
                blockData = 5;
            }
            if (SolidBlockList.isSolid(rot4) && !SolidBlockList.isSolid(rot3)) {
                blockData = 4;
            }
        } else {
            if (SolidBlockList.isSolid(rot2) || SolidBlockList.isSolid(rot6)) {
                if (!SolidBlockList.isSolid(rot1) && !SolidBlockList.isSolid(rot5)) {
                    blockData = 2;
                }
            }
        }
    } else {
        blockData = 5;
        if (rot1 == CHEST_BLOCK) {
            rot5 = blockStorage.getBlockAt(startX - 1, startY, startZ - 1);
        } else {
            rot5 = blockStorage.getBlockAt(startX - 1, startY, startZ + 1);
        }
        if (rot1 == CHEST_BLOCK) {
            rot6 = blockStorage.getBlockAt(startX + 1, startY, startZ - 1);
        } else {
            rot6 = blockStorage.getBlockAt(startX + 1, startY, startZ + 1);
        }
        if (SolidBlockList.isSolid(rot4) || SolidBlockList.isSolid(rot6)) {
            if (!SolidBlockList.isSolid(rot3) && !SolidBlockList.isSolid(rot5)) {
                blockData = 4;
            }
        }
    }
    return blockData;
}
Also used : BlockStorage(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage)

Aggregations

BlockStorage (com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage)9 BlockStorage (com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage)7 ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)6 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)4 BlockLocation (com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation)4 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)4 ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)4 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)4 NumberTag (com.github.steveice10.opennbt.tag.builtin.NumberTag)4 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)4 Position (com.viaversion.viaversion.api.minecraft.Position)4 ArrayList (java.util.ArrayList)4 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)3 V1_2Chunk (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2Chunk)3 V1_2MultiBlockArray (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2MultiBlockArray)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInput (java.io.DataInput)3 DataInputStream (java.io.DataInputStream)3 IOException (java.io.IOException)3 List (java.util.List)3