2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2023-09-25 00:35:24 +02:00
|
|
|
import static codechicken.nei.NEIClientConfig.canCheatItem;
|
|
|
|
|
import static codechicken.nei.NEIClientConfig.canPerformAction;
|
|
|
|
|
import static codechicken.nei.NEIClientConfig.getStringArrSetting;
|
|
|
|
|
import static codechicken.nei.NEIClientConfig.getStringSetting;
|
|
|
|
|
import static codechicken.nei.NEIClientConfig.hasSMPCounterPart;
|
|
|
|
|
import static codechicken.nei.NEIClientConfig.invCreativeMode;
|
|
|
|
|
import static codechicken.nei.NEIClientConfig.world;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-08-20 18:41:22 +09:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
import java.io.StringWriter;
|
2022-08-19 15:03:42 +03:00
|
|
|
import java.math.BigInteger;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
import java.text.DecimalFormatSymbols;
|
2022-06-24 12:32:13 +01:00
|
|
|
import java.text.MessageFormat;
|
|
|
|
|
import java.text.NumberFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
2022-08-19 15:03:42 +03:00
|
|
|
import java.util.HashMap;
|
2022-06-24 12:32:13 +01:00
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
2022-08-19 15:03:42 +03:00
|
|
|
import java.util.Locale;
|
|
|
|
|
import java.util.Map;
|
2022-08-20 18:41:22 +09:00
|
|
|
import java.util.Set;
|
2022-06-24 12:32:13 +01:00
|
|
|
import java.util.stream.Collectors;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2023-09-25 00:35:24 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
|
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.util.ChatComponentTranslation;
|
|
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
|
|
|
|
import net.minecraft.util.IChatComponent;
|
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
|
|
|
|
|
import org.lwjgl.input.Keyboard;
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Iterables;
|
|
|
|
|
|
|
|
|
|
import codechicken.lib.inventory.InventoryRange;
|
|
|
|
|
import codechicken.lib.inventory.InventoryUtils;
|
|
|
|
|
import codechicken.lib.util.LangProxy;
|
|
|
|
|
import codechicken.nei.api.GuiInfo;
|
|
|
|
|
import codechicken.nei.api.IInfiniteItemHandler;
|
|
|
|
|
import codechicken.nei.api.ItemInfo;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public class NEIClientUtils extends NEIServerUtils {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public static LangProxy lang = new LangProxy("nei");
|
|
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
/** Formats a number with group separator and at most 2 fraction digits. */
|
|
|
|
|
private static final Map<Locale, DecimalFormat> decimalFormatters = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
public static final int ALT_HASH = 1 << 27;
|
|
|
|
|
public static final int SHIFT_HASH = 1 << 26;
|
|
|
|
|
public static final int CTRL_HASH = 1 << 25;
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public static Minecraft mc() {
|
|
|
|
|
return Minecraft.getMinecraft();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String translate(String key, Object... params) {
|
|
|
|
|
return lang.format(key, params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void printChatMessage(IChatComponent msg) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (mc().ingameGUI != null) mc().ingameGUI.getChatGUI().printChatMessage(msg);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
private static DecimalFormat getDecimalFormat() {
|
|
|
|
|
return decimalFormatters.computeIfAbsent(Locale.getDefault(Locale.Category.FORMAT), locale -> {
|
|
|
|
|
DecimalFormat numberFormat = new DecimalFormat(); // uses the necessary locale inside anyway
|
|
|
|
|
numberFormat.setGroupingUsed(true);
|
|
|
|
|
numberFormat.setMaximumFractionDigits(2);
|
|
|
|
|
numberFormat.setRoundingMode(RoundingMode.HALF_UP);
|
|
|
|
|
DecimalFormatSymbols decimalFormatSymbols = numberFormat.getDecimalFormatSymbols();
|
|
|
|
|
decimalFormatSymbols.setGroupingSeparator(','); // Use sensible separator for best clarity.
|
|
|
|
|
numberFormat.setDecimalFormatSymbols(decimalFormatSymbols);
|
|
|
|
|
|
|
|
|
|
return numberFormat;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String formatNumbers(BigInteger aNumber) {
|
|
|
|
|
return getDecimalFormat().format(aNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String formatNumbers(long aNumber) {
|
|
|
|
|
return getDecimalFormat().format(aNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String formatNumbers(double aNumber) {
|
|
|
|
|
return getDecimalFormat().format(aNumber);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public static void deleteHeldItem() {
|
|
|
|
|
deleteSlotStack(-999);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void dropHeldItem() {
|
2022-06-24 12:32:13 +01:00
|
|
|
mc().playerController
|
|
|
|
|
.windowClick(((GuiContainer) mc().currentScreen).inventorySlots.windowId, -999, 0, 0, mc().thePlayer);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void deleteSlotStack(int slotNumber) {
|
|
|
|
|
setSlotContents(slotNumber, null, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void decreaseSlotStack(int slotNumber) {
|
2022-06-24 12:32:13 +01:00
|
|
|
ItemStack stack = slotNumber == -999 ? getHeldItem()
|
|
|
|
|
: mc().thePlayer.openContainer.getSlot(slotNumber).getStack();
|
|
|
|
|
if (stack == null) return;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (stack.stackSize == 1) deleteSlotStack(slotNumber);
|
2014-04-29 10:54:20 +10:00
|
|
|
else {
|
|
|
|
|
stack = stack.copy();
|
|
|
|
|
stack.stackSize--;
|
|
|
|
|
setSlotContents(slotNumber, stack, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void deleteEverything() {
|
|
|
|
|
NEICPH.sendDeleteAllItems();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void deleteItemsOfType(ItemStack type) {
|
|
|
|
|
Container c = getGuiContainer().inventorySlots;
|
|
|
|
|
for (int i = 0; i < c.inventorySlots.size(); i++) {
|
|
|
|
|
Slot slot = c.getSlot(i);
|
2022-06-24 12:32:13 +01:00
|
|
|
if (slot == null) continue;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
ItemStack stack = slot.getStack();
|
|
|
|
|
if (stack != null && stack.getItem() == type.getItem() && stack.getItemDamage() == type.getItemDamage()) {
|
|
|
|
|
setSlotContents(i, null, true);
|
|
|
|
|
slot.putStack(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ItemStack getHeldItem() {
|
|
|
|
|
return mc().thePlayer.inventory.getItemStack();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setSlotContents(int slot, ItemStack item, boolean containerInv) {
|
|
|
|
|
NEICPH.sendSetSlot(slot, item, containerInv);
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (slot == -999) mc().thePlayer.inventory.setItemStack(item);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mode -1 = normal cheats, 0 = no infinites, 1 = replenish stack
|
|
|
|
|
*/
|
2014-06-29 20:31:37 +10:00
|
|
|
public static void cheatItem(ItemStack stack, int button, int mode) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!canCheatItem(stack)) return;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
if (mode == -1 && button == 0 && shiftKey() && NEIClientConfig.hasSMPCounterPart()) {
|
2014-04-29 10:54:20 +10:00
|
|
|
for (IInfiniteItemHandler handler : ItemInfo.infiniteHandlers) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!handler.canHandleItem(stack)) continue;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
ItemStack inf = handler.getInfiniteItem(stack);
|
|
|
|
|
if (inf != null) {
|
|
|
|
|
giveStack(inf, inf.stackSize, true);
|
2014-04-29 10:54:20 +10:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
cheatItem(stack, button, 0);
|
2014-04-29 10:54:20 +10:00
|
|
|
} else if (button == 1) {
|
2014-06-29 20:31:37 +10:00
|
|
|
giveStack(stack, 1);
|
2014-04-29 10:54:20 +10:00
|
|
|
} else {
|
2014-06-29 20:31:37 +10:00
|
|
|
if (mode == 1 && stack.stackSize < stack.getMaxStackSize()) {
|
|
|
|
|
giveStack(stack, stack.getMaxStackSize() - stack.stackSize);
|
2014-04-29 10:54:20 +10:00
|
|
|
} else {
|
2022-01-02 23:30:54 +02:00
|
|
|
giveStack(stack);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void giveStack(ItemStack itemstack) {
|
|
|
|
|
giveStack(itemstack, itemstack.stackSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void giveStack(ItemStack itemstack, int i) {
|
|
|
|
|
giveStack(itemstack, i, false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public static void giveStack(ItemStack base, int i, boolean infinite) {
|
|
|
|
|
ItemStack stack = copyStack(base, i);
|
2014-04-29 10:54:20 +10:00
|
|
|
if (hasSMPCounterPart()) {
|
2014-06-29 20:31:37 +10:00
|
|
|
ItemStack typestack = copyStack(stack, 1);
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!infinite && !canItemFitInInventory(mc().thePlayer, stack)
|
|
|
|
|
&& (mc().currentScreen instanceof GuiContainer)) {
|
2014-04-29 10:54:20 +10:00
|
|
|
GuiContainer gui = getGuiContainer();
|
2021-06-05 10:47:58 -07:00
|
|
|
final List<Iterable<Integer>> handlerSlots;
|
|
|
|
|
try {
|
|
|
|
|
GuiInfo.readLock.lock();
|
2022-01-03 16:55:39 +02:00
|
|
|
handlerSlots = GuiInfo.guiHandlers.stream()
|
2022-06-24 12:32:13 +01:00
|
|
|
.map(handler -> handler.getItemSpawnSlots(gui, typestack)).filter(x -> x != null)
|
|
|
|
|
.collect(Collectors.toCollection(LinkedList::new));
|
2021-06-05 10:47:58 -07:00
|
|
|
} finally {
|
|
|
|
|
GuiInfo.readLock.unlock();
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
int increment = typestack.getMaxStackSize();
|
|
|
|
|
int given = 0;
|
2022-06-24 12:32:13 +01:00
|
|
|
for (int slotNo : Iterables.concat(handlerSlots)) {
|
2014-04-29 10:54:20 +10:00
|
|
|
Slot slot = gui.inventorySlots.getSlot(slotNo);
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!slot.isItemValid(typestack) || !InventoryUtils.canStack(slot.getStack(), typestack)) continue;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
int qty = Math.min(stack.stackSize - given, increment);
|
2014-04-29 10:54:20 +10:00
|
|
|
int current = slot.getHasStack() ? slot.getStack().stackSize : 0;
|
|
|
|
|
qty = Math.min(qty, slot.getSlotStackLimit() - current);
|
|
|
|
|
|
|
|
|
|
ItemStack newStack = copyStack(typestack, qty + current);
|
|
|
|
|
slot.putStack(newStack);
|
|
|
|
|
setSlotContents(slotNo, newStack, true);
|
|
|
|
|
given += qty;
|
2022-06-24 12:32:13 +01:00
|
|
|
if (given >= stack.stackSize) break;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
if (given > 0) NEICPH.sendGiveItem(copyStack(typestack, given), false, false);
|
|
|
|
|
} else NEICPH.sendGiveItem(stack, infinite, true);
|
2014-04-29 10:54:20 +10:00
|
|
|
} else {
|
2014-06-29 20:31:37 +10:00
|
|
|
for (int given = 0; given < stack.stackSize;) {
|
|
|
|
|
int qty = Math.min(stack.stackSize - given, stack.getMaxStackSize());
|
2022-06-24 12:32:13 +01:00
|
|
|
sendCommand(
|
|
|
|
|
getStringSetting("command.item"),
|
2014-06-29 20:31:37 +10:00
|
|
|
mc().thePlayer.getCommandSenderName(),
|
|
|
|
|
Item.getIdFromItem(stack.getItem()),
|
|
|
|
|
qty,
|
|
|
|
|
stack.getItemDamage(),
|
|
|
|
|
stack.hasTagCompound() ? stack.getTagCompound().toString() : "",
|
|
|
|
|
Item.itemRegistry.getNameForObject(stack.getItem()));
|
2014-04-29 10:54:20 +10:00
|
|
|
given += qty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean canItemFitInInventory(EntityPlayer player, ItemStack itemstack) {
|
|
|
|
|
return InventoryUtils.getInsertibleQuantity(new InventoryRange(player.inventory, 0, 36), itemstack) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean shiftKey() {
|
|
|
|
|
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean controlKey() {
|
2023-02-28 16:53:59 +02:00
|
|
|
if (Minecraft.isRunningOnMac) {
|
|
|
|
|
return Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA);
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getGamemode() {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (invCreativeMode()) return 2;
|
|
|
|
|
else if (mc().playerController.isInCreativeMode()) return 1;
|
|
|
|
|
else if (mc().playerController.currentGameType.isAdventure()) return 3;
|
|
|
|
|
else return 0;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isValidGamemode(String s) {
|
2022-06-24 12:32:13 +01:00
|
|
|
return s.equals("survival")
|
|
|
|
|
|| canPerformAction(s) && Arrays.asList(getStringArrSetting("inventory.gamemodes")).contains(s);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getNextGamemode() {
|
|
|
|
|
int mode = getGamemode();
|
|
|
|
|
int nmode = mode;
|
|
|
|
|
while (true) {
|
|
|
|
|
nmode = (nmode + 1) % NEIActions.gameModes.length;
|
2022-06-24 12:32:13 +01:00
|
|
|
if (nmode == mode || isValidGamemode(NEIActions.gameModes[nmode])) break;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
return nmode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void cycleGamemode() {
|
|
|
|
|
int mode = getGamemode();
|
|
|
|
|
int nmode = getNextGamemode();
|
2022-06-24 12:32:13 +01:00
|
|
|
if (mode == nmode) return;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (hasSMPCounterPart()) NEICPH.sendGamemode(nmode);
|
|
|
|
|
else sendCommand(
|
|
|
|
|
getStringSetting("command.creative"),
|
|
|
|
|
getGameType(nmode),
|
|
|
|
|
mc().thePlayer.getCommandSenderName());
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static long getTime() {
|
|
|
|
|
return mc().theWorld.getWorldInfo().getWorldTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setTime(long l) {
|
|
|
|
|
mc().theWorld.getWorldInfo().setWorldTime(l);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setHourForward(int hour) {
|
|
|
|
|
long day = (getTime() / 24000L) * 24000L;
|
|
|
|
|
long newTime = day + 24000L + hour * 1000;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (hasSMPCounterPart()) NEICPH.sendSetTime(hour);
|
|
|
|
|
else sendCommand(getStringSetting("command.time"), newTime);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void sendCommand(String command, Object... args) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (command.length() == 0) return;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
NumberFormat numberformat = NumberFormat.getIntegerInstance();
|
|
|
|
|
numberformat.setGroupingUsed(false);
|
|
|
|
|
MessageFormat messageformat = new MessageFormat(command);
|
|
|
|
|
for (int i = 0; i < args.length; i++) if (args[i] instanceof Integer || args[i] instanceof Long)
|
|
|
|
|
messageformat.setFormatByArgumentIndex(i, numberformat);
|
|
|
|
|
|
|
|
|
|
mc().thePlayer.sendChatMessage(messageformat.format(args));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isRaining() {
|
|
|
|
|
return mc().theWorld.getWorldInfo().isRaining();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void toggleRaining() {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (hasSMPCounterPart()) NEICPH.sendToggleRain();
|
|
|
|
|
else sendCommand(getStringSetting("command.rain"), isRaining() ? 0 : 1);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void healPlayer() {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (hasSMPCounterPart()) NEICPH.sendHeal();
|
|
|
|
|
else sendCommand(getStringSetting("command.heal"), mc().thePlayer.getCommandSenderName());
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void toggleMagnetMode() {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (hasSMPCounterPart()) NEICPH.sendToggleMagnetMode();
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ArrayList<int[]> concatIntegersToRanges(List<Integer> damages) {
|
2019-12-30 20:19:16 -08:00
|
|
|
ArrayList<int[]> ranges = new ArrayList<>();
|
2014-04-29 10:54:20 +10:00
|
|
|
if (damages.size() == 0) return ranges;
|
|
|
|
|
|
|
|
|
|
Collections.sort(damages);
|
|
|
|
|
int start = -1;
|
|
|
|
|
int next = 0;
|
|
|
|
|
for (Integer i : damages) {
|
|
|
|
|
if (start == -1) {
|
|
|
|
|
start = next = i;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (next + 1 != i) {
|
2022-06-24 12:32:13 +01:00
|
|
|
ranges.add(new int[] { start, next });
|
2014-04-29 10:54:20 +10:00
|
|
|
start = next = i;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
next = i;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
ranges.add(new int[] { start, next });
|
2014-04-29 10:54:20 +10:00
|
|
|
return ranges;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ArrayList<int[]> addIntegersToRanges(List<int[]> ranges, List<Integer> damages) {
|
2022-06-24 12:32:13 +01:00
|
|
|
for (int[] range : ranges) for (int integer = range[0]; integer <= range[1]; integer++) damages.add(integer);
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
return concatIntegersToRanges(damages);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
public static String cropText(FontRenderer fontRenderer, String text, int containerWidth) {
|
|
|
|
|
|
|
|
|
|
int textWidth = fontRenderer.getStringWidth(text);
|
|
|
|
|
|
|
|
|
|
if (textWidth > containerWidth) {
|
|
|
|
|
textWidth += fontRenderer.getStringWidth("...");
|
|
|
|
|
|
|
|
|
|
while (textWidth > containerWidth) {
|
|
|
|
|
textWidth -= fontRenderer.getCharWidth(text.charAt(text.length() - 1));
|
|
|
|
|
text = text.substring(0, text.length() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text + "...";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public static boolean safeKeyDown(int keyCode) {
|
|
|
|
|
try {
|
|
|
|
|
return Keyboard.isKeyDown(keyCode);
|
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setItemQuantity(int i) {
|
|
|
|
|
world.nbt.setInteger("quantity", i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GuiContainer getGuiContainer() {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (mc().currentScreen instanceof GuiContainer) return (GuiContainer) mc().currentScreen;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean altKey() {
|
|
|
|
|
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
public static int getMetaHash() {
|
|
|
|
|
if (Keyboard.getEventKeyState()) {
|
|
|
|
|
int hash = 0;
|
|
|
|
|
|
|
|
|
|
if (altKey()) {
|
|
|
|
|
hash = hash | ALT_HASH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shiftKey()) {
|
|
|
|
|
hash = hash | SHIFT_HASH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (controlKey()) {
|
|
|
|
|
hash = hash | CTRL_HASH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getKeyHash() {
|
|
|
|
|
|
|
|
|
|
if (Keyboard.getEventKeyState()) {
|
|
|
|
|
final int keycode = Keyboard.getEventKey();
|
|
|
|
|
|
|
|
|
|
if (keycode != Keyboard.KEY_LSHIFT && keycode != Keyboard.KEY_RSHIFT
|
|
|
|
|
&& keycode != Keyboard.KEY_LCONTROL
|
|
|
|
|
&& keycode != Keyboard.KEY_RCONTROL
|
|
|
|
|
&& keycode != Keyboard.KEY_LMENU
|
|
|
|
|
&& keycode != Keyboard.KEY_RMENU) {
|
|
|
|
|
return getMetaHash() + keycode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Keyboard.CHAR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public static void playClickSound() {
|
2022-06-24 12:32:13 +01:00
|
|
|
mc().getSoundHandler()
|
|
|
|
|
.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
2014-06-29 20:31:37 +10:00
|
|
|
}
|
2022-08-20 18:41:22 +09:00
|
|
|
|
|
|
|
|
public static void reportErrorBuffered(Throwable e, Set<String> buffer, String cause) {
|
|
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
|
e.printStackTrace(new PrintWriter(sw));
|
|
|
|
|
String stackTrace = cause + sw;
|
|
|
|
|
if (buffer.contains(stackTrace)) return;
|
|
|
|
|
|
|
|
|
|
System.err.println("Error while rendering: " + cause);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
buffer.add(stackTrace);
|
|
|
|
|
|
|
|
|
|
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
|
|
|
|
if (player != null) {
|
|
|
|
|
IChatComponent chat = new ChatComponentTranslation("nei.chat.render.error");
|
|
|
|
|
chat.getChatStyle().setColor(EnumChatFormatting.RED);
|
|
|
|
|
player.addChatComponentMessage(chat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void reportErrorBuffered(Throwable e, Set<String> buffer, ItemStack cause) {
|
|
|
|
|
if (cause != null) {
|
|
|
|
|
reportErrorBuffered(e, buffer, cause.toString());
|
|
|
|
|
} else {
|
|
|
|
|
reportErrorBuffered(e, buffer, "null");
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|