mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
add zombie, prototype of new entity system (wip)
This commit is contained in:
parent
707fc357bc
commit
e869478e79
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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.data;
|
||||||
|
|
||||||
|
import com.google.common.collect.HashBiMap;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Zombie;
|
||||||
|
import javafx.util.Pair;
|
||||||
|
|
||||||
|
public final class EntityClassMappings {
|
||||||
|
public static final HashBiMap<Class<? extends Entity>, Pair<String, String>> ENTITY_CLASS_MAPPINGS = HashBiMap.create();
|
||||||
|
|
||||||
|
static {
|
||||||
|
ENTITY_CLASS_MAPPINGS.put(Zombie.class, new Pair<>("minecraft", "zombie"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class<? extends Entity> getByIdentifier(String mod, String identifier) {
|
||||||
|
return ENTITY_CLASS_MAPPINGS.inverse().get(new Pair<>(mod, identifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,5 +15,6 @@ package de.bixilon.minosoft.data;
|
|||||||
|
|
||||||
public enum Mappings {
|
public enum Mappings {
|
||||||
BLOCKS,
|
BLOCKS,
|
||||||
REGISTRIES
|
REGISTRIES,
|
||||||
|
ENTITIES
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.data;
|
package de.bixilon.minosoft.data;
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.Entity;
|
|
||||||
import de.bixilon.minosoft.data.entities.Velocity;
|
import de.bixilon.minosoft.data.entities.Velocity;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -32,6 +32,14 @@ public class EntityInformation {
|
|||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityInformation(String mod, String identifier, int maxHealth, int width, int height) {
|
||||||
|
this.mod = mod;
|
||||||
|
this.identifier = identifier;
|
||||||
|
this.maxHealth = maxHealth;
|
||||||
|
this.width = this.length = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMod() {
|
public String getMod() {
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ public class EntityMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object get(EntityMetaDataFields field) {
|
public Object get(EntityMetaDataFields field) {
|
||||||
int index = connection.getMapping().getEntityMappings().getEntityMetaDatIndex(field);
|
int index = connection.getMapping().getEntityMetaDatIndex(field);
|
||||||
if (containsKey(index)) {
|
if (containsKey(index)) {
|
||||||
return super.get(index);
|
return super.get(index);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,13 @@ public enum EntityMetaDataFields {
|
|||||||
LIVING_ENTITY_EFFECT_AMBIENCE(false),
|
LIVING_ENTITY_EFFECT_AMBIENCE(false),
|
||||||
LIVING_ENTITY_ARROW_COUNT(0),
|
LIVING_ENTITY_ARROW_COUNT(0),
|
||||||
LIVING_ENTITY_ABSORPTION_HEARTS(0),
|
LIVING_ENTITY_ABSORPTION_HEARTS(0),
|
||||||
LIVING_ENTITY_BED_POSITION;
|
LIVING_ENTITY_BED_POSITION,
|
||||||
|
|
||||||
|
MOB_FLAGS(0),
|
||||||
|
|
||||||
|
ZOMBIE_IS_BABY(false),
|
||||||
|
ZOMBIE_SPECIAL_TYPE(0),
|
||||||
|
ZOMBIE_DROWNING_CONVERSION(false);
|
||||||
|
|
||||||
final Object defaultValue;
|
final Object defaultValue;
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
package de.bixilon.minosoft.data.entities;
|
package de.bixilon.minosoft.data.entities;
|
||||||
|
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
|
|
||||||
public enum Objects {
|
public enum Objects {
|
||||||
/*
|
/*
|
||||||
|
@ -11,8 +11,9 @@
|
|||||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.bixilon.minosoft.data.entities;
|
package de.bixilon.minosoft.data.entities.entities;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.entities.*;
|
||||||
import de.bixilon.minosoft.data.inventory.InventorySlots;
|
import de.bixilon.minosoft.data.inventory.InventorySlots;
|
||||||
import de.bixilon.minosoft.data.inventory.Slot;
|
import de.bixilon.minosoft.data.inventory.Slot;
|
||||||
import de.bixilon.minosoft.data.mappings.MobEffect;
|
import de.bixilon.minosoft.data.mappings.MobEffect;
|
||||||
@ -37,7 +38,7 @@ public abstract class Entity {
|
|||||||
protected EntityMetaData metaData;
|
protected EntityMetaData metaData;
|
||||||
|
|
||||||
public Entity(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) {
|
public Entity(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) {
|
||||||
this.information = connection.getMapping().getEntityMappings().getEntityInformation(getClass());
|
this.information = connection.getMapping().getEntityInformation(getClass());
|
||||||
this.entityId = entityId;
|
this.entityId = entityId;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
@ -136,7 +137,6 @@ public abstract class Entity {
|
|||||||
return information;
|
return information;
|
||||||
}
|
}
|
||||||
|
|
||||||
// meta data
|
|
||||||
|
|
||||||
private boolean getEntityFlag(int bitMask) {
|
private boolean getEntityFlag(int bitMask) {
|
||||||
return metaData.getSets().getBitMask(EntityMetaDataFields.ENTITY_FLAGS, bitMask);
|
return metaData.getSets().getBitMask(EntityMetaDataFields.ENTITY_FLAGS, bitMask);
|
@ -11,8 +11,11 @@
|
|||||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.bixilon.minosoft.data.entities;
|
package de.bixilon.minosoft.data.entities.entities;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityMetaDataFields;
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityRotation;
|
||||||
|
import de.bixilon.minosoft.data.entities.Location;
|
||||||
import de.bixilon.minosoft.data.player.Hands;
|
import de.bixilon.minosoft.data.player.Hands;
|
||||||
import de.bixilon.minosoft.data.world.BlockPosition;
|
import de.bixilon.minosoft.data.world.BlockPosition;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
@ -24,7 +27,7 @@ public abstract class LivingEntity extends Entity {
|
|||||||
super(connection, entityId, uuid, location, rotation);
|
super(connection, entityId, uuid, location, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// meta data
|
|
||||||
private boolean getLivingEntityFlag(int bitMask) {
|
private boolean getLivingEntityFlag(int bitMask) {
|
||||||
return metaData.getSets().getBitMask(EntityMetaDataFields.LIVING_ENTITY_FLAGS, bitMask);
|
return metaData.getSets().getBitMask(EntityMetaDataFields.LIVING_ENTITY_FLAGS, bitMask);
|
||||||
}
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.data.entities.entities;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityMetaDataFields;
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityRotation;
|
||||||
|
import de.bixilon.minosoft.data.entities.Location;
|
||||||
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class Mob extends LivingEntity {
|
||||||
|
public Mob(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) {
|
||||||
|
super(connection, entityId, uuid, location, rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getMobFlags(int bitMask) {
|
||||||
|
return metaData.getSets().getBitMask(EntityMetaDataFields.MOB_FLAGS, bitMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNoAi() {
|
||||||
|
return getMobFlags(0x01);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLeftHanded() {
|
||||||
|
return getMobFlags(0x02);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAggressive() {
|
||||||
|
return getMobFlags(0x04);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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.data.entities.entities;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityRotation;
|
||||||
|
import de.bixilon.minosoft.data.entities.Location;
|
||||||
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class Monster extends PathfinderMob {
|
||||||
|
public Monster(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) {
|
||||||
|
super(connection, entityId, uuid, location, rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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.data.entities.entities;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityRotation;
|
||||||
|
import de.bixilon.minosoft.data.entities.Location;
|
||||||
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class PathfinderMob extends Mob {
|
||||||
|
public PathfinderMob(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) {
|
||||||
|
super(connection, entityId, uuid, location, rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.data.entities.entities;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityMetaDataFields;
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityRotation;
|
||||||
|
import de.bixilon.minosoft.data.entities.Location;
|
||||||
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Zombie extends Monster {
|
||||||
|
public Zombie(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) {
|
||||||
|
super(connection, entityId, uuid, location, rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isBaby() {
|
||||||
|
return metaData.getSets().getBoolean(EntityMetaDataFields.ZOMBIE_IS_BABY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSpecialType() {
|
||||||
|
return metaData.getSets().getInt(EntityMetaDataFields.ZOMBIE_SPECIAL_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConvertingToDrowned() {
|
||||||
|
return metaData.getSets().getBoolean(EntityMetaDataFields.ZOMBIE_DROWNING_CONVERSION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,9 @@
|
|||||||
package de.bixilon.minosoft.data.mappings;
|
package de.bixilon.minosoft.data.mappings;
|
||||||
|
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityInformation;
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityMetaDataFields;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||||
import de.bixilon.minosoft.data.mappings.particle.Particle;
|
import de.bixilon.minosoft.data.mappings.particle.Particle;
|
||||||
import de.bixilon.minosoft.data.mappings.statistics.Statistic;
|
import de.bixilon.minosoft.data.mappings.statistics.Statistic;
|
||||||
@ -35,7 +38,7 @@ public class CustomMapping {
|
|||||||
final HashBiMap<Integer, Enchantment> enchantmentMap = HashBiMap.create();
|
final HashBiMap<Integer, Enchantment> enchantmentMap = HashBiMap.create();
|
||||||
final HashBiMap<Integer, Particle> particleIdMap = HashBiMap.create();
|
final HashBiMap<Integer, Particle> particleIdMap = HashBiMap.create();
|
||||||
final HashBiMap<Integer, Statistic> statisticIdMap = HashBiMap.create();
|
final HashBiMap<Integer, Statistic> statisticIdMap = HashBiMap.create();
|
||||||
final EntityMappings entityMappings = null; //ToDo
|
final EntityMappings entityMappings = new EntityMappings();
|
||||||
Version version;
|
Version version;
|
||||||
HashMap<String, HashBiMap<String, Dimension>> dimensionIdentifierMap = new HashMap<>();
|
HashMap<String, HashBiMap<String, Dimension>> dimensionIdentifierMap = new HashMap<>();
|
||||||
|
|
||||||
@ -186,6 +189,17 @@ public class CustomMapping {
|
|||||||
return version.getMapping().getIdByEnchantment(enchantment);
|
return version.getMapping().getIdByEnchantment(enchantment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityInformation getEntityInformation(Class<? extends Entity> clazz) {
|
||||||
|
if (entityMappings.getEntityInformation(clazz) != null) {
|
||||||
|
return entityMappings.getEntityInformation(clazz);
|
||||||
|
}
|
||||||
|
return version.getMapping().getEntityInformation(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEntityMetaDatIndex(EntityMetaDataFields field) {
|
||||||
|
return version.getMapping().getEntityMetaDatIndex(field);
|
||||||
|
}
|
||||||
|
|
||||||
public void unload() {
|
public void unload() {
|
||||||
motiveIdentifierMap.clear();
|
motiveIdentifierMap.clear();
|
||||||
particleIdentifierMap.clear();
|
particleIdentifierMap.clear();
|
||||||
@ -206,7 +220,10 @@ public class CustomMapping {
|
|||||||
dimensionIdentifierMap = dimensions;
|
dimensionIdentifierMap = dimensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityMappings getEntityMappings() {
|
public Class<? extends Entity> getEntityClassById(int id) {
|
||||||
return entityMappings;
|
if (entityMappings.getEntityClassById(id) != null) {
|
||||||
|
return entityMappings.getEntityClassById(id);
|
||||||
|
}
|
||||||
|
return version.getMapping().getEntityClassById(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,18 +14,38 @@
|
|||||||
package de.bixilon.minosoft.data.mappings;
|
package de.bixilon.minosoft.data.mappings;
|
||||||
|
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import de.bixilon.minosoft.data.entities.Entity;
|
|
||||||
import de.bixilon.minosoft.data.entities.EntityInformation;
|
import de.bixilon.minosoft.data.entities.EntityInformation;
|
||||||
import de.bixilon.minosoft.data.entities.EntityMetaDataFields;
|
import de.bixilon.minosoft.data.entities.EntityMetaDataFields;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class EntityMappings {
|
public class EntityMappings {
|
||||||
private final HashBiMap<Class<? extends Entity>, EntityInformation> entityInformationMap = HashBiMap.create();
|
private final HashBiMap<Class<? extends Entity>, EntityInformation> entityInformationMap;
|
||||||
|
private final HashMap<EntityMetaDataFields, Integer> indexMapping;
|
||||||
|
private final HashBiMap<Integer, Class<? extends Entity>> entityIdMapping;
|
||||||
|
|
||||||
|
public EntityMappings() {
|
||||||
|
this.entityInformationMap = HashBiMap.create();
|
||||||
|
this.indexMapping = new HashMap<>();
|
||||||
|
this.entityIdMapping = HashBiMap.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityMappings(HashBiMap<Class<? extends Entity>, EntityInformation> entityInformationMap, HashMap<EntityMetaDataFields, Integer> indexMapping, HashBiMap<Integer, Class<? extends Entity>> entityIdMapping) {
|
||||||
|
this.entityInformationMap = entityInformationMap;
|
||||||
|
this.indexMapping = indexMapping;
|
||||||
|
this.entityIdMapping = entityIdMapping;
|
||||||
|
}
|
||||||
|
|
||||||
public EntityInformation getEntityInformation(Class<? extends Entity> clazz) {
|
public EntityInformation getEntityInformation(Class<? extends Entity> clazz) {
|
||||||
return entityInformationMap.get(clazz);
|
return entityInformationMap.get(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEntityMetaDatIndex(EntityMetaDataFields field) {
|
public int getEntityMetaDatIndex(EntityMetaDataFields field) {
|
||||||
return 0; // ToDo
|
return indexMapping.get(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<? extends Entity> getEntityClassById(int id) {
|
||||||
|
return entityIdMapping.get(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,11 @@ package de.bixilon.minosoft.data.mappings.versions;
|
|||||||
|
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import de.bixilon.minosoft.data.EntityClassMappings;
|
||||||
import de.bixilon.minosoft.data.Mappings;
|
import de.bixilon.minosoft.data.Mappings;
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityInformation;
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityMetaDataFields;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.data.mappings.*;
|
import de.bixilon.minosoft.data.mappings.*;
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.Blocks;
|
import de.bixilon.minosoft.data.mappings.blocks.Blocks;
|
||||||
@ -23,6 +27,7 @@ import de.bixilon.minosoft.data.mappings.particle.Particle;
|
|||||||
import de.bixilon.minosoft.data.mappings.statistics.Statistic;
|
import de.bixilon.minosoft.data.mappings.statistics.Statistic;
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class VersionMapping {
|
public class VersionMapping {
|
||||||
@ -32,7 +37,6 @@ public class VersionMapping {
|
|||||||
HashBiMap<String, Particle> particleIdentifierMap;
|
HashBiMap<String, Particle> particleIdentifierMap;
|
||||||
HashBiMap<String, Statistic> statisticIdentifierMap;
|
HashBiMap<String, Statistic> statisticIdentifierMap;
|
||||||
HashBiMap<Integer, Item> itemMap;
|
HashBiMap<Integer, Item> itemMap;
|
||||||
HashBiMap<Integer, String> entityMap;
|
|
||||||
HashBiMap<Integer, Motive> motiveIdMap;
|
HashBiMap<Integer, Motive> motiveIdMap;
|
||||||
HashBiMap<Integer, MobEffect> mobEffectMap;
|
HashBiMap<Integer, MobEffect> mobEffectMap;
|
||||||
HashBiMap<Integer, Dimension> dimensionMap;
|
HashBiMap<Integer, Dimension> dimensionMap;
|
||||||
@ -41,6 +45,7 @@ public class VersionMapping {
|
|||||||
HashBiMap<Integer, Enchantment> enchantmentMap;
|
HashBiMap<Integer, Enchantment> enchantmentMap;
|
||||||
HashBiMap<Integer, Particle> particleIdMap;
|
HashBiMap<Integer, Particle> particleIdMap;
|
||||||
HashBiMap<Integer, Statistic> statisticIdMap;
|
HashBiMap<Integer, Statistic> statisticIdMap;
|
||||||
|
EntityMappings entityMappings;
|
||||||
|
|
||||||
public VersionMapping(Version version) {
|
public VersionMapping(Version version) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
@ -66,10 +71,6 @@ public class VersionMapping {
|
|||||||
return itemMap.inverse().get(item);
|
return itemMap.inverse().get(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEntityIdentifierById(int versionId) {
|
|
||||||
return "minecraft:" + entityMap.get(versionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Motive getMotiveById(int versionId) {
|
public Motive getMotiveById(int versionId) {
|
||||||
return motiveIdMap.get(versionId);
|
return motiveIdMap.get(versionId);
|
||||||
}
|
}
|
||||||
@ -128,11 +129,6 @@ public class VersionMapping {
|
|||||||
}
|
}
|
||||||
itemMap.put(itemId, item);
|
itemMap.put(itemId, item);
|
||||||
}
|
}
|
||||||
entityMap = HashBiMap.create();
|
|
||||||
JsonObject entityJson = data.getAsJsonObject("entity_type").getAsJsonObject("entries");
|
|
||||||
for (String identifier : entityJson.keySet()) {
|
|
||||||
entityMap.put(entityJson.getAsJsonObject(identifier).get("id").getAsInt(), identifier);
|
|
||||||
}
|
|
||||||
enchantmentMap = HashBiMap.create();
|
enchantmentMap = HashBiMap.create();
|
||||||
JsonObject enchantmentJson = data.getAsJsonObject("enchantment").getAsJsonObject("entries");
|
JsonObject enchantmentJson = data.getAsJsonObject("enchantment").getAsJsonObject("entries");
|
||||||
for (String identifier : enchantmentJson.keySet()) {
|
for (String identifier : enchantmentJson.keySet()) {
|
||||||
@ -191,6 +187,36 @@ public class VersionMapping {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case BLOCKS -> blockMap = Blocks.load("minecraft", data, version.getVersionId() < ProtocolDefinition.FLATTING_VERSION_ID);
|
case BLOCKS -> blockMap = Blocks.load("minecraft", data, version.getVersionId() < ProtocolDefinition.FLATTING_VERSION_ID);
|
||||||
|
case ENTITIES -> {
|
||||||
|
HashBiMap<Class<? extends Entity>, EntityInformation> entityInformationMap = HashBiMap.create();
|
||||||
|
HashMap<EntityMetaDataFields, Integer> indexMapping = new HashMap<>();
|
||||||
|
HashBiMap<Integer, Class<? extends Entity>> entityIdMap = HashBiMap.create();
|
||||||
|
|
||||||
|
for (String mod : data.keySet()) {
|
||||||
|
JsonObject modJson = data.getAsJsonObject(mod);
|
||||||
|
for (String identifier : modJson.keySet()) {
|
||||||
|
JsonObject identifierJson = modJson.getAsJsonObject(identifier);
|
||||||
|
if (!identifier.startsWith("~abstract")) {
|
||||||
|
// not abstract, has attributes
|
||||||
|
Class<? extends Entity> clazz = EntityClassMappings.getByIdentifier(mod, identifier);
|
||||||
|
entityInformationMap.put(clazz, new EntityInformation(mod, identifier, identifierJson.get("maxHealth").getAsInt(), identifierJson.get("length").getAsInt(), identifierJson.get("width").getAsInt(), identifierJson.get("height").getAsInt()));
|
||||||
|
|
||||||
|
entityIdMap.put(identifierJson.get("id").getAsInt(), clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// meta data index
|
||||||
|
if (identifierJson.has("data")) {
|
||||||
|
JsonObject metaDataJson = identifierJson.getAsJsonObject("data");
|
||||||
|
for (String field : metaDataJson.keySet()) {
|
||||||
|
indexMapping.put(EntityMetaDataFields.valueOf(field), metaDataJson.get(field).getAsInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entityMappings = new EntityMappings(entityInformationMap, indexMapping, entityIdMap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
loaded.add(type);
|
loaded.add(type);
|
||||||
}
|
}
|
||||||
@ -200,7 +226,6 @@ public class VersionMapping {
|
|||||||
particleIdentifierMap.clear();
|
particleIdentifierMap.clear();
|
||||||
statisticIdentifierMap.clear();
|
statisticIdentifierMap.clear();
|
||||||
itemMap.clear();
|
itemMap.clear();
|
||||||
entityMap.clear();
|
|
||||||
motiveIdMap.clear();
|
motiveIdMap.clear();
|
||||||
mobEffectMap.clear();
|
mobEffectMap.clear();
|
||||||
dimensionMap.clear();
|
dimensionMap.clear();
|
||||||
@ -219,4 +244,16 @@ public class VersionMapping {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityInformation getEntityInformation(Class<? extends Entity> clazz) {
|
||||||
|
return entityMappings.getEntityInformation(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEntityMetaDatIndex(EntityMetaDataFields field) {
|
||||||
|
return entityMappings.getEntityMetaDatIndex(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<? extends Entity> getEntityClassById(int id) {
|
||||||
|
return entityMappings.getEntityClassById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ public class Versions {
|
|||||||
static {
|
static {
|
||||||
mappingsHashMap.put("registries", Mappings.REGISTRIES);
|
mappingsHashMap.put("registries", Mappings.REGISTRIES);
|
||||||
mappingsHashMap.put("blocks", Mappings.BLOCKS);
|
mappingsHashMap.put("blocks", Mappings.BLOCKS);
|
||||||
|
mappingsHashMap.put("entities", Mappings.ENTITIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Version getVersionById(int versionId) {
|
public static Version getVersionById(int versionId) {
|
||||||
@ -125,7 +126,13 @@ public class Versions {
|
|||||||
HashMap<String, JsonObject> files = Util.readJsonTarStream(AssetsManager.readAssetAsStream(String.format("mappings/%s", version.getVersionName())));
|
HashMap<String, JsonObject> files = Util.readJsonTarStream(AssetsManager.readAssetAsStream(String.format("mappings/%s", version.getVersionName())));
|
||||||
|
|
||||||
for (Map.Entry<String, Mappings> mappingSet : mappingsHashMap.entrySet()) {
|
for (Map.Entry<String, Mappings> mappingSet : mappingsHashMap.entrySet()) {
|
||||||
JsonObject data = files.get(mappingSet.getKey() + ".json").getAsJsonObject("minecraft");
|
JsonObject data;
|
||||||
|
//ToDo
|
||||||
|
if (mappingSet.getValue() == Mappings.ENTITIES) {
|
||||||
|
data = Util.readJsonAsset("mapping/entities.json"); // ToDo
|
||||||
|
} else {
|
||||||
|
data = files.get(mappingSet.getKey() + ".json").getAsJsonObject("minecraft");
|
||||||
|
}
|
||||||
loadVersionMappings(mappingSet.getValue(), data, versionId);
|
loadVersionMappings(mappingSet.getValue(), data, versionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.data.world;
|
package de.bixilon.minosoft.data.world;
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.Entity;
|
|
||||||
import de.bixilon.minosoft.data.entities.block.BlockEntityMetaData;
|
import de.bixilon.minosoft.data.entities.block.BlockEntityMetaData;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.data.mappings.Dimension;
|
import de.bixilon.minosoft.data.mappings.Dimension;
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.Blocks;
|
import de.bixilon.minosoft.data.mappings.blocks.Blocks;
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.modding.event.events;
|
package de.bixilon.minosoft.modding.event.events;
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.Entity;
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketDestroyEntity;
|
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketDestroyEntity;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.modding.event.events;
|
package de.bixilon.minosoft.modding.event.events;
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.Entity;
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.data.inventory.InventorySlots;
|
import de.bixilon.minosoft.data.inventory.InventorySlots;
|
||||||
import de.bixilon.minosoft.data.inventory.Slot;
|
import de.bixilon.minosoft.data.inventory.Slot;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.modding.event.events;
|
package de.bixilon.minosoft.modding.event.events;
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.Entity;
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.*;
|
import de.bixilon.minosoft.protocol.packets.clientbound.play.*;
|
||||||
|
|
||||||
|
@ -13,7 +13,11 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.*;
|
import de.bixilon.minosoft.data.entities.EntityMetaData;
|
||||||
|
import de.bixilon.minosoft.data.entities.EntityRotation;
|
||||||
|
import de.bixilon.minosoft.data.entities.Location;
|
||||||
|
import de.bixilon.minosoft.data.entities.Velocity;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||||
@ -40,7 +44,7 @@ public class PacketSpawnMob implements ClientboundPacket {
|
|||||||
} else {
|
} else {
|
||||||
type = buffer.readVarInt();
|
type = buffer.readVarInt();
|
||||||
}
|
}
|
||||||
Class<? extends Entity> typeClass = null; //ToDo
|
Class<? extends Entity> typeClass = buffer.getConnection().getMapping().getEntityClassById(type);
|
||||||
Location location;
|
Location location;
|
||||||
if (buffer.getVersionId() < 100) {
|
if (buffer.getVersionId() < 100) {
|
||||||
location = new Location(buffer.readFixedPointNumberInteger(), buffer.readFixedPointNumberInteger(), buffer.readFixedPointNumberInteger());
|
location = new Location(buffer.readFixedPointNumberInteger(), buffer.readFixedPointNumberInteger(), buffer.readFixedPointNumberInteger());
|
||||||
|
@ -13,7 +13,11 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.*;
|
import de.bixilon.minosoft.data.entities.EntityRotation;
|
||||||
|
import de.bixilon.minosoft.data.entities.Location;
|
||||||
|
import de.bixilon.minosoft.data.entities.Objects;
|
||||||
|
import de.bixilon.minosoft.data.entities.Velocity;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.serverbound.play;
|
package de.bixilon.minosoft.protocol.packets.serverbound.play;
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.Entity;
|
|
||||||
import de.bixilon.minosoft.data.entities.Location;
|
import de.bixilon.minosoft.data.entities.Location;
|
||||||
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.data.player.Hands;
|
import de.bixilon.minosoft.data.player.Hands;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
|
@ -16,7 +16,7 @@ package de.bixilon.minosoft.protocol.protocol;
|
|||||||
import de.bixilon.minosoft.Minosoft;
|
import de.bixilon.minosoft.Minosoft;
|
||||||
import de.bixilon.minosoft.config.ConfigurationPaths;
|
import de.bixilon.minosoft.config.ConfigurationPaths;
|
||||||
import de.bixilon.minosoft.data.GameModes;
|
import de.bixilon.minosoft.data.GameModes;
|
||||||
import de.bixilon.minosoft.data.entities.Entity;
|
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.Blocks;
|
import de.bixilon.minosoft.data.mappings.blocks.Blocks;
|
||||||
import de.bixilon.minosoft.data.mappings.recipes.Recipes;
|
import de.bixilon.minosoft.data.mappings.recipes.Recipes;
|
||||||
import de.bixilon.minosoft.data.mappings.versions.Version;
|
import de.bixilon.minosoft.data.mappings.versions.Version;
|
||||||
|
44
src/main/java/de/bixilon/minosoft/util/Pair.java
Normal file
44
src/main/java/de/bixilon/minosoft/util/Pair.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Pair<K, V> {
|
||||||
|
|
||||||
|
public final K key;
|
||||||
|
public final V value;
|
||||||
|
|
||||||
|
public Pair(K key, V value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Pair<?, ?> pair = (Pair<?, ?>) o;
|
||||||
|
return Objects.equals(key, pair.key) && Objects.equals(value, pair.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return String.format("%s=%s", key, value);
|
||||||
|
}
|
||||||
|
}
|
44
src/main/resources/assets/mapping/entities.json
Normal file
44
src/main/resources/assets/mapping/entities.json
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"minecraft": {
|
||||||
|
"~abstract_entity": {
|
||||||
|
"data": {
|
||||||
|
"ENTITY_FLAGS": 0,
|
||||||
|
"ENTITY_AIR_SUPPLY": 1,
|
||||||
|
"ENTITY_CUSTOM_NAME": 2,
|
||||||
|
"ENTITY_CUSTOM_NAME_VISIBLE": 3,
|
||||||
|
"ENTITY_SILENT": 4,
|
||||||
|
"ENTITY_NO_GRAVITY": 5,
|
||||||
|
"ENTITY_POSE": 6,
|
||||||
|
"ENTITY_TICKS_FROZEN": 7
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"~abstract_living_entity": {
|
||||||
|
"data": {
|
||||||
|
"LIVING_ENTITY_FLAGS": 8,
|
||||||
|
"LIVING_ENTITY_HEALTH": 9,
|
||||||
|
"LIVING_ENTITY_EFFECT_COLOR": 10,
|
||||||
|
"LIVING_ENTITY_EFFECT_AMBIENCE": 11,
|
||||||
|
"LIVING_ENTITY_ARROW_COUNT": 12,
|
||||||
|
"LIVING_ENTITY_ABSORPTION_HEARTS": 13,
|
||||||
|
"LIVING_ENTITY_BED_POSITION": 14
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"~abstract_mob": {
|
||||||
|
"data": {
|
||||||
|
"MOB_FLAGS": 15
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zombie": {
|
||||||
|
"id": 102,
|
||||||
|
"length": 0.6,
|
||||||
|
"width": 0.6,
|
||||||
|
"height": 1.95,
|
||||||
|
"maxHealth": 20,
|
||||||
|
"data": {
|
||||||
|
"ZOMBIE_IS_BABY": 16,
|
||||||
|
"ZOMBIE_SPECIAL_TYPE": 17,
|
||||||
|
"ZOMBIE_DROWNING_CONVERSION": 18
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user