3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Move MetaTypes methods up into abstract class

Dieser Commit ist enthalten in:
Nassim Jahnke 2021-11-17 11:13:14 +01:00
Ursprung 6a8aa497b0
Commit 8be1fc9340
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
5 geänderte Dateien mit 60 neuen und 57 gelöschten Zeilen

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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;
}
}