Skip to content

Commit

Permalink
Merge branch 'v7.46.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Dec 3, 2024
2 parents d76ab14 + ae9a909 commit 8a4ea2e
Show file tree
Hide file tree
Showing 16 changed files with 549 additions and 389 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ loader_version=0.16.9
fabric_version=0.107.0+1.21.3

# Mod Properties
mod_version = v7.46.2-MC1.21.3
mod_version = v7.46.3-MC1.21.3
maven_group = net.wurstclient
archives_base_name = Wurst-Client

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/wurstclient/WurstClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public enum WurstClient
public static MinecraftClient MC;
public static IMinecraftClient IMC;

public static final String VERSION = "7.46.2";
public static final String VERSION = "7.46.3";
public static final String MC_VERSION = "1.21.3";

private WurstAnalytics analytics;
Expand Down
18 changes: 2 additions & 16 deletions src/main/java/net/wurstclient/commands/CopyItemCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
import net.wurstclient.command.CmdError;
import net.wurstclient.command.CmdException;
import net.wurstclient.command.CmdSyntaxError;
import net.wurstclient.command.Command;
import net.wurstclient.util.ChatUtils;
import net.wurstclient.util.CmdUtils;

public final class CopyItemCmd extends Command
{
Expand All @@ -38,7 +38,7 @@ public void call(String[] args) throws CmdException

AbstractClientPlayerEntity player = getPlayer(args[0]);
ItemStack item = getItem(player, args[1]);
giveItem(item);
CmdUtils.giveItem(item);

ChatUtils.message("Item copied.");
}
Expand Down Expand Up @@ -80,18 +80,4 @@ private ItemStack getItem(AbstractClientPlayerEntity player, String slot)
throw new CmdSyntaxError();
}
}

private void giveItem(ItemStack stack) throws CmdError
{
int slot = MC.player.getInventory().getEmptySlot();
if(slot < 0)
throw new CmdError("Cannot give item. Your inventory is full.");

if(slot < 9)
slot += 36;

CreativeInventoryActionC2SPacket packet =
new CreativeInventoryActionC2SPacket(slot, stack);
MC.player.networkHandler.sendPacket(packet);
}
}
44 changes: 3 additions & 41 deletions src/main/java/net/wurstclient/commands/GiveCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@
import net.minecraft.component.type.NbtComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.StringNbtReader;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.InvalidIdentifierException;
import net.wurstclient.command.CmdError;
import net.wurstclient.command.CmdException;
import net.wurstclient.command.CmdSyntaxError;
import net.wurstclient.command.Command;
import net.wurstclient.util.ChatUtils;
import net.wurstclient.util.CmdUtils;
import net.wurstclient.util.MathUtils;

public final class GiveCmd extends Command
Expand All @@ -50,13 +46,7 @@ public void call(String[] args) throws CmdException
throw new CmdError("Creative mode only.");

// id/name
Item item = getItem(args[0]);

if(item == Items.AIR && MathUtils.isInteger(args[0]))
item = Item.byRawId(Integer.parseInt(args[0]));

if(item == Items.AIR)
throw new CmdError("Item \"" + args[0] + "\" could not be found.");
Item item = CmdUtils.parseItem(args[0]);

// amount
int amount = 1;
Expand Down Expand Up @@ -94,35 +84,7 @@ public void call(String[] args) throws CmdException
}

// give item
if(!placeStackInHotbar(stack))
throw new CmdError("Please clear a slot in your hotbar.");
CmdUtils.giveItem(stack);
ChatUtils.message("Item" + (amount > 1 ? "s" : "") + " created.");
}

private Item getItem(String id) throws CmdSyntaxError
{
try
{
return Registries.ITEM.get(Identifier.of(id));

}catch(InvalidIdentifierException e)
{
throw new CmdSyntaxError("Invalid item: " + id);
}
}

