ViaVersion/api/src/main/java/com/viaversion/viaversion/api/minecraft/Particle.java

107 lines
3.3 KiB
Java
Raw Normal View History

/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
2024-01-12 10:01:48 +01:00
* 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.
*/
2023-10-21 05:00:39 +02:00
package com.viaversion.viaversion.api.minecraft;
2018-04-02 17:06:25 +02:00
2023-10-21 05:00:39 +02:00
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
2023-10-21 05:00:39 +02:00
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
2018-04-02 17:06:25 +02:00
2023-10-21 05:00:39 +02:00
public final class Particle {
private final List<ParticleData<?>> arguments = new ArrayList<>(4);
2018-04-02 17:06:25 +02:00
private int id;
2023-10-21 05:00:39 +02:00
public Particle(final int id) {
2018-04-02 17:06:25 +02:00
this.id = id;
}
public int getId() {
return id;
}
2023-10-21 05:00:39 +02:00
public void setId(final int id) {
this.id = id;
}
2023-11-09 06:35:07 +01:00
public <T> ParticleData<T> getArgument(final int index) {
2023-10-21 05:00:39 +02:00
//noinspection unchecked
2023-11-09 06:35:07 +01:00
return (ParticleData<T>) arguments.get(index);
}
public <T> ParticleData<T> removeArgument(final int index) {
//noinspection unchecked
return (ParticleData<T>) arguments.remove(index);
}
2023-10-21 05:00:39 +02:00
public List<ParticleData<?>> getArguments() {
return arguments;
}
2023-10-21 05:00:39 +02:00
public <T> void add(final Type<T> type, final T value) {
arguments.add(new ParticleData<>(type, value));
}
2023-11-09 06:35:07 +01:00
public <T> void add(final int index, final Type<T> type, final T value) {
arguments.add(index, new ParticleData<>(type, value));
}
2023-10-21 05:00:39 +02:00
public static final class ParticleData<T> {
private final Type<T> type;
private T value;
2023-10-21 05:00:39 +02:00
public ParticleData(final Type<T> type, final T value) {
this.type = type;
this.value = value;
}
2023-10-21 05:00:39 +02:00
public Type<T> getType() {
return type;
}
2023-10-21 05:00:39 +02:00
public T getValue() {
return value;
}
2023-10-21 05:00:39 +02:00
public void setValue(final T value) {
this.value = value;
}
2023-10-21 05:00:39 +02:00
public void write(final ByteBuf buf) throws Exception {
type.write(buf, value);
}
2023-10-21 05:00:39 +02:00
public void write(final PacketWrapper wrapper) {
wrapper.write(type, value);
}
2023-06-06 13:28:02 +02:00
@Override
public String toString() {
return "ParticleData{" +
"type=" + type +
", value=" + value +
'}';
}
2018-04-02 17:06:25 +02:00
}
}