1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-30 09:07:55 +00:00

Merge branch 'mc-1.21.x' into mc-1.21.y

This commit is contained in:
Jonathan Coates
2025-05-16 18:38:21 +01:00
33 changed files with 258 additions and 285 deletions

View File

@@ -59,10 +59,10 @@ public final class SelectUpgradeModel<T> implements TurtleUpgradeModel {
}
private TurtleUpgradeModel getModel(UpgradeData<ITurtleUpgrade> upgrade) {
var value = upgrade.data().get(component);
if (value == null || value.isEmpty()) return fallback;
var value = upgrade.get(component);
if (value == null) return fallback;
var model = cases.get(value.get());
var model = cases.get(value);
return model != null ? model : fallback;
}

View File

@@ -7,8 +7,11 @@ package dan200.computercraft.api.upgrades;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponentGetter;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.world.item.ItemStack;
import org.jspecify.annotations.Nullable;
/**
* An upgrade (i.e. a {@link ITurtleUpgrade}) and its current upgrade data.
@@ -17,7 +20,9 @@ import net.minecraft.world.item.ItemStack;
* @param data The upgrade's data.
* @param <T> The type of upgrade, either {@link ITurtleUpgrade} or {@link IPocketUpgrade}.
*/
public record UpgradeData<T extends UpgradeBase>(Holder.Reference<T> holder, DataComponentPatch data) {
public record UpgradeData<T extends UpgradeBase>(
Holder.Reference<T> holder, DataComponentPatch data
) implements DataComponentGetter {
/**
* A utility method to construct a new {@link UpgradeData} instance.
*
@@ -66,4 +71,17 @@ public record UpgradeData<T extends UpgradeBase>(Holder.Reference<T> holder, Dat
public ItemStack getUpgradeItem() {
return upgrade().getUpgradeItem(data).copy();
}
/**
* Get a component from the upgrade's {@link #data()} .
*
* @param component The component get.
* @param <U> The type of the component's value.
* @return The component, or {@code null} if not present.
*/
@Override
public <U> @Nullable U get(DataComponentType<? extends U> component) {
var result = data().get(component);
return result == null ? null : result.orElse(null);
}
}