ViaVersion/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BannerPatternLayer.java

64 lines
2.6 KiB
Java
Raw Normal View History

2024-02-28 22:15:31 +01:00
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 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.item.data;
2024-03-06 16:53:37 +01:00
import com.viaversion.viaversion.api.minecraft.Holder;
2024-02-28 22:15:31 +01:00
import com.viaversion.viaversion.api.type.Type;
2024-03-06 16:53:37 +01:00
import com.viaversion.viaversion.api.type.types.ArrayType;
2024-02-28 22:15:31 +01:00
import io.netty.buffer.ByteBuf;
2024-03-06 16:53:37 +01:00
public final class BannerPatternLayer {
2024-02-28 22:15:31 +01:00
2024-03-06 16:53:37 +01:00
public static final Type<BannerPatternLayer> TYPE = new Type<BannerPatternLayer>(BannerPatternLayer.class) {
2024-02-28 22:15:31 +01:00
@Override
2024-03-06 16:53:37 +01:00
public BannerPatternLayer read(final ByteBuf buffer) throws Exception {
final Holder<BannerPattern> pattern = BannerPattern.TYPE.read(buffer);
2024-03-09 16:56:02 +01:00
final int color = Type.VAR_INT.readPrimitive(buffer);
2024-03-06 16:53:37 +01:00
return new BannerPatternLayer(pattern, color);
2024-02-28 22:15:31 +01:00
}
@Override
2024-03-06 16:53:37 +01:00
public void write(final ByteBuf buffer, final BannerPatternLayer value) throws Exception {
BannerPattern.TYPE.write(buffer, value.pattern);
2024-03-09 16:56:02 +01:00
Type.VAR_INT.writePrimitive(buffer, value.dyeColor);
2024-02-28 22:15:31 +01:00
}
};
2024-03-06 16:53:37 +01:00
public static final Type<BannerPatternLayer[]> ARRAY_TYPE = new ArrayType<>(TYPE);
2024-02-28 22:15:31 +01:00
2024-03-06 16:53:37 +01:00
private final Holder<BannerPattern> pattern;
2024-03-09 16:56:02 +01:00
private final int dyeColor;
2024-02-28 22:15:31 +01:00
2024-03-09 16:56:02 +01:00
public BannerPatternLayer(final Holder<BannerPattern> pattern, final int dyeColor) {
2024-03-06 16:53:37 +01:00
this.pattern = pattern;
2024-03-09 16:56:02 +01:00
this.dyeColor = dyeColor;
2024-02-28 22:15:31 +01:00
}
2024-03-06 16:53:37 +01:00
public Holder<BannerPattern> pattern() {
return pattern;
2024-02-28 22:15:31 +01:00
}
2024-03-09 16:56:02 +01:00
public int dyeColor() {
return dyeColor;
2024-02-28 22:15:31 +01:00
}
}