private boolean placeStackInHotbar(ItemStack stack)
{
for(int i = 0; i < 9; i++)
{
if(!MC.player.getInventory().getStack(i).isEmpty())
continue;

MC.player.networkHandler.sendPacket(
new CreativeInventoryActionC2SPacket(36 + i, stack));
return true;
}

return false;
}
}
13 changes: 2 additions & 11 deletions src/main/java/net/wurstclient/commands/ItemListCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.wurstclient.settings.Setting;
import net.wurstclient.util.ChatUtils;
import net.wurstclient.util.CmdUtils;
import net.wurstclient.util.ItemUtils;
import net.wurstclient.util.MathUtils;

@DontBlock
Expand Down Expand Up @@ -80,11 +79,7 @@ private void add(Feature feature, ItemListSetting setting, String[] args)
if(args.length != 4)
throw new CmdSyntaxError();

String inputItemName = args[3];
Item item = ItemUtils.getItemFromNameOrID(inputItemName);
if(item == null)
throw new CmdSyntaxError(
"\"" + inputItemName + "\" is not a valid item.");
Item item = CmdUtils.parseItem(args[3]);

String itemName = Registries.ITEM.getId(item).toString();
int index = Collections.binarySearch(setting.getItemNames(), itemName);
Expand All @@ -101,11 +96,7 @@ private void remove(Feature feature, ItemListSetting setting, String[] args)
if(args.length != 4)
throw new CmdSyntaxError();

String inputItemName = args[3];
Item item = ItemUtils.getItemFromNameOrID(inputItemName);
if(item == null)
throw new CmdSyntaxError(
"\"" + inputItemName + "\" is not a valid item.");
Item item = CmdUtils.parseItem(args[3]);

String itemName = Registries.ITEM.getId(item).toString();
int index = Collections.binarySearch(setting.getItemNames(), itemName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private void updatePingers(ArrayList<WurstServerPinger> pingers)
}
}
pingers.remove(i);
i -= 1;
}
}

Expand Down
34 changes: 34 additions & 0 deletions src/main/java/net/wurstclient/test/AltManagerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.client.MinecraftClient;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.widget.ButtonWidget;

public enum AltManagerTest
{
;

public static void testAltManagerButton(MinecraftClient mc)
{
System.out.println("Checking AltManager button position");

if(!(mc.currentScreen instanceof TitleScreen))
throw new RuntimeException("Not on the title screen");

ButtonWidget multiplayerButton = findButton(mc, "menu.multiplayer");
ButtonWidget realmsButton = findButton(mc, "menu.online");
ButtonWidget altManagerButton = findButton(mc, "Alt Manager");

checkButtonPosition(altManagerButton, realmsButton.getRight() + 4,
multiplayerButton.getBottom() + 4);
}
}
42 changes: 42 additions & 0 deletions src/main/java/net/wurstclient/test/CopyItemCmdTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.client.option.Perspective;
import net.minecraft.item.Items;

public enum CopyItemCmdTest
{
;

public static void testCopyItemCmd()
{
System.out.println("Testing .copyitem command");
setPerspective(Perspective.THIRD_PERSON_FRONT);

// Put on a golden helmet
runChatCommand("item replace entity @s armor.head with golden_helmet");
takeScreenshot("copyitem_command_setup");
assertNoItemInSlot(0);
assertOneItemInSlot(39, Items.GOLDEN_HELMET);

// .copyitem the helmet
String playerName = submitAndGet(mc -> mc.player.getName().getString());
runWurstCommand("copyitem " + playerName + " head");
takeScreenshot("copyitem_command_result");
assertOneItemInSlot(0, Items.GOLDEN_HELMET);
assertOneItemInSlot(39, Items.GOLDEN_HELMET);

// Clean up
setPerspective(Perspective.FIRST_PERSON);
runChatCommand("clear");
clearChat();
}
}
28 changes: 28 additions & 0 deletions src/main/java/net/wurstclient/test/GiveCmdTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.item.Items;

public enum GiveCmdTest
{
;

public static void testGiveCmd()
{
System.out.println("Testing .give command");
runWurstCommand("give diamond");
assertOneItemInSlot(0, Items.DIAMOND);

// Clean up
runChatCommand("clear");
clearChat();
}
}
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();
}
}
Loading

0 comments on commit 8a4ea2e

Please sign in to comment.