mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-22 14:34:59 +01:00
Add some code comments, update BungeeCord version check
This commit is contained in:
parent
8779eab5e5
commit
94d77b403b
4 changed files with 30 additions and 4 deletions
|
@ -83,7 +83,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
|
|||
// Copied from ViaVersion.
|
||||
// https://github.com/ViaVersion/ViaVersion/blob/b8072aad86695cc8ec6f5e4103e43baf3abf6cc5/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java#L43
|
||||
try {
|
||||
ProtocolConstants.class.getField("MINECRAFT_1_21");
|
||||
ProtocolConstants.class.getField("MINECRAFT_1_21_4");
|
||||
} catch (NoSuchFieldException e) {
|
||||
geyserLogger.error(" / \\");
|
||||
geyserLogger.error(" / \\");
|
||||
|
|
|
@ -128,6 +128,7 @@ public class WolfEntity extends TameableEntity {
|
|||
public void setBody(ItemStack stack) {
|
||||
super.setBody(stack);
|
||||
isCurseOfBinding = ItemUtils.hasEffect(session, stack, EnchantmentComponent.PREVENT_ARMOR_CHANGE);
|
||||
// Not using ItemStack#getDataComponents as that wouldn't include default item components
|
||||
repairableItems = GeyserItemStack.from(stack).getComponent(DataComponentType.REPAIRABLE);
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,10 @@ public class GeyserItemStack {
|
|||
return isEmpty() ? null : components;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this GeyserItemStack has any additional components on top of
|
||||
* the base item components.
|
||||
*/
|
||||
public boolean hasNonBaseComponents() {
|
||||
return components != null;
|
||||
}
|
||||
|
@ -137,6 +141,15 @@ public class GeyserItemStack {
|
|||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stored data component for a given {@link DataComponentType}, or null.
|
||||
* <p>
|
||||
* This method will first check the additional components that may exist,
|
||||
* and fallback to the item's default (or, "base") components if need be.
|
||||
* @param type the {@link DataComponentType} to query
|
||||
* @return the value for said type, or null.
|
||||
* @param <T> the value's type
|
||||
*/
|
||||
@Nullable
|
||||
public <T> T getComponent(@NonNull DataComponentType<T> type) {
|
||||
if (components == null) {
|
||||
|
|
|
@ -100,21 +100,33 @@ public class Item {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a modifiable DataComponents map. Should only be used when it must be modified.
|
||||
* Otherwise, prefer using GeyserItemStack's getComponent
|
||||
* Returns an unmodifiable {@link DataComponents} view containing known data components.
|
||||
* Optionally, additional components can be provided to replace (or add to)
|
||||
* the items' base components.
|
||||
* To add data components, use {@link GeyserItemStack#getOrCreateComponents()}.
|
||||
*/
|
||||
@NonNull
|
||||
@UnmodifiableView
|
||||
public DataComponents gatherComponents(DataComponents others) {
|
||||
public DataComponents gatherComponents(@Nullable DataComponents others) {
|
||||
if (others == null) {
|
||||
return baseComponents;
|
||||
}
|
||||
|
||||
// Start with the base components that always exist
|
||||
DataComponents components = baseComponents.clone();
|
||||
// Add all additional components; these can override base components!
|
||||
// e.g. custom stack size
|
||||
components.getDataComponents().putAll(others.getDataComponents());
|
||||
|
||||
// Return an unmodified map of the merged components
|
||||
return new DataComponents(ImmutableMap.copyOf(components.getDataComponents()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this items value (or null) for a specific {@link DataComponentType}.
|
||||
* Prefer using {@link GeyserItemStack#getComponent(DataComponentType)}
|
||||
* to also query additional components that would override the default ones.
|
||||
*/
|
||||
@Nullable
|
||||
public <T> T getComponent(@NonNull DataComponentType<T> type) {
|
||||
return baseComponents.get(type);
|
||||
|
|
Loading…
Reference in a new issue