diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/BlockPosition.java b/src/main/java/de/bixilon/minosoft/game/datatypes/BlockPosition.java index f0dda0b8f..9977d772e 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/BlockPosition.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/BlockPosition.java @@ -50,4 +50,9 @@ public class BlockPosition { public ChunkLocation getChunkLocation() { return new ChunkLocation(getX() / 16, getZ() / 16); } + + @Override + public String toString() { + return String.format("%s %s %s", getX(), getY(), getZ()); + } } diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/Direction.java b/src/main/java/de/bixilon/minosoft/game/datatypes/Direction.java new file mode 100644 index 000000000..0424fd7ec --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/Direction.java @@ -0,0 +1,42 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes; + +public enum Direction { + DOWN(0), + UP(1), + NORTH(2), + SOUTH(3), + WEST(3), + EAST(3); + + final int id; + + Direction(int id) { + this.id = id; + } + + public static Direction byId(int id) { + for (Direction g : values()) { + if (g.getId() == id) { + return g; + } + } + return null; + } + + public int getId() { + return id; + } +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/Slot.java b/src/main/java/de/bixilon/minosoft/game/datatypes/Slot.java new file mode 100644 index 000000000..9a2f299b3 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/Slot.java @@ -0,0 +1,40 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes; + +import net.querz.nbt.io.NamedTag; + +public class Slot { + int itemId; + int itemCount; + NamedTag nbt; + + public Slot(int itemId, int itemCount, NamedTag nbt) { + this.itemId = itemId; + this.itemCount = itemCount; + this.nbt = nbt; + } + + public int getItemId() { + return this.itemId; + } + + public int getItemCount() { + return itemCount; + } + + public NamedTag getNbt() { + return nbt; + } +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/Vector.java b/src/main/java/de/bixilon/minosoft/game/datatypes/Vector.java new file mode 100644 index 000000000..c621fa33b --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/Vector.java @@ -0,0 +1,52 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes; + +public class Vector { + final int x; + final int y; + final int z; + + public Vector(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getZ() { + return z; + } + + @Override + public boolean equals(Object obj) { + if (super.equals(obj)) { + return true; + } + Vector pos = (Vector) obj; + return pos.getX() == getX() && pos.getY() == getY() && pos.getZ() == getZ(); + } + + @Override + public String toString() { + return String.format("%s %s %s", getX(), getY(), getZ()); + } +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Entity.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Entity.java index de394746e..81efc46a0 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Entity.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Entity.java @@ -13,6 +13,8 @@ package de.bixilon.minosoft.game.datatypes.entities; +import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData; + public interface Entity { Mobs getEntityType(); @@ -40,7 +42,7 @@ public interface Entity { float getHeight(); - EntityMetaData getMetaData(); + EntityMetaData getMetaData(); void setMetaData(EntityMetaData data); diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Mobs.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Mobs.java index 38d106fa0..4cbb7077d 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Mobs.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Mobs.java @@ -18,6 +18,7 @@ import de.bixilon.minosoft.game.datatypes.Identifier; public enum Mobs { ZOMBIE(new Identifier("zombie"), 54, Zombie.class), PLAYER(null, 92, OtherPlayer.class); + // ToDo all mobs final Identifier identifier; final int type; diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/OtherPlayer.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/OtherPlayer.java index efe5facc8..dcdd4fb09 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/OtherPlayer.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/OtherPlayer.java @@ -15,6 +15,8 @@ package de.bixilon.minosoft.game.datatypes.entities; import de.bixilon.minosoft.game.datatypes.PlayerPropertyData; +import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData; +import de.bixilon.minosoft.game.datatypes.entities.meta.HumanMetaData; import java.util.UUID; @@ -29,11 +31,11 @@ public class OtherPlayer implements Mob { int pitch; int headYaw; short currentItem; - EntityMetaData metaData; + HumanMetaData metaData; float health; - Status status = Status.STANDING; + Pose status = Pose.STANDING; - public OtherPlayer(int id, String name, UUID uuid, PlayerPropertyData[] properties, Location location, int yaw, int pitch, short currentItem, EntityMetaData metaData) { + public OtherPlayer(int id, String name, UUID uuid, PlayerPropertyData[] properties, Location location, int yaw, int pitch, short currentItem, HumanMetaData metaData) { this.id = id; this.name = name; this.uuid = uuid; @@ -106,44 +108,39 @@ public class OtherPlayer implements Mob { @Override public float getWidth() { switch (status) { - case STANDING: - case SNEAKING: - case GLIDING: - case SWIMMING: + default: return 0.6F; case SLEEPING: return 0.2F; } - return 0; // thanks java for that useless line... } @Override public float getHeight() { switch (status) { - case STANDING: + default: return 1.8F; case SNEAKING: return 1.5F; - case GLIDING: + case FLYING: case SWIMMING: return 0.6F; case SLEEPING: return 0.2F; } - return 0; // thanks java for that useless line... } @Override - public EntityMetaData getMetaData() { + public HumanMetaData getMetaData() { return metaData; } @Override public void setMetaData(EntityMetaData data) { - this.metaData = data; + this.metaData = (HumanMetaData) data; } @Override @@ -177,13 +174,6 @@ public class OtherPlayer implements Mob { return currentItem; } - enum Status { - STANDING, - SNEAKING, - SLEEPING, - GLIDING, - SWIMMING - } @Override public int getHeadYaw() { @@ -194,4 +184,8 @@ public class OtherPlayer implements Mob { public void setHeadYaw(int headYaw) { this.headYaw = headYaw; } + + public Pose getStatus() { + return status; + } } diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/EntityMetaData.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Pose.java similarity index 63% rename from src/main/java/de/bixilon/minosoft/game/datatypes/entities/EntityMetaData.java rename to src/main/java/de/bixilon/minosoft/game/datatypes/entities/Pose.java index 8ba25cdff..abf61c3ec 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/EntityMetaData.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Pose.java @@ -13,27 +13,31 @@ package de.bixilon.minosoft.game.datatypes.entities; -import net.querz.nbt.io.NBTUtil; -import net.querz.nbt.io.NamedTag; +public enum Pose { + STANDING(0), + FLYING(1), + SLEEPING(2), + SWIMMING(3), + SPIN_ATTACK(4), + SNEAKING(5), + DYING(6); -import java.io.IOException; + final int id; -public class EntityMetaData { - NamedTag nbt; - - public EntityMetaData(byte[] nbt) { - try { - this.nbt = NBTUtil.read(new String(nbt)); - } catch (IOException e) { - e.printStackTrace(); - } + Pose(int id) { + this.id = id; } - public EntityMetaData(String nbt) { - try { - this.nbt = NBTUtil.read(nbt); - } catch (IOException e) { - e.printStackTrace(); + public static Pose byId(int id) { + for (Pose g : values()) { + if (g.getId() == id) { + return g; + } } + return null; + } + + public int getId() { + return id; } } diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/RelativeLocation.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/RelativeLocation.java index 15cdad76a..63d02fc2e 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/RelativeLocation.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/RelativeLocation.java @@ -44,4 +44,9 @@ public class RelativeLocation { RelativeLocation that = (RelativeLocation) obj; return that.getX() == getX() && that.getY() == getY() && that.getZ() == getZ(); } + + @Override + public String toString() { + return String.format("%s %s %s", getX(), getY(), getZ()); + } } diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Zombie.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Zombie.java index df52a42ab..cf4799a4a 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Zombie.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Zombie.java @@ -13,6 +13,10 @@ package de.bixilon.minosoft.game.datatypes.entities; +import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData; +import de.bixilon.minosoft.game.datatypes.entities.meta.ZombieMetaData; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; public class Zombie implements Mob { final int id; @@ -21,16 +25,16 @@ public class Zombie implements Mob { int yaw; int pitch; int headYaw; - EntityMetaData metaData; + ZombieMetaData metaData; float health; - public Zombie(int id, Location location, int yaw, int pitch, Velocity velocity, EntityMetaData metaData) { + public Zombie(int id, Location location, int yaw, int pitch, Velocity velocity, InByteBuffer buffer, ProtocolVersion v) { this.id = id; this.location = location; this.yaw = yaw; this.pitch = pitch; this.velocity = velocity; - this.metaData = metaData; + this.metaData = new ZombieMetaData(buffer, v); } @Override @@ -102,13 +106,13 @@ public class Zombie implements Mob { } @Override - public EntityMetaData getMetaData() { + public ZombieMetaData getMetaData() { return metaData; } @Override public void setMetaData(EntityMetaData data) { - this.metaData = data; + this.metaData = (ZombieMetaData) data; } @Override diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/AgeableMetaData.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/AgeableMetaData.java new file mode 100644 index 000000000..eaf1b3f40 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/AgeableMetaData.java @@ -0,0 +1,36 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes.entities.meta; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class AgeableMetaData extends MobMetaData { + + public AgeableMetaData(InByteBuffer buffer, ProtocolVersion v) { + super(buffer, v); + } + + + public int getAge() { + //ToDo custom Potion Effect Color Type + switch (version) { + case VERSION_1_7_10: + return (int) sets.get(12).getData(); + } + return 0; + } + + +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/EntityMetaData.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/EntityMetaData.java new file mode 100644 index 000000000..851cd8fce --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/EntityMetaData.java @@ -0,0 +1,293 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes.entities.meta; + +import de.bixilon.minosoft.game.datatypes.Vector; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; +import de.bixilon.minosoft.util.BitByte; + +import java.util.HashMap; + +public class EntityMetaData { + HashMap sets = new HashMap<>(); + ProtocolVersion version; + + public EntityMetaData(InByteBuffer buffer, ProtocolVersion v) { + version = v; + switch (v) { + case VERSION_1_7_10: + byte item = buffer.readByte(); + while (item != 0x7F) { + byte index = (byte) (item & 0x1F); + Object data; + Type_1_7_10 type = Type_1_7_10.byId((item & 0xFF) >> 5); + switch (type) { + case BYTE: + data = buffer.readByte(); + break; + case SHORT: + data = buffer.readShort(); + break; + case INT: + data = buffer.readInteger(); + break; + case FLOAT: + data = buffer.readFloat(); + break; + case STRING: + data = buffer.readString(); + break; + case VECTOR: + data = new Vector(buffer.readInteger(), buffer.readInteger(), buffer.readInteger()); + break; + default: + throw new IllegalStateException("Unexpected value: " + type); + } + sets.put(index, new MetaDataSet(index, data)); + + + item = buffer.readByte(); + } + + break; + /* + case VERSION_1_15_2: + byte index = buffer.readByte(); + while (index != -1) { // 0xFF + // still data here + int id = buffer.readVarInt(); + Type type = Type.byId(id); + Object data; + switch (type) { + case BYTE: + data = buffer.readByte(); + break; + case VAR_INT: + case OPT_BLOCK_ID: + case OPT_VAR_INT: + data = buffer.readVarInt(); + break; + case FLOAT: + data = buffer.readFloat(); + break; + case STRING: + data = buffer.readString(); + break; + case CHAT: + data = buffer.readChatComponent(); + break; + case OPT_CHAT: + if (buffer.readBoolean()) { + data = buffer.readChatComponent(); + } + break; + case SLOT: + data = buffer.readSlot(); + break; + case BOOLEAN: + data = buffer.readBoolean(); + break; + case ROTATION: + //ToDo + buffer.readFloat(); + buffer.readFloat(); + buffer.readFloat(); + break; + case POSITION: + data = buffer.readBlockPosition(); + break; + case OPT_POSITION: + if (buffer.readBoolean()) { + data = buffer.readBlockPosition(); + } + break; + case DIRECTION: + data = buffer.readDirection(); + break; + case OPT_UUID: + if (buffer.readBoolean()) { + data = buffer.readUUID(); + } + break; + case NBT: + data = buffer.readNBT(); + break; + case PARTICLE: + data = buffer.readParticle(); + break; + case POSE: + data = buffer.readPose(); + break; + + } + + + index = buffer.readByte(); + } + */ + } + + + } + + public HashMap getSets() { + return sets; + } + + public boolean onFire() { + switch (version) { + case VERSION_1_7_10: + return BitByte.isBitSet((byte) sets.get(0).getData(), 0); + } + return false; + } + + public boolean isSneaking() { + switch (version) { + case VERSION_1_7_10: + return BitByte.isBitSet((byte) sets.get(0).getData(), 1); + } + return false; + } + + public boolean isSprinting() { + switch (version) { + case VERSION_1_7_10: + return BitByte.isBitSet((byte) sets.get(0).getData(), 2); + } + return false; + } + + public boolean isEating() { + switch (version) { + case VERSION_1_7_10: + return BitByte.isBitSet((byte) sets.get(0).getData(), 3); + } + return false; + } + + public boolean isDrinking() { + return isEating(); + } + + public boolean isBlocking() { + return isEating(); + } + + public boolean isInvisible() { + switch (version) { + case VERSION_1_7_10: + return BitByte.isBitSet((byte) sets.get(0).getData(), 4); + } + return false; + } + + enum Type implements Types { + BYTE(0), + VAR_INT(1), + FLOAT(2), + STRING(3), + CHAT(4), + OPT_CHAT(5), + SLOT(6), + BOOLEAN(7), + ROTATION(8), + POSITION(9), + OPT_POSITION(10), + DIRECTION(11), + OPT_UUID(12), + OPT_BLOCK_ID(13), + NBT(13), + PARTICLE(14), + VILLAGER_DATA(15), + OPT_VAR_INT(17), + POSE(18); + + + final int id; + + Type(int id) { + this.id = id; + } + + public static Type byId(int id) { + for (Type s : values()) { + if (s.getId() == id) { + return s; + } + } + return null; + } + + + public int getId() { + return id; + } + } + + enum Type_1_7_10 implements Types { + BYTE(0), + SHORT(1), + INT(2), + FLOAT(3), + STRING(4), + SLOT(5), + VECTOR(6); + + + final int id; + + Type_1_7_10(int id) { + this.id = id; + } + + public static Type_1_7_10 byId(int id) { + for (Type_1_7_10 s : values()) { + if (s.getId() == id) { + return s; + } + } + return null; + } + + public int getId() { + return id; + } + } + + interface Types { + int getId(); + } + + public class MetaDataSet { + final int index; + final Object data; + + public MetaDataSet(int index, Object data) { + this.index = index; + this.data = data; + } + + public Object getData() { + return data; + } + + public int getIndex() { + return index; + } + } + + +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/HumanMetaData.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/HumanMetaData.java new file mode 100644 index 000000000..63a10983e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/HumanMetaData.java @@ -0,0 +1,52 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes.entities.meta; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; +import de.bixilon.minosoft.util.BitByte; + +public class HumanMetaData extends MobMetaData { + + public HumanMetaData(InByteBuffer buffer, ProtocolVersion v) { + super(buffer, v); + } + + + public boolean hideCape() { + switch (version) { + case VERSION_1_7_10: + return BitByte.isBitSet((byte) sets.get(16).getData(), 1); + } + return false; + } + + public float getAbsorptionHearts() { + switch (version) { + case VERSION_1_7_10: + return (float) sets.get(17).getData(); + } + return 0.0F; + } + + public int getScore() { + switch (version) { + case VERSION_1_7_10: + return (int) sets.get(18).getData(); + } + return 0; + } + + +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/MobMetaData.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/MobMetaData.java new file mode 100644 index 000000000..3907cab49 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/MobMetaData.java @@ -0,0 +1,77 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes.entities.meta; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class MobMetaData extends EntityMetaData { + + public MobMetaData(InByteBuffer buffer, ProtocolVersion v) { + super(buffer, v); + } + + + public float getHealth() { + switch (version) { + case VERSION_1_7_10: + return (float) sets.get(6).getData(); + } + return 0.0F; + } + + public int getPotionEffectColor() { + //ToDo custom Potion Effect Color Type + switch (version) { + case VERSION_1_7_10: + return (int) sets.get(7).getData(); + } + return 0; + } + + + public byte getPotionEffectAmbient() { + switch (version) { + case VERSION_1_7_10: + return (byte) sets.get(8).getData(); + } + return 0; + } + + public byte getNumberOfArrowsInEntity() { + switch (version) { + case VERSION_1_7_10: + return (byte) sets.get(9).getData(); + } + return 0; + } + + public String getNameTag() { + switch (version) { + case VERSION_1_7_10: + return (String) sets.get(10).getData(); + } + return null; + } + + public byte getAlwaysShowNameTag() { + switch (version) { + case VERSION_1_7_10: + return (byte) sets.get(11).getData(); + } + return 0; + } + + +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/ZombieMetaData.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/ZombieMetaData.java new file mode 100644 index 000000000..bd8748486 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/meta/ZombieMetaData.java @@ -0,0 +1,51 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes.entities.meta; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class ZombieMetaData extends MobMetaData { + + public ZombieMetaData(InByteBuffer buffer, ProtocolVersion v) { + super(buffer, v); + } + + + public boolean isChild() { + switch (version) { + case VERSION_1_7_10: + return ((byte) sets.get(12).getData()) == 0x01; + } + return false; + } + + public boolean isVillager() { + switch (version) { + case VERSION_1_7_10: + return ((byte) sets.get(13).getData()) == 0x01; + } + return false; + } + + public boolean isConverting() { + switch (version) { + case VERSION_1_7_10: + return ((byte) sets.get(14).getData()) == 0x01; + } + return false; + } + + +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/particle/BlockParticle.java b/src/main/java/de/bixilon/minosoft/game/datatypes/particle/BlockParticle.java new file mode 100644 index 000000000..0a2c9a8b0 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/particle/BlockParticle.java @@ -0,0 +1,30 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes.particle; + +public class BlockParticle implements Particle { + final int blockState; + + public BlockParticle(int blockState) { + this.blockState = blockState; + } + + public Particles getParticle() { + return Particles.BLOCK; + } + + public int getBlockState() { + return this.blockState; + } +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/particle/OtherParticles.java b/src/main/java/de/bixilon/minosoft/game/datatypes/particle/OtherParticles.java new file mode 100644 index 000000000..e7480df91 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/particle/OtherParticles.java @@ -0,0 +1,26 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes.particle; + +public class OtherParticles implements Particle { + Particles type; + + public OtherParticles(Particles type) { + this.type = type; + } + + public Particles getParticle() { + return type; + } +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/particle/Particle.java b/src/main/java/de/bixilon/minosoft/game/datatypes/particle/Particle.java new file mode 100644 index 000000000..54b398cd2 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/particle/Particle.java @@ -0,0 +1,18 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes.particle; + +public interface Particle { + Particles getParticle(); +} diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/particle/Particles.java b/src/main/java/de/bixilon/minosoft/game/datatypes/particle/Particles.java new file mode 100644 index 000000000..911e0869b --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/particle/Particles.java @@ -0,0 +1,70 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes.particle; + +import de.bixilon.minosoft.game.datatypes.Identifier; + +public enum Particles { + AMBIENT_ENTITY_EFFECT(new Identifier("ambient_entity_effect"), 0), + ANGRY_VILLAGER(new Identifier("angry_villager"), 1), + BARRIER(new Identifier("barrier"), 2), + BLOCK(new Identifier("block"), 3, BlockParticle.class); + // ToDo other particles + + final Identifier identifier; + final int id; + final Class clazz; + + Particles(Identifier identifier, int id, Class clazz) { + this.identifier = identifier; + this.id = id; + this.clazz = clazz; + } + + Particles(Identifier identifier, int id) { + this.identifier = identifier; + this.id = id; + this.clazz = OtherParticles.class; + } + + public static Particles byIdentifier(Identifier identifier) { + for (Particles b : values()) { + if (b.getIdentifier().equals(identifier)) { + return b; + } + } + return null; + } + + public static Particles byType(int type) { + for (Particles b : values()) { + if (b.getId() == type) { + return b; + } + } + return null; + } + + public Identifier getIdentifier() { + return identifier; + } + + public int getId() { + return id; + } + + public Class getClazz() { + return clazz; + } +} diff --git a/src/main/java/de/bixilon/minosoft/objects/Player.java b/src/main/java/de/bixilon/minosoft/objects/Player.java index 648b9ab57..450c8c53e 100644 --- a/src/main/java/de/bixilon/minosoft/objects/Player.java +++ b/src/main/java/de/bixilon/minosoft/objects/Player.java @@ -16,6 +16,7 @@ package de.bixilon.minosoft.objects; import de.bixilon.minosoft.game.datatypes.GameMode; import de.bixilon.minosoft.game.datatypes.World; import de.bixilon.minosoft.game.datatypes.entities.Location; +import de.bixilon.minosoft.game.datatypes.entities.meta.HumanMetaData; import java.util.UUID; @@ -31,6 +32,7 @@ public class Player { byte selectedSlot; short level; short totalExperience; + HumanMetaData metaData; public Player(Account acc) { this.acc = acc; @@ -124,4 +126,12 @@ public class Player { public void setTotalExperience(short totalExperience) { this.totalExperience = totalExperience; } + + public HumanMetaData getMetaData() { + return metaData; + } + + public void setMetaData(HumanMetaData metaData) { + this.metaData = metaData; + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/Network.java b/src/main/java/de/bixilon/minosoft/protocol/network/Network.java index 258cb8765..1a3136a09 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/Network.java +++ b/src/main/java/de/bixilon/minosoft/protocol/network/Network.java @@ -63,7 +63,6 @@ public class Network { socket.setKeepAlive(true); DataOutputStream dOut = new DataOutputStream(socket.getOutputStream()); DataInputStream dIn = new DataInputStream(socket.getInputStream()); - socket.getInputStream(); while (connection.getConnectionState() != ConnectionState.DISCONNECTING) { @@ -81,11 +80,6 @@ public class Network { binQueue.remove(0); } - if (dIn.available() == 0) { - // nothing to receive - Util.sleep(1); - continue; - } // everything sent for now, waiting for data if (dIn.available() > 0) { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestoryEntity.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestroyEntity.java similarity index 96% rename from src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestoryEntity.java rename to src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestroyEntity.java index a8e8c3cbf..1c4739948 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestoryEntity.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestroyEntity.java @@ -22,7 +22,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; import java.util.Arrays; -public class PacketDestoryEntity implements ClientboundPacket { +public class PacketDestroyEntity implements ClientboundPacket { int[] entityIds; @Override diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMetadata.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMetadata.java new file mode 100644 index 000000000..9c04f6f54 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMetadata.java @@ -0,0 +1,71 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData; +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +import java.lang.reflect.InvocationTargetException; + +public class PacketEntityMetadata implements ClientboundPacket { + int entityId; + InPacketBuffer buffer; + ProtocolVersion v; + + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + entityId = buffer.readInteger(); + this.v = v; + this.buffer = buffer; + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Received entity metadata (entityId=%d", entityId)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public int getEntityId() { + return entityId; + } + + public InPacketBuffer getRawEntityData() { + return buffer; + } + + public EntityMetaData getEntityData(Class clazz) { + try { + return clazz.getConstructor(InByteBuffer.class, ProtocolVersion.class).newInstance(buffer, v); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + } + return null; + } + +} + diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnMob.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnMob.java index c454598bb..4b6d7a973 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnMob.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnMob.java @@ -13,9 +13,13 @@ package de.bixilon.minosoft.protocol.packets.clientbound.play; -import de.bixilon.minosoft.game.datatypes.entities.*; +import de.bixilon.minosoft.game.datatypes.entities.Location; +import de.bixilon.minosoft.game.datatypes.entities.Mob; +import de.bixilon.minosoft.game.datatypes.entities.Mobs; +import de.bixilon.minosoft.game.datatypes.entities.Velocity; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; import de.bixilon.minosoft.protocol.protocol.PacketHandler; import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; @@ -36,11 +40,10 @@ public class PacketSpawnMob implements ClientboundPacket { int pitch = buffer.readByte(); int headPitch = buffer.readByte(); Velocity velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort()); - EntityMetaData metaData = buffer.readEntityMetaData(); assert type != null; try { - mob = (Mob) type.getClazz().getConstructor(int.class, Location.class, int.class, int.class, Velocity.class, EntityMetaData.class).newInstance(entityId, location, yaw, pitch, velocity, metaData); + mob = (Mob) type.getClazz().getConstructor(int.class, Location.class, int.class, int.class, Velocity.class, InByteBuffer.class, ProtocolVersion.class).newInstance(entityId, location, yaw, pitch, velocity, buffer, v); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPlayer.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPlayer.java index 2395f7c20..3c9248621 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPlayer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPlayer.java @@ -14,9 +14,9 @@ package de.bixilon.minosoft.protocol.packets.clientbound.play; import de.bixilon.minosoft.game.datatypes.PlayerPropertyData; -import de.bixilon.minosoft.game.datatypes.entities.EntityMetaData; import de.bixilon.minosoft.game.datatypes.entities.Location; import de.bixilon.minosoft.game.datatypes.entities.OtherPlayer; +import de.bixilon.minosoft.game.datatypes.entities.meta.HumanMetaData; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; @@ -46,7 +46,7 @@ public class PacketSpawnPlayer implements ClientboundPacket { int pitch = buffer.readByte(); short currentItem = buffer.readShort(); - EntityMetaData metaData = buffer.readEntityMetaData(); + HumanMetaData metaData = new HumanMetaData(buffer, v); this.player = new OtherPlayer(entityId, name, uuid, properties, location, yaw, pitch, currentItem, metaData); break; diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowItems.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowItems.java new file mode 100644 index 000000000..69feb91e5 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowItems.java @@ -0,0 +1,58 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.game.datatypes.Slot; +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketWindowItems implements ClientboundPacket { + byte windowId; + Slot[] data; + + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + windowId = buffer.readByte(); + data = new Slot[buffer.readShort()]; + for (int i = 0; i < data.length; i++) { + data[i] = buffer.readSlot(); + } + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Inventory slot change: %d", data.length)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public byte getWindowId() { + return windowId; + } + + public Slot[] getData() { + return data; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java index 974ea3896..06954f4fd 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java @@ -15,9 +15,17 @@ package de.bixilon.minosoft.protocol.protocol; import de.bixilon.minosoft.game.datatypes.BlockPosition; import de.bixilon.minosoft.game.datatypes.ChatComponent; -import de.bixilon.minosoft.game.datatypes.entities.EntityMetaData; +import de.bixilon.minosoft.game.datatypes.Direction; +import de.bixilon.minosoft.game.datatypes.Slot; +import de.bixilon.minosoft.game.datatypes.entities.Pose; +import de.bixilon.minosoft.game.datatypes.particle.BlockParticle; +import de.bixilon.minosoft.game.datatypes.particle.OtherParticles; +import de.bixilon.minosoft.game.datatypes.particle.Particle; +import de.bixilon.minosoft.game.datatypes.particle.Particles; +import net.querz.nbt.io.NamedTag; import org.json.JSONObject; +import java.lang.reflect.InvocationTargetException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.UUID; @@ -180,8 +188,41 @@ public class InByteBuffer { return bytes.length - pos; } - public EntityMetaData readEntityMetaData() { + + public Direction readDirection() { + return Direction.byId(readVarInt()); + } + + public Pose readPose() { + return Pose.byId(readVarInt()); + } + + public Particle readParticle() { + Particles type = Particles.byType(readVarInt()); + try { + if (type.getClazz() == OtherParticles.class) { + return type.getClazz().getConstructor(Particles.class).newInstance(type); + } else if (type.getClazz() == BlockParticle.class) { + return type.getClazz().getConstructor(int.class).newInstance(readVarInt()); + } + //ToDo + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + } + return null; + } + + public NamedTag readNBT() { //ToDo return null; } + + public Slot readSlot() { + if (readBoolean()) { + return new Slot(readVarInt(), readByte(), readNBT()); + } + //else no data + return null; + + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java index 97758f70f..9701001e4 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -17,6 +17,7 @@ import de.bixilon.minosoft.Minosoft; import de.bixilon.minosoft.config.GameConfiguration; import de.bixilon.minosoft.game.datatypes.GameMode; import de.bixilon.minosoft.game.datatypes.entities.Mob; +import de.bixilon.minosoft.game.datatypes.entities.meta.HumanMetaData; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.network.Connection; import de.bixilon.minosoft.protocol.packets.clientbound.login.PacketEncryptionKeyRequest; @@ -163,7 +164,7 @@ public class PacketHandler { connection.getPlayer().getWorld().getEntity(pkg.getEntityId()).setPitch(pkg.getPitch()); } - public void handle(PacketDestoryEntity pkg) { + public void handle(PacketDestroyEntity pkg) { for (int entityId : pkg.getEntityIds()) { connection.getPlayer().getWorld().removeEntity(entityId); } @@ -187,4 +188,17 @@ public class PacketHandler { public void handle(PacketEntityHeadRotation pkg) { ((Mob) connection.getPlayer().getWorld().getEntity(pkg.getEntityId())).setHeadYaw(pkg.getHeadYaw()); } + + public void handle(PacketWindowItems pkg) { + } + + public void handle(PacketEntityMetadata pkg) { + if (pkg.getEntityId() == connection.getPlayer().getEntityId()) { + // our own meta data...set it + connection.getPlayer().setMetaData((HumanMetaData) pkg.getEntityData(HumanMetaData.class)); + } else { + connection.getPlayer().getWorld().getEntity(pkg.getEntityId()).setMetaData(pkg.getEntityData(connection.getPlayer().getWorld().getEntity(pkg.getEntityId()).getMetaData().getClass())); + + } + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java index fc4bec46f..49b9973b9 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java @@ -66,10 +66,12 @@ public interface Protocol { packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_POSITION_AND_ROTATION, PacketEntityPositionAndRotation.class); packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_POSITION, PacketEntityPosition.class); packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_ROTATION, PacketEntityRotation.class); - packetClassMapping.put(Packets.Clientbound.PLAY_DESTROY_ENTITIES, PacketDestoryEntity.class); + packetClassMapping.put(Packets.Clientbound.PLAY_DESTROY_ENTITIES, PacketDestroyEntity.class); packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_VELOCITY, PacketEntityVelocity.class); packetClassMapping.put(Packets.Clientbound.PLAY_SPAWN_PLAYER, PacketSpawnPlayer.class); packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_TELEPORT, PacketEntityTeleport.class); packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_HEAD_LOOK, PacketEntityHeadRotation.class); + packetClassMapping.put(Packets.Clientbound.PLAY_WINDOW_ITEMS, PacketWindowItems.class); + packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_METADATA, PacketEntityMetadata.class); } } \ No newline at end of file