Search in sources :

Example 1 with CPacketCreativeInventoryAction

use of net.minecraft.network.play.client.CPacketCreativeInventoryAction in project Wurst-MC-1.12 by Wurst-Imperium.

the class ModifyCmd method call.

@Override
public void call(String[] args) throws CmdException {
    EntityPlayerSP player = WMinecraft.getPlayer();
    if (!player.capabilities.isCreativeMode)
        throw new CmdError("Creative mode only.");
    if (args.length < 1)
        throw new CmdSyntaxError();
    ItemStack item = player.inventory.getCurrentItem();
    if (item == null)
        throw new CmdError("You need an item in your hand.");
    if (args[0].equalsIgnoreCase("add")) {
        if (args.length < 2)
            throw new CmdSyntaxError();
        String v = "";
        for (int i = 1; i < args.length; i++) v += args[i] + " ";
        if (!item.hasTagCompound())
            item.setTagCompound(new NBTTagCompound());
        try {
            NBTTagCompound value = JsonToNBT.getTagFromJson(v);
            item.getTagCompound().merge(value);
        } catch (NBTException e) {
            e.printStackTrace();
            throw new CmdError("NBT data is invalid.");
        }
    } else if (args[0].equalsIgnoreCase("set")) {
        if (args.length < 2)
            throw new CmdSyntaxError();
        String v = "";
        for (int i = 1; i < args.length; i++) v += args[i] + " ";
        try {
            NBTTagCompound value = JsonToNBT.getTagFromJson(v);
            item.setTagCompound(value);
        } catch (NBTException e) {
            e.printStackTrace();
            throw new CmdError("NBT data is invalid.");
        }
    } else if (args[0].equalsIgnoreCase("remove")) {
        if (args.length != 2)
            throw new CmdSyntaxError();
        NBTPath path = parseNBTPath(item.getTagCompound(), args[1]);
        if (path == null)
            throw new CmdError("The path does not exist.");
        path.base.removeTag(path.key);
    } else if (args[0].equalsIgnoreCase("metadata")) {
        if (args.length != 2)
            throw new CmdSyntaxError();
        if (!MiscUtils.isInteger(args[1]))
            throw new CmdSyntaxError("Value must be a number.");
        item.setItemDamage(Integer.parseInt(args[1]));
    } else
        throw new CmdSyntaxError();
    WConnection.sendPacket(new CPacketCreativeInventoryAction(36 + player.inventory.currentItem, item));
    ChatUtils.message("Item modified.");
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CPacketCreativeInventoryAction(net.minecraft.network.play.client.CPacketCreativeInventoryAction) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack) NBTException(net.minecraft.nbt.NBTException)

Example 2 with CPacketCreativeInventoryAction

use of net.minecraft.network.play.client.CPacketCreativeInventoryAction in project Wurst-MC-1.12 by Wurst-Imperium.

the class DropCmd method onUpdate.

@Override
public void onUpdate() {
    if (infinite) {
        Item item = null;
        while (item == null) item = Item.getItemById(new Random().nextInt(431));
        WConnection.sendPacket(new CPacketCreativeInventoryAction(-1, new ItemStack(item, 64)));
        return;
    }
    if (wurst.special.yesCheatSpf.getProfile().ordinal() >= Profile.OLDER_NCP.ordinal()) {
        timer++;
        if (timer >= 5) {
            WPlayerController.windowClick_THROW(counter);
            counter++;
            timer = 0;
            if (counter >= 45)
                wurst.events.remove(UpdateListener.class, this);
        }
    } else {
        for (int i = 9; i < 45; i++) WPlayerController.windowClick_THROW(i);
        wurst.events.remove(UpdateListener.class, this);
    }
}
Also used : Item(net.minecraft.item.Item) Random(java.util.Random) CPacketCreativeInventoryAction(net.minecraft.network.play.client.CPacketCreativeInventoryAction) ItemStack(net.minecraft.item.ItemStack) UpdateListener(net.wurstclient.events.UpdateListener)

Example 3 with CPacketCreativeInventoryAction

use of net.minecraft.network.play.client.CPacketCreativeInventoryAction in project SpongeCommon by SpongePowered.

the class MixinPacketUtil method creativeCheck.

/**
 * @author gabizou
 * @reason Overwrites our sanity check for catching an exploited item stack.
 */
@Overwrite
private static boolean creativeCheck(Packet<?> packet, EntityPlayerMP playerMP) {
    if (!(packet instanceof CPacketCreativeInventoryAction)) {
        return false;
    }
    if (!SpongeImpl.getGlobalConfig().getConfig().getExploits().isPreventItemNameOverflow()) {
        return true;
    }
    // Fix string overflow exploit in creative mode
    CPacketCreativeInventoryAction creativePacket = (CPacketCreativeInventoryAction) packet;
    ItemStack itemstack = creativePacket.getStack();
    if (!itemstack.isEmpty() && itemstack.getDisplayName().length() > 32767) {
        SpongeHooks.logExploitItemNameOverflow(playerMP, itemstack.getDisplayName().length());
        playerMP.connection.disconnect(new TextComponentString("You have been kicked for attempting to perform an itemstack name overflow exploit."));
        isExploit = true;
        return false;
    }
    return true;
}
Also used : CPacketCreativeInventoryAction(net.minecraft.network.play.client.CPacketCreativeInventoryAction) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with CPacketCreativeInventoryAction

use of net.minecraft.network.play.client.CPacketCreativeInventoryAction in project Wurst-MC-1.12 by Wurst-Imperium.

the class RepairCmd method call.

@Override
public void call(String[] args) throws CmdException {
    if (args.length > 0)
        throw new CmdSyntaxError();
    // check for creative mode
    EntityPlayerSP player = WMinecraft.getPlayer();
    if (!player.capabilities.isCreativeMode)
        throw new CmdError("Creative mode only.");
    // validate item
    ItemStack item = player.inventory.getCurrentItem();
    if (item == null)
        throw new CmdError("You need an item in your hand.");
    if (!item.isItemStackDamageable())
        throw new CmdError("This item can't take damage.");
    if (!item.isItemDamaged())
        throw new CmdError("This item is not damaged.");
    // repair item
    item.setItemDamage(0);
    WConnection.sendPacket(new CPacketCreativeInventoryAction(36 + player.inventory.currentItem, item));
}
Also used : CPacketCreativeInventoryAction(net.minecraft.network.play.client.CPacketCreativeInventoryAction) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)4 CPacketCreativeInventoryAction (net.minecraft.network.play.client.CPacketCreativeInventoryAction)4 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)2 Random (java.util.Random)1 Item (net.minecraft.item.Item)1 NBTException (net.minecraft.nbt.NBTException)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 UpdateListener (net.wurstclient.events.UpdateListener)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1