Update registry data

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-11-10 16:45:46 +01:00
parent 736977cb0f
commit e75b9f238d
5 changed files with 25 additions and 63 deletions

View File

@ -158,7 +158,7 @@ dependencies {
}
api "com.github.Minestom:DependencyGetter:v1.0.1"
implementation 'com.github.Minestom:MinestomDataGenerator:7636d5d473'
implementation 'com.github.Minestom:MinestomDataGenerator:47da93dd5a99280314d7e6137d2c81e7793f0fdb'
// Adventure, for user-interface
api "net.kyori:adventure-api:$adventureVersion"

View File

@ -25,7 +25,7 @@ dependencies {
// SLF4J is the base logger for most libraries, therefore we can hook it into log4j2.
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
// Contains the json files
implementation 'com.github.Minestom:MinestomDataGenerator:7636d5d473'
implementation 'com.github.Minestom:MinestomDataGenerator:47da93dd5a99280314d7e6137d2c81e7793f0fdb'
}

View File

@ -189,8 +189,8 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
Entity.ENTITY_BY_ID.put(id, this);
Entity.ENTITY_BY_UUID.put(uuid, this);
this.gravityAcceleration = EntityTypeImpl.getAcceleration(entityType.name());
this.gravityDragPerTick = EntityTypeImpl.getDrag(entityType.name());
this.gravityAcceleration = entityType.registry().acceleration();
this.gravityDragPerTick = entityType.registry().drag();
}
public Entity(@NotNull EntityType entityType) {

View File

@ -46,8 +46,6 @@ record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType {
private static final Registry.Container<EntityType> CONTAINER = new Registry.Container<>(Registry.Resource.ENTITIES,
(container, namespace, object) -> container.register(new EntityTypeImpl(Registry.entity(namespace, object, null))));
private static final Map<String, BiFunction<Entity, Metadata, EntityMeta>> ENTITY_META_SUPPLIER = createMetaMap();
private static final Map<String, Double> ACCELERATION_MAP = createAccelerationMap();
private static final Map<String, Double> DRAG_MAP = createDragMap();
static EntityType get(@NotNull String namespace) {
return CONTAINER.get(namespace);
@ -69,14 +67,6 @@ record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType {
return ENTITY_META_SUPPLIER.get(entityType.name()).apply(entity, metadata);
}
static double getAcceleration(String namespace) {
return ACCELERATION_MAP.getOrDefault(namespace, 0.08);
}
static double getDrag(String namespace) {
return DRAG_MAP.getOrDefault(namespace, 0.02);
}
private static Map<String, BiFunction<Entity, Metadata, EntityMeta>> createMetaMap() {
Map<String, BiFunction<Entity, Metadata, EntityMeta>> supplier = new HashMap<>();
supplier.put("minecraft:area_effect_cloud", AreaEffectCloudMeta::new);
@ -194,54 +184,6 @@ record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType {
return supplier;
}
private static Map<String, Double> createDragMap() {
Map<String, Double> result = new HashMap<>();
result.put("minecraft:boat", 0d);
result.put("minecraft:llama_spit", 0.01);
result.put("minecraft:ender_pearl", 0.01);
result.put("minecraft:potion", 0.01);
result.put("minecraft:snowball", 0.01);
result.put("minecraft:egg", 0.01);
result.put("minecraft:trident", 0.01);
result.put("minecraft:spectral_arrow", 0.01);
result.put("minecraft:arrow", 0.01);
result.put("minecraft:minecart", 0.05);
result.put("minecraft:fishing_bobber", 0.08);
return result;
}
private static Map<String, Double> createAccelerationMap() {
Map<String, Double> result = new HashMap<>();
result.put("minecraft:item_frame", 0d);
result.put("minecraft:egg", 0.03);
result.put("minecraft:fishing_bobber", 0.03);
result.put("minecraft:experience_bottle", 0.03);
result.put("minecraft:ender_pearl", 0.03);
result.put("minecraft:potion", 0.03);
result.put("minecraft:snowball", 0.03);
result.put("minecraft:boat", 0.04);
result.put("minecraft:tnt", 0.04);
result.put("minecraft:falling_block", 0.04);
result.put("minecraft:item", 0.04);
result.put("minecraft:minecart", 0.04);
result.put("minecraft:arrow", 0.05);
result.put("minecraft:spectral_arrow", 0.05);
result.put("minecraft:trident", 0.05);
result.put("minecraft:llama_spit", 0.06);
result.put("minecraft:fireball", 0.1);
result.put("minecraft:wither_skull", 0.1);
result.put("minecraft:dragon_fireball", 0.1);
return result;
}
@Override
public String toString() {
return name();

View File

@ -173,7 +173,15 @@ public final class Registry {
this.air = getBoolean("air", false);
this.solid = getBoolean("solid");
this.liquid = getBoolean("liquid", false);
this.blockEntity = getString("blockEntity", null);
{
Map<String, Object> blockEntity = element("blockEntity");
if (blockEntity != null) {
this.blockEntity = (String) blockEntity.get("namespace");
} else {
this.blockEntity = null;
}
}
{
final String materialNamespace = getString("correspondingItem", null);
this.materialSupplier = materialNamespace != null ? () -> Material.fromNamespaceId(materialNamespace) : () -> null;
@ -324,6 +332,8 @@ public final class Registry {
private final String translationKey;
private final double width;
private final double height;
private final double drag;
private final double acceleration;
private final EntitySpawnType spawnType;
private EntityEntry(String namespace, Map<String, Object> main, Map<String, Object> override) {
@ -333,6 +343,8 @@ public final class Registry {
this.translationKey = getString("translationKey");
this.width = getDouble("width");
this.height = getDouble("height");
this.drag = getDouble("drag", 0.02);
this.acceleration = getDouble("acceleration", 0.08);
this.spawnType = EntitySpawnType.valueOf(getString("packetType").toUpperCase(Locale.ROOT));
}
@ -356,6 +368,14 @@ public final class Registry {
return height;
}
public double drag() {
return drag;
}
public double acceleration() {
return acceleration;
}
public EntitySpawnType spawnType() {
return spawnType;
}