|
| 1 | +package tools.redstone.redstonetools.features.commands; |
| 2 | + |
| 3 | +import com.google.auto.service.AutoService; |
| 4 | +import tools.redstone.redstonetools.features.AbstractFeature; |
| 5 | +import tools.redstone.redstonetools.features.Feature; |
| 6 | +import tools.redstone.redstonetools.features.arguments.Argument; |
| 7 | +import tools.redstone.redstonetools.features.feedback.Feedback; |
| 8 | +import tools.redstone.redstonetools.utils.RedstoneUtils; |
| 9 | +import com.mojang.brigadier.exceptions.CommandSyntaxException; |
| 10 | +import net.minecraft.enchantment.Enchantment; |
| 11 | +import net.minecraft.item.ItemStack; |
| 12 | +import net.minecraft.item.Items; |
| 13 | +import net.minecraft.nbt.NbtCompound; |
| 14 | +import net.minecraft.nbt.NbtList; |
| 15 | +import net.minecraft.server.command.ServerCommandSource; |
| 16 | +import net.minecraft.text.Text; |
| 17 | +import net.minecraft.util.registry.Registry; |
| 18 | +import java.util.Random; |
| 19 | + |
| 20 | +import static tools.redstone.redstonetools.features.arguments.serializers.IntegerSerializer.integer; |
| 21 | + |
| 22 | +@AutoService(AbstractFeature.class) |
| 23 | +@Feature(name = "Signal Strength Barrel", description = "Creates a barrel with the specified signal strength.", command = "ss") |
| 24 | +public class SsBarrelFeature extends CommandFeature { |
| 25 | + private static final int BARREL_CONTAINER_SLOTS = 27; |
| 26 | + |
| 27 | + public static final Argument<Integer> signalStrength = Argument |
| 28 | + .ofType(integer(0, 15)) |
| 29 | + .withDefault(15); |
| 30 | + |
| 31 | + @Override |
| 32 | + protected Feedback execute(ServerCommandSource source) throws CommandSyntaxException { |
| 33 | + var stack = new ItemStack(Items.BARREL); |
| 34 | + |
| 35 | + // {BlockEntityTag:{Items:[{Slot:0,id:redstone,Count:3},{Slot:1,id:redstone,Count:61}]}} |
| 36 | + var items = new NbtList(); |
| 37 | + |
| 38 | + for (int i = 0; i < RedstoneUtils.signalStrengthToNonStackableItemCount(signalStrength.getValue(), BARREL_CONTAINER_SLOTS); i++) { |
| 39 | + var item = new NbtCompound(); |
| 40 | + item.putByte("Slot", (byte) i); |
| 41 | + item.putString("id", Registry.ITEM.getId(Items.TOTEM_OF_UNDYING).toString()); |
| 42 | + item.putByte("Count", (byte) 1); |
| 43 | + items.add(item); |
| 44 | + } |
| 45 | + |
| 46 | + stack.getOrCreateSubNbt("BlockEntityTag").put("Items", items); |
| 47 | + stack.setCustomName(Text.of(signalStrength.getValue().toString())); |
| 48 | + stack.addEnchantment(Enchantment.byRawId(0),0); |
| 49 | + stack.getOrCreateNbt().putBoolean("HideFlags", true); |
| 50 | + |
| 51 | + source.getPlayer().giveItemStack(stack); |
| 52 | + |
| 53 | + //funny |
| 54 | + if(signalStrength.getValue() == 0) |
| 55 | + |
| 56 | + { |
| 57 | + String[] funny = { |
| 58 | + "Why would you want this??", "Wtf are you going to use this for?", "What for?", |
| 59 | + "... Ok, if you're sure.", "I'm 99% sure you could just use any other block.", |
| 60 | + "This seems unnecessary.", "Is that a typo?", "Do you just like the glint?", |
| 61 | + "Wow, what a fancy but otherwise useless barrel.", "For decoration?"}; |
| 62 | + return Feedback.success(funny[new Random( |
| 63 | + |
| 64 | + ).nextInt(funny.length)]); |
| 65 | + } |
| 66 | + |
| 67 | + return Feedback.none(); |
| 68 | + } |
| 69 | +} |
0 commit comments