3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 00:00:41 +01:00

Changes as I was randomly staring at the code

Dieser Commit ist enthalten in:
Camotoy 2022-10-17 23:36:46 -04:00
Ursprung 657968f872
Commit 0e07991edf
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
10 geänderte Dateien mit 23 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -57,7 +57,7 @@ public class DefaultBlockMinecartEntity extends MinecartEntity {
@Override @Override
public void setCustomBlock(IntEntityMetadata entityMetadata) { public void setCustomBlock(IntEntityMetadata entityMetadata) {
customBlock = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); customBlock = entityMetadata.getPrimitiveValue();
if (showCustomBlock) { if (showCustomBlock) {
dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(customBlock)); dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(customBlock));

Datei anzeigen

@ -96,7 +96,7 @@ public enum BitArrayVersion {
// Padded palettes aren't able to use bitwise operations due to their padding. // Padded palettes aren't able to use bitwise operations due to their padding.
return new PaddedBitArray(this, size, words); return new PaddedBitArray(this, size, words);
} else if (this == V0) { } else if (this == V0) {
return new SingletonBitArray(); return SingletonBitArray.INSTANCE;
} else { } else {
return new Pow2BitArray(this, size, words); return new Pow2BitArray(this, size, words);
} }

Datei anzeigen

@ -26,13 +26,12 @@
package org.geysermc.geyser.level.chunk.bitarray; package org.geysermc.geyser.level.chunk.bitarray;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.IntArrays;
public class SingletonBitArray implements BitArray { public class SingletonBitArray implements BitArray {
public static final SingletonBitArray INSTANCE = new SingletonBitArray(); public static final SingletonBitArray INSTANCE = new SingletonBitArray();
private static final int[] EMPTY_ARRAY = new int[0]; private SingletonBitArray() {
public SingletonBitArray() {
} }
@Override @Override
@ -56,7 +55,7 @@ public class SingletonBitArray implements BitArray {
@Override @Override
public int[] getWords() { public int[] getWords() {
return EMPTY_ARRAY; return IntArrays.EMPTY_ARRAY;
} }
@Override @Override

Datei anzeigen

@ -29,8 +29,8 @@ import org.geysermc.geyser.registry.loader.RegistryLoader;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.OptionalInt;
import java.util.function.Function; import java.util.function.ToIntFunction;
/** /**
* An abstract registry holding a map of various registrations as defined by {@link M}. * 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 key the key
* @param mapper the mapper * @param mapper the mapper
* @param <U> the type
* @return the mapped value from the given key if present * @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); V value = this.get(key);
if (value == null) { if (value == null) {
return Optional.empty(); return OptionalInt.empty();
} else { } else {
return Optional.ofNullable(mapper.apply(value)); return OptionalInt.of(mapper.applyAsInt(value));
} }
} }

Datei anzeigen

@ -34,6 +34,7 @@ import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.item.custom.CustomItemData; import org.geysermc.geyser.api.item.custom.CustomItemData;
import org.geysermc.geyser.api.item.custom.CustomRenderOffsets; import org.geysermc.geyser.api.item.custom.CustomRenderOffsets;
import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData; 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.GeyserCustomMappingData;
import org.geysermc.geyser.item.components.ToolBreakSpeedsUtils; import org.geysermc.geyser.item.components.ToolBreakSpeedsUtils;
import org.geysermc.geyser.item.components.WearableSlot; import org.geysermc.geyser.item.components.WearableSlot;
@ -171,7 +172,8 @@ public class CustomItemRegistryPopulator {
itemProperties.putBoolean("allow_off_hand", customItemData.allowOffhand()); itemProperties.putBoolean("allow_off_hand", customItemData.allowOffhand());
itemProperties.putBoolean("hand_equipped", isTool); itemProperties.putBoolean("hand_equipped", isTool);
itemProperties.putInt("max_stack_size", stackSize); 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() componentBuilder.putCompound("minecraft:durability", NbtMap.builder()
.putCompound("damage_chance", NbtMap.builder() .putCompound("damage_chance", NbtMap.builder()
.putInt("max", 1) .putInt("max", 1)

Datei anzeigen

@ -28,9 +28,9 @@ package org.geysermc.geyser.session;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
import javax.annotation.Nonnull;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; 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); Objects.requireNonNull(xuid);
for (GeyserSession session : sessions.values()) { for (GeyserSession session : sessions.values()) {
if (session.xuid().equals(xuid)) { if (session.xuid().equals(xuid)) {

Datei anzeigen

@ -39,8 +39,8 @@ public class CrossbowTranslator extends NbtItemStackTranslator {
@Override @Override
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) { 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()) { if (!chargedProjectiles.getValue().isEmpty()) {
CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0); CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0);

Datei anzeigen

@ -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.ItemRemapper;
import org.geysermc.geyser.translator.inventory.item.NbtItemStackTranslator; import org.geysermc.geyser.translator.inventory.item.NbtItemStackTranslator;
import java.util.Arrays;
import java.util.List; import java.util.List;
@ItemRemapper @ItemRemapper
public class LeatherArmorTranslator extends NbtItemStackTranslator { 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"); "minecraft:leather_leggings", "minecraft:leather_boots", "minecraft:leather_horse_armor");
@Override @Override
@ -47,10 +46,9 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
if (displayTag == null) { if (displayTag == null) {
return; return;
} }
IntTag color = displayTag.get("color"); IntTag color = displayTag.remove("color");
if (color != null) { if (color != null) {
itemTag.put(new IntTag("customColor", color.getValue())); itemTag.put(new IntTag("customColor", color.getValue()));
displayTag.remove("color");
} }
} }

Datei anzeigen

@ -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.mc.protocol.data.game.level.block.BlockEntityType;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; 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.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder; import com.nukkitx.nbt.NbtMapBuilder;
import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.network.GameProtocol;
@ -40,7 +41,7 @@ public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
public void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState) { public void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState) {
ListTag items = tag.get("Items"); ListTag items = tag.get("Items");
int i = 1; 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)); builder.put("Item" + i, getItem((CompoundTag) itemTag));
i++; i++;
} }

Datei anzeigen

@ -72,7 +72,7 @@ public class CustomItemsTest {
tagToCustomItemWithDamage = new Object2IntOpenHashMap<>(); tagToCustomItemWithDamage = new Object2IntOpenHashMap<>();
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag("");
tag.put(new IntTag("CustomModelData", 6)); addCustomModelData(6, tag);
// Test item with no damage should be treated as unbreakable // Test item with no damage should be treated as unbreakable
tagToCustomItemWithDamage.put(tag, optionsToId.getInt(a)); tagToCustomItemWithDamage.put(tag, optionsToId.getInt(a));
@ -121,7 +121,7 @@ public class CustomItemsTest {
tagToCustomItemWithNoDamage = new Object2IntOpenHashMap<>(); tagToCustomItemWithNoDamage = new Object2IntOpenHashMap<>();
tag = new CompoundTag(""); 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 // Damage predicates existing mean an item will never match if the item mapping has no max damage
tagToCustomItemWithNoDamage.put(tag, -1); tagToCustomItemWithNoDamage.put(tag, -1);