1.9.4: EntityMetaData

This commit is contained in:
Bixilon 2020-06-29 16:07:09 +02:00
parent 0f6d0d8f60
commit 007d21f9e0
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
62 changed files with 1319 additions and 270 deletions

View File

@ -16,7 +16,7 @@ package de.bixilon.minosoft.game.datatypes.entities;
import de.bixilon.minosoft.game.datatypes.entities.mob.*;
public enum Mobs {
PLAYER(92, OtherPlayer.class),
PLAYER(105, OtherPlayer.class),
CREEPER(50, Creeper.class),
SKELETON(51, Skeleton.class),
SPIDER(52, Spider.class),
@ -35,6 +35,7 @@ public enum Mobs {
BAT(65, Bat.class),
WITCH(66, Witch.class),
GUARDIAN(68, Guardian.class),
SHULKER(69, Shulker.class),
PIG(90, Pig.class),
SHEEP(91, Sheep.class),
COW(92, Cow.class),

View File

@ -28,6 +28,7 @@ public enum Objects implements EntityEnumInterface {
FIRE_CHARGE(64, FireCharge.class),
ENDER_PEARL(65, Enderpearl.class),
WITHER_SKULL(66, WitherSkull.class),
SHULKER_BULLET(67, ShulkerBullet.class),
FALLING_BLOCK(70, FallingBlock.class),
ITEM_FRAME(71, ItemFrame.class),
EYE_OF_ENDER(72, EyeOfEnder.class),
@ -37,7 +38,11 @@ public enum Objects implements EntityEnumInterface {
FIREWORK(76, Firework.class),
LEASH_KNOT(77, LeashKnot.class),
ARMOR_STAND(78, ArmorStand.class),
FISHING_FLOAT(90, FishingFloat.class);
FISHING_FLOAT(90, FishingFloat.class),
SPECTRAL_ARROW(91, SpectralArrow.class),
DRAGON_FIREBALL(93, DragonFireball.class);
//ToDO: size changed between versions, fix it!
final int type;
final Class<? extends EntityObject> clazz;

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class AgeableMetaData extends MobMetaData {
public class AgeableMetaData extends InsentientMetaData {
public AgeableMetaData(InByteBuffer buffer) {
super(buffer);
@ -32,7 +32,14 @@ public class AgeableMetaData extends MobMetaData {
}
public boolean isAdult() {
return getAge() >= 0;
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return getAge() >= 0;
case VERSION_1_9_4:
return (boolean) sets.get(11).getData();
}
return false;
}

View File

@ -0,0 +1,60 @@
/*
* 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.Color;
import de.bixilon.minosoft.game.datatypes.particle.Particles;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class AreaEffectCloudMetaData extends MobMetaData {
public AreaEffectCloudMetaData(InByteBuffer buffer) {
super(buffer);
}
public float getRadius() {
switch (version) {
case VERSION_1_9_4:
return (float) sets.get(5).getData();
}
return 0;
}
public Color getColor() {
switch (version) {
case VERSION_1_9_4:
return Color.byId((int) sets.get(6).getData());
}
return Color.WHITE;
}
public boolean ignoreRadius() {
switch (version) {
case VERSION_1_9_4:
return (boolean) sets.get(7).getData();
}
return false;
}
public Particles getParticle() {
switch (version) {
case VERSION_1_9_4:
return Particles.byType((int) sets.get(8).getData());
}
return null;
}
}

View File

@ -27,7 +27,7 @@ public class ArmorStandMetaData extends MobMetaData {
public boolean isSmall() {
switch (version) {
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(10).getData(), 0);
return BitByte.isBitMask((byte) sets.get(10).getData(), 0x01);
}
return false;
}
@ -35,7 +35,7 @@ public class ArmorStandMetaData extends MobMetaData {
public boolean hasGravity() {
switch (version) {
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(10).getData(), 1);
return BitByte.isBitMask((byte) sets.get(10).getData(), 0x02);
}
return false;
}
@ -43,7 +43,7 @@ public class ArmorStandMetaData extends MobMetaData {
public boolean hasArms() {
switch (version) {
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(10).getData(), 2);
return BitByte.isBitMask((byte) sets.get(10).getData(), 0x04);
}
return false;
}
@ -51,7 +51,7 @@ public class ArmorStandMetaData extends MobMetaData {
public boolean removeBasePlate() {
switch (version) {
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(10).getData(), 3);
return BitByte.isBitMask((byte) sets.get(10).getData(), 0x08);
}
return false;
}
@ -59,54 +59,60 @@ public class ArmorStandMetaData extends MobMetaData {
public boolean hasMarker() {
switch (version) {
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(10).getData(), 4);
return BitByte.isBitMask((byte) sets.get(10).getData(), 0x10);
}
return false;
}
public EntityRotation getHeadPosition() {
public EntityRotation getHeadRotation() {
switch (version) {
case VERSION_1_8:
case VERSION_1_9_4:
return (EntityRotation) sets.get(11).getData();
}
return null;
}
public EntityRotation getBodyPosition() {
public EntityRotation getBodyRotation() {
switch (version) {
case VERSION_1_8:
case VERSION_1_9_4:
return (EntityRotation) sets.get(12).getData();
}
return null;
}
public EntityRotation getLeftArmPosition() {
public EntityRotation getLeftArmRotation() {
switch (version) {
case VERSION_1_8:
case VERSION_1_9_4:
return (EntityRotation) sets.get(13).getData();
}
return null;
}
public EntityRotation getRightArmPosition() {
public EntityRotation getRightArmRotation() {
switch (version) {
case VERSION_1_8:
case VERSION_1_9_4:
return (EntityRotation) sets.get(14).getData();
}
return null;
}
public EntityRotation getLeftLegPosition() {
public EntityRotation getLeftLegRotation() {
switch (version) {
case VERSION_1_8:
case VERSION_1_9_4:
return (EntityRotation) sets.get(15).getData();
}
return null;
}
public EntityRotation getRightLegPosition() {
public EntityRotation getRightLegRotation() {
switch (version) {
case VERSION_1_8:
case VERSION_1_9_4:
return (EntityRotation) sets.get(16).getData();
}
return null;

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
public class ArrowMetaData extends EntityMetaData {
@ -26,6 +27,8 @@ public class ArrowMetaData extends EntityMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(16).getData() == 0x01;
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(5).getData(), 0x01);
}
return false;
}

View File

@ -14,8 +14,9 @@
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
public class BatMetaData extends MobMetaData {
public class BatMetaData extends InsentientMetaData {
public BatMetaData(InByteBuffer buffer) {
super(buffer);
@ -27,6 +28,8 @@ public class BatMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(16).getData() == 0x01;
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(16).getData(), 0x01);
}
return false;
}

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
public class BlazeMetaData extends MobMetaData {
@ -27,6 +28,8 @@ public class BlazeMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(16).getData() == 0x01;
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(16).getData(), 0x01);
}
return false;
}

View File

@ -26,6 +26,8 @@ public class BoatMetaData extends EntityMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(17).getData();
case VERSION_1_9_4:
return (int) sets.get(5).getData();
}
return 0;
}
@ -35,6 +37,8 @@ public class BoatMetaData extends EntityMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(18).getData();
case VERSION_1_9_4:
return (int) sets.get(6).getData();
}
return 0;
}
@ -44,8 +48,34 @@ public class BoatMetaData extends EntityMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (float) sets.get(19).getData();
case VERSION_1_9_4:
return (float) sets.get(7).getData();
}
return 0;
}
public int getType() {
switch (version) {
case VERSION_1_9_4:
return (int) sets.get(8).getData();
}
return 0;
}
public boolean isRightPaddleTurning() {
switch (version) {
case VERSION_1_9_4:
return (boolean) sets.get(9).getData();
}
return false;
}
public boolean isLeftPaddleTurning() {
switch (version) {
case VERSION_1_9_4:
return (boolean) sets.get(10).getData();
}
return false;
}
}

View File

@ -0,0 +1,41 @@
/*
* 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.TextComponent;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class CommandBlockMinecartMetaData extends EntityMetaData {
public CommandBlockMinecartMetaData(InByteBuffer buffer) {
super(buffer);
}
public String getCommand() {
switch (version) {
case VERSION_1_9_4:
return (String) sets.get(11).getData();
}
return "";
}
public TextComponent getLastOutput() {
switch (version) {
case VERSION_1_9_4:
return (TextComponent) sets.get(12).getData();
}
return null;
}
}

View File

@ -22,21 +22,33 @@ public class CreeperMetaData extends MobMetaData {
}
public byte getState() {
public int getState() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(16).getData();
case VERSION_1_9_4:
return (int) sets.get(11).getData();
}
return -1;
}
public boolean isPowered() {
public boolean isCharged() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(17).getData() == 0x01;
case VERSION_1_9_4:
return (boolean) sets.get(12).getData();
}
return false;
}
public boolean isIgnited() {
switch (version) {
case VERSION_1_9_4:
return (boolean) sets.get(13).getData();
}
return false;
}

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class EnderCrystalMetaData extends EntityMetaData {
@ -29,4 +30,20 @@ public class EnderCrystalMetaData extends EntityMetaData {
}
return 0;
}
public BlockPosition getBeamTarget() {
switch (version) {
case VERSION_1_9_4:
return (BlockPosition) sets.get(5).getData();
}
return null;
}
public boolean showBottom() {
switch (version) {
case VERSION_1_9_4:
return (boolean) sets.get(6).getData();
}
return true;
}
}

View File

@ -0,0 +1,34 @@
/*
* 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;
public class EnderDragonMetaData extends InsentientMetaData {
public EnderDragonMetaData(InByteBuffer buffer) {
super(buffer);
}
public int getDragonPhase() {
switch (version) {
case VERSION_1_9_4:
return ((int) sets.get(11).getData());
}
return 0;
}
}

View File

@ -28,6 +28,8 @@ public class EndermanMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return Blocks.byId((short) sets.get(16).getData(), (byte) sets.get(17).getData());
case VERSION_1_9_4:
return (Blocks) sets.get(11).getData();
}
return Blocks.AIR;
}
@ -37,6 +39,8 @@ public class EndermanMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(18).getData() == 0x01;
case VERSION_1_9_4:
return (boolean) sets.get(12).getData();
}
return false;
}

View File

@ -14,141 +14,50 @@
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.game.datatypes.EntityRotation;
import de.bixilon.minosoft.game.datatypes.MapSet;
import de.bixilon.minosoft.game.datatypes.Vector;
import de.bixilon.minosoft.game.datatypes.VersionValueMap;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
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 {
final HashMap<Integer, MetaDataSet> sets = new HashMap<>();
final ProtocolVersion version;
/*
1.7.10: https://wiki.vg/index.php?title=Entity_metadata&oldid=5991
1.8: https://wiki.vg/index.php?title=Entity_metadata&oldid=6611
1.9.4; https://wiki.vg/index.php?title=Entity_metadata&oldid=7955
*/
public EntityMetaData(InByteBuffer buffer) {
version = buffer.getVersion();
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
case VERSION_1_8: {
byte item = buffer.readByte();
while (item != 0x7F) {
byte index = (byte) (item & 0x1F);
Object data;
TypeLegacy type = TypeLegacy.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;
case SLOT:
data = buffer.readSlot();
break;
case POSITION:
data = new EntityRotation(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
break;
default:
throw new IllegalStateException("Unexpected value: " + type);
}
sets.put((int) index, new MetaDataSet(index, data));
Types type = Types.byId((item & 0xFF) >> 5, buffer.getVersion());
sets.put((int) index, new MetaDataSet(index, getData(type, buffer)));
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.readPosition();
break;
case OPT_POSITION:
if (buffer.readBoolean()) {
data = buffer.readPosition();
}
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();
}
*/
case VERSION_1_9_4:
byte index = buffer.readByte();
while (index != (byte) 0xFF) {
Types type = Types.byId(buffer.readByte(), buffer.getVersion());
sets.put((int) index, new MetaDataSet(index, getData(type, buffer)));
index = buffer.readByte();
}
}
@ -162,7 +71,7 @@ public class EntityMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(0).getData(), 0);
return BitByte.isBitMask((byte) sets.get(0).getData(), 0x01);
}
return false;
}
@ -171,7 +80,7 @@ public class EntityMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(0).getData(), 1);
return BitByte.isBitMask((byte) sets.get(0).getData(), 0x02);
}
return false;
}
@ -180,7 +89,7 @@ public class EntityMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(0).getData(), 2);
return BitByte.isBitMask((byte) sets.get(0).getData(), 0x08);
}
return false;
}
@ -189,7 +98,7 @@ public class EntityMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(0).getData(), 3);
return BitByte.isBitMask((byte) sets.get(0).getData(), 0x10);
}
return false;
}
@ -206,89 +115,182 @@ public class EntityMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(0).getData(), 4);
return BitByte.isBitSet((byte) sets.get(0).getData(), 0x20);
}
return false;
}
enum Type implements Types {
public boolean isGlowing() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(0).getData(), 0x40);
}
return false;
}
public boolean isFlyingWithElytra() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(0).getData(), 0x80);
}
return false;
}
public String getNameTag() {
switch (version) {
case VERSION_1_9_4:
return (String) sets.get(2).getData();
}
return null;
}
public boolean isCustomNameVisible() {
switch (version) {
case VERSION_1_9_4:
return (boolean) sets.get(3).getData();
}
return false;
}
public boolean isSilent() {
switch (version) {
case VERSION_1_9_4:
return (boolean) sets.get(4).getData();
}
return false;
}
public Object getData(Types type, InByteBuffer buffer) {
Object data = null;
switch (type) {
case BYTE:
data = buffer.readByte();
break;
case VAR_INT:
data = buffer.readVarInt();
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 CHAT:
data = buffer.readTextComponent();
break;
case BOOLEAN:
data = buffer.readBoolean();
break;
case VECTOR:
data = new Vector(buffer.readInteger(), buffer.readInteger(), buffer.readInteger());
break;
case SLOT:
data = buffer.readSlot();
break;
case ROTATION:
data = new EntityRotation(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
break;
case POSITION:
data = buffer.readPosition();
break;
case OPT_CHAT:
if (buffer.readBoolean()) {
data = buffer.readTextComponent();
}
break;
case OPT_POSITION:
if (buffer.readBoolean()) {
data = buffer.readPosition();
}
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;
case BLOCK_ID:
int blockId = buffer.readVarInt();
data = Blocks.byId(blockId >> 4, blockId & 0xF);
break;
default:
throw new IllegalStateException("Unexpected value: " + type);
}
return data;
}
enum 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);
SHORT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 1), new MapSet<>(ProtocolVersion.VERSION_1_9_4, 1000)}), // got removed in 1.9
INT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 2), new MapSet<>(ProtocolVersion.VERSION_1_9_4, 1001)}),
VAR_INT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_9_4, 1)}),
FLOAT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 3), new MapSet<>(ProtocolVersion.VERSION_1_9_4, 2)}),
STRING(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 4), new MapSet<>(ProtocolVersion.VERSION_1_9_4, 3)}),
CHAT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_9_4, 4)}),
OPT_CHAT(-1),
SLOT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 5)}),
BOOLEAN(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_9_4, 6)}),
VECTOR(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 6), new MapSet<>(ProtocolVersion.VERSION_1_9_4, 1002)}),
ROTATION(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 7)}),
POSITION(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_9_4, 8)}),
OPT_POSITION(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_9_4, 9)}),
DIRECTION(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_9_4, 10)}),
OPT_UUID(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_9_4, 11)}),
BLOCK_ID(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_9_4, 14)}),
OPT_BLOCK_ID(-1),
NBT(-1),
PARTICLE(-1),
VILLAGER_DATA(-1),
OPT_VAR_INT(-1),
POSE(-1);
//ToDo: add all types by version
final int id;
final VersionValueMap<Integer> valueMap;
Type(int id) {
this.id = id;
Types(MapSet<ProtocolVersion, Integer>[] values) {
valueMap = new VersionValueMap<>(values, true);
}
public static Type byId(int id) {
for (Type s : values()) {
if (s.getId() == id) {
return s;
Types(int id) {
valueMap = new VersionValueMap<>(id);
}
public static Types byId(int id, ProtocolVersion version) {
for (Types types : values()) {
if (types.getId(version) == id) {
return types;
}
}
return null;
}
public int getId() {
return id;
public int getId(ProtocolVersion version) {
return valueMap.get(version);
}
}
enum TypeLegacy implements Types {
BYTE(0),
SHORT(1),
INT(2),
FLOAT(3),
STRING(4),
SLOT(5),
VECTOR(6),
POSITION(7);
final int id;
TypeLegacy(int id) {
this.id = id;
}
public static TypeLegacy byId(int id) {
for (TypeLegacy s : values()) {
if (s.getId() == id) {
return s;
}
}
return null;
}
public int getId() {
return id;
}
}
interface Types {
int getId();
}
public static class MetaDataSet {
final int index;
final Object data;
@ -306,6 +308,4 @@ public class EntityMetaData {
return index;
}
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.world.BlockPosition;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class FallingBlockMetaData extends EntityMetaData {
public FallingBlockMetaData(InByteBuffer buffer) {
super(buffer);
}
public BlockPosition getSpawnPosition() {
switch (version) {
case VERSION_1_9_4:
return (BlockPosition) sets.get(5).getData();
}
return null;
}
}

View File

@ -27,6 +27,8 @@ public class FireworkMetaData extends EntityMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (Slot) sets.get(8).getData();
case VERSION_1_9_4:
return (Slot) sets.get(5).getData();
}
return null;
}

View File

@ -0,0 +1,34 @@
/*
* 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;
public class FishingHookMetaData extends MobMetaData {
public FishingHookMetaData(InByteBuffer buffer) {
super(buffer);
}
public int getHookedEntityId() {
switch (version) {
case VERSION_1_9_4:
return (int) sets.get(5).getData();
}
return -1;
}
}

View File

@ -21,11 +21,13 @@ public class FurnaceMinecartMetaData extends EntityMetaData {
super(buffer);
}
public boolean getPowered() {
public boolean isPowered() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(16).getData() == 0x01;
return (byte) sets.get(16).getData() == 0x01;
case VERSION_1_9_4:
return (boolean) sets.get(11).getData();
}
return false;
}

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class GhastMetaData extends MobMetaData {
public class GhastMetaData extends InsentientMetaData {
public GhastMetaData(InByteBuffer buffer) {
super(buffer);
@ -26,6 +26,8 @@ public class GhastMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(16).getData() == 0x01;
case VERSION_1_9_4:
return (boolean) sets.get(11).getData();
}
return false;
}

View File

@ -25,7 +25,9 @@ public class GuardianMetaData extends MobMetaData {
public boolean isElderly() {
switch (version) {
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(16).getData(), 1);
return BitByte.isBitMask((byte) sets.get(16).getData(), 0x02);
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(11).getData(), 0x04);
}
return false;
}
@ -33,16 +35,20 @@ public class GuardianMetaData extends MobMetaData {
public boolean isRetractingSpikes() {
switch (version) {
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(16).getData(), 2);
return BitByte.isBitSet((byte) sets.get(16).getData(), 0x04);
case VERSION_1_9_4:
return BitByte.isBitSet((byte) sets.get(11).getData(), 0x02);
}
return false;
}
public int getTargetId() {
public int getTargetEntityId() {
switch (version) {
case VERSION_1_8:
return (int) sets.get(17).getData();
case VERSION_1_9_4:
return (int) sets.get(12).getData();
}
return 0;
}

View File

@ -16,6 +16,8 @@ package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
import java.util.UUID;
public class HorseMetaData extends AgeableMetaData {
public HorseMetaData(InByteBuffer buffer) {
@ -27,7 +29,9 @@ public class HorseMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 1);
return BitByte.isBitMask((int) sets.get(16).getData(), 0x01);
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x01);
}
return false;
}
@ -36,7 +40,9 @@ public class HorseMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 2);
return BitByte.isBitMask((int) sets.get(16).getData(), 0x02);
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x02);
}
return false;
}
@ -45,7 +51,9 @@ public class HorseMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 3);
return BitByte.isBitMask((int) sets.get(16).getData(), 0x04);
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x04);
}
return false;
}
@ -54,7 +62,9 @@ public class HorseMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 4);
return BitByte.isBitMask((int) sets.get(16).getData(), 0x08);
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x08);
}
return false;
}
@ -63,7 +73,9 @@ public class HorseMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 5);
return BitByte.isBitMask((int) sets.get(16).getData(), 0x10);
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x10);
}
return false;
}
@ -72,7 +84,9 @@ public class HorseMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 6);
return BitByte.isBitMask((int) sets.get(16).getData(), 0x40);
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x40);
}
return false;
}
@ -81,7 +95,9 @@ public class HorseMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 7);
return BitByte.isBitMask((int) sets.get(16).getData(), 0x80);
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x80);
}
return false;
}
@ -90,7 +106,9 @@ public class HorseMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return HorseType.byId((Integer) sets.get(19).getData());
return HorseType.byId((int) sets.get(19).getData());
case VERSION_1_9_4:
return HorseType.byId((int) sets.get(13).getData());
}
return null;
}
@ -100,6 +118,8 @@ public class HorseMetaData extends AgeableMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return HorseColor.byId((int) sets.get(20).getData() & 0xFF);
case VERSION_1_9_4:
return HorseColor.byId((int) sets.get(14).getData() & 0xFF);
}
return null;
}
@ -109,6 +129,8 @@ public class HorseMetaData extends AgeableMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return HorseDots.byId((int) sets.get(20).getData() & 0xFF00);
case VERSION_1_9_4:
return HorseDots.byId((int) sets.get(14).getData() & 0xFF00);
}
return null;
}
@ -123,11 +145,21 @@ public class HorseMetaData extends AgeableMetaData {
return null;
}
public UUID getOwnerUUID() {
switch (version) {
case VERSION_1_9_4:
return (UUID) sets.get(15).getData();
}
return null;
}
public HorseArmor getArmor() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return HorseArmor.byId((int) sets.get(21).getData());
case VERSION_1_9_4:
return HorseArmor.byId((int) sets.get(16).getData());
}
return null;
}

View File

@ -13,8 +13,8 @@
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.game.datatypes.player.Hand;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
public class HumanMetaData extends MobMetaData {
@ -23,20 +23,13 @@ public class HumanMetaData extends MobMetaData {
}
public boolean hideCape() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(16).getData(), 1);
}
return false;
}
public float getAbsorptionHearts() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return (float) sets.get(17).getData();
case VERSION_1_9_4:
return (float) sets.get(10).getData();
}
return 0.0F;
}
@ -46,9 +39,20 @@ public class HumanMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(18).getData();
case VERSION_1_9_4:
return (int) sets.get(11).getData();
}
return 0;
}
public Hand getMainHand() {
switch (version) {
case VERSION_1_9_4:
return Hand.byId((byte) sets.get(13).getData());
}
return Hand.RIGHT;
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.util.BitByte;
public class InsentientMetaData extends MobMetaData {
public InsentientMetaData(InByteBuffer buffer) {
super(buffer);
}
@Override
public boolean hasAI() {
switch (version) {
case VERSION_1_8:
return (byte) sets.get(15).getData() == 0x01;
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(10).getData(), 0x01);
default:
return super.hasAI();
}
}
public boolean isLeftHanded() {
switch (version) {
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(10).getData(), 0x02);
}
return false;
}
}

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
public class IronGolemMetaData extends MobMetaData {
@ -26,6 +27,8 @@ public class IronGolemMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(16).getData() == 0x01;
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(11).getData(), 0x01);
}
return false;
}

View File

@ -28,6 +28,8 @@ public class ItemFrameMetaData extends EntityMetaData {
return (Slot) sets.get(2).getData();
case VERSION_1_8:
return (Slot) sets.get(8).getData();
case VERSION_1_9_4:
return (Slot) sets.get(5).getData();
}
return null;
}
@ -38,6 +40,8 @@ public class ItemFrameMetaData extends EntityMetaData {
return (byte) sets.get(3).getData();
case VERSION_1_8:
return (byte) sets.get(9).getData();
case VERSION_1_9_4:
return (byte) sets.get(6).getData();
}
return 0;
}

View File

@ -27,6 +27,8 @@ public class ItemMetaData extends EntityMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (Slot) sets.get(10).getData();
case VERSION_1_9_4:
return (Slot) sets.get(5).getData();
}
return null;
}

View File

@ -27,6 +27,8 @@ public class MinecartMetaData extends EntityMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(17).getData();
case VERSION_1_9_4:
return (int) sets.get(5).getData();
}
return 0;
}
@ -36,15 +38,19 @@ public class MinecartMetaData extends EntityMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(18).getData();
case VERSION_1_9_4:
return (int) sets.get(6).getData();
}
return 0;
}
public float getDamageTaken() {
public float getMultiplier() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return (float) sets.get(19).getData();
case VERSION_1_9_4:
return (float) sets.get(7).getData();
}
return 0;
}
@ -54,6 +60,8 @@ public class MinecartMetaData extends EntityMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return Blocks.byId((int) sets.get(20).getData() & 0xFF, (int) sets.get(20).getData() >>> 4);
case VERSION_1_9_4:
return (Blocks) sets.get(8).getData();
}
return Blocks.AIR;
}
@ -62,6 +70,8 @@ public class MinecartMetaData extends EntityMetaData {
switch (version) {
case VERSION_1_8:
return (int) sets.get(21).getData();
case VERSION_1_9_4:
return (int) sets.get(9).getData();
}
return 0;
}
@ -69,7 +79,9 @@ public class MinecartMetaData extends EntityMetaData {
public boolean isShowingBlock() {
switch (version) {
case VERSION_1_8:
return (int) sets.get(22).getData() == 0x01;
return (byte) sets.get(22).getData() == 0x01;
case VERSION_1_9_4:
return (boolean) sets.get(10).getData();
}
return false;
}

View File

@ -14,7 +14,9 @@
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.game.datatypes.entities.StatusEffects;
import de.bixilon.minosoft.game.datatypes.player.Hand;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
public class MobMetaData extends EntityMetaData {
@ -27,57 +29,68 @@ public class MobMetaData extends EntityMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
case VERSION_1_9_4:
return (float) sets.get(6).getData();
}
return 0.0F;
}
public StatusEffects getPotionEffectColor() {
// ToDo: color?
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
case VERSION_1_9_4:
return StatusEffects.byId((int) sets.get(7).getData());
}
return null;
}
public byte getPotionEffectAmbient() {
public boolean isPotionEffectAmbient() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(8).getData();
return (byte) sets.get(8).getData() == 0x01;
case VERSION_1_9_4:
return (boolean) sets.get(8).getData();
}
return 0;
return false;
}
public byte getNumberOfArrowsInEntity() {
public int getNumberOfArrowsInEntity() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(9).getData();
case VERSION_1_9_4:
return (int) sets.get(9).getData();
}
return 0;
}
@Override
public String getNameTag() {
switch (version) {
case VERSION_1_7_10:
return (String) sets.get(10).getData();
case VERSION_1_8:
return (String) sets.get(2).getData();
default:
return super.getNameTag();
}
return null;
}
public byte getAlwaysShowNameTag() {
@Override
public boolean isCustomNameVisible() {
switch (version) {
case VERSION_1_7_10:
return (byte) sets.get(11).getData();
return (byte) sets.get(11).getData() == 0x01;
case VERSION_1_8:
return (byte) sets.get(3).getData();
return (byte) sets.get(3).getData() == 0x01;
default:
return super.isCustomNameVisible();
}
return 0;
}
public boolean hasAI() {
@ -88,5 +101,22 @@ public class MobMetaData extends EntityMetaData {
return false;
}
public boolean hasHandActive() {
switch (version) {
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(5).getData(), 0x01);
}
return false;
}
public Hand getActiveHand() {
//ToDo main, offhand
switch (version) {
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(5).getData(), 0x01) ? Hand.LEFT : Hand.RIGHT;
}
return Hand.RIGHT;
}
}

View File

@ -22,11 +22,13 @@ public class OcelotMetaData extends TameableMetaData {
}
public byte getType() {
public int getType() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(18).getData();
case VERSION_1_9_4:
return (int) sets.get(14).getData();
}
return 0x00;
}

View File

@ -27,6 +27,8 @@ public class PigMetaData extends AgeableMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(16).getData() == 0x01;
case VERSION_1_9_4:
return (boolean) sets.get(12).getData();
}
return false;
}

View File

@ -0,0 +1,33 @@
/*
* 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.inventory.Slot;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class PotionMetaData extends EntityMetaData {
public PotionMetaData(InByteBuffer buffer) {
super(buffer);
}
public Slot getPotion() {
switch (version) {
case VERSION_1_9_4:
return (Slot) sets.get(5).getData();
}
return null;
}
}

View File

@ -0,0 +1,31 @@
/*
* 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;
public class PrimedTNTMetaData extends EntityMetaData {
public PrimedTNTMetaData(InByteBuffer buffer) {
super(buffer);
}
public int getFuseTime() {
switch (version) {
case VERSION_1_9_4:
return (int) sets.get(5).getData();
}
return 0;
}
}

View File

@ -26,6 +26,8 @@ public class RabbitMetaData extends TameableMetaData {
switch (version) {
case VERSION_1_8:
return (byte) sets.get(18).getData();
case VERSION_1_9_4:
return (byte) sets.get(12).getData();
}
return 0;
}

View File

@ -29,6 +29,8 @@ public class SheepMetaData extends AgeableMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return Color.byId((byte) sets.get(16).getData() & 0xF);
case VERSION_1_9_4:
return Color.byId((byte) sets.get(12).getData() & 0xF);
}
return Color.WHITE;
}
@ -37,7 +39,9 @@ public class SheepMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((byte) sets.get(16).getData(), 5);
return BitByte.isBitMask((byte) sets.get(16).getData(), 0x10);
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(12).getData(), 0x10);
}
return false;
}

View File

@ -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.game.datatypes.Direction;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class ShulkerMetaData extends MobMetaData {
public ShulkerMetaData(InByteBuffer buffer) {
super(buffer);
}
public Direction getDirection() {
switch (version) {
case VERSION_1_9_4:
return (Direction) sets.get(11).getData();
}
return null;
}
public BlockPosition getAttachmentPosition() {
switch (version) {
case VERSION_1_9_4:
return (BlockPosition) sets.get(12).getData();
}
return null;
}
public byte getShieldHeight() {
switch (version) {
case VERSION_1_9_4:
return (byte) sets.get(13).getData();
}
return 0;
}
}

View File

@ -26,6 +26,16 @@ public class SkeletonMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(13).getData() == 0x01;
case VERSION_1_9_4:
return (byte) sets.get(11).getData() == 0x01;
}
return false;
}
public boolean isSwingingArms() {
switch (version) {
case VERSION_1_9_4:
return (boolean) sets.get(12).getData();
}
return false;
}

View File

@ -15,17 +15,19 @@ package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class SlimeMetaData extends MobMetaData {
public class SlimeMetaData extends InsentientMetaData {
public SlimeMetaData(InByteBuffer buffer) {
super(buffer);
}
public byte getSize() {
public int getSize() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(16).getData();
case VERSION_1_9_4:
return (int) sets.get(11).getData();
}
return 0;
}

View File

@ -0,0 +1,34 @@
/*
* 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.util.BitByte;
public class SnowGolemMetaData extends MobMetaData {
public SnowGolemMetaData(InByteBuffer buffer) {
super(buffer);
}
public boolean hasNoPumpkinHead() {
switch (version) {
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(10).getData(), 0x10);
}
return false;
}
}

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
public class SpiderMetaData extends MobMetaData {
@ -27,6 +28,8 @@ public class SpiderMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(16).getData() == 0x01;
case VERSION_1_9_4:
return BitByte.isBitMask((byte) sets.get(11).getData(), 0x01);
}
return false;
}

View File

@ -16,6 +16,8 @@ package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.util.BitByte;
import java.util.UUID;
public class TameableMetaData extends AgeableMetaData {
public TameableMetaData(InByteBuffer buffer) {
@ -27,7 +29,9 @@ public class TameableMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 0);
return BitByte.isBitMask((int) sets.get(16).getData(), 0x01);
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x01);
}
return false;
}
@ -36,7 +40,17 @@ public class TameableMetaData extends AgeableMetaData {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 2);
return BitByte.isBitMask((int) sets.get(16).getData(), 0x04);
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x04);
}
return false;
}
public boolean isAngry() {
switch (version) {
case VERSION_1_9_4:
return BitByte.isBitMask((int) sets.get(12).getData(), 0x02);
}
return false;
}
@ -50,4 +64,12 @@ public class TameableMetaData extends AgeableMetaData {
return null;
}
public UUID getOwnerUUID() {
switch (version) {
case VERSION_1_9_4:
return (UUID) sets.get(13).getData();
}
return null;
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.Color;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class TippedArrowMetaData extends ArrowMetaData {
public TippedArrowMetaData(InByteBuffer buffer) {
super(buffer);
}
public Color getColor() {
switch (version) {
case VERSION_1_9_4:
return Color.byId((int) sets.get(6).getData());
}
return null;
}
}

View File

@ -27,6 +27,8 @@ public class VillagerMetaData extends AgeableMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return VillagerType.byId((int) sets.get(16).getData());
case VERSION_1_9_4:
return VillagerType.byId((int) sets.get(12).getData());
}
return VillagerType.FARMER;
}

View File

@ -26,6 +26,8 @@ public class WitchMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (byte) sets.get(21).getData() == 0x01;
case VERSION_1_9_4:
return (boolean) sets.get(11).getData();
}
return false;
}

View File

@ -26,6 +26,8 @@ public class WitherMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(17).getData();
case VERSION_1_9_4:
return (int) sets.get(11).getData();
}
return 0;
}
@ -35,6 +37,8 @@ public class WitherMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(18).getData();
case VERSION_1_9_4:
return (int) sets.get(12).getData();
}
return 0;
}
@ -44,6 +48,8 @@ public class WitherMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(19).getData();
case VERSION_1_9_4:
return (int) sets.get(13).getData();
}
return 0;
}
@ -53,6 +59,8 @@ public class WitherMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return (int) sets.get(20).getData();
case VERSION_1_9_4:
return (int) sets.get(14).getData();
}
return 0;
}

View File

@ -0,0 +1,32 @@
/*
* 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;
public class WitherSkullMetaData extends TameableMetaData {
public WitherSkullMetaData(InByteBuffer buffer) {
super(buffer);
}
public boolean isInvulnerable() {
switch (version) {
case VERSION_1_9_4:
return (boolean) sets.get(5).getData();
}
return false;
}
}

View File

@ -24,15 +24,18 @@ public class WolfMetaData extends TameableMetaData {
}
@Override
public boolean isAngry() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return BitByte.isBitSet((int) sets.get(16).getData(), 1);
default:
return super.isAngry();
}
return false;
}
public float getHealth() {
switch (version) {
case VERSION_1_7_10:
@ -42,12 +45,22 @@ public class WolfMetaData extends TameableMetaData {
return 0.00F;
}
public float getDamageTaken() {
switch (version) {
case VERSION_1_9_4:
return (float) sets.get(14).getData();
}
return 0.00F;
}
public boolean isBegging() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return ((byte) sets.get(19).getData()) == 0x01;
case VERSION_1_9_4:
return ((boolean) sets.get(15).getData());
}
return false;
}
@ -57,6 +70,8 @@ public class WolfMetaData extends TameableMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return Color.byId((byte) sets.get(20).getData());
case VERSION_1_9_4:
return Color.byId((byte) sets.get(16).getData());
}
return Color.WHITE;
}

View File

@ -27,6 +27,8 @@ public class ZombieMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return ((byte) sets.get(12).getData()) == 0x01;
case VERSION_1_9_4:
return ((boolean) sets.get(11).getData());
}
return false;
}
@ -36,6 +38,8 @@ public class ZombieMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return ((byte) sets.get(13).getData()) == 0x01;
case VERSION_1_9_4:
return ((int) sets.get(12).getData()) >= 0x01; // returns the villager type
}
return false;
}
@ -45,6 +49,16 @@ public class ZombieMetaData extends MobMetaData {
case VERSION_1_7_10:
case VERSION_1_8:
return ((byte) sets.get(14).getData()) == 0x01;
case VERSION_1_9_4:
return ((boolean) sets.get(13).getData());
}
return false;
}
public boolean areHandsHeldUp() {
switch (version) {
case VERSION_1_9_4:
return ((boolean) sets.get(14).getData());
}
return false;
}

View File

@ -14,16 +14,16 @@
package de.bixilon.minosoft.game.datatypes.entities.mob;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EnderDragonMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.MobMetaData;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class EnderDragon extends Mob implements MobInterface {
MobMetaData metaData;
EnderDragonMetaData metaData;
public EnderDragon(int id, Location location, short yaw, short pitch, Velocity velocity, InByteBuffer buffer) {
super(id, location, yaw, pitch, velocity);
this.metaData = new MobMetaData(buffer);
this.metaData = new EnderDragonMetaData(buffer);
}
@Override
@ -32,13 +32,13 @@ public class EnderDragon extends Mob implements MobInterface {
}
@Override
public MobMetaData getMetaData() {
public EnderDragonMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = (MobMetaData) metaData;
this.metaData = (EnderDragonMetaData) metaData;
}
@Override
@ -55,4 +55,9 @@ public class EnderDragon extends Mob implements MobInterface {
public int getMaxHealth() {
return 200;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return EnderDragonMetaData.class;
}
}

View File

@ -0,0 +1,63 @@
/*
* 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.mob;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.ShulkerMetaData;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class Shulker extends Mob implements MobInterface {
ShulkerMetaData metaData;
public Shulker(int id, Location location, short yaw, short pitch, Velocity velocity, InByteBuffer buffer) {
super(id, location, yaw, pitch, velocity);
this.metaData = new ShulkerMetaData(buffer);
}
@Override
public Mobs getEntityType() {
return Mobs.SHULKER;
}
@Override
public ShulkerMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = (ShulkerMetaData) metaData;
}
@Override
public float getWidth() {
return 1.0F;
}
@Override
public float getHeight() {
return 1.0F;
}
@Override
public int getMaxHealth() {
return 30;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return ShulkerMetaData.class;
}
}

View File

@ -15,15 +15,15 @@ package de.bixilon.minosoft.game.datatypes.entities.mob;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.MobMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.SnowGolemMetaData;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class SnowGolem extends Mob implements MobInterface {
MobMetaData metaData;
SnowGolemMetaData metaData;
public SnowGolem(int id, Location location, short yaw, short pitch, Velocity velocity, InByteBuffer buffer) {
super(id, location, yaw, pitch, velocity);
this.metaData = new MobMetaData(buffer);
this.metaData = new SnowGolemMetaData(buffer);
}
@Override
@ -32,13 +32,13 @@ public class SnowGolem extends Mob implements MobInterface {
}
@Override
public MobMetaData getMetaData() {
public SnowGolemMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = (MobMetaData) metaData;
this.metaData = (SnowGolemMetaData) metaData;
}
@Override
@ -55,4 +55,9 @@ public class SnowGolem extends Mob implements MobInterface {
public int getMaxHealth() {
return 4;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return SnowGolemMetaData.class;
}
}

View File

@ -0,0 +1,63 @@
/*
* 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.objects;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
public class DragonFireball extends EntityObject implements ObjectInterface {
final int thrower;
EntityMetaData metaData;
public DragonFireball(int id, Location location, short yaw, short pitch, int additionalInt) {
super(id, location, yaw, pitch, null);
// objects do not spawn with metadata... reading additional info from the following int
this.thrower = additionalInt;
}
public DragonFireball(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.thrower = additionalInt;
}
@Override
public Objects getEntityType() {
return Objects.DRAGON_FIREBALL;
}
@Override
public EntityMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = metaData;
}
@Override
public float getWidth() {
return 0.3125F;
}
@Override
public float getHeight() {
return 0.3125F;
}
public int getThrower() {
return thrower;
}
}

View File

@ -16,9 +16,10 @@ package de.bixilon.minosoft.game.datatypes.entities.objects;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.FallingBlockMetaData;
public class FallingBlock extends EntityObject implements ObjectInterface {
EntityMetaData metaData;
FallingBlockMetaData metaData;
final Blocks block;
public FallingBlock(int id, Location location, short yaw, short pitch, int additionalInt) {
@ -38,13 +39,13 @@ public class FallingBlock extends EntityObject implements ObjectInterface {
}
@Override
public EntityMetaData getMetaData() {
public FallingBlockMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = metaData;
this.metaData = (FallingBlockMetaData) metaData;
}
@Override
@ -58,6 +59,12 @@ public class FallingBlock extends EntityObject implements ObjectInterface {
}
public Blocks getBlock() {
//ToDo depends on protocol version
return block;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return FallingBlockMetaData.class;
}
}

View File

@ -15,9 +15,10 @@ package de.bixilon.minosoft.game.datatypes.entities.objects;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.FishingHookMetaData;
public class LeashKnot extends EntityObject implements ObjectInterface {
EntityMetaData metaData;
FishingHookMetaData metaData;
public LeashKnot(int id, Location location, short yaw, short pitch, int additionalInt) {
super(id, location, yaw, pitch, null);
@ -34,13 +35,13 @@ public class LeashKnot extends EntityObject implements ObjectInterface {
}
@Override
public EntityMetaData getMetaData() {
public FishingHookMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = metaData;
this.metaData = (FishingHookMetaData) metaData;
}
@Override
@ -53,4 +54,8 @@ public class LeashKnot extends EntityObject implements ObjectInterface {
return 0.5F;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return FishingHookMetaData.class;
}
}

View File

@ -15,9 +15,10 @@ package de.bixilon.minosoft.game.datatypes.entities.objects;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.PrimedTNTMetaData;
public class PrimedTNT extends EntityObject implements ObjectInterface {
EntityMetaData metaData;
PrimedTNTMetaData metaData;
public PrimedTNT(int id, Location location, short yaw, short pitch, int additionalInt) {
super(id, location, yaw, pitch, null);
@ -40,7 +41,7 @@ public class PrimedTNT extends EntityObject implements ObjectInterface {
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = metaData;
this.metaData = (PrimedTNTMetaData) metaData;
}
@Override
@ -52,4 +53,9 @@ public class PrimedTNT extends EntityObject implements ObjectInterface {
public float getHeight() {
return 0.98F;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return PrimedTNTMetaData.class;
}
}

View File

@ -0,0 +1,63 @@
/*
* 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.objects;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
public class ShulkerBullet extends EntityObject implements ObjectInterface {
final int shooter;
EntityMetaData metaData;
public ShulkerBullet(int id, Location location, short yaw, short pitch, int additionalInt) {
super(id, location, yaw, pitch, null);
// objects do not spawn with metadata... reading additional info from the following int
this.shooter = additionalInt;
}
public ShulkerBullet(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.shooter = additionalInt;
}
@Override
public Objects getEntityType() {
return Objects.SHULKER_BULLET;
}
@Override
public EntityMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = metaData;
}
@Override
public float getWidth() {
return 0.3125F;
}
@Override
public float getHeight() {
return 0.3125F;
}
public int getShooter() {
return shooter;
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.objects;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.ArrowMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
public class SpectralArrow extends EntityObject implements ObjectInterface {
final int shooter;
ArrowMetaData metaData;
public SpectralArrow(int id, Location location, short yaw, short pitch, int additionalInt) {
super(id, location, yaw, pitch, null);
// objects do not spawn with metadata... reading additional info from the following int
this.shooter = additionalInt;
}
public SpectralArrow(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.shooter = additionalInt;
}
@Override
public Objects getEntityType() {
return Objects.SPECTRAL_ARROW;
}
@Override
public ArrowMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = (ArrowMetaData) metaData;
}
@Override
public float getWidth() {
return 0.5F;
}
@Override
public float getHeight() {
return 0.5F;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return ArrowMetaData.class;
}
public int getShooter() {
return shooter;
}
}

View File

@ -15,20 +15,21 @@ package de.bixilon.minosoft.game.datatypes.entities.objects;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.PotionMetaData;
public class ThrownPotion extends EntityObject implements ObjectInterface {
EntityMetaData metaData;
int potion; //ToDo
PotionMetaData metaData;
StatusEffects potion; //ToDo
public ThrownPotion(int id, Location location, short yaw, short pitch, int additionalInt) {
super(id, location, yaw, pitch, null);
// objects do not spawn with metadata... reading additional info from the following int
this.potion = additionalInt;
this.potion = StatusEffects.byId(additionalInt);
}
public ThrownPotion(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.potion = additionalInt;
this.potion = StatusEffects.byId(additionalInt);
}
@Override
@ -37,13 +38,13 @@ public class ThrownPotion extends EntityObject implements ObjectInterface {
}
@Override
public EntityMetaData getMetaData() {
public PotionMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = metaData;
this.metaData = (PotionMetaData) metaData;
}
@Override
@ -56,4 +57,8 @@ public class ThrownPotion extends EntityObject implements ObjectInterface {
return 0.25F;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return PotionMetaData.class;
}
}

View File

@ -15,10 +15,11 @@ package de.bixilon.minosoft.game.datatypes.entities.objects;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
import de.bixilon.minosoft.game.datatypes.entities.meta.WitherSkullMetaData;
public class WitherSkull extends EntityObject implements ObjectInterface {
final int thrower;
EntityMetaData metaData;
WitherSkullMetaData metaData;
public WitherSkull(int id, Location location, short yaw, short pitch, int additionalInt) {
super(id, location, yaw, pitch, null);
@ -37,13 +38,13 @@ public class WitherSkull extends EntityObject implements ObjectInterface {
}
@Override
public EntityMetaData getMetaData() {
public WitherSkullMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = metaData;
this.metaData = (WitherSkullMetaData) metaData;
}
@Override
@ -59,4 +60,9 @@ public class WitherSkull extends EntityObject implements ObjectInterface {
public int getThrower() {
return thrower;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return WitherSkullMetaData.class;
}
}

View File

@ -24,6 +24,15 @@ public enum Hand {
this.id = id;
}
public static Hand byId(int id) {
for (Hand h : values()) {
if (h.getId() == id) {
return h;
}
}
return null;
}
public int getId() {
return id;
}

View File

@ -96,10 +96,7 @@ public class PacketSpawnObject implements ClientboundPacket {
try {
// velocity present AND metadata
Velocity velocity = null;
if (data != 0) {
velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort());
}
Velocity velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort());
object = type.getClazz().getConstructor(int.class, Location.class, short.class, short.class, int.class, Velocity.class).newInstance(entityId, location, yaw, pitch, data, velocity);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();

View File

@ -21,6 +21,12 @@ public class BitByte {
return bitSet;
}
public static boolean isBitMask(int in, int mask) {
boolean bitSet;
bitSet = ((in & mask) == mask);
return bitSet;
}
public static boolean isBitSetShort(short in, int pos) {
boolean bitSet;
int mask = 1 << pos;