mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
wip: 1.14.4 EntityMetaData
This commit is contained in:
parent
2b0a11e14d
commit
63f17d5df7
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.game.datatypes.MapSet;
|
||||||
|
import de.bixilon.minosoft.game.datatypes.VersionValueMap;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
|
||||||
|
public class VillagerData {
|
||||||
|
final int type;
|
||||||
|
final int profession;
|
||||||
|
final int level;
|
||||||
|
|
||||||
|
public VillagerData(int type, int profession, int level) {
|
||||||
|
this.type = type;
|
||||||
|
this.profession = profession;
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProfession() {
|
||||||
|
return profession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum VillagerProfessions {
|
||||||
|
NONE(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 0)}),
|
||||||
|
ARMORER(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 1)}),
|
||||||
|
BUTCHER(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 4), new MapSet<>(ProtocolVersion.VERSION_1_14_4, 2)}),
|
||||||
|
CARTOGRAPHER(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 3)}),
|
||||||
|
CLERIC(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 4)}),
|
||||||
|
FARMER(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 0), new MapSet<>(ProtocolVersion.VERSION_1_14_4, 5)}),
|
||||||
|
FISHERMAN(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 6)}),
|
||||||
|
FLETCHER(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 7)}),
|
||||||
|
LEATHER_WORKER(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 8)}),
|
||||||
|
LIBRARIAN(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 1), new MapSet<>(ProtocolVersion.VERSION_1_14_4, 9)}),
|
||||||
|
MASON(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 10)}),
|
||||||
|
NITWIT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 5), new MapSet<>(ProtocolVersion.VERSION_1_14_4, 11)}),
|
||||||
|
SHEPHERD(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 12)}),
|
||||||
|
TOOL_SMITH(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 13)}),
|
||||||
|
WEAPON_SMITH(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 14)}),
|
||||||
|
PRIEST(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 2), new MapSet<>(ProtocolVersion.VERSION_1_14_4, -1)}),
|
||||||
|
BLACKSMITH(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 3), new MapSet<>(ProtocolVersion.VERSION_1_14_4, -1)}),
|
||||||
|
|
||||||
|
HUSK(new MapSet[]{}); // used earlier (ZombieVillagerMeta)
|
||||||
|
|
||||||
|
final VersionValueMap<Integer> valueMap;
|
||||||
|
|
||||||
|
VillagerProfessions(MapSet<ProtocolVersion, Integer>[] values) {
|
||||||
|
valueMap = new VersionValueMap<>(values, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VillagerProfessions byId(int id, ProtocolVersion version) {
|
||||||
|
for (VillagerProfessions profession : values()) {
|
||||||
|
if (profession.getId(version) == id) {
|
||||||
|
return profession;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId(ProtocolVersion version) {
|
||||||
|
return valueMap.get(version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum VillagerTypes {
|
||||||
|
DESSERT(0),
|
||||||
|
JUNGLE(1),
|
||||||
|
PLAINS(2),
|
||||||
|
SAVANNA(3),
|
||||||
|
SNOW(4),
|
||||||
|
SWAMP(5),
|
||||||
|
TAIGA(6);
|
||||||
|
|
||||||
|
final int id;
|
||||||
|
|
||||||
|
VillagerTypes(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VillagerTypes byId(int id) {
|
||||||
|
for (VillagerTypes type : values()) {
|
||||||
|
if (type.getId() == id) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ package de.bixilon.minosoft.game.datatypes.entities.meta;
|
|||||||
|
|
||||||
import de.bixilon.minosoft.game.datatypes.*;
|
import de.bixilon.minosoft.game.datatypes.*;
|
||||||
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
|
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
|
||||||
|
import de.bixilon.minosoft.game.datatypes.entities.VillagerData;
|
||||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
import de.bixilon.minosoft.util.BitByte;
|
import de.bixilon.minosoft.util.BitByte;
|
||||||
@ -109,6 +110,12 @@ public class EntityMetaData {
|
|||||||
int blockId = buffer.readVarInt();
|
int blockId = buffer.readVarInt();
|
||||||
data = Blocks.getBlock(blockId, buffer.getVersion());
|
data = Blocks.getBlock(blockId, buffer.getVersion());
|
||||||
break;
|
break;
|
||||||
|
case OPT_VAR_INT:
|
||||||
|
data = buffer.readVarInt() - 1;
|
||||||
|
break;
|
||||||
|
case VILLAGER_DATA:
|
||||||
|
data = new VillagerData(buffer.readVarInt(), buffer.readVarInt(), buffer.readVarInt());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + type);
|
throw new IllegalStateException("Unexpected value: " + type);
|
||||||
}
|
}
|
||||||
@ -299,9 +306,9 @@ public class EntityMetaData {
|
|||||||
OPT_BLOCK_ID(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_10, 12), new MapSet<>(ProtocolVersion.VERSION_1_13_2, 13)}),
|
OPT_BLOCK_ID(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_10, 12), new MapSet<>(ProtocolVersion.VERSION_1_13_2, 13)}),
|
||||||
NBT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_12_2, 13), new MapSet<>(ProtocolVersion.VERSION_1_13_2, 14)}),
|
NBT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_12_2, 13), new MapSet<>(ProtocolVersion.VERSION_1_13_2, 14)}),
|
||||||
PARTICLE(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_13_2, 15)}),
|
PARTICLE(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_13_2, 15)}),
|
||||||
VILLAGER_DATA(-1),
|
VILLAGER_DATA(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 16)}),
|
||||||
OPT_VAR_INT(-1),
|
OPT_VAR_INT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 17)}),
|
||||||
POSE(-1);
|
POSE(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_14_4, 18)});
|
||||||
|
|
||||||
final VersionValueMap<Integer> valueMap;
|
final VersionValueMap<Integer> valueMap;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.bixilon.minosoft.game.datatypes.entities.meta;
|
package de.bixilon.minosoft.game.datatypes.entities.meta;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.game.datatypes.entities.VillagerData;
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -24,7 +25,7 @@ public class HuskMetaData extends ZombieMetaData {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VillagerMetaData.VillagerType getType() {
|
public VillagerData.VillagerProfessions getProfession() {
|
||||||
return null; // ToDo: husk support
|
return VillagerData.VillagerProfessions.HUSK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.bixilon.minosoft.game.datatypes.entities.meta;
|
package de.bixilon.minosoft.game.datatypes.entities.meta;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.game.datatypes.entities.VillagerData;
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -23,49 +24,20 @@ public class VillagerMetaData extends AgeableMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public VillagerType getVillagerType() {
|
public VillagerData.VillagerProfessions getProfession() {
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case VERSION_1_7_10:
|
case VERSION_1_7_10:
|
||||||
case VERSION_1_8:
|
case VERSION_1_8:
|
||||||
return VillagerType.byId((int) sets.get(16).getData());
|
return VillagerData.VillagerProfessions.byId((int) sets.get(16).getData(), version);
|
||||||
case VERSION_1_9_4:
|
case VERSION_1_9_4:
|
||||||
return VillagerType.byId((int) sets.get(12).getData());
|
return VillagerData.VillagerProfessions.byId((int) sets.get(12).getData(), version);
|
||||||
case VERSION_1_10:
|
case VERSION_1_10:
|
||||||
case VERSION_1_11_2:
|
case VERSION_1_11_2:
|
||||||
case VERSION_1_12_2:
|
case VERSION_1_12_2:
|
||||||
case VERSION_1_13_2:
|
case VERSION_1_13_2:
|
||||||
return VillagerType.byId((int) sets.get(13).getData());
|
return VillagerData.VillagerProfessions.byId((int) sets.get(13).getData(), version);
|
||||||
}
|
|
||||||
return VillagerType.FARMER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum VillagerType {
|
|
||||||
FARMER(0),
|
|
||||||
LIBRARIAN(1),
|
|
||||||
PRIEST(2),
|
|
||||||
BLACKSMITH(3),
|
|
||||||
BUTCHER(4),
|
|
||||||
NITWIT(5);
|
|
||||||
|
|
||||||
|
|
||||||
final int id;
|
|
||||||
|
|
||||||
VillagerType(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static VillagerType byId(int id) {
|
|
||||||
for (VillagerType t : values()) {
|
|
||||||
if (t.getId() == id) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
return VillagerData.VillagerProfessions.FARMER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.bixilon.minosoft.game.datatypes.entities.meta;
|
package de.bixilon.minosoft.game.datatypes.entities.meta;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.game.datatypes.entities.VillagerData;
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -39,17 +40,20 @@ public class ZombieMetaData extends MobMetaData {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VillagerMetaData.VillagerType getType() {
|
public VillagerData.VillagerProfessions getProfession() {
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case VERSION_1_7_10:
|
case VERSION_1_7_10:
|
||||||
case VERSION_1_8:
|
case VERSION_1_8:
|
||||||
return VillagerMetaData.VillagerType.byId((byte) sets.get(13).getData() - 1);
|
|
||||||
case VERSION_1_9_4:
|
|
||||||
return VillagerMetaData.VillagerType.byId((int) sets.get(12).getData() - 1);
|
|
||||||
case VERSION_1_10:
|
case VERSION_1_10:
|
||||||
return VillagerMetaData.VillagerType.byId((int) sets.get(13).getData() - 1);
|
byte set = (byte) sets.get(13).getData();
|
||||||
|
if (version == ProtocolVersion.VERSION_1_10 && set == 6) {
|
||||||
|
return VillagerData.VillagerProfessions.HUSK;
|
||||||
|
}
|
||||||
|
return VillagerData.VillagerProfessions.byId(set - 1, version);
|
||||||
|
case VERSION_1_9_4:
|
||||||
|
return VillagerData.VillagerProfessions.byId((int) sets.get(12).getData() - 1, version);
|
||||||
}
|
}
|
||||||
return null; // ToDo: Husk support
|
return VillagerData.VillagerProfessions.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConverting() {
|
public boolean isConverting() {
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.bixilon.minosoft.game.datatypes.entities.meta;
|
package de.bixilon.minosoft.game.datatypes.entities.meta;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.game.datatypes.entities.VillagerData;
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -23,15 +24,16 @@ public class ZombieVillagerMetaData extends ZombieMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VillagerMetaData.VillagerType getType() {
|
public VillagerData.VillagerProfessions getProfession() {
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case VERSION_1_11_2:
|
case VERSION_1_11_2:
|
||||||
case VERSION_1_12_2:
|
case VERSION_1_12_2:
|
||||||
return VillagerMetaData.VillagerType.byId((int) sets.get(16).getData() + 1);
|
return VillagerData.VillagerProfessions.byId((int) sets.get(16).getData(), version);
|
||||||
case VERSION_1_13_2:
|
case VERSION_1_13_2:
|
||||||
return VillagerMetaData.VillagerType.byId((int) sets.get(17).getData() + 1);
|
return VillagerData.VillagerProfessions.byId((int) sets.get(17).getData(), version);
|
||||||
|
default:
|
||||||
|
return super.getProfession();
|
||||||
}
|
}
|
||||||
return VillagerMetaData.VillagerType.FARMER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -42,8 +44,8 @@ public class ZombieVillagerMetaData extends ZombieMetaData {
|
|||||||
return ((boolean) sets.get(15).getData());
|
return ((boolean) sets.get(15).getData());
|
||||||
case VERSION_1_13_2:
|
case VERSION_1_13_2:
|
||||||
return ((boolean) sets.get(16).getData());
|
return ((boolean) sets.get(16).getData());
|
||||||
|
default:
|
||||||
|
return super.isConverting();
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public class PacketEntityTeleport implements ClientboundPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void log() {
|
public void log() {
|
||||||
Log.protocol(String.format("Entity %d moved to %s (yaw=%s, pitch=%s", entityId, location.toString(), yaw, pitch));
|
Log.protocol(String.format("Entity %d moved to %s (yaw=%s, pitch=%s)", entityId, location.toString(), yaw, pitch));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEntityId() {
|
public int getEntityId() {
|
||||||
|
@ -109,7 +109,7 @@ public class PacketMapData implements ClientboundPacket {
|
|||||||
mapId = buffer.readVarInt();
|
mapId = buffer.readVarInt();
|
||||||
scale = buffer.readByte();
|
scale = buffer.readByte();
|
||||||
boolean trackPosition = buffer.readBoolean();
|
boolean trackPosition = buffer.readBoolean();
|
||||||
if (buffer.getVersion().getVersionNumber() >= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
|
if (buffer.getVersion().getVersionNumber() >= ProtocolVersion.VERSION_1_14_4.getVersionNumber()) {
|
||||||
locked = buffer.readBoolean();
|
locked = buffer.readBoolean();
|
||||||
}
|
}
|
||||||
int pinCount = buffer.readVarInt();
|
int pinCount = buffer.readVarInt();
|
||||||
|
@ -376,7 +376,8 @@ public class InByteBuffer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case VERSION_1_12_2:
|
case VERSION_1_12_2:
|
||||||
case VERSION_1_13_2: {
|
case VERSION_1_13_2:
|
||||||
|
case VERSION_1_14_4: {
|
||||||
byte index = readByte();
|
byte index = readByte();
|
||||||
while (index != (byte) 0xFF) {
|
while (index != (byte) 0xFF) {
|
||||||
EntityMetaData.Types type = EntityMetaData.Types.byId(readVarInt(), version);
|
EntityMetaData.Types type = EntityMetaData.Types.byId(readVarInt(), version);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user