Nbt fixes (#349)

* progress towards working nbt

* update item nbt
This commit is contained in:
crazymoose77756
2024-05-17 05:53:58 -04:00
committed by GitHub
parent 3a6a0d80ef
commit 7bdd1353d5
3 changed files with 189 additions and 115 deletions

View File

@@ -2,12 +2,15 @@ package anticope.rejects.commands;
import anticope.rejects.arguments.EnumStringArgumentType; import anticope.rejects.arguments.EnumStringArgumentType;
import anticope.rejects.utils.GiveUtils; import anticope.rejects.utils.GiveUtils;
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import meteordevelopment.meteorclient.commands.Command; import meteordevelopment.meteorclient.commands.Command;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.component.ComponentChanges;
import net.minecraft.component.DataComponentTypes; import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent; import net.minecraft.component.type.NbtComponent;
import net.minecraft.component.type.ProfileComponent;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
@@ -20,8 +23,7 @@ import net.minecraft.text.Text;
import java.util.Collection; import java.util.Collection;
import static com.mojang.brigadier.Command.SINGLE_SUCCESS; import static anticope.rejects.utils.accounts.GetPlayerUUID.getUUID;
import static meteordevelopment.meteorclient.MeteorClient.mc;
public class GiveCommand extends Command { public class GiveCommand extends Command {
@@ -33,86 +35,98 @@ public class GiveCommand extends Command {
@Override @Override
public void build(LiteralArgumentBuilder<CommandSource> builder) { public void build(LiteralArgumentBuilder<CommandSource> builder) {
// TODO : finish this
builder.then(literal("egg").executes(ctx -> { builder.then(literal("egg").executes(ctx -> {
ItemStack inHand = mc.player.getMainHandStack(); ItemStack inHand = mc.player.getMainHandStack();
ItemStack item = new ItemStack(Items.STRIDER_SPAWN_EGG); ItemStack item = new ItemStack(Items.STRIDER_SPAWN_EGG);
NbtCompound ct = new NbtCompound(); NbtCompound ct = new NbtCompound();
NbtCompound itemNbt = inHand
.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT)
.copyNbt();
if (inHand.getItem() instanceof BlockItem) { if (inHand.getItem() instanceof BlockItem) {
itemNbt.putInt("Time", 1); ct.putInt("Time", 1);
itemNbt.putString("id", "minecraft:falling_block"); ct.putString("id", "minecraft:falling_block");
itemNbt.put("BlockState", new NbtCompound()); ct.put("BlockState", new NbtCompound());
itemNbt.getCompound("BlockState").putString("Name", Registries.ITEM.getId(inHand.getItem()).toString()); ct.getCompound("BlockState").putString("Name", Registries.ITEM.getId(inHand.getItem()).toString());
if (inHand.getComponents().contains(DataComponentTypes.BLOCK_ENTITY_DATA)) {
itemNbt.put("TileEntityData", inHand.get(DataComponentTypes.BLOCK_ENTITY_DATA).copyNbt());
}
NbtCompound t = new NbtCompound();
t.put("EntityTag", ct);
item.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(itemNbt));
} else { } else {
ct.putString("id", "minecraft:item"); ct.putString("id", "minecraft:item");
NbtCompound it = new NbtCompound(); NbtCompound itemTag = new NbtCompound();
it.putString("id", Registries.ITEM.getId(inHand.getItem()).toString()); itemTag.putString("id", Registries.ITEM.getId(inHand.getItem()).toString());
it.putInt("Count", inHand.getCount()); itemTag.putInt("Count", inHand.getCount());
if (!inHand.getComponents().isEmpty()) {
it.put("tag", inHand.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).copyNbt()); ct.put("Item", itemTag);
}
ct.put("Item", it);
} }
NbtCompound t = new NbtCompound(); NbtCompound t = new NbtCompound();
t.put("EntityTag", ct); t.put("EntityTag", ct);
item.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(t));
item.set(DataComponentTypes.CUSTOM_NAME, inHand.getName()); var changes = ComponentChanges.builder()
.add(DataComponentTypes.CUSTOM_NAME, inHand.getName())
.add(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(t))
.build();
item.applyChanges(changes);
GiveUtils.giveItem(item); GiveUtils.giveItem(item);
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
})); }));
//TODO: allow for custom cords to place oob //TODO: allow for custom cords to place oob, though optional args
builder.then(literal("holo").then(argument("message", StringArgumentType.greedyString()).executes(ctx -> { builder.then(literal("holo").then(argument("message", StringArgumentType.greedyString()).executes(ctx -> {
String message = ctx.getArgument("message", String.class).replace("&", "\247"); String message = ctx.getArgument("message", String.class).replace("&", "\247");
ItemStack stack = new ItemStack(Items.ARMOR_STAND); ItemStack stack = new ItemStack(Items.STRIDER_SPAWN_EGG);
NbtCompound tag = new NbtCompound(); NbtCompound tag = new NbtCompound();
NbtList NbtList = new NbtList(); NbtList pos = new NbtList();
NbtList.add(NbtDouble.of(mc.player.getX()));
NbtList.add(NbtDouble.of(mc.player.getY())); pos.add(NbtDouble.of(mc.player.getX()));
NbtList.add(NbtDouble.of(mc.player.getZ())); pos.add(NbtDouble.of(mc.player.getY()));
pos.add(NbtDouble.of(mc.player.getZ()));
tag.putString("id", "minecraft:armor_stand");
tag.put("Pos", pos);
tag.putBoolean("Invisible", true); tag.putBoolean("Invisible", true);
tag.putBoolean("Invulnerable", true); tag.putBoolean("Invulnerable", true);
tag.putBoolean("Interpret", true);
tag.putBoolean("NoGravity", true); tag.putBoolean("NoGravity", true);
tag.putBoolean("CustomNameVisible", true); tag.putBoolean("CustomNameVisible", true);
tag.putString("CustomName", Text.literal(message).toString());
tag.put("Pos", NbtList); var changes = ComponentChanges.builder()
stack.set(DataComponentTypes.ENTITY_DATA, NbtComponent.of(tag)); .add(DataComponentTypes.CUSTOM_NAME, Text.literal(message))
.add(DataComponentTypes.ENTITY_DATA, NbtComponent.of(tag))
.build();
stack.applyChanges(changes);
GiveUtils.giveItem(stack); GiveUtils.giveItem(stack);
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
}))); })));
//TODO, make invisible through potion effect
builder.then(literal("bossbar").then(argument("message", StringArgumentType.greedyString()).executes(ctx -> { builder.then(literal("bossbar").then(argument("message", StringArgumentType.greedyString()).executes(ctx -> {
String message = ctx.getArgument("message", String.class).replace("&", "\247"); String message = ctx.getArgument("message", String.class).replace("&", "\247");
ItemStack stack = new ItemStack(Items.BAT_SPAWN_EGG); ItemStack stack = new ItemStack(Items.BAT_SPAWN_EGG);
NbtCompound tag = new NbtCompound(); NbtCompound tag = new NbtCompound();
tag.putString("CustomName", Text.literal(message).toString());
tag.putBoolean("NoAI", true); tag.putBoolean("NoAI", true);
tag.putBoolean("Silent", true); tag.putBoolean("Silent", true);
tag.putBoolean("PersistenceRequired", true); tag.putBoolean("PersistenceRequired", true);
tag.putBoolean("Invisible", true);
tag.put("id", NbtString.of("minecraft:wither")); tag.put("id", NbtString.of("minecraft:wither"));
stack.set(DataComponentTypes.ENTITY_DATA, NbtComponent.of(tag));
var changes = ComponentChanges.builder()
.add(DataComponentTypes.CUSTOM_NAME, Text.literal(message))
.add(DataComponentTypes.ENTITY_DATA, NbtComponent.of(tag))
.build();
stack.applyChanges(changes);
GiveUtils.giveItem(stack); GiveUtils.giveItem(stack);
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
}))); })));
// TODO : resolve textures, should be easy now that UUID is resolved
builder.then(literal("head").then(argument("owner", StringArgumentType.greedyString()).executes(ctx -> { builder.then(literal("head").then(argument("owner", StringArgumentType.greedyString()).executes(ctx -> {
String playerName = ctx.getArgument("owner", String.class); String playerName = ctx.getArgument("owner", String.class);
ItemStack itemStack = new ItemStack(Items.PLAYER_HEAD); ItemStack itemStack = new ItemStack(Items.PLAYER_HEAD);
NbtCompound tag = new NbtCompound();
tag.putString("SkullOwner", playerName); var changes = ComponentChanges.builder()
itemStack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(tag)); .add(DataComponentTypes.PROFILE, new ProfileComponent(new GameProfile(getUUID(playerName), playerName)))
.build();
itemStack.applyChanges(changes);
GiveUtils.giveItem(itemStack); GiveUtils.giveItem(itemStack);
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
}))); })));

View File

@@ -1,21 +1,25 @@
package anticope.rejects.utils; package anticope.rejects.utils;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.component.ComponentChanges;
import net.minecraft.component.DataComponentTypes; import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent; import net.minecraft.component.type.*;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList; import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.StringNbtReader; import net.minecraft.nbt.StringNbtReader;
import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.function.Function; import java.util.function.Function;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
@@ -43,18 +47,21 @@ public class GiveUtils {
new Identifier("lightning_bolt")); new Identifier("lightning_bolt"));
// Some ported from: https://github.com/BleachDrinker420/BleachHack/blob/master/BleachHack-Fabric-1.16/src/main/java/bleach/hack/command/commands/CmdGive.java // Some ported from: https://github.com/BleachDrinker420/BleachHack/blob/master/BleachHack-Fabric-1.16/src/main/java/bleach/hack/command/commands/CmdGive.java
private static final List<Triple<String, Item, String>> STRING_PRESETS = Arrays.asList( private static final List<Triple<String, Item, String>> ENTITY_PRESETS = Arrays.asList(
Triple.of("lag_spawner", Items.SPAWNER, "{BlockEntityTag:{MaxNearbyEntities:32767,RequiredPlayerRange:32767,SpawnCount:32767,MaxSpawnDelay:0,SpawnRange:32767,Delay:0,MinSpawnDelay:0}}"), Triple.of("pigs_egg", Items.CHICKEN_SPAWN_EGG, "{MaxNearbyEntities:1000,RequiredPlayerRange:100,CustomDisplayTile:1b,DisplayState:{Properties:{hinge:\"left\",half:\"upper\",open:\"true\"},Name:\"minecraft:acacia_door\"},SpawnData:{id:\"minecraft:minecart\"},id:\"minecraft:spawner_minecart\",MaxSpawnDelay:0,Delay:1,MinSpawnDelay:0}"),
Triple.of("tnt_spawner", Items.SPAWNER, "{BlockEntityTag:{MaxNearbyEntities:32767,RequiredPlayerRange:32767,SpawnCount:50,SpawnData:{Fuse:1,id:\"minecraft:tnt\"},MaxSpawnDelay:0,SpawnRange:10,Delay:0,MinSpawnDelay:0}}"), Triple.of("end_portal_arrow", Items.ELDER_GUARDIAN_SPAWN_EGG, "{SoundEvent:\"block.end_portal.spawn\",pickup:1b,id:\"minecraft:arrow\"}"),
Triple.of("boat_spawner", Items.SPAWNER, "{BlockEntityTag:{SpawnData:{Type:\"jungle\",CustomName:'{\"text\":\"Boat\",\"color\":\"aqua\",\"bold\":true,\"italic\":true,\"underlined\":true}',Invulnerable:1b,id:\"minecraft:boat\",Glowing:1b,CustomNameVisible:1b},SpawnRange:10,SpawnCount:50}}"), Triple.of("wither_spawn_arrow", Items.ELDER_GUARDIAN_SPAWN_EGG, "{SoundEvent:\"entity.wither.spawn\",pickup:1b,id:\"minecraft:arrow\"}"),
Triple.of("pigs_egg", Items.CHICKEN_SPAWN_EGG, "{EntityTag:{MaxNearbyEntities:1000,RequiredPlayerRange:100,CustomDisplayTile:1b,DisplayState:{Properties:{hinge:\"left\",half:\"upper\",open:\"true\"},Name:\"minecraft:acacia_door\"},SpawnData:{id:\"minecraft:minecart\"},id:\"minecraft:spawner_minecart\",MaxSpawnDelay:0,Delay:1,MinSpawnDelay:0}}"), Triple.of("eg_curse_arrow", Items.ELDER_GUARDIAN_SPAWN_EGG, "{SoundEvent:\"entity.elder_guardian.curse\",pickup:1b,id:\"minecraft:arrow\"}"),
Triple.of("end_portal_arrow", Items.ELDER_GUARDIAN_SPAWN_EGG, "{EntityTag:{SoundEvent:\"block.end_portal.spawn\",pickup:1b,id:\"minecraft:arrow\"}}"), Triple.of("big_slime", Items.SLIME_SPAWN_EGG, "{Size:50,id:\"minecraft:slime\"}"),
Triple.of("wither_spawn_arrow", Items.ELDER_GUARDIAN_SPAWN_EGG, "{EntityTag:{SoundEvent:\"entity.wither.spawn\",pickup:1b,id:\"minecraft:arrow\"}}"), Triple.of("particle_area_expand", Items.SKELETON_SPAWN_EGG, "{Particle:\"angry_villager\",Radius:1.0f,RadiusOnUse:1.0f,Duration:10000,id:\"minecraft:area_effect_cloud\",RadiusPerTick:10.0f}"),
Triple.of("eg_curse_arrow", Items.ELDER_GUARDIAN_SPAWN_EGG, "{EntityTag:{SoundEvent:\"entity.elder_guardian.curse\",pickup:1b,id:\"minecraft:arrow\"}}"), Triple.of("armor_stand_spawner_minecart", Items.BAT_SPAWN_EGG, "{SpawnData:{id:\"minecraft:armor_stand\"},id:\"minecraft:spawner_minecart\"}"),
Triple.of("big_slime", Items.SLIME_SPAWN_EGG, "{EntityTag:{Size:50,id:\"minecraft:slime\"}}"), Triple.of("dud_tnt", Items.DROWNED_SPAWN_EGG, "{Fuse:30000,Invulnerable:1b,id:\"minecraft:tnt\"}")
Triple.of("particle_area_expand", Items.SKELETON_SPAWN_EGG, "{EntityTag:{Particle:\"angry_villager\",Radius:1.0f,RadiusOnUse:1.0f,Duration:10000,id:\"minecraft:area_effect_cloud\",RadiusPerTick:10.0f}}"), );
Triple.of("armor_stand_spawner_minecart", Items.BAT_SPAWN_EGG, "{EntityTag:{SpawnData:{id:\"minecraft:armor_stand\"},id:\"minecraft:spawner_minecart\"}}"),
Triple.of("dud_tnt", Items.DROWNED_SPAWN_EGG, "{EntityTag:{Fuse:30000,Invulnerable:1b,id:\"minecraft:tnt\"}}") private static final List<Triple<String, Item, String>> BLOCK_PRESETS = Arrays.asList(
Triple.of("lag_spawner", Items.SPAWNER, "{MaxNearbyEntities:32767,RequiredPlayerRange:32767,SpawnCount:50,MaxSpawnDelay:0,id:\"minecraft:spawner\",SpawnRange:32767,Delay:0,MinSpawnDelay:0}"),
Triple.of("tnt_spawner", Items.SPAWNER, "{MaxNearbyEntities:32767,RequiredPlayerRange:32767,SpawnCount:50,SpawnData:{entity:{id:\"minecraft:tnt\",fuse:1}},MaxSpawnDelay:0,id:\"minecraft:mob_spawner\",SpawnRange:10,Delay:0,MinSpawnDelay:0}"),
Triple.of("boat_spawner", Items.SPAWNER, "{SpawnCount:50,SpawnData:{entity:{Type:\"jungle\",CustomName:'{\"bold\":true,\"color\":\"aqua\",\"italic\":true,\"text\":\"Boat\",\"underlined\":true}',Invulnerable:1b,id:\"minecraft:boat\",Glowing:1b,CustomNameVisible:1b}},id:\"minecraft:spawner\",SpawnRange:10}")
); );
private static final Random random = new Random(); private static final Random random = new Random();
@@ -68,45 +75,60 @@ public class GiveUtils {
} }
static { static {
STRING_PRESETS.forEach((preset) -> { ENTITY_PRESETS.forEach((preset) -> {
PRESETS.put(preset.getLeft(), (preview) -> { PRESETS.put(preset.getLeft(), (preview) -> {
if (preview) preset.getMiddle().getDefaultStack(); if (preview) preset.getMiddle().getDefaultStack();
ItemStack item = preset.getMiddle().getDefaultStack(); ItemStack item = preset.getMiddle().getDefaultStack();
try { try {
item.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(StringNbtReader.parse(preset.getRight()))); item.set(DataComponentTypes.ENTITY_DATA, NbtComponent.of(StringNbtReader.parse(preset.getRight())));
} catch (CommandSyntaxException e) { } } catch (CommandSyntaxException e) { }
item.set(DataComponentTypes.CUSTOM_NAME, Text.literal(toName(preset.getLeft()))); item.set(DataComponentTypes.CUSTOM_NAME, Text.literal(toName(preset.getLeft())));
return item; return item;
}); });
}); });
BLOCK_PRESETS.forEach((preset) -> {
PRESETS.put(preset.getLeft(), (preview) -> {
if (preview) preset.getMiddle().getDefaultStack();
ItemStack item = preset.getMiddle().getDefaultStack();
try {
item.set(DataComponentTypes.BLOCK_ENTITY_DATA, NbtComponent.of(StringNbtReader.parse(preset.getRight())));
} catch (CommandSyntaxException e) { }
item.set(DataComponentTypes.CUSTOM_NAME, Text.literal(toName(preset.getLeft())));
return item;
});
});
// TODO update
PRESETS.put("force_op", (preview) -> { PRESETS.put("force_op", (preview) -> {
if (preview) Items.SPIDER_SPAWN_EGG.getDefaultStack(); if (preview) Items.SPIDER_SPAWN_EGG.getDefaultStack();
ItemStack item = Items.SPIDER_SPAWN_EGG.getDefaultStack(); ItemStack item = Items.SPIDER_SPAWN_EGG.getDefaultStack();
String nick = mc.player.getName().getString(); String nick = mc.player.getName().getString();
try { try {
item.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(StringNbtReader.parse("{EntityTag:{Time:1,BlockState:{Name:\"minecraft:spawner\"},id:\"minecraft:falling_block\",TileEntityData:{SpawnCount:20,SpawnData:{id:\"minecraft:villager\",Passengers:[{Time:1,BlockState:{Name:\"minecraft:redstone_block\"},id:\"minecraft:falling_block\",Passengers:[{id:\"minecraft:fox\",Passengers:[{Time:1,BlockState:{Name:\"minecraft:activator_rail\"},id:\"minecraft:falling_block\",Passengers:[{Command:\"execute as @e run op "+nick+"\",id:\"minecraft:command_block_minecart\"}]}],NoAI:1b,Health:1.0f,ActiveEffects:[{Duration:1000,Id:20b,Amplifier:4b}]}]}],NoAI:1b,Health:1.0f,ActiveEffects:[{Duration:1000,Id:20b,Amplifier:4b}]},MaxSpawnDelay:100,SpawnRange:10,Delay:1,MinSpawnDelay:100}}}"))); item.set(DataComponentTypes.ENTITY_DATA, NbtComponent.of(StringNbtReader.parse("{Time:1,BlockState:{Name:\"minecraft:spawner\"},id:\"minecraft:falling_block\",TileEntityData:{SpawnCount:20,SpawnData:{id:\"minecraft:villager\",Passengers:[{Time:1,BlockState:{Name:\"minecraft:redstone_block\"},id:\"minecraft:falling_block\",Passengers:[{id:\"minecraft:fox\",Passengers:[{Time:1,BlockState:{Name:\"minecraft:activator_rail\"},id:\"minecraft:falling_block\",Passengers:[{Command:\"execute as @e run op "+nick+"\",id:\"minecraft:command_block_minecart\"}]}],NoAI:1b,Health:1.0f,ActiveEffects:[{Duration:1000,Id:20b,Amplifier:4b}]}]}],NoAI:1b,Health:1.0f,ActiveEffects:[{Duration:1000,Id:20b,Amplifier:4b}]},MaxSpawnDelay:100,SpawnRange:10,Delay:1,MinSpawnDelay:100}}")));
} catch (CommandSyntaxException e) { } } catch (CommandSyntaxException e) { }
item.set(DataComponentTypes.CUSTOM_NAME, Text.of("Force OP")); item.set(DataComponentTypes.CUSTOM_NAME, Text.of("Force OP"));
return item; return item;
}); });
// Thanks wurst !
PRESETS.put("troll_potion", (preview) -> { PRESETS.put("troll_potion", (preview) -> {
if (preview) Items.LINGERING_POTION.getDefaultStack(); if (preview) Items.LINGERING_POTION.getDefaultStack();
ItemStack stack = Items.LINGERING_POTION.getDefaultStack(); ItemStack stack = Items.LINGERING_POTION.getDefaultStack();
NbtList effects = new NbtList(); ArrayList<StatusEffectInstance> effects = new ArrayList<>();
for(int i = 1; i <= 31; i++) for(int i = 1; i <= 31; i++)
{ {
NbtCompound effect = new NbtCompound(); StatusEffect effect =
effect.putByte("Amplifier", (byte)127); Registries.STATUS_EFFECT.getEntry(i).get().value();
effect.putInt("Duration", Integer.MAX_VALUE); RegistryEntry<StatusEffect> entry =
effect.putInt("Id", i); Registries.STATUS_EFFECT.getEntry(effect);
effects.add(effect); effects.add(new StatusEffectInstance(entry, Integer.MAX_VALUE,
Integer.MAX_VALUE));
} }
NbtCompound nbt = new NbtCompound();
nbt.put("CustomPotionEffects", effects); stack.set(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent(Optional.empty(), Optional.empty(),
stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt)); effects));
stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal("Lingering Potion of Trolling")); stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal("Lingering Potion of Trolling"));
return stack; return stack;
}); });
@@ -114,18 +136,20 @@ public class GiveUtils {
PRESETS.put("32k", (preview) -> { PRESETS.put("32k", (preview) -> {
if (preview) return Items.DIAMOND_SWORD.getDefaultStack(); if (preview) return Items.DIAMOND_SWORD.getDefaultStack();
ItemStack stack = Items.DIAMOND_SWORD.getDefaultStack(); ItemStack stack = Items.DIAMOND_SWORD.getDefaultStack();
NbtList enchants = new NbtList();
addEnchant(enchants, "minecraft:sharpness"); stack.apply(DataComponentTypes.ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT, component -> {
addEnchant(enchants, "minecraft:knockback"); ItemEnchantmentsComponent.Builder builder = new ItemEnchantmentsComponent.Builder(component);
addEnchant(enchants, "minecraft:fire_aspect"); builder.add(Enchantments.SHARPNESS, 255);
addEnchant(enchants, "minecraft:looting", (short)10); builder.add(Enchantments.KNOCKBACK, 255);
addEnchant(enchants, "minecraft:sweeping", (short)3); builder.add(Enchantments.FIRE_ASPECT, 255);
addEnchant(enchants, "minecraft:unbreaking"); builder.add(Enchantments.LOOTING, 10);
addEnchant(enchants, "minecraft:mending", (short)1); builder.add(Enchantments.SWEEPING_EDGE, 3);
addEnchant(enchants, "minecraft:vanishing_curse", (short)1); builder.add(Enchantments.UNBREAKING, 255);
NbtCompound nbt = new NbtCompound(); builder.add(Enchantments.MENDING, 1);
nbt.put("Enchantments", enchants); builder.add(Enchantments.VANISHING_CURSE, 1);
stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt)); return builder.build();
});
stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal("Bonk")); stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal("Bonk"));
return stack; return stack;
}); });
@@ -145,25 +169,19 @@ public class GiveUtils {
PRESETS.put("firework", (preview) -> { PRESETS.put("firework", (preview) -> {
if (preview) return Items.FIREWORK_ROCKET.getDefaultStack(); if (preview) return Items.FIREWORK_ROCKET.getDefaultStack();
ItemStack firework = new ItemStack(Items.FIREWORK_ROCKET); ItemStack firework = new ItemStack(Items.FIREWORK_ROCKET);
NbtCompound baseCompound = new NbtCompound(); IntList colors = new IntArrayList(new int[]{1973019,11743532,3887386,5320730,2437522,8073150,2651799,11250603,4408131,14188952,4312372,14602026,6719955,12801229,15435844,15790320});
NbtCompound tagCompound = new NbtCompound(); ArrayList<FireworkExplosionComponent> explosions = new ArrayList<>();
NbtList explosionList = new NbtList(); for(int i = 0; i < 200; i++) {
for(int i = 0; i < 5000; i++) explosions.add(new FireworkExplosionComponent(FireworkExplosionComponent.Type.byId(random.nextInt(5)), colors, colors, true, true));
{
NbtCompound explosionCompound = new NbtCompound();
explosionCompound.putByte("Type", (byte)random.nextInt(5));
int colors[] = {1973019,11743532,3887386,5320730,2437522,8073150,2651799,11250603,4408131,14188952,4312372,14602026,6719955,12801229,15435844,15790320};
explosionCompound.putIntArray("Colors", colors);
explosionList.add(explosionCompound);
} }
tagCompound.putInt("Flight", 0);
tagCompound.put("Explosions", explosionList); var changes = ComponentChanges.builder()
baseCompound.put("Fireworks", tagCompound); .add(DataComponentTypes.FIREWORKS, new FireworksComponent(1, explosions))
firework.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(baseCompound)); .build();
firework.applyChanges(changes);
return firework; return firework;
}); });
@@ -171,12 +189,16 @@ public class GiveUtils {
PRESETS.put(id.getPath()+"_spawn_egg", (preview) -> { PRESETS.put(id.getPath()+"_spawn_egg", (preview) -> {
if (preview) return Items.PIG_SPAWN_EGG.getDefaultStack(); if (preview) return Items.PIG_SPAWN_EGG.getDefaultStack();
ItemStack egg = Items.PIG_SPAWN_EGG.getDefaultStack(); ItemStack egg = Items.PIG_SPAWN_EGG.getDefaultStack();
NbtCompound tag = new NbtCompound();
NbtCompound entityTag = new NbtCompound(); NbtCompound entityTag = new NbtCompound();
entityTag.putString("id", id.toString()); entityTag.putString("id", id.toString());
tag.put("EntityTag", entityTag);
egg.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(tag)); var changes = ComponentChanges.builder()
egg.set(DataComponentTypes.CUSTOM_NAME, Text.literal(String.format("%s", toName(id.getPath())))); .add(DataComponentTypes.CUSTOM_NAME, Text.literal(String.format("%s", toName(id.getPath()))))
.add(DataComponentTypes.ENTITY_DATA, NbtComponent.of(entityTag))
.build();
egg.applyChanges(changes);
return egg; return egg;
}); });
}); });
@@ -194,14 +216,4 @@ public class GiveUtils {
return WordUtils.capitalizeFully(id.toString().replace("_", " ")); return WordUtils.capitalizeFully(id.toString().replace("_", " "));
} }
private static void addEnchant(NbtList tag, String id, short v) {
NbtCompound enchant = new NbtCompound();
enchant.putShort("lvl", v);
enchant.putString("id", id);
tag.add(enchant);
}
private static void addEnchant(NbtList tag, String id) {
addEnchant(tag, id, Short.MAX_VALUE);
}
} }

View File

@@ -0,0 +1,48 @@
package anticope.rejects.utils.accounts;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;
import java.util.stream.Collectors;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
public class GetPlayerUUID {
public static UUID getUUID(String playerName) {
// Thanks Bento
try {
Gson gsonReader = new Gson();
JsonObject jsonObject = gsonReader.fromJson(
getURLContent("https://api.mojang.com/users/profiles/minecraft/" + playerName),
JsonObject.class);
String userIdString = jsonObject.get("id").toString().replace("\"", "")
.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5");
return UUID.fromString(userIdString);
} catch (Exception ignored) {
return UUID.randomUUID();
}
}
private static String getURLContent(String requestedUrl) {
String returnValue;
try {
URL url = new URL(requestedUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
returnValue = br.lines().collect(Collectors.joining());
br.close();
} catch (Exception e) {
returnValue = "";
}
return returnValue;
}
}