Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import io.papermc.paper.datacomponent.item.BannerPatternLayers;
import io.papermc.paper.datacomponent.item.BlockItemDataProperties;
import io.papermc.paper.datacomponent.item.BlocksAttacks;
import io.papermc.paper.datacomponent.item.BrewingFuel;
import io.papermc.paper.datacomponent.item.BundleContents;
import io.papermc.paper.datacomponent.item.ChargedProjectiles;
import io.papermc.paper.datacomponent.item.Consumable;
import io.papermc.paper.datacomponent.item.CookingFuel;
import io.papermc.paper.datacomponent.item.CustomModelData;
import io.papermc.paper.datacomponent.item.DamageResistant;
import io.papermc.paper.datacomponent.item.DeathProtection;
Expand Down Expand Up @@ -401,6 +403,14 @@ public final class DataComponentTypes {
public static final DataComponentType.Valued<SignText> SIGN_TEXT_BACK = valued("sign_text_back");
public static final DataComponentType.NonValued WAXED = unvalued("waxed");
public static final DataComponentType.Valued<DyeColor> CUSHION_COLOR = valued("cushion/color");
/**
* Describes an item that can be used as fuel for a furnace, smoker or blast furnace.
*/
public static final DataComponentType.Valued<CookingFuel> COOKING_FUEL = valued("cooking_fuel");
/**
* Describes an item that can be used as fuel for a brewing stand.
*/
public static final DataComponentType.Valued<BrewingFuel> BREWING_FUEL = valued("brewing_fuel");

private static DataComponentType.NonValued unvalued(@KeyPattern.Value final String key) {
final DataComponentType dataComponentType = Registry.DATA_COMPONENT_TYPE.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.papermc.paper.datacomponent.item;

import io.papermc.paper.datacomponent.DataComponentBuilder;
import io.papermc.paper.loot.number.ResolvableFloat;
import io.papermc.paper.loot.number.ResolvableInt;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;

/**
* Describes an item that can be used as fuel for a brewing stand.
*
* @see io.papermc.paper.datacomponent.DataComponentTypes#BREWING_FUEL
*/
@ApiStatus.NonExtendable
public interface BrewingFuel {

@Contract(value = "-> new", pure = true)
static BrewingFuel.Builder brewingFuel() {
return ItemComponentTypesBridge.bridge().brewingFuel();
}

/**
* @return the number of times this fuel will brew before being consumed
*/
@Contract(pure = true)
ResolvableInt uses();

/**
* @return the speed of the brewing
*/
@Contract(pure = true)
ResolvableFloat speedMultiplier();

/**
* Builder for {@link BrewingFuel}.
*/
@ApiStatus.NonExtendable
interface Builder extends DataComponentBuilder<BrewingFuel> {

/**
* @param uses the number of times this fuel will brew before being consumed
* @return the builder for chaining
* @see #uses()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder uses(int uses);

/**
* @param speedMultiplier the speed of the brewing
* @return the builder for chaining
* @see #speedMultiplier()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder speedMultiplier(float speedMultiplier);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.papermc.paper.datacomponent.item;

import io.papermc.paper.datacomponent.DataComponentBuilder;
import io.papermc.paper.loot.number.ResolvableFloat;
import io.papermc.paper.loot.number.ResolvableInt;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;

/**
* Describes an item that can be used as fuel for a furnace, smoker or blast furnace.
*
* @see io.papermc.paper.datacomponent.DataComponentTypes#COOKING_FUEL
*/
@ApiStatus.NonExtendable
public interface CookingFuel {

@Contract(value = "-> new", pure = true)
static CookingFuel.Builder cookingFuel() {
return ItemComponentTypesBridge.bridge().cookingFuel();
}

/**
* @return the time, in ticks, for which this fuel will burn
*/
@Contract(pure = true)
ResolvableInt burnTime();

/**
* @return the speed of the cooking/smelting
*/
@Contract(pure = true)
ResolvableFloat speedMultiplier();

/**
* Builder for {@link CookingFuel}.
*/
@ApiStatus.NonExtendable
interface Builder extends DataComponentBuilder<CookingFuel> {

/**
* @param speedMultiplier the speed of the cooking/smelting
* @return the builder for chaining
* @see #speedMultiplier()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder speedMultiplier(float speedMultiplier);

/**
* @param burnTime the time, in ticks, for which this fuel will burn
* @return the builder for chaining
* @see #speedMultiplier()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder burnTime(int burnTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ static ItemComponentTypesBridge bridge() {
SignText.Builder signText();

SignText.Builder signText(List<? extends ComponentLike> messages);

BrewingFuel.Builder brewingFuel();

CookingFuel.Builder cookingFuel();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.papermc.paper.loot.number;

import org.bukkit.loot.LootContext;

/**
* Represents a floating point number that can be resolved against a {@link LootContext}.
*/
public interface ResolvableFloat {

/**
* Resolves this floating point number against the given loot context.
*
* @param context the loot context to resolve against.
* @param defaultValue the default value
* @return the resolved number
*/
float resolve(LootContext context, float defaultValue);

/**
* Represents a constant {@link ResolvableFloat}.
*/
interface Constant extends ResolvableFloat {

/**
* @return the constant value
*/
float getValue();

/**
* {@inheritDoc}
*/
@Override
default float resolve(LootContext context, float defaultValue) {
return this.getValue();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.papermc.paper.loot.number;

import org.bukkit.loot.LootContext;

/**
* Represents an integer number that can be resolved against a {@link LootContext}.
*/
public interface ResolvableInt {

/**
* Resolves this integer number against the given loot context.
*
* @param context the loot context to resolve against.
* @param defaultValue the default value
* @return the resolved number
*/
int resolve(LootContext context, int defaultValue);

/**
* Represents a constant {@link ResolvableInt}.
*/
interface Constant extends ResolvableInt {

/**
* @return the constant value
*/
int getValue();

/**
* {@inheritDoc}
*/
@Override
default int resolve(LootContext context, int defaultValue) {
return this.getValue();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Package containing maths-related API, including position API.
*/
@NullMarked
@ApiStatus.Experimental
package io.papermc.paper.loot.number;

import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--- a/net/minecraft/world/level/storage/loot/parameters/LootContextParamSets.java
+++ b/net/minecraft/world/level/storage/loot/parameters/LootContextParamSets.java
@@ -35,6 +_,27 @@
.required(LootContextParams.ENCHANTMENT_ACTIVE)
.required(LootContextParams.ENCHANTMENT_LEVEL)
);
+ // Paper start
+ public static final ContextKeySet ALL_PARAMS_OPTIONAL = register(
+ "generic_optional",
+ builder -> builder.optional(LootContextParams.THIS_ENTITY)
+ .optional(LootContextParams.LAST_DAMAGE_PLAYER)
+ .optional(LootContextParams.DAMAGE_SOURCE)
+ .optional(LootContextParams.ATTACKING_ENTITY)
+ .optional(LootContextParams.DIRECT_ATTACKING_ENTITY)
+ .optional(LootContextParams.ORIGIN)
+ .optional(LootContextParams.BLOCK_STATE)
+ .optional(LootContextParams.BLOCK_ENTITY)
+ .optional(LootContextParams.TOOL)
+ .optional(LootContextParams.EXPLOSION_RADIUS)
+ .optional(LootContextParams.ADDITIONAL_COST_COMPONENT_ALLOWED)
+ .optional(LootContextParams.CONTAINER)
+ .optional(LootContextParams.INTERACTING_ENTITY)
+ .optional(LootContextParams.TARGET_ENTITY)
+ .optional(LootContextParams.ENCHANTMENT_ACTIVE)
+ .optional(LootContextParams.ENCHANTMENT_LEVEL)
+ );
+ // Paper end
public static final ContextKeySet CHEST = register("chest", builder -> builder.required(LootContextParams.ORIGIN).optional(LootContextParams.THIS_ENTITY));
public static final ContextKeySet COMMAND = register(
"command", builder -> builder.required(LootContextParams.ORIGIN).optional(LootContextParams.THIS_ENTITY)
@@ -194,5 +_,11 @@
if (!missingFromAllParams.isEmpty()) {
throw new IllegalStateException("Missing parameters from 'all_params': " + missingFromAllParams);
}
+ // Paper start
+ Set<ContextKey<?>> missingFromAllParamsOptional = Sets.difference(allParams, ALL_PARAMS_OPTIONAL.allowed());
+ if (!missingFromAllParamsOptional.isEmpty()) {
+ throw new IllegalStateException("Missing parameters from 'all_params_optional': " + missingFromAllParamsOptional);
+ }
+ // Paper end
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import io.papermc.paper.datacomponent.item.PaperBannerPatternLayers;
import io.papermc.paper.datacomponent.item.PaperBlockItemDataProperties;
import io.papermc.paper.datacomponent.item.PaperBlocksAttacks;
import io.papermc.paper.datacomponent.item.PaperBrewingFuel;
import io.papermc.paper.datacomponent.item.PaperBundleContents;
import io.papermc.paper.datacomponent.item.PaperChargedProjectiles;
import io.papermc.paper.datacomponent.item.PaperConsumable;
import io.papermc.paper.datacomponent.item.PaperCookingFuel;
import io.papermc.paper.datacomponent.item.PaperCustomModelData;
import io.papermc.paper.datacomponent.item.PaperDamageResistant;
import io.papermc.paper.datacomponent.item.PaperDeathProtection;
Expand Down Expand Up @@ -226,6 +228,8 @@ public static void bootstrap() {
register(DataComponents.SIGN_TEXT_BACK, PaperSignText::new);
registerUntyped(DataComponents.WAXED);
register(DataComponents.CUSHION_COLOR, nms -> DyeColor.getByWoolData((byte) nms.getId()), api -> net.minecraft.world.item.DyeColor.byId(api.getWoolData()));
register(DataComponents.COOKING_FUEL, PaperCookingFuel::new);
register(DataComponents.BREWING_FUEL, PaperBrewingFuel::new);

for (final ResourceKey<DataComponentType<?>> key : BuiltInRegistries.DATA_COMPONENT_TYPE.registryKeySet()) {
if (!ADAPTERS.containsKey(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,14 @@ public SignText.Builder signText() {
public SignText.Builder signText(final List<? extends ComponentLike> messages) {
return new PaperSignText.BuilderImpl(PaperAdventure.asVanilla(new ArrayList<>(ComponentLike.asComponents(messages))));
}

@Override
public BrewingFuel.Builder brewingFuel() {
return new PaperBrewingFuel.BuilderImpl();
}

@Override
public CookingFuel.Builder cookingFuel() {
return new PaperCookingFuel.BuilderImpl();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.papermc.paper.datacomponent.item;

import io.papermc.paper.loot.number.PaperResolvableFloat;
import io.papermc.paper.loot.number.PaperResolvableInt;
import net.minecraft.world.level.storage.loot.providers.number.floats.ResolvableFloat;
import net.minecraft.world.level.storage.loot.providers.number.ints.ResolvableInt;
import org.bukkit.craftbukkit.util.Handleable;

public record PaperBrewingFuel(
net.minecraft.world.item.component.BrewingFuel impl
) implements BrewingFuel, Handleable<net.minecraft.world.item.component.BrewingFuel> {

@Override
public net.minecraft.world.item.component.BrewingFuel getHandle() {
return this.impl;
}

@Override
public io.papermc.paper.loot.number.ResolvableInt uses() {
return PaperResolvableInt.fromVanilla(this.impl.uses());
}

@Override
public io.papermc.paper.loot.number.ResolvableFloat speedMultiplier() {
return PaperResolvableFloat.fromVanilla(this.impl.speedMultiplier());
}

static final class BuilderImpl implements BrewingFuel.Builder {

private int uses = 0;
private float speedMultiplier = 1.0F;

@Override
public Builder uses(int uses) {
this.uses = uses;
return this;
}

@Override
public Builder speedMultiplier(float speedMultiplier) {
this.speedMultiplier = speedMultiplier;
return this;
}

@Override
public BrewingFuel build() {
return new PaperBrewingFuel(
new net.minecraft.world.item.component.BrewingFuel(
new ResolvableInt.Constant(this.uses),
new ResolvableFloat.Constant(this.speedMultiplier)
)
);
}
}
}
Loading
Loading