Skip to content

Commit

Permalink
Add ModifyCmdTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Nov 26, 2024
1 parent fa7d591 commit a0caaeb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/main/java/net/wurstclient/test/ModifyCmdTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2014-2024 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.test;

import static net.wurstclient.test.WurstClientTestHelper.*;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;

public enum ModifyCmdTest
{
;

public static void testModifyCmd()
{
System.out.println("Testing .modify command");

// /give a diamond
runChatCommand("give @s diamond");
assertOneItemInSlot(0, Items.DIAMOND);

// .modify it with NBT data
runWurstCommand("modify add {test:123}");
assertOneItemInSlot(0, Items.DIAMOND);
submitAndWait(mc -> {
ItemStack stack = mc.player.getInventory().getMainHandStack();
NbtCompound nbt = stack.getComponents().getOrDefault(
DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).copyNbt();
if(!nbt.contains("test"))
throw new RuntimeException(
"NBT data is missing the 'test' key");
if(nbt.getInt("test") != 123)
throw new RuntimeException("NBT data is incorrect");
});
runWurstCommand("viewnbt");
takeScreenshot("modify_command_result");

// Clean up
runChatCommand("clear");
clearChat();
}
}
1 change: 1 addition & 0 deletions src/main/java/net/wurstclient/test/WurstE2ETestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private void runTests()
clearChat();

GiveCmdTest.testGiveCmd();
ModifyCmdTest.testModifyCmd();
// TODO: Test more Wurst hacks

System.out.println("Opening inventory");
Expand Down

0 comments on commit a0caaeb

Please sign in to comment.