.give improvements

This commit is contained in:
Cloudburst
2021-05-15 20:00:19 +02:00
parent e965fcd683
commit 18a2b46166
2 changed files with 49 additions and 3 deletions

View File

@@ -6,8 +6,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.ItemStackArgument; import net.minecraft.command.argument.ItemStackArgument;
import net.minecraft.command.argument.ItemStackArgumentType; import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.item.ItemStack; import net.minecraft.item.*;
import net.minecraft.item.Items;
import net.minecraft.nbt.*; import net.minecraft.nbt.*;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket; import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
@@ -17,6 +16,7 @@ import minegame159.meteorclient.utils.player.ChatUtils;
import minegame159.meteorclient.utils.player.SlotUtils; import minegame159.meteorclient.utils.player.SlotUtils;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.registry.Registry;
import static cloudburst.rejects.utils.GiveUtils.createPreset; import static cloudburst.rejects.utils.GiveUtils.createPreset;
import static com.mojang.brigadier.Command.SINGLE_SUCCESS; import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
@@ -32,10 +32,43 @@ public class GiveCommand extends Command {
private final Collection<String> PRESETS = Arrays.asList("forceop", "negs", "stacked", "spawners", "bookban", private final Collection<String> PRESETS = Arrays.asList("forceop", "negs", "stacked", "spawners", "bookban",
"test", "eggs"); "test", "eggs");
private final Collection<String> CONTAINERS = Arrays.asList("chest", "shulker", "trapped_chest", "barrel", private final Collection<String> CONTAINERS = Arrays.asList("chest", "shulker", "trapped_chest", "barrel",
"dispenser"); "dispenser", "egg");
@Override @Override
public void build(LiteralArgumentBuilder<CommandSource> builder) { public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("egg").executes(ctx -> {
ItemStack inHand = mc.player.getMainHandStack();
ItemStack item = new ItemStack(Items.STRIDER_SPAWN_EGG);
CompoundTag ct = new CompoundTag();
if (inHand.getItem() instanceof BlockItem) {
ct.putInt("Time",1);
ct.putString("id", "minecraft:falling_block");
ct.put("BlockState", new CompoundTag());
ct.getCompound("BlockState").putString("Name", Registry.ITEM.getId(inHand.getItem()).toString());
if (inHand.hasTag() && inHand.getTag().contains("BlockEntityTag")) {
ct.put("TileEntityData", inHand.getTag().getCompound("BlockEntityTag"));
}
CompoundTag t = new CompoundTag();
t.put("EntityTag", ct);
item.setTag(t);
} else {
ct.putString("id", "minecraft:item");
CompoundTag it = new CompoundTag();
it.putString("id", Registry.ITEM.getId(inHand.getItem()).toString());
it.putInt("Count",inHand.getCount());
if (inHand.hasTag()) {
it.put("tag", inHand.getTag());
}
ct.put("Item",it);
}
CompoundTag t = new CompoundTag();
t.put("EntityTag", ct);
item.setTag(t);
item.setCustomName(inHand.getName());
addItem(item);
return SINGLE_SUCCESS;
}));
builder.then(literal("holo").then(argument("message", StringArgumentType.greedyString()).executes(ctx -> { builder.then(literal("holo").then(argument("message", StringArgumentType.greedyString()).executes(ctx -> {
if (!mc.player.abilities.creativeMode) { if (!mc.player.abilities.creativeMode) {
ChatUtils.error("Not In Creative Mode!"); ChatUtils.error("Not In Creative Mode!");

View File

@@ -5,6 +5,7 @@ import minegame159.meteorclient.utils.player.ChatUtils;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringNbtReader; import net.minecraft.nbt.StringNbtReader;
import java.util.Random; import java.util.Random;
@@ -28,6 +29,9 @@ public class GiveUtils {
case "dispenser": case "dispenser":
item = new ItemStack(Items.DISPENSER); item = new ItemStack(Items.DISPENSER);
break; break;
case "egg":
item = new ItemStack(Items.CHEST);
break;
default: default:
item = new ItemStack(Items.PINK_SHULKER_BOX); item = new ItemStack(Items.PINK_SHULKER_BOX);
break; break;
@@ -267,6 +271,15 @@ public class GiveUtils {
default: default:
break; break;
} }
if (container.equals("egg")) {
CompoundTag ct = new CompoundTag();
ct.put("EntityTag", StringNbtReader.parse("{Time:1,id:\"minecraft:falling_block\",BlockState:{Name:\"minecraft:chest\"}}"));
((CompoundTag) ct.get("EntityTag")).put("TileEntityData", item.getTag().get("BlockEntityTag"));
ct.put("display", item.getTag().get("display"));
item = new ItemStack(Items.STRIDER_SPAWN_EGG);
item.setTag(ct);
}
} catch (CommandSyntaxException e) { } catch (CommandSyntaxException e) {
ChatUtils.error("An NBT parsing error occured"); ChatUtils.error("An NBT parsing error occured");
} }