mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 11:35:18 +01:00
Add ArrayUtil
This commit is contained in:
parent
b7f388b9ee
commit
e9f547f7ba
@ -37,6 +37,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.Paintings1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.EfficiencyAttributeStorage;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.ArrayUtil;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
|
||||
public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPacket1_20_5, Protocol1_20_5To1_21> {
|
||||
@ -60,7 +61,7 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
|
||||
campfireDamageType.putString("scaling", "when_caused_by_living_non_player");
|
||||
campfireDamageType.putString("message_id", "inFire");
|
||||
campfireDamageType.putFloat("exhaustion", 0.1F);
|
||||
wrapper.set(Types.REGISTRY_ENTRY_ARRAY, 0, addRegistryEntries(entries, new RegistryEntry("minecraft:campfire", campfireDamageType)));
|
||||
wrapper.set(Types.REGISTRY_ENTRY_ARRAY, 0, ArrayUtil.add(entries, new RegistryEntry("minecraft:campfire", campfireDamageType)));
|
||||
} else {
|
||||
handleRegistryData1_20_5(wrapper.user(), type, entries);
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* For type safety and effort reasons, buffer types use arrays instead of lists.
|
||||
* <p>
|
||||
* This class includes simple methods to work with these arrays in case they need to be modified
|
||||
* (obviously being more expensive due to the required array copies for every modification).
|
||||
*/
|
||||
public final class ArrayUtil {
|
||||
|
||||
public static <T> T[] add(final T[] array, final T element) {
|
||||
final int length = array.length;
|
||||
final T[] newArray = Arrays.copyOf(array, length + 1);
|
||||
newArray[length] = element;
|
||||
return newArray;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> T[] add(final T[] array, final T... elements) {
|
||||
final int length = array.length;
|
||||
final T[] newArray = Arrays.copyOf(array, length + elements.length);
|
||||
System.arraycopy(elements, 0, newArray, length, elements.length);
|
||||
return newArray;
|
||||
}
|
||||
|
||||
public static <T> T[] remove(final T[] array, final int index) {
|
||||
final T[] newArray = Arrays.copyOf(array, array.length - 1);
|
||||
System.arraycopy(array, index + 1, newArray, index, newArray.length - index);
|
||||
return newArray;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user