rendering: fix bug in fluid renderer, data: save entity object ids in json

This commit is contained in:
Bixilon 2021-04-09 21:10:41 +02:00
parent f968199fe6
commit 7b928c69da
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 126 additions and 95 deletions

View File

@ -0,0 +1,31 @@
/*
* Minosoft
* Copyright (C) 2021 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
import com.google.gson.JsonObject
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.registry.RegistryItem
import de.bixilon.minosoft.data.mappings.registry.ResourceLocationDeserializer
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
class EntityObjectType(
override val resourceLocation: ResourceLocation,
) : RegistryItem {
companion object : ResourceLocationDeserializer<EntityObjectType> {
override fun deserialize(mappings: VersionMapping?, resourceLocation: ResourceLocation, data: JsonObject): EntityObjectType {
return EntityObjectType(resourceLocation)
}
}
}

View File

@ -1,90 +0,0 @@
/*
* Minosoft
* Copyright (C) 2021 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
import com.google.common.collect.HashBiMap
import de.bixilon.minosoft.data.DefaultEntityFactories
import de.bixilon.minosoft.data.entities.entities.AreaEffectCloud
import de.bixilon.minosoft.data.entities.entities.Entity
import de.bixilon.minosoft.data.entities.entities.boss.enderdragon.EndCrystal
import de.bixilon.minosoft.data.entities.entities.decoration.ArmorStand
import de.bixilon.minosoft.data.entities.entities.decoration.ItemFrame
import de.bixilon.minosoft.data.entities.entities.decoration.LeashFenceKnotEntity
import de.bixilon.minosoft.data.entities.entities.item.FallingBlock
import de.bixilon.minosoft.data.entities.entities.item.ItemEntity
import de.bixilon.minosoft.data.entities.entities.item.PrimedTNT
import de.bixilon.minosoft.data.entities.entities.projectile.*
import de.bixilon.minosoft.data.entities.entities.vehicle.Boat
import de.bixilon.minosoft.data.entities.entities.vehicle.Minecart
import de.bixilon.minosoft.data.entities.meta.EntityMetaData
import de.bixilon.minosoft.data.mappings.entities.EntityFactory
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import glm_.vec3.Vec3
@Deprecated(message = "We will use json for this soon")
enum class EntityObjects(
val id: Int,
val factory: EntityFactory<out Entity>,
) {
BOAT(1, Boat),
ITEM_STACK(2, ItemEntity),
AREA_EFFECT_CLOUD(3, AreaEffectCloud),
MINECART(10, Minecart),
PRIMED_TNT(50, PrimedTNT),
ENDER_CRYSTAL(51, EndCrystal),
ARROW(60, Arrow), // ToDo: Tipped Arrows
SNOWBALL(61, ThrownSnowball),
EGG(62, ThrownEgg),
FIREBALL(63, LargeFireball),
FIRE_CHARGE(64, SmallFireball),
ENDER_PEARL(65, ThrownEnderPearl),
WITHER_SKULL(66, WitherSkull),
SHULKER_BULLET(67, ShulkerBullet),
LLAMA_SPIT(67, LlamaSpit),
FALLING_BLOCK(70, FallingBlock),
ITEM_FRAME(71, ItemFrame),
EYE_OF_ENDER(72, ThrownEyeOfEnder),
THROWN_POTION(73, ThrownPotion),
// FALLING_DRAGON_EGG(74, FallingDragonEgg.class),
THROWN_EXP_BOTTLE(75, ThrownExperienceBottle),
FIREWORK(76, FireworkRocketEntity),
LEASH_KNOT(77, LeashFenceKnotEntity),
ARMOR_STAND(78, ArmorStand),
EVOKER_FANGS(78, EvokerFangs),
FISHING_HOOK(90, FishingHook),
SPECTRAL_ARROW(91, SpectralArrow),
DRAGON_FIREBALL(93, DragonFireball),
TRIDENT(94, ThrownTrident);
fun build(connection: PlayConnection, position: Vec3, rotation: EntityRotation, entityMetaData: EntityMetaData?, versionId: Int): Entity? {
return DefaultEntityFactories.buildEntity(factory, connection, position, rotation, entityMetaData, versionId)
}
companion object {
private val ID_OBJECT_MAP = HashBiMap.create<Int, EntityObjects>()
@JvmStatic
fun byId(id: Int): EntityObjects? {
return ID_OBJECT_MAP[id]
}
init {
for (value in values()) {
ID_OBJECT_MAP[value.id] = value
}
}
}
}

View File

@ -14,10 +14,12 @@
package de.bixilon.minosoft.data.mappings
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.entities.EntityObjectType
import de.bixilon.minosoft.data.entities.meta.EntityMetaData
import de.bixilon.minosoft.data.inventory.InventorySlots
import de.bixilon.minosoft.data.mappings.registry.PerEnumVersionRegistry
import de.bixilon.minosoft.data.mappings.registry.PerVersionRegistry
import de.bixilon.minosoft.data.mappings.registry.Registry
import de.bixilon.minosoft.protocol.packets.clientbound.play.title.TitleClientboundPacketFactory
import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap
@ -35,6 +37,8 @@ object DefaultRegistries {
val TITLE_ACTIONS_REGISTRY = PerEnumVersionRegistry(TitleClientboundPacketFactory.TitleActions)
val ENTITY_OBJECT_REGISTRY: Registry<EntityObjectType> = Registry()
val DEFAULT_PLUGIN_CHANNELS_REGISTRY = PerVersionRegistry<PluginChannel>()
@ -57,6 +61,8 @@ object DefaultRegistries {
DEFAULT_PLUGIN_CHANNELS_REGISTRY.initialize(registriesJson[ResourceLocation("default_plugin_channels")]!!, PluginChannel)
ENTITY_OBJECT_REGISTRY.initialize(registriesJson[ResourceLocation("entity_objects")]!!, null, EntityObjectType)
initialized = true
}

View File

@ -55,7 +55,7 @@ open class Block(
val block = when (data["class"].asString) {
"FluidBlock" -> {
val stillFluid = mappings.fluidRegistry.get(data["still_fluid"].asInt)
val flowingFluid = mappings.fluidRegistry.get(data["flowing_fluid"].asInt)
val flowingFluid = mappings.fluidRegistry.get(data["flow_fluid"].asInt)
renderOverride = mutableListOf()

View File

@ -166,8 +166,8 @@ data class BlockState(
}
owner.renderOverride?.let {
renderers.clear()
renderers.addAll(it)
}
return BlockState(

View File

@ -40,6 +40,7 @@ open class Registry<T : RegistryItem>(
return valueIdMap[value] ?: parentRegistry?.getId(value)!!
}
override fun setParent(parent: Registry<T>?) {
this.parentRegistry = parent
}

View File

@ -13,10 +13,10 @@
package de.bixilon.minosoft.protocol.packets.clientbound.play;
import de.bixilon.minosoft.data.entities.EntityObjects;
import de.bixilon.minosoft.data.entities.EntityRotation;
import de.bixilon.minosoft.data.entities.Velocity;
import de.bixilon.minosoft.data.entities.entities.Entity;
import de.bixilon.minosoft.data.mappings.DefaultRegistries;
import de.bixilon.minosoft.modding.event.events.EntitySpawnEvent;
import de.bixilon.minosoft.protocol.network.connection.PlayConnection;
import de.bixilon.minosoft.protocol.packets.clientbound.PlayClientboundPacket;
@ -65,7 +65,8 @@ public class PacketSpawnObject extends PlayClientboundPacket {
}
if (buffer.getVersionId() < V_19W05A) {
this.entity = EntityObjects.byId(type).build(buffer.getConnection(), position, rotation, null, buffer.getVersionId()); // ToDo: Entity meta data tweaking
var entityResourceLocation = DefaultRegistries.INSTANCE.getENTITY_OBJECT_REGISTRY().get(type).getResourceLocation();
this.entity = buffer.getConnection().getMapping().getEntityRegistry().get(entityResourceLocation).build(buffer.getConnection(), position, rotation, null, buffer.getVersionId()); // ToDo: Entity meta data tweaking
} else {
this.entity = buffer.getConnection().getMapping().getEntityRegistry().get(type).build(buffer.getConnection(), position, rotation, null, buffer.getVersionId());
}

View File

@ -25,5 +25,87 @@
"name": "minecraft:unregister"
}
}
},
"minecraft:entity_objects": {
"0": {
"minecraft:boat": {
"id": 1
},
"minecraft:item": {
"id": 2
},
"minecraft:area_effect_cloud": {
"id": 3
},
"minecraft:minecart": {
"id": 10
},
"minecraft:tnt": {
"id": 50
},
"minecraft:end_crystal": {
"id": 51
},
"minecraft:arrow": {
"id": 60
},
"minecraft:snowball": {
"id": 61
},
"minecraft:egg": {
"id": 62
},
"minecraft:fireball": {
"id": 63
},
"minecraft:small_fireball": {
"id": 64
},
"minecraft:ender_pearl": {
"id": 65
},
"minecraft:wither_skull": {
"id": 66
},
"minecraft:llama_spit": {
"id": 67
},
"minecraft:falling_block": {
"id": 70
},
"minecraft:item_frame": {
"id": 71
},
"minecraft:eye_of_ender": {
"id": 72
},
"minecraft:potion": {
"id": 73
},
"minecraft:experience_bottle": {
"id": 75
},
"minecraft:firework_rocket": {
"id": 76
},
"minecraft:leash_knot": {
"id": 77
},
"minecraft:evoker_fangs": {
"id": 78
},
"minecraft:fishing_bobber": {
"id": 90
},
"minecraft:spectral_arrow": {
"id": 91
},
"minecraft:dragon_fireball": {
"id": 93
},
"minecraft:trident": {
"id": 94
}
}
}
}