mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-26 18:29:07 +00:00
Add stackable milk buckets
This commit is contained in:
@@ -1,23 +1,5 @@
|
||||
--- a/net/minecraft/world/item/BucketItem.java
|
||||
+++ b/net/minecraft/world/item/BucketItem.java
|
||||
@@ -112,6 +_,17 @@
|
||||
return !player.hasInfiniteMaterials() ? new ItemStack(Items.BUCKET) : bucketStack;
|
||||
}
|
||||
|
||||
+ // Sakura start - modify bucket stack size
|
||||
+ @Override
|
||||
+ public void verifyComponentsAfterLoad(ItemStack stack) {
|
||||
+ me.samsuik.sakura.configuration.GlobalConfiguration config = me.samsuik.sakura.configuration.GlobalConfiguration.get();
|
||||
+ int customItemSize = config == null || !config.players.bucketStackSize.isDefined() ? -1 : config.players.bucketStackSize.intValue();
|
||||
+ if (customItemSize > 0 && customItemSize < 100) {
|
||||
+ stack.set(net.minecraft.core.component.DataComponents.MAX_STACK_SIZE, customItemSize);
|
||||
+ }
|
||||
+ }
|
||||
+ // Sakura end - modify bucket stack size
|
||||
+
|
||||
@Override
|
||||
public void checkExtraContent(@Nullable Player player, Level level, ItemStack containerStack, BlockPos pos) {
|
||||
}
|
||||
@@ -147,7 +_,7 @@
|
||||
// CraftBukkit end
|
||||
if (!flag) {
|
||||
|
||||
@@ -4,7 +4,31 @@
|
||||
public static final Item GOLDEN_APPLE = registerItem("golden_apple", new Item.Properties().food(Foods.GOLDEN_APPLE, Consumables.GOLDEN_APPLE));
|
||||
public static final Item ENCHANTED_GOLDEN_APPLE = registerItem(
|
||||
"enchanted_golden_apple",
|
||||
+ me.samsuik.sakura.player.combat.CustomGoldenApple::new, // Sakura - old enchanted golden apples
|
||||
+ me.samsuik.sakura.player.item.LegacyGoldenAppleItem::new, // Sakura - old enchanted golden apples
|
||||
new Item.Properties()
|
||||
.rarity(Rarity.RARE)
|
||||
.food(Foods.ENCHANTED_GOLDEN_APPLE, Consumables.ENCHANTED_GOLDEN_APPLE)
|
||||
@@ -1295,12 +_,12 @@
|
||||
(block, properties) -> new HangingSignItem(block, Blocks.WARPED_WALL_HANGING_SIGN, properties),
|
||||
new Item.Properties().stacksTo(16)
|
||||
);
|
||||
- public static final Item BUCKET = registerItem("bucket", properties -> new BucketItem(Fluids.EMPTY, properties), new Item.Properties().stacksTo(16));
|
||||
+ public static final Item BUCKET = registerItem("bucket", properties -> new me.samsuik.sakura.player.item.StackableBucketItem(Fluids.EMPTY, properties), new Item.Properties().stacksTo(16)); // Sakura - modify bucket stack size
|
||||
public static final Item WATER_BUCKET = registerItem(
|
||||
- "water_bucket", properties -> new BucketItem(Fluids.WATER, properties), new Item.Properties().craftRemainder(BUCKET).stacksTo(1)
|
||||
+ "water_bucket", properties -> new me.samsuik.sakura.player.item.StackableBucketItem(Fluids.WATER, properties), new Item.Properties().craftRemainder(BUCKET).stacksTo(1) // Sakura - modify bucket stack size
|
||||
);
|
||||
public static final Item LAVA_BUCKET = registerItem(
|
||||
- "lava_bucket", properties -> new BucketItem(Fluids.LAVA, properties), new Item.Properties().craftRemainder(BUCKET).stacksTo(1)
|
||||
+ "lava_bucket", properties -> new me.samsuik.sakura.player.item.StackableBucketItem(Fluids.LAVA, properties), new Item.Properties().craftRemainder(BUCKET).stacksTo(1) // Sakura - modify bucket stack size
|
||||
);
|
||||
public static final Item POWDER_SNOW_BUCKET = registerItem(
|
||||
"powder_snow_bucket",
|
||||
@@ -1311,6 +_,7 @@
|
||||
public static final Item LEATHER = registerItem("leather");
|
||||
public static final Item MILK_BUCKET = registerItem(
|
||||
"milk_bucket",
|
||||
+ me.samsuik.sakura.player.item.MilkBucketItem::new, // Sakura - modify bucket stack size
|
||||
new Item.Properties().craftRemainder(BUCKET).component(DataComponents.CONSUMABLE, Consumables.MILK_BUCKET).usingConvertsTo(BUCKET).stacksTo(1)
|
||||
);
|
||||
public static final Item PUFFERFISH_BUCKET = registerItem(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user