diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/MetaType.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/MetaType.java index c84316f13..0feca7ea9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/MetaType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/MetaType.java @@ -46,9 +46,9 @@ public interface MetaType { final class MetaTypeImpl implements MetaType { private final int typeId; - private final Type type; + private final Type type; - MetaTypeImpl(final int typeId, final Type type) { + MetaTypeImpl(final int typeId, final Type type) { this.typeId = typeId; this.type = type; } @@ -59,7 +59,7 @@ public interface MetaType { } @Override - public Type type() { + public Type type() { return type; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/AbstractMetaTypes.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/AbstractMetaTypes.java new file mode 100644 index 000000000..8bd3a4876 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/AbstractMetaTypes.java @@ -0,0 +1,51 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.metadata.types; + +import com.viaversion.viaversion.api.minecraft.metadata.MetaType; +import com.viaversion.viaversion.api.type.Type; + +public abstract class AbstractMetaTypes implements MetaTypes { + + private final MetaType[] values; + + protected AbstractMetaTypes(final int values) { + this.values = new MetaType[values]; + } + + @Override + public MetaType byId(final int id) { + return values[id]; + } + + @Override + public MetaType[] values() { + return values; + } + + protected MetaType add(final int typeId, final Type type) { + final MetaType metaType = MetaType.create(typeId, type); + values[typeId] = metaType; + return metaType; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13.java index 6b2c4b71a..8fd650e5b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13.java @@ -26,9 +26,8 @@ import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; -public final class MetaTypes1_13 implements MetaTypes { +public final class MetaTypes1_13 extends AbstractMetaTypes { - private final MetaType[] values = new MetaType[16]; public final MetaType byteType = add(0, Type.BYTE); public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType floatType = add(2, Type.FLOAT); @@ -47,22 +46,7 @@ public final class MetaTypes1_13 implements MetaTypes { public final MetaType particleType; public MetaTypes1_13(final ParticleType particleType) { + super(16); this.particleType = add(15, particleType); } - - @Override - public MetaType byId(final int id) { - return values[id]; - } - - @Override - public MetaType[] values() { - return values; - } - - private MetaType add(final int typeId, final Type type) { - final MetaType metaType = MetaType.create(typeId, type); - values[typeId] = metaType; - return metaType; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13_2.java index 4495568ce..14b824352 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13_2.java @@ -26,9 +26,8 @@ import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; -public final class MetaTypes1_13_2 implements MetaTypes { +public final class MetaTypes1_13_2 extends AbstractMetaTypes { - private final MetaType[] values = new MetaType[16]; public final MetaType byteType = add(0, Type.BYTE); public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType floatType = add(2, Type.FLOAT); @@ -47,22 +46,7 @@ public final class MetaTypes1_13_2 implements MetaTypes { public final MetaType particleType; public MetaTypes1_13_2(final ParticleType particleType) { + super(16); this.particleType = add(15, particleType); } - - @Override - public MetaType byId(final int id) { - return values[id]; - } - - @Override - public MetaType[] values() { - return values; - } - - private MetaType add(final int typeId, final Type type) { - final MetaType metaType = MetaType.create(typeId, type); - values[typeId] = metaType; - return metaType; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_14.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_14.java index 47b12ea4e..c13c57a3a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_14.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_14.java @@ -26,9 +26,8 @@ import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; -public final class MetaTypes1_14 implements MetaTypes { +public final class MetaTypes1_14 extends AbstractMetaTypes { - private final MetaType[] values = new MetaType[19]; public final MetaType byteType = add(0, Type.BYTE); public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType floatType = add(2, Type.FLOAT); @@ -50,22 +49,7 @@ public final class MetaTypes1_14 implements MetaTypes { public final MetaType poseType = add(18, Type.VAR_INT); public MetaTypes1_14(final ParticleType particleType) { + super(19); this.particleType = add(15, particleType); } - - @Override - public MetaType byId(final int id) { - return values[id]; - } - - @Override - public MetaType[] values() { - return values; - } - - private MetaType add(final int typeId, final Type type) { - final MetaType metaType = MetaType.create(typeId, type); - values[typeId] = metaType; - return metaType; - } }