Skip to content

Commit

Permalink
initial port 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
crazymoose77756 committed May 8, 2024
1 parent 609678b commit c5bc7f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
28 changes: 17 additions & 11 deletions src/main/java/anticope/rejects/commands/GiveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,41 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
ItemStack inHand = mc.player.getMainHandStack();
ItemStack item = new ItemStack(Items.STRIDER_SPAWN_EGG);
NbtCompound ct = new NbtCompound();

NbtCompound itemNbt = inHand
.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT)
.copyNbt();

if (inHand.getItem() instanceof BlockItem) {
ct.putInt("Time", 1);
ct.putString("id", "minecraft:falling_block");
ct.put("BlockState", new NbtCompound());
ct.getCompound("BlockState").putString("Name", Registries.ITEM.getId(inHand.getItem()).toString());
if (inHand.hasNbt() && inHand.getNbt().contains("BlockEntityTag")) {
ct.put("TileEntityData", inHand.getNbt().getCompound("BlockEntityTag"));
itemNbt.putInt("Time", 1);
itemNbt.putString("id", "minecraft:falling_block");
itemNbt.put("BlockState", new NbtCompound());
itemNbt.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.setNbt(t);
item.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(itemNbt));
} else {
ct.putString("id", "minecraft:item");
NbtCompound it = new NbtCompound();
it.putString("id", Registries.ITEM.getId(inHand.getItem()).toString());
it.putInt("Count", inHand.getCount());
if (inHand.hasNbt()) {
it.put("tag", inHand.getNbt());
if (!inHand.getComponents().isEmpty()) {
it.put("tag", inHand.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).copyNbt());
}
ct.put("Item", it);
}
NbtCompound t = new NbtCompound();
t.put("EntityTag", ct);
item.setNbt(t);
item.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(t));
item.set(DataComponentTypes.CUSTOM_NAME, inHand.getName());
GiveUtils.giveItem(item);
return SINGLE_SUCCESS;
}));

//TODO: allow for custom cords to place oob
builder.then(literal("holo").then(argument("message", StringArgumentType.greedyString()).executes(ctx -> {
String message = ctx.getArgument("message", String.class).replace("&", "\247");
ItemStack stack = new ItemStack(Items.ARMOR_STAND);
Expand Down Expand Up @@ -106,7 +112,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
ItemStack itemStack = new ItemStack(Items.PLAYER_HEAD);
NbtCompound tag = new NbtCompound();
tag.putString("SkullOwner", playerName);
itemStack.setNbt(tag);
itemStack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(tag));
GiveUtils.giveItem(itemStack);
return SINGLE_SUCCESS;
})));
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/anticope/rejects/utils/GiveUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package anticope.rejects.utils;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
Expand Down Expand Up @@ -72,7 +73,7 @@ public static void giveItem(ItemStack item) throws CommandSyntaxException {
if (preview) preset.getMiddle().getDefaultStack();
ItemStack item = preset.getMiddle().getDefaultStack();
try {
item.setNbt(StringNbtReader.parse(preset.getRight()));
item.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(StringNbtReader.parse(preset.getRight())));
} catch (CommandSyntaxException e) { }
item.set(DataComponentTypes.CUSTOM_NAME, Text.literal(toName(preset.getLeft())));
return item;
Expand All @@ -83,8 +84,9 @@ public static void giveItem(ItemStack item) throws CommandSyntaxException {
if (preview) Items.SPIDER_SPAWN_EGG.getDefaultStack();
ItemStack item = Items.SPIDER_SPAWN_EGG.getDefaultStack();
String nick = mc.player.getName().getString();

try {
item.setNbt(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.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}}}")));
} catch (CommandSyntaxException e) { }
item.set(DataComponentTypes.CUSTOM_NAME, Text.of("Force OP"));
return item;
Expand All @@ -104,7 +106,7 @@ public static void giveItem(ItemStack item) throws CommandSyntaxException {
}
NbtCompound nbt = new NbtCompound();
nbt.put("CustomPotionEffects", effects);
stack.setNbt(nbt);
stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt));
stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal("Lingering Potion of Trolling"));
return stack;
});
Expand All @@ -123,7 +125,7 @@ public static void giveItem(ItemStack item) throws CommandSyntaxException {
addEnchant(enchants, "minecraft:vanishing_curse", (short)1);
NbtCompound nbt = new NbtCompound();
nbt.put("Enchantments", enchants);
stack.setNbt(nbt);
stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt));
stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal("Bonk"));
return stack;
});
Expand All @@ -136,7 +138,7 @@ public static void giveItem(ItemStack item) throws CommandSyntaxException {
for(int i = 0; i < 40000; i++)
nbtList.add(new NbtList());
nbtCompound.put("nothingsuspicioushere", nbtList);
stack.setNbt(nbtCompound);
stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbtCompound));
stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal("Copy Me"));
return stack;
});
Expand All @@ -161,7 +163,7 @@ public static void giveItem(ItemStack item) throws CommandSyntaxException {
tagCompound.putInt("Flight", 0);
tagCompound.put("Explosions", explosionList);
baseCompound.put("Fireworks", tagCompound);
firework.setNbt(baseCompound);
firework.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(baseCompound));
return firework;
});

Expand All @@ -173,7 +175,7 @@ public static void giveItem(ItemStack item) throws CommandSyntaxException {
NbtCompound entityTag = new NbtCompound();
entityTag.putString("id", id.toString());
tag.put("EntityTag", entityTag);
egg.setNbt(tag);
egg.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(tag));
egg.set(DataComponentTypes.CUSTOM_NAME, Text.literal(String.format("%s", toName(id.getPath()))));
return egg;
});
Expand Down

0 comments on commit c5bc7f6

Please sign in to comment.