9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-28 11:19:08 +00:00

Add stackable milk buckets

This commit is contained in:
Samsuik
2025-02-13 16:26:09 +00:00
parent d3e886a5c8
commit 8a1aeca928
7 changed files with 95 additions and 22 deletions

View File

@@ -42,6 +42,7 @@ public final class GlobalConfiguration extends ConfigurationPart {
public Players players;
public class Players extends ConfigurationPart {
public IntOr.Default bucketStackSize = IntOr.Default.USE_DEFAULT;
public boolean stackableMilkBuckets = false;
}
public Environment environment;

View File

@@ -0,0 +1,21 @@
package me.samsuik.sakura.player.item;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponents;
public final class DataComponentHelper {
public static int bucketMaxStackSize() {
me.samsuik.sakura.configuration.GlobalConfiguration config = me.samsuik.sakura.configuration.GlobalConfiguration.get();
return config == null || !config.players.bucketStackSize.isDefined() ? -1 : config.players.bucketStackSize.intValue();
}
public static DataComponentMap copyComponentsAndModifyMaxStackSize(DataComponentMap componentMap, int maxItemSize) {
if (maxItemSize > 0 && maxItemSize <= 99) {
return DataComponentMap.builder()
.addAll(componentMap)
.set(DataComponents.MAX_STACK_SIZE, maxItemSize)
.build();
}
return componentMap;
}
}

View File

@@ -1,4 +1,4 @@
package me.samsuik.sakura.player.combat;
package me.samsuik.sakura.player.item;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.InteractionHand;
@@ -20,7 +20,7 @@ import java.util.Optional;
@NullMarked
@SuppressWarnings("OptionalAssignedToNull")
public final class CustomGoldenApple extends Item {
public final class LegacyGoldenAppleItem extends Item {
private static final Consumable LEGACY_ENCHANTED_GOLDEN_APPLE = Consumables.defaultFood()
.onConsume(
new ApplyStatusEffectsConsumeEffect(
@@ -34,7 +34,7 @@ public final class CustomGoldenApple extends Item {
)
.build();
public CustomGoldenApple(Properties settings) {
public LegacyGoldenAppleItem(Properties settings) {
super(settings);
}

View File

@@ -0,0 +1,22 @@
package me.samsuik.sakura.player.item;
import me.samsuik.sakura.configuration.GlobalConfiguration;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.jspecify.annotations.NullMarked;
@NullMarked
public final class MilkBucketItem extends Item {
public MilkBucketItem(Properties properties) {
super(properties);
}
@Override
public void verifyComponentsAfterLoad(ItemStack stack) {
int maxStackSize = DataComponentHelper.bucketMaxStackSize();
if (GlobalConfiguration.get().players.stackableMilkBuckets && maxStackSize > 0 && maxStackSize < 100) {
stack.set(DataComponents.MAX_STACK_SIZE, maxStackSize);
}
}
}

View File

@@ -0,0 +1,23 @@
package me.samsuik.sakura.player.item;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.material.Fluid;
import org.jspecify.annotations.NullMarked;
@NullMarked
public final class StackableBucketItem extends BucketItem {
public StackableBucketItem(Fluid content, Properties properties) {
super(content, properties);
}
@Override
public void verifyComponentsAfterLoad(ItemStack stack) {
// It's also possible to override the components method and modify the stack size through the DataComponentHelper
int maxStackSize = DataComponentHelper.bucketMaxStackSize();
if (maxStackSize > 0 && maxStackSize < 100) {
stack.set(DataComponents.MAX_STACK_SIZE, maxStackSize);
}
}
}