mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
entities wip (7): Entity Meta data; slot implementation; particle wip (1)
This commit is contained in:
parent
2f42a11267
commit
d534020344
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
40
src/main/java/de/bixilon/minosoft/game/datatypes/Slot.java
Normal file
40
src/main/java/de/bixilon/minosoft/game/datatypes/Slot.java
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
52
src/main/java/de/bixilon/minosoft/game/datatypes/Vector.java
Normal file
52
src/main/java/de/bixilon/minosoft/game/datatypes/Vector.java
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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());
|
||||
}
|
||||
}
|
@ -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();
|
||||
<T extends EntityMetaData> EntityMetaData getMetaData();
|
||||
|
||||
void setMetaData(EntityMetaData data);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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<Byte, MetaDataSet> 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<Byte, MetaDataSet> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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();
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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<? extends Particle> clazz;
|
||||
|
||||
Particles(Identifier identifier, int id, Class<? extends Particle> 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<? extends Particle> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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<? extends EntityMetaData> clazz) {
|
||||
try {
|
||||
return clazz.getConstructor(InByteBuffer.class, ProtocolVersion.class).newInstance(buffer, v);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user