data: read entity animations from pixlyzer/default registry

This commit is contained in:
Bixilon 2021-04-15 12:37:57 +02:00
parent 968b054478
commit a009167fae
6 changed files with 89 additions and 76 deletions

View File

@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.inventory.InventorySlots
import de.bixilon.minosoft.data.mappings.registry.PerEnumVersionRegistry import de.bixilon.minosoft.data.mappings.registry.PerEnumVersionRegistry
import de.bixilon.minosoft.data.mappings.registry.PerVersionRegistry import de.bixilon.minosoft.data.mappings.registry.PerVersionRegistry
import de.bixilon.minosoft.data.mappings.registry.Registry import de.bixilon.minosoft.data.mappings.registry.Registry
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketEntityAnimation
import de.bixilon.minosoft.protocol.packets.clientbound.play.title.TitleClientboundPacketFactory import de.bixilon.minosoft.protocol.packets.clientbound.play.title.TitleClientboundPacketFactory
import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap
@ -37,6 +38,8 @@ object DefaultRegistries {
val TITLE_ACTIONS_REGISTRY = PerEnumVersionRegistry(TitleClientboundPacketFactory.TitleActions) val TITLE_ACTIONS_REGISTRY = PerEnumVersionRegistry(TitleClientboundPacketFactory.TitleActions)
val ENTITY_ANIMATION_REGISTRY = PerEnumVersionRegistry(PacketEntityAnimation.EntityAnimations)
val ENTITY_OBJECT_REGISTRY: Registry<EntityObjectType> = Registry() val ENTITY_OBJECT_REGISTRY: Registry<EntityObjectType> = Registry()
val DEFAULT_PLUGIN_CHANNELS_REGISTRY = PerVersionRegistry<PluginChannel>() val DEFAULT_PLUGIN_CHANNELS_REGISTRY = PerVersionRegistry<PluginChannel>()
@ -56,6 +59,8 @@ object DefaultRegistries {
TITLE_ACTIONS_REGISTRY.initialize(enumJson[ResourceLocation("title_actions")]!!) TITLE_ACTIONS_REGISTRY.initialize(enumJson[ResourceLocation("title_actions")]!!)
ENTITY_ANIMATION_REGISTRY.initialize(enumJson[ResourceLocation("entity_animations")]!!)
val registriesJson = Minosoft.MINOSOFT_ASSETS_MANAGER.readJsonAsset(REGISTRIES_RESOURCE_LOCATION).asJsonObject.toResourceLocationMap() val registriesJson = Minosoft.MINOSOFT_ASSETS_MANAGER.readJsonAsset(REGISTRIES_RESOURCE_LOCATION).asJsonObject.toResourceLocationMap()

View File

@ -37,6 +37,7 @@ import de.bixilon.minosoft.data.mappings.statistics.Statistic
import de.bixilon.minosoft.gui.rendering.chunk.VoxelShape import de.bixilon.minosoft.gui.rendering.chunk.VoxelShape
import de.bixilon.minosoft.gui.rendering.chunk.models.AABB import de.bixilon.minosoft.gui.rendering.chunk.models.AABB
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketEntityAnimation
import de.bixilon.minosoft.protocol.packets.clientbound.play.title.TitleClientboundPacketFactory import de.bixilon.minosoft.protocol.packets.clientbound.play.title.TitleClientboundPacketFactory
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.collections.Clearable import de.bixilon.minosoft.util.collections.Clearable
@ -69,6 +70,8 @@ class VersionMapping {
val titleActionsRegistry: EnumRegistry<TitleClientboundPacketFactory.TitleActions> = EnumRegistry(values = TitleClientboundPacketFactory.TitleActions) val titleActionsRegistry: EnumRegistry<TitleClientboundPacketFactory.TitleActions> = EnumRegistry(values = TitleClientboundPacketFactory.TitleActions)
val entityAnimationRegistry: EnumRegistry<PacketEntityAnimation.EntityAnimations> = EnumRegistry(values = PacketEntityAnimation.EntityAnimations)
val creativeModeTabRegistry: FakeEnumRegistry<CreativeModeTab> = FakeEnumRegistry() val creativeModeTabRegistry: FakeEnumRegistry<CreativeModeTab> = FakeEnumRegistry()
val biomePrecipitationRegistry: FakeEnumRegistry<BiomePrecipitation> = FakeEnumRegistry() val biomePrecipitationRegistry: FakeEnumRegistry<BiomePrecipitation> = FakeEnumRegistry()
@ -136,10 +139,11 @@ class VersionMapping {
loadEnumRegistry(version, pixlyzerData["entity_meta_data_data_types"], entityMetaDataDataDataTypesRegistry, DefaultRegistries.ENTITY_META_DATA_DATA_TYPES_REGISTRY) loadEnumRegistry(version, pixlyzerData["entity_meta_data_data_types"], entityMetaDataDataDataTypesRegistry, DefaultRegistries.ENTITY_META_DATA_DATA_TYPES_REGISTRY)
loadEnumRegistry(version, pixlyzerData["title_actions"], titleActionsRegistry, DefaultRegistries.TITLE_ACTIONS_REGISTRY) loadEnumRegistry(version, pixlyzerData["title_actions"], titleActionsRegistry, DefaultRegistries.TITLE_ACTIONS_REGISTRY)
loadEnumRegistry(version, pixlyzerData["entity_animations"], entityAnimationRegistry, DefaultRegistries.ENTITY_ANIMATION_REGISTRY)
// id stuff // id stuff
biomeCategoryRegistry.initialize(pixlyzerData["biome_categories"]?.asJsonObject, this, BiomeCategory) biomeCategoryRegistry.initialize(pixlyzerData["biome_categories"]?.asJsonObject, this, BiomeCategory)
biomePrecipitationRegistry.initialize(pixlyzerData["biome_precipations"]?.asJsonObject, this, BiomePrecipitation) biomePrecipitationRegistry.initialize(pixlyzerData["biome_precipitations"]?.asJsonObject, this, BiomePrecipitation)
creativeModeTabRegistry.initialize(pixlyzerData["creative_inventory_tab"]?.asJsonObject, this, CreativeModeTab) creativeModeTabRegistry.initialize(pixlyzerData["creative_inventory_tab"]?.asJsonObject, this, CreativeModeTab)
// id resource location stuff // id resource location stuff

View File

@ -78,6 +78,7 @@ public class PacketEffect extends PlayClientboundPacket {
return this.disableRelativeVolume; return this.disableRelativeVolume;
} }
@Deprecated
public enum EffectEffects { public enum EffectEffects {
// ToDo: find out correct versions // ToDo: find out correct versions

View File

@ -1,75 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.clientbound.play;
import de.bixilon.minosoft.data.VersionValueMap;
import de.bixilon.minosoft.protocol.packets.clientbound.PlayClientboundPacket;
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
import de.bixilon.minosoft.util.logging.Log;
import java.util.Map;
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.*;
public class PacketEntityAnimation extends PlayClientboundPacket {
private final int entityId;
private final EntityAnimations animation;
public PacketEntityAnimation(PlayInByteBuffer buffer) {
this.entityId = buffer.readVarInt();
this.animation = EntityAnimations.byId(buffer.readUnsignedByte(), buffer.getVersionId());
}
@Override
public void log() {
Log.protocol(String.format("[IN] Play entity animation (entityId=%d, animation=%s)", this.entityId, this.animation));
}
public enum EntityAnimations {
// ToDo
SWING_RIGHT_ARM(Map.of(LOWEST_VERSION_SUPPORTED, 0)),
TAKE_DAMAGE(Map.of(LOWEST_VERSION_SUPPORTED, 1)),
LEAVE_BED(Map.of(LOWEST_VERSION_SUPPORTED, 2)),
EAT_FOOD(Map.of(LOWEST_VERSION_SUPPORTED, 3, V_1_9_4, -1)),
SWING_LEFT_ARM(Map.of(V_1_9_4, 3)),
CRITICAL_EFFECT(Map.of(LOWEST_VERSION_SUPPORTED, 4)),
MAGIC_CRITICAL_EFFECT(Map.of(LOWEST_VERSION_SUPPORTED, 5)),
UNKNOWN_1(Map.of(LOWEST_VERSION_SUPPORTED, 102, V_1_8_9, -1)), // name currently unknown // ToDo
SNEAK(Map.of(LOWEST_VERSION_SUPPORTED, 104, V_1_8_9, -1)),
UN_SNEAK(Map.of(LOWEST_VERSION_SUPPORTED, 105, V_1_8_9, -1));
private final VersionValueMap<Integer> valueMap;
EntityAnimations(Map<Integer, Integer> values) {
this.valueMap = new VersionValueMap<>(values);
}
public static EntityAnimations byId(int id, int versionId) {
for (EntityAnimations animation : values()) {
if (animation.getId(versionId) == id) {
return animation;
}
}
return null;
}
public int getId(Integer versionId) {
Integer ret = this.valueMap.get(versionId);
if (ret == null) {
return -2;
}
return ret;
}
}
}

View File

@ -0,0 +1,49 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.clientbound.play
import de.bixilon.minosoft.protocol.packets.clientbound.PlayClientboundPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum
import de.bixilon.minosoft.util.logging.Log
class PacketEntityAnimation(buffer: PlayInByteBuffer) : PlayClientboundPacket() {
val entityId: Int = buffer.readVarInt()
val animation: EntityAnimations = buffer.connection.mapping.entityAnimationRegistry.get(buffer.readVarInt())!!
override fun log() {
Log.protocol("[IN] Play entity animation (entityId=$entityId, animation=$animation)")
}
enum class EntityAnimations {
SWING_MAIN_ARM,
TAKE_DAMAGE,
LEAVE_BED,
EAT_FOOD,
SWING_OFF_ARM,
CRITICAL_EFFECT,
MAGIC_CRITICAL_EFFECT,
UNKNOWN_1,
SNEAK,
UNSNEAK,
;
// ToDo: find out what unknown_1 is, check values, check ids and load data from pixlyzer
companion object : ValuesEnum<EntityAnimations> {
override val VALUES = values()
override val NAME_MAP = KUtil.getEnumValues(VALUES)
}
}
}

View File

@ -214,5 +214,34 @@
"HIDE", "HIDE",
"RESET" "RESET"
] ]
},
"minecraft:entity_animations": {
"0": {
"0": "SWING_MAIN_ARM",
"1": "TAKE_DAMAGE",
"2": "LEAVE_BED",
"3": "EAT_FOOD",
"4": "CRITICAL_EFFECT",
"5": "MAGIC_CRITICAL_EFFECT",
"102": "UNKNOWN_1",
"104": "SNEAK",
"105": "UNSNEAK"
},
"47": {
"0": "SWING_MAIN_ARM",
"1": "TAKE_DAMAGE",
"2": "LEAVE_BED",
"3": "EAT_FOOD",
"4": "CRITICAL_EFFECT",
"5": "MAGIC_CRITICAL_EFFECT"
},
"110": [
"SWING_MAIN_ARM",
"TAKE_DAMAGE",
"LEAVE_BED",
"SWING_OFF_ARM",
"CRITICAL_EFFECT",
"MAGIC_CRITICAL_EFFECT"
]
} }
} }