mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Changes as I was randomly staring at the code
This commit is contained in:
parent
657968f872
commit
0e07991edf
10 changed files with 23 additions and 24 deletions
|
@ -57,7 +57,7 @@ public class DefaultBlockMinecartEntity extends MinecartEntity {
|
|||
|
||||
@Override
|
||||
public void setCustomBlock(IntEntityMetadata entityMetadata) {
|
||||
customBlock = ((IntEntityMetadata) entityMetadata).getPrimitiveValue();
|
||||
customBlock = entityMetadata.getPrimitiveValue();
|
||||
|
||||
if (showCustomBlock) {
|
||||
dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(customBlock));
|
||||
|
|
|
@ -96,7 +96,7 @@ public enum BitArrayVersion {
|
|||
// Padded palettes aren't able to use bitwise operations due to their padding.
|
||||
return new PaddedBitArray(this, size, words);
|
||||
} else if (this == V0) {
|
||||
return new SingletonBitArray();
|
||||
return SingletonBitArray.INSTANCE;
|
||||
} else {
|
||||
return new Pow2BitArray(this, size, words);
|
||||
}
|
||||
|
|
|
@ -26,13 +26,12 @@
|
|||
package org.geysermc.geyser.level.chunk.bitarray;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrays;
|
||||
|
||||
public class SingletonBitArray implements BitArray {
|
||||
public static final SingletonBitArray INSTANCE = new SingletonBitArray();
|
||||
|
||||
private static final int[] EMPTY_ARRAY = new int[0];
|
||||
|
||||
public SingletonBitArray() {
|
||||
private SingletonBitArray() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +55,7 @@ public class SingletonBitArray implements BitArray {
|
|||
|
||||
@Override
|
||||
public int[] getWords() {
|
||||
return EMPTY_ARRAY;
|
||||
return IntArrays.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.geysermc.geyser.registry.loader.RegistryLoader;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
/**
|
||||
* An abstract registry holding a map of various registrations as defined by {@link M}.
|
||||
|
@ -62,15 +62,14 @@ public abstract class AbstractMappedRegistry<K, V, M extends Map<K, V>> extends
|
|||
*
|
||||
* @param key the key
|
||||
* @param mapper the mapper
|
||||
* @param <U> the type
|
||||
* @return the mapped value from the given key if present
|
||||
*/
|
||||
public <U> Optional<U> map(K key, Function<? super V, ? extends U> mapper) {
|
||||
public OptionalInt map(K key, ToIntFunction<? super V> mapper) {
|
||||
V value = this.get(key);
|
||||
if (value == null) {
|
||||
return Optional.empty();
|
||||
return OptionalInt.empty();
|
||||
} else {
|
||||
return Optional.ofNullable(mapper.apply(value));
|
||||
return OptionalInt.of(mapper.applyAsInt(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.geysermc.geyser.GeyserImpl;
|
|||
import org.geysermc.geyser.api.item.custom.CustomItemData;
|
||||
import org.geysermc.geyser.api.item.custom.CustomRenderOffsets;
|
||||
import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData;
|
||||
import org.geysermc.geyser.api.util.TriState;
|
||||
import org.geysermc.geyser.item.GeyserCustomMappingData;
|
||||
import org.geysermc.geyser.item.components.ToolBreakSpeedsUtils;
|
||||
import org.geysermc.geyser.item.components.WearableSlot;
|
||||
|
@ -171,7 +172,8 @@ public class CustomItemRegistryPopulator {
|
|||
itemProperties.putBoolean("allow_off_hand", customItemData.allowOffhand());
|
||||
itemProperties.putBoolean("hand_equipped", isTool);
|
||||
itemProperties.putInt("max_stack_size", stackSize);
|
||||
if (maxDamage > 0) {
|
||||
// Ignore durability if the item's predicate requires that it be unbreakable
|
||||
if (maxDamage > 0 && customItemData.customItemOptions().unbreakable() != TriState.TRUE) {
|
||||
componentBuilder.putCompound("minecraft:durability", NbtMap.builder()
|
||||
.putCompound("damage_chance", NbtMap.builder()
|
||||
.putInt("max", 1)
|
||||
|
|
|
@ -28,9 +28,9 @@ package org.geysermc.geyser.session;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -69,7 +69,7 @@ public final class SessionManager {
|
|||
}
|
||||
}
|
||||
|
||||
public GeyserSession sessionByXuid(@NonNull String xuid) {
|
||||
public GeyserSession sessionByXuid(@Nonnull String xuid) {
|
||||
Objects.requireNonNull(xuid);
|
||||
for (GeyserSession session : sessions.values()) {
|
||||
if (session.xuid().equals(xuid)) {
|
||||
|
|
|
@ -39,8 +39,8 @@ public class CrossbowTranslator extends NbtItemStackTranslator {
|
|||
|
||||
@Override
|
||||
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
|
||||
if (itemTag.get("ChargedProjectiles") != null) {
|
||||
ListTag chargedProjectiles = itemTag.get("ChargedProjectiles");
|
||||
ListTag chargedProjectiles = itemTag.get("ChargedProjectiles");
|
||||
if (chargedProjectiles != null) {
|
||||
if (!chargedProjectiles.getValue().isEmpty()) {
|
||||
CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0);
|
||||
|
||||
|
|
|
@ -32,13 +32,12 @@ import org.geysermc.geyser.session.GeyserSession;
|
|||
import org.geysermc.geyser.translator.inventory.item.ItemRemapper;
|
||||
import org.geysermc.geyser.translator.inventory.item.NbtItemStackTranslator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ItemRemapper
|
||||
public class LeatherArmorTranslator extends NbtItemStackTranslator {
|
||||
|
||||
private static final List<String> ITEMS = Arrays.asList("minecraft:leather_helmet", "minecraft:leather_chestplate",
|
||||
private static final List<String> ITEMS = List.of("minecraft:leather_helmet", "minecraft:leather_chestplate",
|
||||
"minecraft:leather_leggings", "minecraft:leather_boots", "minecraft:leather_horse_armor");
|
||||
|
||||
@Override
|
||||
|
@ -47,10 +46,9 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
|
|||
if (displayTag == null) {
|
||||
return;
|
||||
}
|
||||
IntTag color = displayTag.get("color");
|
||||
IntTag color = displayTag.remove("color");
|
||||
if (color != null) {
|
||||
itemTag.put(new IntTag("customColor", color.getValue()));
|
||||
displayTag.remove("color");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ package org.geysermc.geyser.translator.level.block.entity;
|
|||
import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import org.geysermc.geyser.network.GameProtocol;
|
||||
|
@ -40,7 +41,7 @@ public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
|
|||
public void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState) {
|
||||
ListTag items = tag.get("Items");
|
||||
int i = 1;
|
||||
for (com.github.steveice10.opennbt.tag.builtin.Tag itemTag : items.getValue()) {
|
||||
for (Tag itemTag : items.getValue()) {
|
||||
builder.put("Item" + i, getItem((CompoundTag) itemTag));
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class CustomItemsTest {
|
|||
tagToCustomItemWithDamage = new Object2IntOpenHashMap<>();
|
||||
|
||||
CompoundTag tag = new CompoundTag("");
|
||||
tag.put(new IntTag("CustomModelData", 6));
|
||||
addCustomModelData(6, tag);
|
||||
// Test item with no damage should be treated as unbreakable
|
||||
tagToCustomItemWithDamage.put(tag, optionsToId.getInt(a));
|
||||
|
||||
|
@ -121,7 +121,7 @@ public class CustomItemsTest {
|
|||
tagToCustomItemWithNoDamage = new Object2IntOpenHashMap<>();
|
||||
|
||||
tag = new CompoundTag("");
|
||||
tag.put(new IntTag("CustomModelData", 2));
|
||||
addCustomModelData(2, tag);
|
||||
// Damage predicates existing mean an item will never match if the item mapping has no max damage
|
||||
tagToCustomItemWithNoDamage.put(tag, -1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue