Initial Commit

This commit is contained in:
Chicken-Bomes committed 2014-04-29 10:54:20 +10:00
commit bd9d0a4eff
149 files changed
+18486

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
package codechicken.nei;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation;
import java.util.List;
import static codechicken.lib.gui.GuiDraw.getStringWidth;
public abstract class Button extends Widget
{
public Button(String s)
{
label = s;
}
public Button()
{
label = "";
}
public int contentWidth()
{
return getRenderIcon() == null ? getStringWidth(label) : getRenderIcon().width;
}
@Override
public void draw(int mousex, int mousey)
{
LayoutManager.getLayoutStyle().drawButton(this, mousex, mousey);
}
@Override
public boolean handleClick(int i, int j, int k)
{
if(k == 1 || k == 0)
if(onButtonPress(k == 1))
NEIClientUtils.mc().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
return true;
}
public abstract boolean onButtonPress(boolean rightclick);
public Image getRenderIcon()
{
return icon;
}
@Override
public List<String> handleTooltip(int mx, int my, List<String> tooltip)
{
if(!contains(mx, my))
return tooltip;
String tip = getButtonTip();
if(tip != null)
tooltip.add(tip);
return tooltip;
}
public String getButtonTip()
{
return null;
}
public String getRenderLabel()
{
return label;
}
public String label;
public Image icon;
/**
* 0x4 = state flag, as opposed to 1 click
* 0 = normal
* 1 = on
* 2 = disabled
*/
public int state;
}
+13
View File
@@ -0,0 +1,13 @@
package codechicken.nei;
public abstract class ButtonCycled extends Button
{
@Override
public Image getRenderIcon()
{
return icons[index];
}
public int index;
public Image[] icons;
}
+231
View File
@@ -0,0 +1,231 @@
package codechicken.nei;
import codechicken.core.ClientUtils;
import codechicken.lib.packet.PacketCustom;
import codechicken.nei.api.API;
import codechicken.nei.api.ItemInfo;
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.*;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ClientHandler
{
private static ClientHandler instance;
private ArrayList<EntityItem> SMPmagneticItems = new ArrayList<EntityItem>();
private World lastworld;
private GuiScreen lastGui;
public void addSMPMagneticItem(int i, World world) {
WorldClient cworld = (WorldClient) world;
Entity e = cworld.getEntityByID(i);
if (e == null || !(e instanceof EntityItem)) {
return;
}
SMPmagneticItems.add((EntityItem) e);
}
private void updateMagnetMode(World world, EntityPlayerSP player) {
if (!NEIClientConfig.getMagnetMode()) return;
float distancexz = 16;
float distancey = 8;
double maxspeedxz = 0.5;
double maxspeedy = 0.5;
double speedxz = 0.05;
double speedy = 0.07;
List<EntityItem> items;
if (world.isRemote) {
items = SMPmagneticItems;
} else {
items = world.getEntitiesWithinAABB(EntityItem.class, player.boundingBox.expand(distancexz, distancey, distancexz));
}
for (Iterator<EntityItem> iterator = items.iterator(); iterator.hasNext(); ) {
EntityItem item = iterator.next();
if (item.delayBeforeCanPickup > 0) continue;
if (item.isDead && world.isRemote) iterator.remove();
if (!NEIClientUtils.canItemFitInInventory(player, item.getEntityItem())) continue;
double dx = player.posX - item.posX;
double dy = player.posY + player.getEyeHeight() - item.posY;
double dz = player.posZ - item.posZ;
double absxz = Math.sqrt(dx * dx + dz * dz);
double absy = Math.abs(dy);
if (absxz > distancexz) {
continue;
}
if (absxz > 1) {
dx /= absxz;
dz /= absxz;
}
if (absy > 1) {
dy /= absy;
}
double vx = item.motionX + speedxz * dx;
double vy = item.motionY + speedy * dy;
double vz = item.motionZ + speedxz * dz;
double absvxz = Math.sqrt(vx * vx + vz * vz);
double absvy = Math.abs(vy);
double rationspeedxz = absvxz / maxspeedxz;
if (rationspeedxz > 1) {
vx /= rationspeedxz;
vz /= rationspeedxz;
}
double rationspeedy = absvy / maxspeedy;
if (rationspeedy > 1) {
vy /= rationspeedy;
}
if (absvxz < 0.2 && absxz < 0.2 && world.isRemote) {
item.setDead();
}
item.setVelocity(vx, vy, vz);
}
}
public static void load() {
try {
TMIUninstaller.deleteTMIUninstaller();
if (TMIUninstaller.TMIInstalled()) {
TMIUninstaller.runTMIUninstaller();
NEIClientUtils.mc().shutdownMinecraftApplet();
}
} catch (Exception e) {
System.err.println("Error with TMI Uninstaller");
e.printStackTrace();
}
instance = new ClientHandler();
PacketCustom.assignHandler(NEICPH.channel, new NEICPH());
FMLCommonHandler.instance().bus().register(instance);
MinecraftForge.EVENT_BUS.register(instance);
API.registerHighlightHandler(new DefaultHighlightHandler(), ItemInfo.Layout.HEADER);
HUDRenderer.load();
WorldOverlayRenderer.load();
}
@SubscribeEvent
public void tickEvent(TickEvent.ClientTickEvent event) {
if(event.phase == Phase.END)
return;
Minecraft mc = Minecraft.getMinecraft();
if(mc.theWorld != null) {
loadWorld(mc.theWorld, false);
if (!NEIClientConfig.isEnabled())
return;
KeyManager.tickKeyStates();
NEIController.updateUnlimitedItems(mc.thePlayer.inventory);
if (mc.currentScreen == null)
NEIController.processCreativeCycling(mc.thePlayer.inventory);
updateMagnetMode(mc.theWorld, mc.thePlayer);
}
GuiScreen gui = mc.currentScreen;
if (gui != lastGui) {
if (gui instanceof GuiMainMenu)
lastworld = null;
else if (gui instanceof GuiSelectWorld)
NEIClientConfig.reloadSaves();
}
lastGui = gui;
}
@SubscribeEvent
public void tickEvent(TickEvent.RenderTickEvent event) {
if(event.phase == Phase.END && NEIClientConfig.isEnabled())
HUDRenderer.renderOverlay();
}
@SubscribeEvent
public void renderLastEvent(RenderWorldLastEvent event) {
if (NEIClientConfig.isEnabled())
WorldOverlayRenderer.render(event.partialTicks);
}
public void loadWorld(World world, boolean remote) {
if (world != lastworld) {
SMPmagneticItems.clear();
WorldOverlayRenderer.reset();
if (!remote) {
NEIClientConfig.setHasSMPCounterPart(false);
NEIClientConfig.setInternalEnabled(false);
if (!Minecraft.getMinecraft().isSingleplayer())//wait for server to initiate
NEIClientConfig.loadWorld("remote/" + ClientUtils.getServerIP().replace(':', '~'));
}
lastworld = world;
}
}
public static ClientHandler instance() {
return instance;
}
public static RuntimeException throwCME(final String message) {
final GuiScreen errorGui = new GuiErrorScreen(null, null)
{
@Override
public void handleMouseInput() {}
@Override
public void handleKeyboardInput() {}
@Override
public void drawScreen(int par1, int par2, float par3) {
drawDefaultBackground();
String[] s_msg = message.split("\n");
for (int i = 0; i < s_msg.length; ++i)
drawCenteredString(fontRendererObj, s_msg[i], width / 2, height / 3 + 12 * i, 0xFFFFFFFF);
}
};
@SuppressWarnings("serial")
CustomModLoadingErrorDisplayException e = new CustomModLoadingErrorDisplayException()
{
@Override
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {
Minecraft.getMinecraft().displayGuiScreen(errorGui);
}
@Override
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime) {}
};
throw e;
}
}
@@ -0,0 +1,112 @@
package codechicken.nei;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
public class ContainerCreativeInv extends Container
{
private class SlotArmor extends Slot
{
int armorType;
public SlotArmor(IInventory inv, int x, int y, int slot, int armor) {
super(inv, x, y, slot);
armorType = armor;
}
@Override
public int getSlotStackLimit() {
return 1;
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack != null && stack.getItem().isValidArmor(stack, armorType, player);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getBackgroundIconIndex() {
return ItemArmor.func_94602_b(armorType);
}
}
private class SlotBlockArmor extends SlotArmor
{
public SlotBlockArmor(IInventory inv, int x, int y, int slot, int armor) {
super(inv, x, y, slot, armor);
}
@Override
public boolean isItemValid(ItemStack stack) {
return super.isItemValid(stack) || stack != null;// && Block.getBlockFromItem(stack.getItem()) != Blocks.air;
}
}
public EntityPlayer player;
public ContainerCreativeInv(EntityPlayer player, ExtendedCreativeInv extraInv) {
this.player = player;
InventoryPlayer invPlayer = player.inventory;
for (int row = 0; row < 6; row++)
for (int col = 0; col < 9; col++)
addSlotToContainer(new Slot(extraInv, col + row * 9, 8 + col * 18, 5 + row * 18));
for (int row = 0; row < 3; ++row)
for (int col = 0; col < 9; ++col)
addSlotToContainer(new Slot(invPlayer, col + row * 9 + 9, 8 + col * 18, 118 + row * 18));
for (int col = 0; col < 9; ++col)
addSlotToContainer(new Slot(invPlayer, col, 8 + col * 18, 176));
addSlotToContainer(new SlotBlockArmor(invPlayer, invPlayer.getSizeInventory() - 1, -15, 23, 0));
for (int armorType = 1; armorType < 4; armorType++)
addSlotToContainer(new SlotArmor(invPlayer, invPlayer.getSizeInventory() - 1 - armorType, -15, 23 + armorType * 18, armorType));
}
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotIndex) {
ItemStack transferredStack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex);
if (slot != null && slot.getHasStack()) {
ItemStack stack = slot.getStack();
transferredStack = stack.copy();
if (stack.getItem() instanceof ItemArmor) {
ItemArmor armor = (ItemArmor) stack.getItem();
if (!getSlot(90 + armor.armorType).getHasStack()) {
getSlot(90 + armor.armorType).putStack(transferredStack);
slot.putStack(null);
return transferredStack;
}
}
if (slotIndex < 54) {
if (!this.mergeItemStack(stack, 54, 90, true))
return null;
} else if (!this.mergeItemStack(stack, 0, 54, false)) {
return null;
}
if (stack.stackSize == 0)
slot.putStack(null);
else
slot.onSlotChanged();
}
return transferredStack;
}
public boolean canInteractWith(EntityPlayer var1) {
return true;
}
}
@@ -0,0 +1,322 @@
package codechicken.nei;
import codechicken.lib.render.CCRenderState;
import net.minecraft.client.gui.Gui;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerEnchantment;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
/**
* This is crap code, don't ever do this.
*/
public class ContainerEnchantmentModifier extends ContainerEnchantment
{
public static class EnchantmentHash
{
public EnchantmentHash(Enchantment e, int i, int l) {
enchantment = e;
state = i;
level = l;
}
Enchantment enchantment;
int state;
int level;
}
public ArrayList<EnchantmentHash> slotEnchantment = new ArrayList<EnchantmentHash>();
int level = 5;
public int scrollclicky = -1;
public float scrollpercent;
public int scrollmousey;
public float percentscrolled;
public int relx = 60;
public int rely = 14;
public int height = 57;
public int cwidth = 101;
public int slotheight = 19;
public GuiEnchantmentModifier parentscreen;
public ContainerEnchantmentModifier(InventoryPlayer inventoryplayer, World world, int i, int j, int k) {
super(inventoryplayer, world, i, j, k);
}
public int getNumSlots() {
return slotEnchantment.size();
}
public int getScrollBarHeight() {
int sbarh = (int) ((height / (float) getContentHeight()) * height);
if (sbarh > height) {
return height;
} else if (sbarh < height / 15) {
return height / 15;
} else {
return sbarh;
}
}
public int getScrollBarWidth() {
return 7;
}
public int getContentHeight() {
return slotheight * getNumSlots();
}
public int getScrolledSlots() {
int slots = getNumSlots();
int shownslots = height / slotheight;
return (int) (percentscrolled * (slots - shownslots) + 0.5F);
}
private int getClickedSlot(int mousey) {
return ((mousey - rely) / slotheight) + getScrolledSlots();
}
public void calculatePercentScrolled() {
int barempty = height - getScrollBarHeight();
if (scrollclicky >= 0) {
int scrolldiff = scrollmousey - scrollclicky;
percentscrolled = scrolldiff / (float) barempty + scrollpercent;
}
if (percentscrolled < 0) {
percentscrolled = 0;
}
if (percentscrolled > 1) {
percentscrolled = 1;
}
int sbary = rely + (int) (barempty * percentscrolled + 0.5);
percentscrolled = (sbary - rely) / (float) barempty;
}
public boolean clickScrollBar(int mousex, int mousey, int button) {
mousex -= parentscreen.guiLeft;
mousey -= parentscreen.guiTop;
int barempty = height - getScrollBarHeight();
int sbary = rely + (int) (barempty * percentscrolled + 0.5);
if (button == 0 &&
getScrollBarHeight() < height && //the scroll bar can move (not full length)
mousex >= relx + cwidth && mousex < relx + cwidth + getScrollBarWidth() &&
mousey >= rely && mousey < rely + height)//in the scroll pane
{
if (mousey < sbary) {
percentscrolled = (mousey - rely) / (float) barempty;
calculatePercentScrolled();
} else if (mousey > sbary + getScrollBarHeight()) {
percentscrolled = (mousey - rely - getScrollBarHeight() + 1) / (float) barempty;
calculatePercentScrolled();
} else {
scrollclicky = mousey;
scrollpercent = percentscrolled;
scrollmousey = mousey;
}
return true;
}
return false;
}
public void mouseUp(int mousex, int mousey, int button) {
if (scrollclicky >= 0 && button == 0)//we were scrolling and we released mouse
{
scrollclicky = -1;
}
}
public boolean clickButton(int mousex, int mousey, int button) {
mousex -= parentscreen.guiLeft;
mousey -= parentscreen.guiTop;
if (mousex >= relx && mousex < relx + cwidth &&
mousey >= rely && mousey <= rely + height)//in the box
{
int slot = getClickedSlot(mousey);
if (slot >= getNumSlots()) return false;
toggleSlotEnchantment(slot);
return true;
}
return false;
}
private void toggleSlotEnchantment(int slot) {
EnchantmentHash e = slotEnchantment.get(slot);
if (e.state == 2) {
NEICPH.sendModifyEnchantment(e.enchantment.effectId, 0, false);
e.state = 0;
} else if (e.state == 1) {
return;
} else {
NEICPH.sendModifyEnchantment(e.enchantment.effectId, level, true);
e.state = 2;
}
updateEnchantmentOptions(GuiEnchantmentModifier.validateEnchantments());
}
public boolean addEnchantment(int e, int level) {
if (e < Enchantment.enchantmentsList.length && Enchantment.enchantmentsList[e] != null) {
((Slot) inventorySlots.get(0)).getStack().addEnchantment(Enchantment.enchantmentsList[e], level);
return true;
}
return false;
}
public void removeEnchantment(int e) {
ItemStack stack = ((Slot) inventorySlots.get(0)).getStack();
NBTTagList nbttaglist = stack.getEnchantmentTagList();
if (nbttaglist != null) {
for (int i = 0; i < nbttaglist.tagCount(); i++) {
int ID = nbttaglist.getCompoundTagAt(i).getShort("id");
if (ID == e) {
nbttaglist.removeTag(i);
if (nbttaglist.tagCount() == 0)
stack.getTagCompound().removeTag("ench");
if (stack.getTagCompound().hasNoTags())
stack.setTagCompound(null);
return;
}
}
}
}
public boolean canInteractWith(EntityPlayer entityplayer) {
return true;
}
public void onCraftMatrixChanged(IInventory iinventory) {
if (parentscreen != null)
updateEnchantmentOptions(GuiEnchantmentModifier.validateEnchantments());
}
public void updateEnchantmentOptions(boolean validate) {
int numoptions = slotEnchantment.size();
slotEnchantment.clear();
ItemStack toolstack = getSlot(0).getStack();
if (toolstack == null) {
percentscrolled = 0;
return;
}
Item item = toolstack.getItem();
int enchantablity = item.getItemEnchantability();
if (enchantablity == 0 && validate) {
percentscrolled = 0;
return;
}
for (Enchantment e : Enchantment.enchantmentsList) {
if (e == null || e.type == null || (!e.type.canEnchantItem(item) && validate)) {
continue;
}
int state = 0;
int level = -1;
if (NEIServerUtils.stackHasEnchantment(toolstack, e.effectId)) {
state = 2;
level = NEIServerUtils.getEnchantmentLevel(toolstack, e.effectId);
} else if (NEIServerUtils.doesEnchantmentConflict(NEIServerUtils.getEnchantments(toolstack), e) && validate) {
state = 1;
}
slotEnchantment.add(new EnchantmentHash(e, state, level));
}
if (numoptions != slotEnchantment.size()) {
percentscrolled = 0;
}
}
public void drawSlots(GuiEnchantmentModifier gui) {
for (int slot = 0; slot < 3; slot++) {
int shade = 0;
String text = "";
int containerslot = slot + getScrolledSlots();
if (containerslot + 1 > slotEnchantment.size()) {
shade = 1;
} else {
EnchantmentHash e = slotEnchantment.get(containerslot);
shade = e.state;
text = e.enchantment.getTranslatedName(e.level == -1 ? level : e.level);
if (gui.mc.fontRenderer.getStringWidth(text) > 95 && text.contains("Projectile")) {
text = text.replace("Projectile", "Proj");
}
if (gui.mc.fontRenderer.getStringWidth(text) > 95 && text.contains("Protection")) {
text = text.replace("Protection", "Protect");
}
if (gui.mc.fontRenderer.getStringWidth(text) > 95 && text.contains("Bane of")) {
text = text.replace("Bane of ", "");
}
}
CCRenderState.changeTexture("textures/gui/container/enchanting_table.png");
GL11.glColor3f(1, 1, 1);
if (hasScrollBar()) {
gui.drawTexturedModalRect(relx, rely + slot * slotheight, 0, gui.ySize + slotheight * shade, cwidth - 30, slotheight);
gui.drawTexturedModalRect(relx + cwidth - 30, rely + slot * slotheight, cwidth - 23, gui.ySize + slotheight * shade, 30, slotheight);
} else {
gui.drawTexturedModalRect(relx, rely + slot * slotheight, 0, gui.ySize + slotheight * shade, cwidth + 7, slotheight);
}
gui.getFontRenderer().drawString(text, relx + 4, rely + slot * slotheight + 5, textColourFromState(shade));
}
}
private boolean hasScrollBar() {
return getNumSlots() > 3;
}
public void drawScrollBar(GuiEnchantmentModifier gui) {
if (!hasScrollBar()) return;
int sbary = rely + (int) ((height - getScrollBarHeight()) * percentscrolled + 0.5);
int sbarx = relx + cwidth;
Gui.drawRect(sbarx, rely, sbarx + getScrollBarWidth(), rely + height, 0xFF202020);//background
Gui.drawRect(sbarx, sbary, sbarx + getScrollBarWidth(), sbary + getScrollBarHeight(), 0xFF8B8B8B);//corners
Gui.drawRect(sbarx, sbary, sbarx + getScrollBarWidth() - 1, sbary + getScrollBarHeight() - 1, 0xFFF0F0F0);//topleft up
Gui.drawRect(sbarx + 1, sbary + 1, sbarx + getScrollBarWidth() - 1, sbary + getScrollBarHeight() - 1, 0xFF555555);//bottom right down
Gui.drawRect(sbarx + 1, sbary + 1, sbarx + getScrollBarWidth() - 2, sbary + getScrollBarHeight() - 2, 0xFFC6C6C6);//scrollbar
}
private int textColourFromState(int shade) {
switch(shade) {
case 0: return 0x685e4a;
case 1: return 0x407f10;
default: return 0xffff80;
}
}
public void onUpdate(int mousex, int mousey) {
processScrollMouse(mousey);
}
public void processScrollMouse(int mousey) {
mousey -= parentscreen.guiTop;
if (scrollclicky >= 0) {
int scrolldiff = mousey - scrollclicky;
int barupallowed = (int) ((height - getScrollBarHeight()) * scrollpercent + 0.5);
int bardownallowed = (height - getScrollBarHeight()) - barupallowed;
if (-scrolldiff > barupallowed) {
scrollmousey = scrollclicky - barupallowed;
} else if (scrolldiff > bardownallowed) {
scrollmousey = scrollclicky + bardownallowed;
} else {
scrollmousey = mousey;
}
calculatePercentScrolled();
}
}
}
@@ -0,0 +1,162 @@
package codechicken.nei;
import codechicken.core.inventory.ContainerExtended;
import codechicken.core.inventory.SlotHandleClicks;
import codechicken.lib.inventory.InventoryNBT;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.lib.packet.PacketCustom;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.PotionEffect;
public class ContainerPotionCreator extends ContainerExtended
{
public class SlotPotion extends Slot
{
public SlotPotion(IInventory inv, int slotIndex, int x, int y) {
super(inv, slotIndex, x, y);
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack.getItem() instanceof ItemPotion;
}
@Override
public void onSlotChanged() {
super.onSlotChanged();
if (getHasStack()) {
ItemStack stack = getStack();
if (!stack.hasTagCompound())
stack.setTagCompound(new NBTTagCompound());
if (!stack.getTagCompound().hasKey("CustomPotionEffects"))
stack.getTagCompound().setTag("CustomPotionEffects", new NBTTagList());
}
}
}
public class SlotPotionStore extends SlotHandleClicks
{
public SlotPotionStore(IInventory inv, int slotIndex, int x, int y) {
super(inv, slotIndex, x, y);
}
@Override
public ItemStack slotClick(ContainerExtended container, EntityPlayer player, int button, int modifier) {
ItemStack held = player.inventory.getItemStack();
if (button == 0 && modifier == 1) {
NEIClientUtils.cheatItem(getStack(), button, -1);
} else if (button == 1) {
putStack(null);
} else if (held != null) {
if (isItemValid(held)) {
putStack(InventoryUtils.copyStack(held, 1));
player.inventory.setItemStack(null);
}
} else if (getHasStack())
player.inventory.setItemStack(getStack());
return null;
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack.getItem() instanceof ItemPotion;
}
}
public static class InventoryPotionStore extends InventoryNBT
{
public InventoryPotionStore() {
super(9, NEIClientConfig.global.nbt.getCompoundTag("potionStore"));
}
@Override
public void markDirty() {
super.markDirty();
NEIClientConfig.global.nbt.setTag("potionStore", tag);
NEIClientConfig.global.saveNBT();
}
}
InventoryPlayer playerInv;
InventoryBasic potionInv;
IInventory potionStoreInv;
public ContainerPotionCreator(InventoryPlayer inventoryPlayer, IInventory potionStoreInv) {
playerInv = inventoryPlayer;
potionInv = new InventoryBasic("Potion", true, 1);
this.potionStoreInv = potionStoreInv;
addSlotToContainer(new SlotPotion(potionInv, 0, 25, 102));
for (int i = 0; i < 9; i++)
addSlotToContainer(new SlotPotionStore(potionStoreInv, i, 8 + i * 18, 14));
bindPlayerInventory(inventoryPlayer, 8, 125);
}
@Override
public boolean doMergeStackAreas(int slotIndex, ItemStack stack) {
if (slotIndex < 10)
return mergeItemStack(stack, 10, 46, true);
return mergeItemStack(stack, 0, 1, false);
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return true;
}
@Override
public void onContainerClosed(EntityPlayer player) {
super.onContainerClosed(player);
if (!player.worldObj.isRemote)
InventoryUtils.dropOnClose(player, potionInv);
}
@SuppressWarnings("unchecked")
@Override
public void handleInputPacket(PacketCustom packet) {
ItemStack potion = potionInv.getStackInSlot(0);
if (potion == null)
return;
boolean add = packet.readBoolean();
int effectID = packet.readUByte();
NBTTagList effects = potion.getTagCompound().getTagList("CustomPotionEffects", 10);
NBTTagList newEffects = new NBTTagList();
for(int i = 0; i < effects.tagCount(); i++) {
NBTTagCompound tag = effects.getCompoundTagAt(i);
PotionEffect e = PotionEffect.readCustomPotionEffectFromNBT(tag);
if(e.getPotionID() != effectID)
newEffects.appendTag(tag);
}
if(add)
newEffects.appendTag(new PotionEffect(effectID, packet.readInt(), packet.readUByte()).writeCustomPotionEffectToNBT(new NBTTagCompound()));
potion.getTagCompound().setTag("CustomPotionEffects", newEffects);
}
public void setPotionEffect(int effectID, int duration, int amplifier) {
PacketCustom packet = NEICPH.createContainerPacket();
packet.writeBoolean(true);
packet.writeByte(effectID);
packet.writeInt(duration);
packet.writeByte(amplifier);
packet.sendToServer();
}
public void removePotionEffect(int effectID) {
PacketCustom packet = NEICPH.createContainerPacket();
packet.writeBoolean(false);
packet.writeByte(effectID);
packet.sendToServer();
}
}
@@ -0,0 +1,50 @@
package codechicken.nei;
import codechicken.nei.api.IHighlightHandler;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import java.util.List;
public class DefaultHighlightHandler implements IHighlightHandler
{
@Override
public List<String> handleTextData(ItemStack stack, World world, EntityPlayer player, MovingObjectPosition mop, List<String> currenttip, ItemInfo.Layout layout)
{
String name = null;
try
{
String s = GuiContainerManager.itemDisplayNameShort(stack);
if(s != null && !s.endsWith("Unnamed"))
name = s;
if(name != null)
currenttip.add(name);
}
catch(Exception e)
{
}
if(stack.getItem() == Items.redstone)
{
int md = world.getBlockMetadata(mop.blockX, mop.blockY, mop.blockZ);
String s = ""+md;
if(s.length() < 2)
s=" "+s;
currenttip.set(currenttip.size()-1, name+" "+s);
}
return currenttip;
}
@Override
public ItemStack identifyHighlight(World world, EntityPlayer player, MovingObjectPosition mop)
{
return null;
}
}
@@ -0,0 +1,109 @@
package codechicken.nei;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class ExtendedCreativeInv implements IInventory
{
PlayerSave playerSave;
Side side;
public ExtendedCreativeInv(PlayerSave playerSave, Side side) {
this.playerSave = playerSave;
this.side = side;
}
@Override
public int getSizeInventory() {
return 54;
}
@Override
public ItemStack getStackInSlot(int slot) {
if (side.isClient())
return NEIClientConfig.creativeInv[slot];
return playerSave.creativeInv[slot];
}
@Override
public ItemStack decrStackSize(int slot, int size) {
ItemStack item = getStackInSlot(slot);
if (item != null) {
if (item.stackSize <= size) {
ItemStack itemstack = item;
setInventorySlotContents(slot, null);
markDirty();
return itemstack;
}
ItemStack itemstack1 = item.splitStack(size);
if (item.stackSize == 0) {
setInventorySlotContents(slot, null);
}
markDirty();
return itemstack1;
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
synchronized (this) {
ItemStack stack = getStackInSlot(slot);
setInventorySlotContents(slot, null);
return stack;
}
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
if (side.isClient())
NEIClientConfig.creativeInv[slot] = stack;
else
playerSave.creativeInv[slot] = stack;
markDirty();
}
@Override
public String getInventoryName() {
return "Extended Creative";
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public void markDirty() {
if (side.isServer())
playerSave.setCreativeDirty();
}
@Override
public boolean isUseableByPlayer(EntityPlayer var1) {
return true;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return true;
}
@Override
public boolean hasCustomInventoryName() {
return true;
}
}
@@ -0,0 +1,338 @@
package codechicken.nei;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import java.util.*;
import static codechicken.nei.NEIServerUtils.*;
public class FastTransferManager
{
/**
* Based on the general assumption that we want to fill top to bottom, left to right
*/
public static class SlotPositionComparator implements Comparator<Integer>
{
Container container;
public SlotPositionComparator(Container c) {
container = c;
}
@Override
public int compare(Integer arg0, Integer arg1) {
Slot slot1 = container.getSlot(arg0);
Slot slot2 = container.getSlot(arg1);
if (slot2.yDisplayPosition != slot1.yDisplayPosition)
return slot1.yDisplayPosition - slot2.yDisplayPosition;
return slot1.xDisplayPosition - slot2.xDisplayPosition;
}
}
public LinkedList<LinkedList<Integer>> slotZones = new LinkedList<LinkedList<Integer>>();
public HashMap<Integer, Integer> slotZoneMap = new HashMap<Integer, Integer>();
private void generateSlotMap(Container container, ItemStack stack) {
stack = stack.copy();
stack.stackSize = 1;
for (int slotNo = 0; slotNo < container.inventorySlots.size(); slotNo++) {
if (slotZoneMap.containsKey(slotNo) || !container.getSlot(slotNo).isItemValid(stack))
continue;
HashSet<Integer> connectedSlots = new HashSet<Integer>();
findConnectedSlots(container, slotNo, connectedSlots);
LinkedList<Integer> zoneSlots = new LinkedList<Integer>(connectedSlots);
Collections.sort(zoneSlots, new SlotPositionComparator(container));
slotZones.add(zoneSlots);
for (int i : zoneSlots) {
slotZoneMap.put(i, slotZones.size() - 1);
}
}
}
private void findConnectedSlots(Container container, int slotNo, HashSet<Integer> connectedSlots) {
connectedSlots.add(slotNo);
Slot slot = container.getSlot(slotNo);
final int threshold = 18;
for (int i = 0; i < container.inventorySlots.size(); i++) {
if (connectedSlots.contains(i))
continue;
Slot slot1 = container.getSlot(i);
if (Math.abs(slot.xDisplayPosition - slot1.xDisplayPosition) <= threshold && Math.abs(slot.yDisplayPosition - slot1.yDisplayPosition) <= threshold) {
findConnectedSlots(container, i, connectedSlots);
}
}
}
public static int findSlotWithItem(Container container, ItemStack teststack) {
for (int slotNo = 0; slotNo < container.inventorySlots.size(); slotNo++) {
ItemStack stack = container.getSlot(slotNo).getStack();
if (stack != null && areStacksSameType(stack, teststack))
return slotNo;
}
return -1;
}
public static void clearSlots(Container container) {
for (int slotNo = 0; slotNo < container.inventorySlots.size(); slotNo++)
((Slot) container.inventorySlots.get(slotNo)).putStack(null);
}
public void performMassTransfer(GuiContainer window, int fromSlot, int toSlot, ItemStack heldStack) {
generateSlotMap(window.inventorySlots, heldStack);
Integer fromZone = slotZoneMap.get(fromSlot);
Integer toZone = slotZoneMap.get(toSlot);
if (fromZone == null || toZone == null || fromZone == toZone)
return;
if (NEIClientUtils.getHeldItem() != null && !areStacksSameType(heldStack, NEIClientUtils.getHeldItem()))
return;
if (!fillZoneWithHeldItem(window, toZone))
return;
for (int transferFrom : slotZones.get(fromZone)) {
ItemStack transferStack = window.inventorySlots.getSlot(transferFrom).getStack();
if (!areStacksSameType(heldStack, transferStack))
continue;
clickSlot(window, transferFrom);
if (!fillZoneWithHeldItem(window, toZone)) {
clickSlot(window, transferFrom);
return;
}
}
}
/**
* @return The slot that one item from the source slot will end up in apon shift clicking, -1 if none.
*/
public int findShiftClickDestinationSlot(Container container, int fromSlot) {
LinkedList<ItemStack> save = saveContainer(container);
Slot slot = container.getSlot(fromSlot);
ItemStack stack = slot.getStack();
if (stack == null)
return -1;
stack.stackSize = 1;
slot.putStack(stack.copy());
LinkedList<ItemStack> compareBefore = saveContainer(container);
container.slotClick(fromSlot, 0, 1, NEIClientUtils.mc().thePlayer);
LinkedList<ItemStack> compareAfter = saveContainer(container);
try {
//if(compareAfter.get(fromSlot) != null)//transfer failed
//return -1;
for (int i = 0; i < compareBefore.size(); i++) {
if (i == fromSlot)
continue;
ItemStack before = compareBefore.get(i);
ItemStack after = compareAfter.get(i);
if (!areStacksIdentical(before, after) && after != null) {
if ((before == null && areStacksSameType(stack, after)) ||//transfered into this empty slot
(areStacksSameType(stack, after) &&
after.stackSize -
before.stackSize > 0))//it added to this stack
return i;
}
}
return -1;
} finally {
restoreContainer(container, save);
}
}
public LinkedList<ItemStack> saveContainer(Container container) {
LinkedList<ItemStack> stacks = new LinkedList<ItemStack>();
for (int i = 0; i < container.inventorySlots.size(); i++)
stacks.add(copyStack(container.getSlot(i).getStack()));
return stacks;
}
public void restoreContainer(Container container, LinkedList<ItemStack> items) {
for (int i = 0; i < container.inventorySlots.size(); i++) {
container.getSlot(i).putStack(items.get(i));
}
container.slotClick(-999, 0, 0, NEIClientUtils.mc().thePlayer);
}
public void transferItem(GuiContainer window, int fromSlot) {
int toSlot = findShiftClickDestinationSlot(window.inventorySlots, fromSlot);
if (toSlot == -1)
return;
Slot from = window.inventorySlots.getSlot(fromSlot);
if (from.isItemValid(from.getStack()))
moveOneItem(window, fromSlot, toSlot);
else//slots that you can't put stuff in
moveOutputSet(window, fromSlot, toSlot);
}
public void moveOutputSet(GuiContainer window, int fromSlot, int toSlot) {
if (NEIClientUtils.getHeldItem() != null)
return;
clickSlot(window, fromSlot);//pickup fromSlot
if (NEIClientUtils.getHeldItem() == null)//maybe this container does auto transfers. No need to pick up the final item
return;
clickSlot(window, toSlot);//place one in toSlot
}
public void moveOneItem(GuiContainer window, int fromSlot, int toSlot) {
clickSlot(window, fromSlot);//pickup fromSlot
clickSlot(window, toSlot, 1);//place one in toSlot
clickSlot(window, fromSlot);//place down in fromSlot
}
public void retrieveItem(GuiContainer window, int toSlot) {
Slot slot = window.inventorySlots.getSlot(toSlot);
ItemStack slotStack = slot.getStack();
if (slotStack == null ||
slotStack.stackSize == slot.getSlotStackLimit() ||
slotStack.stackSize == slotStack.getMaxStackSize())
return;
generateSlotMap(window.inventorySlots, slotStack);
Integer destZone = slotZoneMap.get(toSlot);
if (destZone == null)//slots that don't accept
return;
int firstZoneSlot = findShiftClickDestinationSlot(window.inventorySlots, toSlot);
int firstZone = -1;
if (firstZoneSlot != -1) {
Integer integer = slotZoneMap.get(firstZoneSlot);
if (integer != null) {
firstZone = integer;
if (retrieveItemFromZone(window, firstZone, toSlot))
return;
}
}
for (int zone = 0; zone < slotZones.size(); zone++) {
if (zone == destZone || zone == firstZone)
continue;
if (retrieveItemFromZone(window, zone, toSlot))
return;
}
retrieveItemFromZone(window, destZone, toSlot);
}
private boolean retrieveItemFromZone(GuiContainer window, int zone, int toSlot) {
ItemStack stack = window.inventorySlots.getSlot(toSlot).getStack();
for (int i : slotZones.get(zone)) {
if (i == toSlot)
continue;
Slot slot = window.inventorySlots.getSlot(i);
ItemStack stack1 = slot.getStack();
if (areStacksSameType(stack, stack1) &&
stack1.stackSize != slot.getSlotStackLimit() && //get from full stacks on second pass
stack1.stackSize != stack1.getMaxStackSize()) {
moveOneItem(window, i, toSlot);
return true;
}
}
for (int i : slotZones.get(zone)) {
if (i == toSlot)
continue;
Slot slot = window.inventorySlots.getSlot(i);
ItemStack stack1 = slot.getStack();
if (areStacksSameType(stack, stack1)) {
moveOneItem(window, i, toSlot);
return true;
}
}
return false;
}
public static void clickSlot(GuiContainer window, int slotIndex) {
clickSlot(window, slotIndex, 0);
}
public static void clickSlot(GuiContainer window, int slotIndex, int button) {
clickSlot(window, slotIndex, button, 0);
}
public static void clickSlot(GuiContainer window, int slotIndex, int button, int modifier) {
GuiContainerManager.getManager(window).handleSlotClick(slotIndex, button, modifier);
}
private boolean fillZoneWithHeldItem(GuiContainer window, int zoneIndex) {
for (int transferTo : slotZones.get(zoneIndex)) {
ItemStack held = NEIClientUtils.getHeldItem();
if (held == null)
break;
ItemStack inToSlot = window.inventorySlots.getSlot(transferTo).getStack();
if (!areStacksSameType(inToSlot, held))
continue;
clickSlot(window, transferTo);
}
for (int transferTo : slotZones.get(zoneIndex))//repeat on empty slots
{
ItemStack held = NEIClientUtils.getHeldItem();
if (held == null)
break;
ItemStack inToSlot = window.inventorySlots.getSlot(transferTo).getStack();
if (inToSlot != null)
continue;
clickSlot(window, transferTo);
}
return NEIClientUtils.getHeldItem() == null;
}
public void throwAll(GuiContainer window, int pickedUpFromSlot) {
ItemStack held = NEIClientUtils.getHeldItem();
if (held == null)
return;
clickSlot(window, -999);
generateSlotMap(window.inventorySlots, held);
for (int slotIndex : slotZones.get(slotZoneMap.get(pickedUpFromSlot))) {
Slot slot = window.inventorySlots.getSlot(slotIndex);
if (areStacksSameType(held, slot.getStack())) {
clickSlot(window, slotIndex);
clickSlot(window, -999);
}
}
}
}
@@ -0,0 +1,99 @@
package codechicken.nei;
import codechicken.lib.render.CCRenderState;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import static codechicken.nei.NEIClientUtils.translate;
public class GuiEnchantmentModifier extends GuiContainer
{
ContainerEnchantmentModifier container;
public GuiEnchantmentModifier(InventoryPlayer inventoryplayer, World world, int i, int j, int k) {
super(new ContainerEnchantmentModifier(inventoryplayer, world, i, j, k));
container = (ContainerEnchantmentModifier) inventorySlots;
container.parentscreen = this;
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
fontRendererObj.drawString(translate("enchant"), 12, 6, 0x404040);
fontRendererObj.drawString(translate("enchant.level"), 19, 20, 0x404040);
}
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
GL11.glColor4f(1, 1, 1, 1);
CCRenderState.changeTexture("textures/gui/container/enchanting_table.png");
GL11.glTranslatef(guiLeft, guiTop, 0);
drawTexturedModalRect(0, 0, 0, 0, xSize, ySize);
container.onUpdate(i, j);
container.drawSlots(this);
container.drawScrollBar(this);
String levelstring = "" + container.level;
fontRendererObj.drawString(levelstring, 33 - fontRendererObj.getStringWidth(levelstring) / 2, 34, 0xFF606060);
GL11.glTranslatef(-guiLeft, -guiTop, 0);
}
public void initGui() {
super.initGui();
buttonList.add(new GuiNEIButton(0, width / 2 - 78, height / 2 - 52, 12, 12, "<"));
buttonList.add(new GuiNEIButton(1, width / 2 - 44, height / 2 - 52, 12, 12, ">"));
buttonList.add(new GuiNEIButton(2, width / 2 - 80, height / 2 - 15, 50, 12, lockDisplayString()));
}
private String lockDisplayString() {
return validateEnchantments() ? translate("enchant.locked") : translate("enchant.unlocked");
}
public static boolean validateEnchantments() {
return NEIClientConfig.world.nbt.getBoolean("validateenchantments");
}
public static void toggleEnchantmentValidation() {
NEIClientConfig.world.nbt.setBoolean("validateenchantments", !validateEnchantments());
NEIClientConfig.world.saveNBT();
}
protected void actionPerformed(GuiButton guibutton) {
if (guibutton.id == 0) {
changeLevel(-1);
} else if (guibutton.id == 1) {
changeLevel(1);
} else if (guibutton.id == 2) {
toggleEnchantmentValidation();
container.updateEnchantmentOptions(validateEnchantments());
guibutton.displayString = lockDisplayString();
}
}
private void changeLevel(int i) {
container.level += i;
((GuiButton) buttonList.get(0)).enabled = container.level != 1;
((GuiButton) buttonList.get(1)).enabled = container.level != 10;
}
protected void mouseClicked(int i, int j, int k) {
if (container.clickButton(i, j, k)) return;
if (container.clickScrollBar(i, j, k)) return;
super.mouseClicked(i, j, k);
}
protected void mouseMovedOrUp(int i, int j, int k) {
container.mouseUp(i, j, k);
super.mouseMovedOrUp(i, j, k);
}
public FontRenderer getFontRenderer() {
return fontRendererObj;
}
}
@@ -0,0 +1,56 @@
package codechicken.nei;
import codechicken.lib.render.CCRenderState;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import java.util.Arrays;
import java.util.List;
public class GuiExtendedCreativeInv extends GuiContainer implements INEIGuiHandler
{
public GuiExtendedCreativeInv(Container par1Container) {
super(par1Container);
ySize = 198;
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
GL11.glColor4f(1, 1, 1, 1);
CCRenderState.changeTexture("nei:textures/gui/inv.png");
int x = guiLeft;
int y = guiTop - 4;
drawTexturedModalRect(x - 23, y, 0, 0, 199, 204);
}
@Override
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
return currentVisibility;
}
@Override
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
return NEIServerUtils.getRange(0, 54);
}
@Override
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
return Arrays.asList(new TaggedInventoryArea("ExtendedCreativeInv", 0, 54, inventorySlots));
}
@Override
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) {
return false;
}
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
return false;
}
}
+41
View File
@@ -0,0 +1,41 @@
package codechicken.nei;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
public class GuiNEIButton extends GuiButton
{
protected static ResourceLocation guiTex = new ResourceLocation("textures/gui/widgets.png");
public GuiNEIButton(int i, int j, int k, int l, int i1, String s)
{
super(i, j, k, l, i1, s);
}
public void drawButton(Minecraft minecraft, int i, int j)
{
if(!visible)
return;
FontRenderer fontrenderer = minecraft.fontRenderer;
minecraft.renderEngine.bindTexture(guiTex);
GL11.glColor4f(1, 1, 1, 1);
boolean flag = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height;
int k = getHoverState(flag);
drawTexturedModalRect(xPosition, yPosition, 0, 46 + k * 20, width / 2, height / 2);//top left
drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 46 + k * 20, width / 2, height / 2);//top right
drawTexturedModalRect(xPosition, yPosition + height / 2, 0, 46 + k * 20 + 20 - height / 2, width / 2, height / 2);//bottom left
drawTexturedModalRect(xPosition + width / 2, yPosition + height / 2, 200 - width / 2, 46 + k * 20 + 20 - height / 2, width / 2, height / 2);//bottom right
mouseDragged(minecraft, i, j);
if(!enabled)
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffa0a0a0);
else if(flag)
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffffa0);
else
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xe0e0e0);
}
}
+330
View File
@@ -0,0 +1,330 @@
package codechicken.nei;
import codechicken.core.gui.GuiCCButton;
import codechicken.core.gui.GuiCCTextField;
import codechicken.core.gui.GuiScrollSlot;
import codechicken.core.inventory.GuiContainerWidget;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.FontUtils;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
public class GuiPotionCreator extends GuiContainerWidget
{
public class GuiSlotPotionEffects extends GuiScrollSlot
{
public int selectedslot = -1;
public boolean enabled = true;
private ArrayList<Potion> validPotions = new ArrayList<Potion>();
public GuiSlotPotionEffects(int x, int y) {
super(x, y, 108, 76);
for (Potion p : Potion.potionTypes)
if (p != null)
validPotions.add(p);
setSmoothScroll(false);
setContentSize(x, y, height);
}
@Override
public int getSlotHeight() {
return 19;
}
@Override
public void drawSlotBox(float frame) {
drawRect(x, y, x + width, y + height, 0xFF000000);
}
@Override
public void drawOverlay(float frame) {
}
@Override
public boolean drawLineGuide() {
return false;
}
@Override
public int getScrollBarWidth() {
return 7;
}
@Override
protected void drawSlot(int slot, int x, int y, int mx, int my, boolean selected, float frame) {
GL11.glColor4f(1, 1, 1, 1);
Potion potion = validPotions.get(slot);
PotionEffect effect = getEffect(potion.id);
boolean blank = effect == null;
if (effect == null)
effect = new PotionEffect(potion.id, 1200, 0);
int shade = selectedslot == slot ? 2 : blank ? 1 : 0;
CCRenderState.changeTexture("textures/gui/container/enchanting_table.png");
drawTexturedModalRect(x, y, 0, 166 + getSlotHeight() * shade, width - 30, getSlotHeight());
drawTexturedModalRect(x + width - 30, y, width - 23, 166 + getSlotHeight() * shade, 30, getSlotHeight());
if (potion.hasStatusIcon()) {
CCRenderState.changeTexture("textures/gui/container/inventory.png");
int icon = potion.getStatusIconIndex();
drawTexturedModalRect(x + 1, y + 1, 0 + icon % 8 * 18, 198 + icon / 8 * 18, 18, 18);
}
String name = StatCollector.translateToLocal(potion.getName());
String amp = effect.getAmplifier() > 0 ? " " + translateAmplifier(effect.getAmplifier()) : "";
int textColour = shade == 0 ? 0x685e4a : shade == 1 ? 0x407f10 : 0xffff80;
if (fontRenderer.getStringWidth(name + amp) < width - 20) {
fontRenderer.drawString(name + amp, x + 20, y + 1, textColour);
} else {
fontRenderer.drawString(name, x + 20, y + 1, textColour);
FontUtils.drawRightString(amp, x + width - 10, y + 10, textColour);
}
String duration = Potion.getDurationString(effect);
textColour = shade == 0 ? 0xA0A0A0 : shade == 1 ? 0x808080 : 0xCCCCCC;
fontRenderer.drawStringWithShadow(duration, x + 20, y + 10, textColour);
}
private PotionEffect getEffect(int id) {
ItemStack potion = container.potionInv.getStackInSlot(0);
if (potion != null && potion.hasTagCompound() && potion.getTagCompound().hasKey("CustomPotionEffects")) {
NBTTagList potionTagList = potion.getTagCompound().getTagList("CustomPotionEffects", 10);
for (int i = 0; i < potionTagList.tagCount(); i++) {
PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT(potionTagList.getCompoundTagAt(i));
if (effect.getPotionID() == id)
return effect;
}
}
return null;
}
@Override
protected int getNumSlots() {
return validPotions.size();
}
@Override
protected boolean isSlotSelected(int slot) {
return slot == selectedslot;
}
@Override
protected void slotClicked(int slot, int button, int mx, int my, boolean doubleclick) {
if (!enabled)
return;
if (button == 0) {
select(slot);
applyEffect();
} else if (button == 1) {
deselect();
container.removePotionEffect(validPotions.get(slot).id);
}
}
public void selectNext() {
if (selectedslot >= 0 && selectedslot + 1 < getNumSlots()) {
select(selectedslot + 1);
showSlot(selectedslot);
}
}
public void selectPrev() {
if (selectedslot > 0) {
select(selectedslot - 1);
showSlot(selectedslot);
}
}
public void setEnabled(boolean b) {
if (b == enabled)
return;
enabled = b;
if (!enabled)
deselect();
}
private void select(int slot) {
selectedslot = slot;
durationField.setEnabled(true);
PotionEffect effect = getEffect(validPotions.get(slot).id);
if (effect == null)
effect = new PotionEffect(validPotions.get(slot).id, 1200, 0);
durationField.setDurationTicks(effect.getDuration());
amplifier = effect.getAmplifier();
validateInputButtons();
}
private void deselect() {
selectedslot = -1;
durationField.setEnabled(false);
ampDown.setEnabled(false);
ampUp.setEnabled(false);
}
public int selectedPotion() {
return validPotions.get(selectedslot).id;
}
}
public class GuiDurationField extends GuiCCTextField
{
private String baseValue;
public GuiDurationField(int x, int y, int width, int height) {
super(x, y, width, height, "100");
setMaxStringLength(4);
setAllowedCharacters("0123456789");
baseValue = getText();
}
public void setDurationTicks(int i) {
i /= 20;
String minutes = Integer.toString(i / 60);
String seconds = Integer.toString(i % 60);
if (seconds.length() == 1)
seconds = '0' + seconds;
setText(minutes + seconds);
}
@Override
public void setEnabled(boolean b) {
super.setEnabled(b);
if (!isEnabled())
setText("100");
}
@Override
public void onFocusChanged() {
if (isFocused())
baseValue = getText();
else {
if (!validateValue())
setText(baseValue);
else
applyEffect();
}
}
@Override
public void onTextChanged(String oldText) {
validateInputButtons();
}
private boolean validateValue() {
try {
int i = Integer.parseInt(getText());
return i > 1 && getDurationTicks() < Short.MAX_VALUE && i / 100 <= 60 && i % 100 < 60;
} catch (NumberFormatException nfe) {
return false;
}
}
@Override
public void drawText() {
String s = getText();
String seconds = s.substring(Math.max(0, s.length() - 2), Math.max(0, s.length() - 2) + Math.min(s.length(), 2));
String minutes = s.length() < 3 ? "" : s.substring(0, s.length() - 2);
int ty = y + height / 2 - 4;
int tcolour = getTextColour();
FontUtils.drawCenteredString(":", x + width / 2 + 1, ty, tcolour);
FontUtils.drawRightString(seconds, x + width - 3, ty, tcolour);
FontUtils.drawRightString(minutes, x + width / 2 - 1, ty, tcolour);
}
@Override
public int getTextColour() {
return isFocused() ? 0xCCCCCC : 0x909090;
}
public int getDurationTicks() {
int i = Integer.parseInt(getText());
return ((i / 100) * 60 + (i % 100)) * 20;
}
}
int amplifier = 0;
GuiCCButton ampDown;
GuiCCButton ampUp;
GuiSlotPotionEffects slotPotionEffects;
GuiDurationField durationField;
ContainerPotionCreator container;
public GuiPotionCreator(InventoryPlayer inventoryplayer) {
super(new ContainerPotionCreator(inventoryplayer, new ContainerPotionCreator.InventoryPotionStore()), 176, 208);
container = (ContainerPotionCreator) inventorySlots;
}
public void applyEffect() {
if (slotPotionEffects.selectedslot >= 0)
container.setPotionEffect(slotPotionEffects.selectedPotion(), durationField.getDurationTicks(), amplifier);
}
public String translateAmplifier(int amplifier) {
switch (amplifier) {
case 0:
return "I";
case 1:
return "II";
case 2:
return "III";
case 3:
return "IV";
case 4:
return "V";
}
return Integer.toString(amplifier);
}
public void validateInputButtons() {
ampDown.setEnabled(amplifier > 0);
ampUp.setEnabled(amplifier < 3);
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
//fontRenderer.drawString("Potion", 12, 6, 0x404040);
}
@Override
public void drawBackground() {
CCRenderState.changeTexture("nei:textures/gui/potion.png");
drawTexturedModalRect(0, 0, 0, 0, xSize, ySize);
FontUtils.drawCenteredString("Favourite Potions", xSize / 2, 4, 0x404040);
fontRendererObj.drawString("Duration", 12, 40, 0x404040);
fontRendererObj.drawString("Level", 19, 73, 0x404040);
FontUtils.drawCenteredString(translateAmplifier(amplifier), 33, 86, 0xFF606060);
}
@Override
public void addWidgets() {
add(ampDown = new GuiCCButton(10, 84, 12, 12, "<").setActionCommand("ampDown"));
add(ampUp = new GuiCCButton(44, 84, 12, 12, ">").setActionCommand("ampUp"));
add(durationField = new GuiDurationField(15, 53, 35, 12));
add(slotPotionEffects = new GuiSlotPotionEffects(60, 38));
}
@Override
public void updateScreen() {
super.updateScreen();
slotPotionEffects.setEnabled(container.potionInv.getStackInSlot(0) != null);
}
@Override
public void actionPerformed(String ident, Object... params) {
if (ident.equals("ampDown"))
amplifier--;
else if (ident.equals("ampUp"))
amplifier++;
applyEffect();
validateInputButtons();
}
}
+96
View File
@@ -0,0 +1,96 @@
package codechicken.nei;
import codechicken.lib.config.ConfigTag;
import codechicken.nei.KeyManager.IKeyStateTracker;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static codechicken.lib.gui.GuiDraw.*;
public class HUDRenderer implements IKeyStateTracker
{
@Override
public void tickKeyStates() {
if (KeyManager.keyStates.get("world.highlight_tips").down) {
ConfigTag tag = NEIClientConfig.getSetting("world.highlight_tips");
tag.setBooleanValue(!tag.getBooleanValue());
}
}
public static void renderOverlay() {
Minecraft mc = Minecraft.getMinecraft();
if (mc.currentScreen == null &&
mc.theWorld != null &&
!mc.gameSettings.keyBindPlayerList.getIsKeyPressed() &&
NEIClientConfig.getBooleanSetting("world.highlight_tips") &&
mc.objectMouseOver != null &&
mc.objectMouseOver.typeOfHit == MovingObjectType.BLOCK) {
World world = mc.theWorld;
ArrayList<ItemStack> items = ItemInfo.getIdentifierItems(world, mc.thePlayer, mc.objectMouseOver);
if (items.isEmpty())
return;
int minDamage = Integer.MAX_VALUE;
ItemStack stack = null;
for(ItemStack astack : items) {
if(astack.getItem() != null && astack.getItemDamage() < minDamage) {
stack = astack;
minDamage = stack.getItemDamage();
}
}
renderOverlay(stack, ItemInfo.getText(stack, world, mc.thePlayer, mc.objectMouseOver), getPositioning());
}
}
public static void renderOverlay(ItemStack stack, List<String> textData, Point pos) {
int w = 0;
for (String s : textData)
w = Math.max(w, getStringWidth(s) + 29);
int h = Math.max(24, 10 + 10 * textData.size());
Dimension size = displaySize();
int x = (size.width - w - 1) * pos.x / 10000;
int y = (size.height - h - 1) * pos.y / 10000;
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
drawTooltipBox(x, y, w, h);
int ty = (h - 8 * textData.size()) / 2;
for (int i = 0; i < textData.size(); i++)
drawString(textData.get(i), x + 24, y + ty + 10 * i, 0xFFA0A0A0, true);
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
if (stack.getItem() != null)
GuiContainerManager.drawItem(x + 5, y + h / 2 - 8, stack);
}
private static Point getPositioning() {
return new Point(
NEIClientConfig.getSetting("world.highlight_tips.x").getIntValue(),
NEIClientConfig.getSetting("world.highlight_tips.y").getIntValue());
}
public static void load() {
KeyManager.trackers.add(new HUDRenderer());
}
}
+17
View File
@@ -0,0 +1,17 @@
package codechicken.nei;
public class Image
{
public int x;
public int y;
public int width;
public int height;
public Image(int i, int j, int k, int l)
{
x = i;
y = j;
width = k;
height = l;
}
}
@@ -0,0 +1,55 @@
package codechicken.nei;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.nei.api.IInfiniteItemHandler;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public class InfiniteStackSizeHandler implements IInfiniteItemHandler
{
@Override
public void onPickup(ItemStack heldItem)
{
heldItem.stackSize = 1;
}
@Override
public void onPlaceInfinite(ItemStack heldItem)
{
heldItem.stackSize = 111;
}
@Override
public boolean canHandleItem(ItemStack stack)
{
return !stack.isItemStackDamageable();
}
@Override
public boolean isItemInfinite(ItemStack stack)
{
return stack.stackSize == -1 || stack.stackSize > 100;
}
@Override
public void replenishInfiniteStack(InventoryPlayer inv, int slotNo)
{
ItemStack stack = inv.getStackInSlot(slotNo);
stack.stackSize = 111;
for(int i = 0; i < inv.getSizeInventory(); i++)
{
if(i == slotNo)
continue;
if(NEIServerUtils.areStacksSameType(stack, inv.getStackInSlot(i)))
inv.setInventorySlotContents(i, null);
}
}
@Override
public ItemStack getInfiniteItem(ItemStack typeStack)
{
return InventoryUtils.copyStack(typeStack, -1);
}
}
@@ -0,0 +1,38 @@
package codechicken.nei;
import codechicken.nei.api.IInfiniteItemHandler;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public class InfiniteToolHandler implements IInfiniteItemHandler
{
@Override
public void onPickup(ItemStack heldItem) {
heldItem.setItemDamage(0);
}
@Override
public void onPlaceInfinite(ItemStack heldItem) {
heldItem.setItemDamage(-32000);
}
@Override
public void replenishInfiniteStack(InventoryPlayer inv, int slotNo) {
inv.getStackInSlot(slotNo).setItemDamage(-32000);
}
@Override
public boolean canHandleItem(ItemStack stack) {
return stack.getItem().isDamageable() && stack.getMaxStackSize() == 1;
}
@Override
public boolean isItemInfinite(ItemStack stack) {
return stack.getItemDamage() < -30000;
}
@Override
public ItemStack getInfiniteItem(ItemStack typeStack) {
return new ItemStack(typeStack.getItem(), 1, -32000);
}
}
@@ -0,0 +1,20 @@
package codechicken.nei;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
public class InventoryCraftingDummy extends InventoryCrafting
{
public InventoryCraftingDummy()
{
super(new Container()
{
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return true;
}
}, 3, 3);
}
}
+370
View File
@@ -0,0 +1,370 @@
package codechicken.nei;
import codechicken.nei.ItemPanel.ItemPanelObject;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.guihook.GuiContainerManager;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class ItemList
{
public static List<ItemStack> items = new ArrayList<ItemStack>();
public static ListMultimap<Item, ItemStack> itemMap = ArrayListMultimap.create();
private static boolean matching = false;
private static boolean loading = false;
private static boolean research = false;
private static boolean reload = false;
private static HashSet<Item> erroredItems = new HashSet<Item>();
private static interface ItemMatcher
{
public boolean matches(ItemStack item);
}
/*private static class SubsetItemMatcher implements ItemMatcher
{
final List<SubSetRangeTag> tags;
public SubsetItemMatcher(List<SubSetRangeTag> tags)
{
this.tags = tags;
}
@Override
public boolean matches(ItemStack item)
{
for(SubSetRangeTag tag : tags)
if(tag.isItemInRange(item.getItem(), item.getItemDamage()))
return true;
return false;
}
}*/
private static class PatternItemMatcher implements ItemMatcher
{
Pattern pattern;
public PatternItemMatcher(Pattern pattern) {
this.pattern = pattern;
}
@Override
public boolean matches(ItemStack item) {
return pattern.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(GuiContainerManager.concatenatedDisplayName(item, true).toLowerCase())).find();
}
}
private static class EverythingItemMatcher implements ItemMatcher
{
@Override
public boolean matches(ItemStack item) {
return true;
}
}
private static class NothingItemMatcher implements ItemMatcher
{
@Override
public boolean matches(ItemStack item) {
return false;
}
}
public static ItemMatcher getSearchMatcher() {
String matchstring = NEIClientConfig.getSearchExpression().toLowerCase();
/*if(matchstring.startsWith("@") && matchstring.length() > 1)
{
LinkedList<SubSetRangeTag> tags = new LinkedList<SubSetRangeTag>();
try
{
String pattern = matchstring.substring(1);
for(SubSetRangeTag tag : DropDownFile.dropDownInstance.allTags())
if(CommonUtils.filterText(tag.qualifiedname).toLowerCase().contains(pattern))
tags.add(tag);
if(tags.isEmpty())
return new NothingItemMatcher();
return new SubsetItemMatcher(tags);
}
catch(PatternSyntaxException e)
{
return new NothingItemMatcher();
}
}*/
{
matchstring = matchstring.replace(".", "");
matchstring = matchstring.replace("?", ".");
matchstring = matchstring.replace("*", ".+?");
Pattern pattern = null;
try {
pattern = Pattern.compile(matchstring);
} catch (PatternSyntaxException ignored) {}
if (pattern == null || pattern.toString().equals(""))
return new EverythingItemMatcher();
return new PatternItemMatcher(pattern);
}
}
public static boolean itemMatchesSearch(ItemStack item) {
return getSearchMatcher().matches(item);
}
public static interface IItemCounter
{
public Item getItem();
public Thread getThread();
}
@SuppressWarnings("serial")
public static class TimeoutException extends RuntimeException
{
public final Item itemID;
public TimeoutException(String msg, Item lastItem) {
super(msg);
itemID = lastItem;
}
}
public static class ThreadLoadMonitor extends Thread
{
IItemCounter loadingThread;
public ThreadLoadMonitor(IItemCounter handle) {
super("NEI Load Monitor");
loadingThread = handle;
}
@SuppressWarnings("deprecation")
@Override
public void run() {
if(true) return;
Item lastItem = null;
long lastTime = System.currentTimeMillis();
while (loadingThread.getThread().isAlive()) {
if (lastItem != loadingThread.getItem()) {
lastTime = System.currentTimeMillis();
lastItem = loadingThread.getItem();
} else if (System.currentTimeMillis() - lastTime > 2000 && lastItem != null) {
loadingThread.getThread().stop(new TimeoutException("Took to long to advance item", lastItem));
}
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {}
}
}
}
public static class ThreadMatchSearch extends Thread implements IItemCounter
{
private Item item;
public ThreadMatchSearch() {
super("NEI Item Searching Thread");
matching = true;
}
@Override
public Item getItem() {
return item;
}
@Override
public Thread getThread() {
return this;
}
@Override
public void run() {
//new ThreadLoadMonitor(this).start();
try {
startMatch:
while (matching) {
try {
ArrayList<ItemPanelObject> visibleitems = new ArrayList<ItemPanelObject>();
ItemMatcher matcher = getSearchMatcher();
for (ItemStack stack : items) {
item = stack.getItem();
if (research) {
research = false;
continue startMatch;
}
/*if(stack.hasTagCompound() ? NEIClientConfig.vishash.isItemHidden(item, stack.stackTagCompound) : NEIClientConfig.vishash.isItemHidden(item, stack.getItemDamage()))
continue;*/
if (NEIClientConfig.bannedBlocks.contains(stack))
continue;
if (matcher.matches(stack))
visibleitems.add(new ItemPanelStack(stack));
}
ItemPanel.visibleitems = visibleitems;
} catch (TimeoutException e) {
System.err.println("Removing itemID: " + e.itemID + " from list.");
e.printStackTrace();
erroredItems.add(e.itemID);
loadItems();
}
matching = false;
}
}
finally {
matching = false;
}
}
}
private static HashSet<String> stackTraces = new HashSet<String>();
public static class ThreadLoadItems extends Thread implements IItemCounter
{
private Item item;
public ThreadLoadItems() {
super("NEI Item Loading Thread");
loading = true;
}
@Override
public Item getItem() {
return item;
}
@Override
public Thread getThread() {
return this;
}
@Override
public void run() {
new ThreadLoadMonitor(this).start();
startSearch:
while (loading) {
try {
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
ArrayList<ItemStack> permutations = new ArrayList<ItemStack>();
ListMultimap<Item, ItemStack> itemMap = ArrayListMultimap.create();
for (Item item : (Iterable<Item>) Item.itemRegistry) {
this.item = item;
if (reload) {
reload = false;
continue startSearch;
}
if (item == null || ItemInfo.isHidden(item))
continue;
permutations.clear();
permutations.addAll(ItemInfo.getItemOverrides(item));
if(permutations.isEmpty()) {
try {
item.getSubItems(item, null, permutations);
} catch (Exception e) {
System.err.println("Removing itemID: " + item + " from list.");
e.printStackTrace();
erroredItems.add(item);
continue;
}
}
if(permutations.isEmpty()) {
HashSet<String> damageIconSet = new HashSet<String>();
for (int damage = 0; damage < 16; damage++) {
ItemStack itemstack = new ItemStack(item, 1, damage);
try {
IIcon icon = item.getIconIndex(itemstack);
String name = GuiContainerManager.concatenatedDisplayName(itemstack, false);
String s = name + "@" + (icon == null ? 0 : icon.hashCode());
if (!damageIconSet.contains(s)) {
damageIconSet.add(s);
permutations.add(itemstack);
}
} catch (Throwable t) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
String stackTrace = itemstack + sw.toString();
if (!stackTraces.contains(stackTrace)) {
System.err.println("NEI: Omitting #" + this.item + ":" + damage + " " + item.getClass().getSimpleName());
t.printStackTrace();
stackTraces.add(stackTrace);
}
}
}
}
for(Iterator<ItemStack> it = permutations.iterator(); it.hasNext(); )
if(ItemInfo.isHidden(it.next()))
it.remove();
items.addAll(permutations);
itemMap.putAll(item, permutations);
}
item = null;
/*DropDownFile dropDownInstance = DropDownFile.dropDownInstance;
dropDownInstance.resetHashes();
for(ItemStack stack : items)
{
if(reload)
{
reload = false;
continue startSearch;
}
dropDownInstance.addItemIfInRange(stack.getItem(), stack.getItemDamage(), stack.stackTagCompound);
}
dropDownInstance.updateState();*/
ItemList.items = items;
ItemList.itemMap = itemMap;
if (reload) {
reload = false;
continue;
}
loading = false;
} catch (TimeoutException e) {
System.err.println("Removing itemID: " + e.itemID + " from list.");
e.printStackTrace();
erroredItems.add(e.itemID);
}
}
updateSearch();
}
}
public static boolean isMatching() {
return matching;
}
public static void updateSearch() {
if (matching)
research = true;
else
new ThreadMatchSearch().start();
}
public static void loadItems() {
if (loading)
reload = true;
else
new ThreadLoadItems().start();
}
}
+139
View File
@@ -0,0 +1,139 @@
package codechicken.nei;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ItemMobSpawner extends ItemBlock
{
private static Map<Integer, EntityLiving> entityHashMap;
private static Map<Integer, String> IDtoNameMap;
public static int idPig;
private static boolean loaded;
public ItemMobSpawner(World world) {
super(Blocks.mob_spawner);
hasSubtypes = true;
MinecraftForgeClient.registerItemRenderer(this, new SpawnerRenderer());
entityHashMap = new HashMap<Integer, EntityLiving>();
IDtoNameMap = new HashMap<Integer, String>();
loadSpawners(world);
}
/**
* These are ASM translated from BlockMobSpawner
*/
public static int placedX;
public static int placedY;
public static int placedZ;
@Override
public IIcon getIconFromDamage(int par1) {
return Blocks.mob_spawner.getBlockTextureFromSide(0);
}
public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10) {
if (super.onItemUse(itemstack, entityplayer, world, x, y, z, par7, par8, par9, par10) && world.isRemote) {
TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) world.getTileEntity(placedX, placedY, placedZ);
if (tileentitymobspawner != null) {
setDefaultTag(itemstack);
String mobtype = IDtoNameMap.get(itemstack.getItemDamage());
if (mobtype != null) {
NEICPH.sendMobSpawnerID(placedX, placedY, placedZ, mobtype);
tileentitymobspawner.func_145881_a().setEntityName(mobtype);
}
}
return true;
}
return false;
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
setDefaultTag(itemstack);
int meta = itemstack.getItemDamage();
if (meta == 0) {
meta = idPig;
}
Entity e = getEntity(meta);
if (e == null) return;
list.add("\u00A7" + (e instanceof IMob ? "4" : "3") + IDtoNameMap.get(meta));
}
public static EntityLiving getEntity(int ID) {
EntityLiving entityliving = entityHashMap.get(ID);
if (entityliving == null) {
World world = NEIClientUtils.mc().theWorld;
loadSpawners(world);
try {
Class<?> class1 = (Class<?>) EntityList.IDtoClassMapping.get(ID);
if (class1 != null && EntityLiving.class.isAssignableFrom(class1)) {
entityliving = (EntityLiving) class1.getConstructor(new Class[]{World.class}).newInstance(new Object[]{world});
}
} catch (Throwable t) {
t.printStackTrace();
}
entityHashMap.put(ID, entityliving);
}
return entityliving;
}
private void setDefaultTag(ItemStack itemstack) {
if (!IDtoNameMap.containsKey(itemstack.getItemDamage()))
itemstack.setItemDamage(idPig);
}
public static void loadSpawners(World world) {
if (loaded) return;
loaded = true;
try {
HashMap<Class<Entity>, String> classToStringMapping = (HashMap<Class<Entity>, String>) EntityList.classToStringMapping;
HashMap<Class<Entity>, Integer> classToIDMapping = (HashMap<Class<Entity>, Integer>) EntityList.classToIDMapping;
for (Class<Entity> eclass : classToStringMapping.keySet()) {
if (!EntityLiving.class.isAssignableFrom(eclass))
continue;
try {
EntityLiving entityliving = (EntityLiving) eclass.getConstructor(new Class[]{World.class}).newInstance(new Object[]{world});
entityliving.isChild();
int id = classToIDMapping.get(eclass);
String name = classToStringMapping.get(eclass);
if (name.equals("EnderDragon"))
continue;
IDtoNameMap.put(id, name);
if (name.equals("Pig"))
idPig = id;
} catch (Throwable t) {
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
@Override
public void getSubItems(Item item, CreativeTabs tab, List list) {
for(int i : IDtoNameMap.keySet())
list.add(new ItemStack(item, 1, i));
}
}
+381
View File
@@ -0,0 +1,381 @@
package codechicken.nei;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.api.GuiInfo;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.List;
import static codechicken.lib.gui.GuiDraw.drawRect;
public class ItemPanel extends Widget
{
public class ItemPanelSlot
{
public ItemPanelObject contents;
public int slotIndex;
public ItemPanelSlot(int index)
{
contents = visibleitems.get(index);
slotIndex = index;
}
public ItemStack getItemStack()
{
return contents instanceof ItemPanelStack ? ((ItemPanelStack)contents).item : null;
}
}
public static interface ItemPanelObject
{
void draw(int x, int y);
List<String> handleTooltip(List<String> tooltip);
}
public void resize()
{
marginLeft = x + (width % 18) / 2;
marginTop = y + (height % 18) / 2;
columns = width / 18;
rows = height / 18;
calculatePage();
updateValidSlots();
}
private void calculatePage() {
if(itemsPerPage == 0)
numPages = 0;
else
numPages = (int)Math.ceil((float)visibleitems.size() / (float)itemsPerPage);
if(firstIndex >= visibleitems.size())
firstIndex = 0;
if(numPages == 0)
page = 0;
else
page = firstIndex/itemsPerPage+1;
}
private void updateValidSlots() {
GuiContainer gui = NEIClientUtils.getGuiContainer();
validSlotMap = new boolean[rows*columns];
itemsPerPage = 0;
for(int i = 0; i < validSlotMap.length; i++)
if(slotValid(gui, i)) {
validSlotMap[i] = true;
itemsPerPage++;
}
}
private boolean slotValid(GuiContainer gui, int i) {
Rectangle4i rect = getSlotRect(i);
for(INEIGuiHandler handler : GuiInfo.guiHandlers)
if(handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h))
return false;
return true;
}
public Rectangle4i getSlotRect(int i) {
return getSlotRect(i/columns, i%columns);
}
public Rectangle4i getSlotRect(int row, int column) {
return new Rectangle4i(marginLeft+column*18, marginTop+row*18, 18, 18);
}
@Override
public void draw(int mousex, int mousey)
{
if(itemsPerPage == 0)
return;
GuiContainerManager.enableMatrixStackLogging();
int index = firstIndex;
for(int i = 0; i < rows*columns && index < visibleitems.size(); i++) {
if(validSlotMap[i]) {
Rectangle4i rect = getSlotRect(i);
if(rect.contains(mousex, mousey))
drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555);//highlight
visibleitems.get(index).draw(rect.x, rect.y);
index++;
}
}
GuiContainerManager.disableMatrixStackLogging();
}
@Override
public void postDraw(int mousex, int mousey)
{
if(draggedStack != null)
{
GuiContainerManager.drawItems.zLevel += 100;
GuiContainerManager.drawItem(mousex - 8, mousey - 8, draggedStack);
GuiContainerManager.drawItems.zLevel -= 100;
}
}
@Override
public void mouseDragged(int mousex, int mousey, int button, long heldTime)
{
if(mouseDownSlot >= 0 && draggedStack == null && NEIClientUtils.getHeldItem() == null)
{
ItemPanelSlot mouseOverSlot = getSlotMouseOver(mousex, mousey);
ItemStack stack = new ItemPanelSlot(mouseDownSlot).getItemStack();
if(stack != null && (mouseOverSlot == null || mouseOverSlot.slotIndex != mouseDownSlot || heldTime > 500))
{
int amount = NEIClientConfig.getItemQuantity();
if(amount == 0)
amount = stack.getMaxStackSize();
draggedStack = NEIServerUtils.copyStack(stack, amount);
}
}
}
@Override
public boolean handleClick(int mousex, int mousey, int button)
{
if(handleDraggedClick(mousex, mousey, button))
return true;
if(NEIClientUtils.getHeldItem() != null)
{
for(INEIGuiHandler handler : GuiInfo.guiHandlers)
if(handler.hideItemPanelSlot(NEIClientUtils.getGuiContainer(), mousex, mousey, 1, 1))
return false;
if(NEIClientConfig.canPerformAction("delete") && NEIClientConfig.canPerformAction("item"))
{
if(button == 1)
NEIClientUtils.decreaseSlotStack(-999);
else
NEIClientUtils.deleteHeldItem();
}
else
{
NEIClientUtils.dropHeldItem();
}
return true;
}
ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
if(hoverSlot != null)
{
if(button == 2)
{
ItemStack stack = hoverSlot.getItemStack();
if(stack != null)
{
int amount = NEIClientConfig.getItemQuantity();
if(amount == 0)
amount = stack.getMaxStackSize();
draggedStack = NEIServerUtils.copyStack(stack, amount);
}
}
else
{
mouseDownSlot = hoverSlot.slotIndex;
}
return true;
}
return false;
}
private boolean handleDraggedClick(int mousex, int mousey, int button)
{
if(draggedStack == null)
return false;
GuiContainer gui = NEIClientUtils.getGuiContainer();
boolean handled = false;
for(INEIGuiHandler handler : GuiInfo.guiHandlers)
if(handler.handleDragNDrop(gui, mousex, mousey, draggedStack, button))
{
handled = true;
if(draggedStack.stackSize == 0)
{
draggedStack = null;
return true;
}
}
if(handled)
return true;
Slot overSlot = gui.getSlotAtPosition(mousex, mousey);
if(overSlot != null && overSlot.isItemValid(draggedStack))
{
if(NEIClientConfig.canPerformAction("item"))
{
int contents = overSlot.getHasStack() ? overSlot.getStack().stackSize : 0;
int add = button == 0 ? draggedStack.stackSize : 1;
if(overSlot.getHasStack() && !NEIServerUtils.areStacksSameType(draggedStack, overSlot.getStack()))
contents = 0;
int total = Math.min(contents+add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize()));
if(total > contents)
{
NEIClientUtils.setSlotContents(overSlot.slotNumber, NEIServerUtils.copyStack(draggedStack, total), true);
NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false);
draggedStack.stackSize-=total-contents;
}
if(draggedStack.stackSize == 0)
draggedStack = null;
}
else
{
draggedStack = null;
}
}
else if(mousex < gui.guiLeft || mousey < gui.guiTop || mousex >= gui.guiLeft+gui.xSize || mousey >= gui.guiTop+gui.ySize)
{
draggedStack = null;
}
return true;
}
@Override
public boolean handleClickExt(int mousex, int mousey, int button)
{
return handleDraggedClick(mousex, mousey, button);
}
@Override
public void mouseUp(int mousex, int mousey, int button)
{
ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
if(hoverSlot != null && hoverSlot.slotIndex == mouseDownSlot && hoverSlot.getItemStack() != null && draggedStack == null)
{
ItemStack item = hoverSlot.getItemStack();
if(NEIController.manager.window instanceof GuiRecipe || !NEIClientConfig.canPerformAction("item"))
{
if(button == 0)
GuiCraftingRecipe.openRecipeGui("item", item);
else if(button == 1)
GuiUsageRecipe.openRecipeGui("item", item);
draggedStack = null;
mouseDownSlot = -1;
return;
}
NEIClientUtils.cheatItem(item, button, -1);
}
mouseDownSlot = -1;
}
@Override
public boolean onMouseWheel(int i, int mousex, int mousey)
{
if(!contains(mousex, mousey))
return false;
scroll(-i);
return true;
}
@Override
public boolean handleKeyPress(int keyID, char keyChar)
{
if(keyID == NEIClientConfig.getKeyBinding("gui.next"))
{
scroll(1);
return true;
}
if(keyID == NEIClientConfig.getKeyBinding("gui.prev"))
{
scroll(-1);
return true;
}
return false;
}
@Override
public ItemStack getStackMouseOver(int mousex, int mousey)
{
ItemPanelSlot slot = getSlotMouseOver(mousex, mousey);
return slot == null ? null : slot.getItemStack();
}
public ItemPanelSlot getSlotMouseOver(int mousex, int mousey)
{
int index = firstIndex;
for(int i = 0; i < rows*columns && index < visibleitems.size(); i++)
if(validSlotMap[i]) {
if(getSlotRect(i).contains(mousex, mousey))
return new ItemPanelSlot(index);
index++;
}
return null;
}
@Override
public List<String> handleTooltip(int mx, int my, List<String> tooltip)
{
if(getSlotMouseOver(mx, my) == null)
return tooltip;
return getSlotMouseOver(mx, my).contents.handleTooltip(tooltip);
}
public void scroll(int i)
{
if(itemsPerPage != 0) {
int oldIndex = firstIndex;
firstIndex += i*itemsPerPage;
if(firstIndex >= visibleitems.size())
firstIndex = 0;
if(firstIndex < 0)
if(oldIndex > 0)
firstIndex = 0;
else
firstIndex = (visibleitems.size()-1)/itemsPerPage*itemsPerPage;
calculatePage();
}
}
public int getPage()
{
return page;
}
public int getNumPages()
{
return numPages;
}
public static ArrayList<ItemPanelObject> visibleitems = new ArrayList<ItemPanelObject>();
public ItemStack draggedStack;
public int mouseDownSlot = -1;
private int marginLeft;
private int marginTop;
private int rows;
private int columns;
private boolean[] validSlotMap;
private int firstIndex;
private int itemsPerPage;
private int page;
private int numPages;
}
+29
View File
@@ -0,0 +1,29 @@
package codechicken.nei;
import codechicken.nei.ItemPanel.ItemPanelObject;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.item.ItemStack;
import java.util.List;
public class ItemPanelStack implements ItemPanelObject
{
public ItemStack item;
public ItemPanelStack(ItemStack itemstack)
{
item = itemstack;
}
@Override
public void draw(int x, int y)
{
GuiContainerManager.drawItem(x+1, y+1, item);
}
@Override
public List<String> handleTooltip(List<String> tooltip)
{
return tooltip;
}
}
@@ -0,0 +1,56 @@
package codechicken.nei;
public class ItemQuantityField extends TextField
{
public ItemQuantityField(String ident)
{
super(ident);
centered = true;
}
@Override
public boolean isValid(String string)
{
if(string.equals(""))
return true;
try
{
return Integer.parseInt(string) >= 0;
}
catch(NumberFormatException nfe)
{
return false;
}
}
public int intValue()
{
return intValue(text());
}
public int intValue(String s)
{
try
{
return Integer.parseInt(s);
}
catch(NumberFormatException nfe)
{
return 0;
}
}
@Override
public void loseFocus()
{
setText(Integer.toString(NEIClientConfig.getItemQuantity()));
}
@Override
public void onTextChange(String oldText)
{
if(intValue(oldText) != intValue())//hacky recursion stopper
NEIClientUtils.setItemQuantity(intValue());
}
}
+230
View File
@@ -0,0 +1,230 @@
package codechicken.nei;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import java.util.*;
import static codechicken.lib.inventory.InventoryUtils.actualDamage;
import static codechicken.lib.inventory.InventoryUtils.newItemStack;
import static net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE;
/**
* A maplike class for ItemStack keys with wildcard damage/NBT. Optimised for lookup
*/
public class ItemStackMap <T>
{
public static class StackMetaKey
{
public int damage;
public NBTTagCompound tag;
public StackMetaKey(int damage, NBTTagCompound tag) {
this.damage = damage;
this.tag = tag;
}
public StackMetaKey(ItemStack key) {
this(actualDamage(key), key.stackTagCompound);
}
public int hashCode() {
return damage*31+Objects.hashCode(tag);
}
public boolean equals(Object o) {
if(!(o instanceof StackMetaKey))
return false;
StackMetaKey t = (StackMetaKey)o;
return damage == t.damage && Objects.equals(tag, t.tag);
}
}
public static class Entry<T>
{
public ItemStack key;
public T value;
public Entry(ItemStack key, T value) {
this.key = key;
this.value = value;
}
}
public class DetailMap
{
public T wildcard;
public HashMap<Integer, T> damageMap;
public HashMap<NBTTagCompound, T> tagMap;
public HashMap<StackMetaKey, T> metaMap;
public T get(ItemStack key) {
if(wildcard != null)
return wildcard;
if(damageMap != null) {
T ret = damageMap.get(actualDamage(key));
if(ret != null) return ret;
}
if(tagMap != null) {
T ret = tagMap.get(key.stackTagCompound);
if(ret != null) return ret;
}
if(metaMap != null)
return metaMap.get(new StackMetaKey(key));
return null;
}
public void put(ItemStack key, T value) {
switch(getKeyType(actualDamage(key), key.stackTagCompound)) {
case 0:
if(metaMap == null) metaMap = new HashMap<StackMetaKey, T>();
metaMap.put(new StackMetaKey(key), value);
break;
case 1:
if(tagMap == null) tagMap = new HashMap<NBTTagCompound, T>();
tagMap.put(key.stackTagCompound, value);
break;
case 2:
if(damageMap == null) damageMap = new HashMap<Integer, T>();
damageMap.put(actualDamage(key), value);
break;
case 3:
wildcard = value;
break;
}
}
public T remove(ItemStack key) {
switch(getKeyType(actualDamage(key), key.stackTagCompound)) {
case 0:
return metaMap != null ? metaMap.remove(new StackMetaKey(key)) : null;
case 1:
return tagMap != null ? tagMap.remove(key.stackTagCompound) : null;
case 2:
return damageMap != null ? damageMap.remove(actualDamage(key)) : null;
case 3:
T ret = wildcard;
wildcard = null;
return ret;
}
return null;
}
public void addKeys(Item item, List<ItemStack> list) {
if(wildcard != null)
list.add(newItemStack(item, 1, WILDCARD_VALUE, WILDCARD_TAG));
if(damageMap != null)
for(int damage : damageMap.keySet())
list.add(newItemStack(item, 1, damage, WILDCARD_TAG));
if(tagMap != null)
for(NBTTagCompound tag : tagMap.keySet())
list.add(newItemStack(item, 1, WILDCARD_VALUE, tag));
if(metaMap != null)
for(StackMetaKey key : metaMap.keySet())
list.add(newItemStack(item, 1, key.damage, key.tag));
}
public void addValues(LinkedList<T> list) {
if(wildcard != null)
list.add(wildcard);
if(damageMap != null)
list.addAll(damageMap.values());
if(tagMap != null)
list.addAll(tagMap.values());
if(metaMap != null)
list.addAll(metaMap.values());
}
public void addEntries(Item item, LinkedList<Entry<T>> list) {
if(wildcard != null)
list.add(new Entry<T>(newItemStack(item, 1, WILDCARD_VALUE, WILDCARD_TAG), wildcard));
if(damageMap != null)
for(Map.Entry<Integer, T> entry : damageMap.entrySet())
list.add(new Entry<T>(newItemStack(item, 1, entry.getKey(), WILDCARD_TAG), entry.getValue()));
if(tagMap != null)
for(Map.Entry<NBTTagCompound, T> entry : tagMap.entrySet())
list.add(new Entry<T>(newItemStack(item, 1, WILDCARD_VALUE, entry.getKey()), entry.getValue()));
if(metaMap != null)
for(Map.Entry<StackMetaKey, T> entry : metaMap.entrySet())
list.add(new Entry<T>(newItemStack(item, 1, entry.getKey().damage, entry.getKey().tag), entry.getValue()));
}
}
public static int getKeyType(int damage, NBTTagCompound tag) {
int i = 0;
if(isWildcard(damage)) i = 1;
if(isWildcard(tag)) i |= 2;
return i;
}
public static boolean isWildcard(int damage) {
return damage == WILDCARD_VALUE;
}
public static boolean isWildcard(NBTTagCompound tag) {
return tag != null && tag.getBoolean("*");
}
public static NBTTagCompound WILDCARD_TAG;
static {
WILDCARD_TAG = new NBTTagCompound();
WILDCARD_TAG.setBoolean("*", true);
}
protected HashMap<Item, DetailMap> itemMap = new HashMap<Item, DetailMap>();
public T get(ItemStack key) {
if(key == null || key.getItem() == null)
return null;
DetailMap map = itemMap.get(key.getItem());
return map == null ? null : map.get(key);
}
public void put(ItemStack key, T value) {
if(key == null || key.getItem() == null)
return;
DetailMap map = itemMap.get(key.getItem());
if(map == null)
itemMap.put(key.getItem(), map = new DetailMap());
map.put(key, value);
}
public void clear() {
itemMap.clear();
}
public T remove(ItemStack key) {
if (key == null || key.getItem() == null)
return null;
DetailMap map = itemMap.get(key.getItem());
return map == null ? null : map.remove(key);
}
public List<ItemStack> keys() {
LinkedList<ItemStack> list = new LinkedList<ItemStack>();
for(Map.Entry<Item, DetailMap> entry : itemMap.entrySet())
entry.getValue().addKeys(entry.getKey(), list);
return list;
}
public List<T> values() {
LinkedList<T> list = new LinkedList<T>();
for(DetailMap map : itemMap.values())
map.addValues(list);
return list;
}
public List<Entry<T>> entries() {
LinkedList<Entry<T>> list = new LinkedList<Entry<T>>();
for(Map.Entry<Item, DetailMap> entry : itemMap.entrySet())
entry.getValue().addEntries(entry.getKey(), list);
return list;
}
}
+35
View File
@@ -0,0 +1,35 @@
package codechicken.nei;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import java.util.List;
public class ItemStackSet
{
ItemStackMap<Object> underlying = new ItemStackMap<Object>();
public void add(ItemStack item) {
underlying.put(item, new Object());
}
public boolean remove(ItemStack item) {
return underlying.remove(item) != null;
}
public boolean contains(ItemStack item) {
return underlying.get(item) != null;
}
public boolean containsAll(Item item) {
return underlying.itemMap.containsKey(item) && underlying.itemMap.get(item).wildcard != null;
}
public List<ItemStack> values() {
return underlying.keys();
}
public void clear() {
underlying.clear();
}
}
+52
View File
@@ -0,0 +1,52 @@
package codechicken.nei;
import org.lwjgl.input.Keyboard;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
/**
* Good old down/held/up keystate tracker
*/
public class KeyManager
{
public static interface IKeyStateTracker
{
public void tickKeyStates();
}
public static class KeyState
{
public boolean down;
public boolean held;
public boolean up;
}
public static HashMap<String, KeyState> keyStates = new HashMap<String, KeyState>();
public static LinkedList<IKeyStateTracker> trackers = new LinkedList<IKeyStateTracker>();
public static void tickKeyStates()
{
for(Entry<String, KeyState> entry : keyStates.entrySet())
{
int keyCode = NEIClientConfig.getKeyBinding(entry.getKey());
boolean down = keyCode != 0 && Keyboard.isKeyDown(keyCode);
KeyState state = entry.getValue();
if(down)
{
state.down = !state.held;
state.up = false;
}
else
{
state.up = state.held;
state.down = false;
}
state.held = down;
}
for(IKeyStateTracker tracker : trackers)
tracker.tickKeyStates();
}
}
+32
View File
@@ -0,0 +1,32 @@
package codechicken.nei;
import static codechicken.lib.gui.GuiDraw.drawString;
import static codechicken.lib.gui.GuiDraw.drawStringC;
public class Label extends Widget
{
boolean centered;
int colour;
String text;
public Label(String s, boolean center, int color)
{
text = s;
centered = center;
colour = color;
}
public Label(String s, boolean center)
{
this(s, center, 0xFFFFFFFF);
}
@Override
public void draw(int mousex, int mousey)
{
if(centered)
drawStringC(text, x, y, colour);
else
drawString(text, x, y, colour);
}
}
+19
View File
@@ -0,0 +1,19 @@
package codechicken.nei;
import net.minecraft.util.StatCollector;
public class LangProxy
{
public final String namespace;
public LangProxy(String namespace) {
this.namespace = namespace+".";
}
public String translate(String key) {
return StatCollector.translateToLocal(namespace+key);
}
public String format(String key, Object... params) {
return StatCollector.translateToLocalFormatted(namespace+key, params);
}
}
+811
View File
@@ -0,0 +1,811 @@
package codechicken.nei;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.KeyManager.IKeyStateTracker;
import codechicken.nei.api.*;
import codechicken.nei.guihook.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.renderer.InventoryEffectRenderer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import org.lwjgl.opengl.GL11;
import java.util.HashMap;
import java.util.List;
import java.util.TreeSet;
import static codechicken.lib.gui.GuiDraw.*;
import static codechicken.nei.NEIClientConfig.*;
import static codechicken.nei.NEIClientUtils.*;
public class LayoutManager implements IContainerInputHandler, IContainerTooltipHandler, IContainerDrawHandler, IContainerObjectHandler, IKeyStateTracker
{
private static LayoutManager instance;
private static Widget inputFocused;
/**
* Sorted bottom first
*/
private static TreeSet<Widget> drawWidgets;
/**
* Sorted top first
*/
private static TreeSet<Widget> controlWidgets;
public static ItemPanel itemPanel;
public static Button dropDown;
public static TextField searchField;
public static Button options;
public static Button prev;
public static Button next;
public static Label pageLabel;
public static Button more;
public static Button less;
public static ItemQuantityField quantity;
public static SaveLoadButton[] stateButtons;
public static Button[] deleteButtons;
public static Button delete;
public static ButtonCycled gamemode;
public static Button rain;
public static Button magnet;
public static Button[] timeButtons = new Button[4];
public static Button heal;
public static IRecipeOverlayRenderer overlayRenderer;
public static HashMap<Integer, LayoutStyle> layoutStyles = new HashMap<Integer, LayoutStyle>();
public static void load() {
API.addLayoutStyle(0, new LayoutStyleMinecraft());
API.addLayoutStyle(1, new LayoutStyleTMIOld());
instance = new LayoutManager();
KeyManager.trackers.add(instance);
GuiContainerManager.addInputHandler(instance);
GuiContainerManager.addTooltipHandler(instance);
GuiContainerManager.addDrawHandler(instance);
GuiContainerManager.addObjectHandler(instance);
init();
}
@Override
public void onPreDraw(GuiContainer gui) {
if (!isHidden() && isEnabled() && gui instanceof InventoryEffectRenderer)//Reset the gui to the center of the screen, for potion effect offsets etc
{
gui.guiLeft = (gui.width - gui.xSize) / 2;
gui.guiTop = (gui.height - gui.ySize) / 2;
if (gui instanceof GuiContainerCreative && gui.buttonList.size() >= 2) {
GuiButton button1 = (GuiButton) gui.buttonList.get(0);
GuiButton button2 = (GuiButton) gui.buttonList.get(1);
button1.xPosition = gui.guiLeft;
button2.xPosition = gui.guiLeft + gui.xSize - 20;
}
}
}
@Override
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
if (isHidden())
return;
for (Widget widget : controlWidgets)
widget.onGuiClick(mousex, mousey);
}
@Override
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
if (isHidden())
return false;
if (!isEnabled())
return options.contains(mousex, mousey) && options.handleClick(mousex, mousey, button);
for (Widget widget : controlWidgets) {
widget.onGuiClick(mousex, mousey);
if (widget.contains(mousex, mousey) ? widget.handleClick(mousex, mousey, button) : widget.handleClickExt(mousex, mousey, button))
return true;
}
return false;
}
@Override
public boolean objectUnderMouse(GuiContainer gui, int mousex, int mousey) {
if (!isHidden() && isEnabled()) {
for (Widget widget : controlWidgets)
if (widget.contains(mousex, mousey))
return true;
}
return false;
}
public boolean keyTyped(GuiContainer gui, char keyChar, int keyID) {
if (isEnabled() && !isHidden()) {
if (inputFocused != null)
return inputFocused.handleKeyPress(keyID, keyChar);
for (Widget widget : controlWidgets)
if (widget.handleKeyPress(keyID, keyChar))
return true;
}
return false;
}
@Override
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {
}
@Override
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyID) {
if (keyID == getKeyBinding("gui.hide")) {
toggleBooleanSetting("inventory.hidden");
return true;
}
if (isEnabled() && !isHidden()) {
for (Widget widget : controlWidgets)
if (inputFocused == null)
widget.lastKeyTyped(keyID, keyChar);
}
return false;
}
public void onMouseUp(GuiContainer gui, int mx, int my, int button) {
if (!isHidden() && isEnabled()) {
for (Widget widget : controlWidgets)
widget.mouseUp(mx, my, button);
}
}
@Override
public void onMouseDragged(GuiContainer gui, int mx, int my, int button, long heldTime) {
if (!isHidden() && isEnabled()) {
for (Widget widget : controlWidgets)
widget.mouseDragged(mx, my, button, heldTime);
}
}
@Override
public ItemStack getStackUnderMouse(GuiContainer gui, int mousex, int mousey) {
if (!isHidden() && isEnabled()) {
for (Widget widget : controlWidgets) {
ItemStack stack = widget.getStackMouseOver(mousex, mousey);
if (stack != null)
return stack;
}
}
return null;
}
public void renderObjects(GuiContainer gui, int mousex, int mousey) {
if (!isHidden()) {
layout(gui);
if (isEnabled()) {
getLayoutStyle().drawBackground(GuiContainerManager.getManager(gui));
for (Widget widget : drawWidgets)
widget.draw(mousex, mousey);
} else {
options.draw(mousex, mousey);
}
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
}
@Override
public void postRenderObjects(GuiContainer gui, int mousex, int mousey) {
if (!isHidden() && isEnabled()) {
for (Widget widget : drawWidgets)
widget.postDraw(mousex, mousey);
}
}
@Override
public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
if (!isHidden() && isEnabled() && GuiContainerManager.shouldShowTooltip(gui)) {
for (Widget widget : controlWidgets)
currenttip = widget.handleTooltip(mousex, mousey, currenttip);
}
return currenttip;
}
@Override
public List<String> handleItemDisplayName(GuiContainer gui, ItemStack stack, List<String> currenttip) {
String overridename = ItemInfo.getNameOverride(stack);
if (overridename != null)
currenttip.set(0, overridename);
String mainname = currenttip.get(0);
if (showIDs()) {
mainname += " " + Item.getIdFromItem(stack.getItem());
if (stack.getItemDamage() != 0)
mainname += ":" + stack.getItemDamage();
currenttip.set(0, mainname);
}
return currenttip;
}
@Override
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey, List<String> currenttip) {
return currenttip;
}
public static void layout(GuiContainer gui) {
VisiblityData visiblity = new VisiblityData();
if (isHidden())
visiblity.showNEI = false;
if (gui.height - gui.ySize <= 40)
visiblity.showSearchSection = false;
if (gui.guiLeft - 4 < 76)
visiblity.showWidgets = false;
for (INEIGuiHandler handler : GuiInfo.guiHandlers)
handler.modifyVisiblity(gui, visiblity);
visiblity.translateDependancies();
getLayoutStyle().layout(gui, visiblity);
updateWidgetVisiblities(gui, visiblity);
}
private static void init() {
itemPanel = new ItemPanel();
dropDown = new Button("NEI Subsets")
{
@Override
public boolean onButtonPress(boolean rightclick) {
return false;
}
};
searchField = new SearchField("search");
options = new Button("Options")
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (!rightclick) {
getOptionList().showGui(getGuiContainer());
return true;
}
return false;
}
@Override
public String getRenderLabel() {
return translate("inventory.options");
}
};
prev = new Button("Prev")
{
public boolean onButtonPress(boolean rightclick) {
if (!rightclick) {
LayoutManager.itemPanel.scroll(-1);
return true;
}
return false;
}
@Override
public String getRenderLabel() {
return translate("inventory.prev");
}
};
next = new Button("Next")
{
public boolean onButtonPress(boolean rightclick) {
if (!rightclick) {
LayoutManager.itemPanel.scroll(1);
return true;
}
return false;
}
@Override
public String getRenderLabel() {
return translate("inventory.next");
}
};
pageLabel = new Label("(0/0)", true);
more = new Button("+")
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (rightclick)
return false;
int modifier = controlKey() ? 64 : shiftKey() ? 10 : 1;
int quantity = getItemQuantity() + modifier;
if (quantity < 0)
quantity = 0;
setItemQuantity(quantity);
return true;
}
};
less = new Button("-")
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (rightclick)
return false;
int modifier = controlKey() ? -64 : shiftKey() ? -10 : -1;
int quantity = getItemQuantity() + modifier;
if (quantity < 0)
quantity = 0;
setItemQuantity(quantity);
return true;
}
};
quantity = new ItemQuantityField("quantity");
stateButtons = new SaveLoadButton[7];
deleteButtons = new Button[7];
for (int i = 0; i < 7; i++) {
final int savestate = i;
stateButtons[i] = new SaveLoadButton("")
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (isStateSaved(savestate))
loadState(savestate);
else
saveState(savestate);
return true;
}
@Override
public void onTextChange() {
NBTTagCompound statelist = global.nbt.getCompoundTag("statename");
global.nbt.setTag("statename", statelist);
statelist.setString("" + savestate, label);
global.saveNBT();
}
};
deleteButtons[i] = new Button("x")
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (!rightclick) {
clearState(savestate);
return true;
}
return false;
}
};
}
delete = new Button()
{
@Override
public boolean onButtonPress(boolean rightclick) {
if ((state & 0x3) == 2)
return false;
ItemStack held = getHeldItem();
if (held != null) {
if (shiftKey()) {
deleteHeldItem();
deleteItemsOfType(held);
} else if (rightclick)
decreaseSlotStack(-999);
else
deleteHeldItem();
} else if (shiftKey())
deleteEverything();
else
NEIController.toggleDeleteMode();
return true;
}
public String getButtonTip() {
if ((state & 0x3) != 2) {
if (shiftKey())
return translate("inventory.delete.all");
if (NEIController.canUseDeleteMode())
return getStateTip("delete", state);
}
return null;
}
@Override
public void postDraw(int mousex, int mousey) {
if(contains(mousex, mousey) && getHeldItem() != null && (state & 0x3) != 2)
GuiDraw.drawTip(mousex + 9, mousey, translate("inventory.delete." + (shiftKey() ? "all" : "one"), GuiContainerManager.itemDisplayNameShort(getHeldItem())));
}
};
gamemode = new ButtonCycled()
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (!rightclick) {
cycleGamemode();
return true;
}
return false;
}
public String getButtonTip() {
return translate("inventory.gamemode." + getNextGamemode());
}
};
gamemode.icons = new Image[3];
rain = new Button()
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (handleDisabledButtonPress("rain", rightclick))
return true;
if (!rightclick) {
toggleRaining();
return true;
}
return false;
}
public String getButtonTip() {
return getStateTip("rain", state);
}
};
magnet = new Button()
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (!rightclick) {
toggleMagnetMode();
return true;
}
return false;
}
public String getButtonTip() {
return getStateTip("magnet", state);
}
};
for (int i = 0; i < 4; i++) {
final int zone = i;
timeButtons[i] = new Button()
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (handleDisabledButtonPress(NEIActions.timeZones[zone], rightclick))
return true;
if (!rightclick) {
setHourForward(zone * 6);
return true;
}
return false;
}
@Override
public String getButtonTip() {
return getTimeTip(NEIActions.timeZones[zone], state);
}
};
}
heal = new Button()
{
@Override
public boolean onButtonPress(boolean rightclick) {
if (!rightclick) {
healPlayer();
return true;
}
return false;
}
@Override
public String getButtonTip() {
return translate("inventory.heal");
}
};
delete.state |= 0x4;
gamemode.state |= 0x4;
rain.state |= 0x4;
magnet.state |= 0x4;
}
private static String getStateTip(String name, int state) {
String sfx = (state & 0x3) == 2 ? "enable" :
(state & 0x3) == 1 ? "0" : "1";
return translate("inventory." + name + "." + sfx);
}
private static String getTimeTip(String name, int state) {
String sfx = (state & 0x3) == 2 ? "enable" : "set";
return translate("inventory." + name + "." + sfx);
}
private static boolean handleDisabledButtonPress(String ident, boolean rightclick) {
if (!NEIActions.canDisable.contains(ident))
return false;
if (rightclick != disabledActions.contains(ident))
return setPropertyDisabled(ident, rightclick);
return false;
}
private static boolean setPropertyDisabled(String ident, boolean disable) {
if (disable && NEIActions.base(ident).equals("time")) {
int count = 0;
for (int i = 0; i < 4; i++) {
if (disabledActions.contains(NEIActions.timeZones[i]))
count++;
}
if (count == 3)
return false;
}
if (hasSMPCounterPart())
NEICPH.sendSetPropertyDisabled(ident, disable);
return true;
}
@Override
public void load(GuiContainer gui) {
if (isEnabled()) {
setInputFocused(null);
ItemList.loadItems();
overlayRenderer = null;
getLayoutStyle().init();
layout(gui);
}
NEIController.load(gui);
if (checkCreativeInv(gui)) {
if (gui.mc.currentScreen instanceof GuiContainerCreative)//makes cycle transititions seemless. Only closes if we are opening from fresh
gui.mc.displayGuiScreen(null);
return;
}
}
@Override
public void refresh(GuiContainer gui) {
}
public boolean checkCreativeInv(GuiContainer gui) {
if (gui instanceof GuiContainerCreative && invCreativeMode()) {
NEICPH.sendCreativeInv(true);
return true;
} else if (gui instanceof GuiExtendedCreativeInv && !invCreativeMode()) {
NEICPH.sendCreativeInv(false);
return true;
}
return false;
}
public static void updateWidgetVisiblities(GuiContainer gui, VisiblityData visiblity) {
drawWidgets = new TreeSet<Widget>(new WidgetZOrder(false));
controlWidgets = new TreeSet<Widget>(new WidgetZOrder(true));
if (!visiblity.showNEI)
return;
addWidget(options);
if (visiblity.showItemPanel) {
addWidget(itemPanel);
addWidget(prev);
addWidget(next);
addWidget(pageLabel);
if (canPerformAction("item")) {
addWidget(more);
addWidget(less);
addWidget(quantity);
}
}
if (visiblity.showSearchSection) {
addWidget(dropDown);
addWidget(searchField);
}
if (canPerformAction("item") && visiblity.showStateButtons) {
for (int i = 0; i < 7; i++) {
addWidget(stateButtons[i]);
if (isStateSaved(i))
addWidget(deleteButtons[i]);
}
}
if (visiblity.showUtilityButtons) {
if (canPerformAction("time")) {
for (int i = 0; i < 4; i++)
addWidget(timeButtons[i]);
}
if (canPerformAction("rain"))
addWidget(rain);
if (canPerformAction("heal"))
addWidget(heal);
if (canPerformAction("magnet"))
addWidget(magnet);
if (isValidGamemode("creative") ||
isValidGamemode("creative+") ||
isValidGamemode("adventure"))
addWidget(gamemode);
if (canPerformAction("delete"))
addWidget(delete);
}
}
public static LayoutStyle getLayoutStyle(int id) {
LayoutStyle style = layoutStyles.get(id);
if (style == null)
style = layoutStyles.get(0);
return style;
}
public static LayoutStyle getLayoutStyle() {
return getLayoutStyle(NEIClientConfig.getLayoutStyle());
}
private static void addWidget(Widget widget) {
drawWidgets.add(widget);
controlWidgets.add(widget);
}
@Override
public void guiTick(GuiContainer gui) {
if (checkCreativeInv(gui))
return;
if (!isEnabled())
return;
for (Widget widget : controlWidgets)
widget.update();
}
@Override
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
if (isHidden() || !isEnabled())
return false;
for (Widget widget : controlWidgets)
if (widget.onMouseWheel(scrolled, mousex, mousey))
return true;
return false;
}
@Override
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
}
@Override
public boolean shouldShowTooltip(GuiContainer gui) {
return itemPanel.draggedStack == null;
}
public static Widget getInputFocused() {
return inputFocused;
}
public static void setInputFocused(Widget widget) {
if (inputFocused != null)
inputFocused.loseFocus();
inputFocused = widget;
if (inputFocused != null)
inputFocused.gainFocus();
}
@Override
public void renderSlotUnderlay(GuiContainer gui, Slot slot) {
if (overlayRenderer != null)
overlayRenderer.renderOverlay(GuiContainerManager.getManager(gui), slot);
}
@Override
public void renderSlotOverlay(GuiContainer window, Slot slot) {
ItemStack item = slot.getStack();
if (world.nbt.getBoolean("searchinventories") && (item == null ? !getSearchExpression().equals("") : !ItemList.itemMatchesSearch(item))) {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glTranslatef(0, 0, 150);
drawRect(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, 0x80000000);
GL11.glTranslatef(0, 0, -150);
GL11.glEnable(GL11.GL_LIGHTING);
}
}
public static void drawIcon(int x, int y, Image image) {
changeTexture("nei:textures/nei_sprites.png");
GL11.glColor4f(1, 1, 1, 1);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
drawTexturedModalRect(x, y, image.x, image.y, image.width, image.height);
GL11.glDisable(GL11.GL_BLEND);
}
public static void drawButtonBackground(int x, int y, int w, int h, boolean edges, int type) {
int wtiles = 0;
int ew = w;//end width
if (w / 2 > 100) {
wtiles = (w - 200) / 50 + 1;
ew = 200;
}
int w1 = ew / 2;
int h1 = h / 2;
int w2 = (ew + 1) / 2;
int h2 = (h + 1) / 2;
int x2 = x + w - w2;
int y2 = y + h - h2;
int ty = 46 + type * 20;
int te = (edges ? 0 : 1);//tex edges
int ty1 = ty + te;
int tx1 = te;
int tx3 = 75;
//halfway the 1 is for odd number adjustment
int ty2 = ty + 20 - h2 - te;
int tx2 = 200 - w2 - te;
changeTexture("textures/gui/widgets.png");
drawTexturedModalRect(x, y, tx1, ty1, w1, h1);//top left
drawTexturedModalRect(x, y2, tx1, ty2, w1, h2);//bottom left
for (int tile = 0; tile < wtiles; tile++) {
int tilex = x + w1 + 50 * tile;
drawTexturedModalRect(tilex, y, tx3, ty1, 50, h1);//top
drawTexturedModalRect(tilex, y2, tx3, ty2, 50, h2);//bottom
}
drawTexturedModalRect(x2, y, tx2, ty1, w2, h1);//top right
drawTexturedModalRect(x2, y2, tx2, ty2, w2, h2);//bottom right
}
public static LayoutManager instance() {
return instance;
}
@Override
public void tickKeyStates() {
if (Minecraft.getMinecraft().currentScreen != null)
return;
if (KeyManager.keyStates.get("world.dawn").down)
timeButtons[0].onButtonPress(false);
if (KeyManager.keyStates.get("world.noon").down)
timeButtons[1].onButtonPress(false);
if (KeyManager.keyStates.get("world.dusk").down)
timeButtons[2].onButtonPress(false);
if (KeyManager.keyStates.get("world.midnight").down)
timeButtons[3].onButtonPress(false);
if (KeyManager.keyStates.get("world.rain").down)
rain.onButtonPress(false);
if (KeyManager.keyStates.get("world.heal").down)
heal.onButtonPress(false);
if (KeyManager.keyStates.get("world.creative").down)
gamemode.onButtonPress(false);
}
}
+153
View File
@@ -0,0 +1,153 @@
package codechicken.nei;
import codechicken.nei.api.LayoutStyle;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.nbt.NBTTagCompound;
import static codechicken.lib.gui.GuiDraw.getStringWidth;
import static codechicken.nei.LayoutManager.*;
import static codechicken.nei.NEIClientConfig.*;
public abstract class LayoutStyleDefault extends LayoutStyle
{
@Override
public void layout(GuiContainer gui, VisiblityData visiblity) {
int windowWidth = gui.width;
int windowHeight = gui.height;
int containerWidth = gui.xSize;
int containerLeft = gui.guiLeft;
reset();
prev.y = 2;
prev.height = 16;
prev.width = containerLeft / 3;
prev.x = (containerWidth + windowWidth) / 2 + 2;
next.x = windowWidth - prev.width - 2;
next.y = prev.y;
next.width = prev.width;
next.height = prev.height;
pageLabel.x = containerLeft * 3 / 2 + containerWidth + 1;
pageLabel.y = prev.y + 5;
pageLabel.text = "(" + itemPanel.getPage() + "/" + itemPanel.getNumPages() + ")";
itemPanel.y = prev.height + prev.y;
itemPanel.x = (containerWidth + windowWidth) / 2 + 3;
itemPanel.width = windowWidth - 3 - itemPanel.x;
itemPanel.height = windowHeight - 15 - itemPanel.y;
if (!canPerformAction("item"))
itemPanel.height += 15;
itemPanel.resize();
more.width = more.height = less.width = less.height = 16;
less.x = prev.x;
more.x = windowWidth - less.width - 2;
more.y = less.y = windowHeight - more.height - 2;
quantity.x = less.x + less.width + 2;
quantity.y = less.y;
quantity.width = more.x - quantity.x - 2;
quantity.height = less.height;
options.x = isEnabled() ? 0 : 6;
options.y = isEnabled() ? windowHeight - 22 : windowHeight - 28;
options.width = 80;
options.height = 22;
delete.state = 0x4;
if (NEIController.getDeleteMode())
delete.state |= 1;
else if (!visiblity.enableDeleteMode)
delete.state |= 2;
rain.state = 0x4;
if (disabledActions.contains("rain"))
rain.state |= 2;
else if (NEIClientUtils.isRaining())
rain.state |= 1;
gamemode.state = 0x4;
if (NEIClientUtils.getGamemode() != 0) {
gamemode.state |= 0x1;
gamemode.index = NEIClientUtils.getGamemode() - 1;
} else {
if (NEIClientUtils.isValidGamemode("creative"))
gamemode.index = 0;
else if (NEIClientUtils.isValidGamemode("creative+"))
gamemode.index = 1;
else if (NEIClientUtils.isValidGamemode("adventure"))
gamemode.index = 2;
}
magnet.state = 0x4 | (getMagnetMode() ? 1 : 0);
if (canPerformAction("delete"))
layoutButton(delete);
if (canPerformAction("rain"))
layoutButton(rain);
if (NEIClientUtils.isValidGamemode("creative") ||
NEIClientUtils.isValidGamemode("creative+") ||
NEIClientUtils.isValidGamemode("adventure"))
layoutButton(gamemode);
if (canPerformAction("magnet"))
layoutButton(magnet);
if (canPerformAction("time")) {
for (int i = 0; i < 4; i++) {
timeButtons[i].state = disabledActions.contains(NEIActions.timeZones[i]) ? 2 : 0;
layoutButton(timeButtons[i]);
}
}
if (canPerformAction("heal"))
layoutButton(heal);
searchField.y = windowHeight - searchField.height - 2;
dropDown.height = 20;
dropDown.width = prev.x - dropDown.x - 3;
searchField.height = 20;
searchField.width = 150;
searchField.x = (windowWidth - searchField.width) / 2;
if (!visiblity.showItemSection) {
//TODO dropDown.setDropDown(0);
searchField.setFocus(false);
}
int maxWidth = 0;
for (int i = 0; i < 7; i++) {
deleteButtons[i].width = 16;
deleteButtons[i].height = 16;
NBTTagCompound statelist = global.nbt.getCompoundTag("statename");
global.nbt.setTag("statename", statelist);
String name = statelist.getString("" + i);
if (statelist.getTag("" + i) == null) {
name = "" + (i + 1);
statelist.setString("" + i, name);
}
stateButtons[i].label = name;
stateButtons[i].saved = isStateSaved(i);
int width = getStringWidth(stateButtons[i].getRenderLabel()) + 26;
if (width + 22 > containerLeft)
width = containerLeft - 22;
if (width > maxWidth)
maxWidth = width;
}
for (int i = 0; i < 7; i++) {
stateButtons[i].x = 0;
stateButtons[i].y = 58 + i * 22;
stateButtons[i].height = 20;
stateButtons[i].x = 0;
stateButtons[i].width = maxWidth;
deleteButtons[i].x = stateButtons[i].width + 3;
deleteButtons[i].y = stateButtons[i].y + 2;
}
}
public abstract void layoutButton(Button button);
}
@@ -0,0 +1,89 @@
package codechicken.nei;
import org.lwjgl.opengl.GL11;
import static codechicken.lib.gui.GuiDraw.drawStringC;
import static codechicken.nei.LayoutManager.*;
public class LayoutStyleMinecraft extends LayoutStyleDefault
{
int stateButtonCount;
int clickButtonCount;
@Override
public String getName() {
return "minecraft";
}
@Override
public void init() {
delete.icon = new Image(144, 12, 12, 12);
gamemode.icons[0] = new Image(132, 12, 12, 12);
gamemode.icons[1] = new Image(156, 12, 12, 12);
gamemode.icons[2] = new Image(168, 12, 12, 12);
rain.icon = new Image(120, 12, 12, 12);
magnet.icon = new Image(180, 24, 12, 12);
timeButtons[0].icon = new Image(132, 24, 12, 12);
timeButtons[1].icon = new Image(120, 24, 12, 12);
timeButtons[2].icon = new Image(144, 24, 12, 12);
timeButtons[3].icon = new Image(156, 24, 12, 12);
heal.icon = new Image(168, 24, 12, 12);
dropDown.x = 90;
}
@Override
public void reset() {
stateButtonCount = clickButtonCount = 0;
}
@Override
public void layoutButton(Button button) {
if ((button.state & 0x4) != 0) {
button.x = 6 + stateButtonCount * 20;
button.y = 3;
stateButtonCount++;
} else {
button.x = 6 + (clickButtonCount % 4) * 20;
button.y = 3 + (1 + clickButtonCount / 4) * 18;
clickButtonCount++;
}
button.height = 17;
button.width = button.contentWidth() + 6;
}
@Override
public void drawButton(Button b, int mousex, int mousey) {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glColor4f(1, 1, 1, 1);
int tex;
if ((b.state & 0x3) == 2)
tex = 0;
else if ((b.state & 0x4) == 0 && b.contains(mousex, mousey) ||//not a state button and mouseover
(b.state & 0x3) == 1)//state active
tex = 2;
else
tex = 1;
LayoutManager.drawButtonBackground(b.x, b.y, b.width, b.height, true, tex);
Image icon = b.getRenderIcon();
if (icon == null) {
int colour = tex == 2 ? 0xffffa0 :
tex == 0 ? 0x601010 : 0xe0e0e0;
drawStringC(b.getRenderLabel(), b.x + b.width / 2, b.y + (b.height - 8) / 2, colour);
} else {
GL11.glColor4f(1, 1, 1, 1);
int iconx = b.x + (b.width - icon.width) / 2;
int icony = b.y + (b.height - icon.height) / 2;
LayoutManager.drawIcon(iconx, icony, icon);
}
}
@Override
public boolean texturedButtons() {
return true;
}
}
+127
View File
@@ -0,0 +1,127 @@
package codechicken.nei;
import codechicken.nei.guihook.GuiContainerManager;
import static codechicken.lib.gui.GuiDraw.drawRect;
import static codechicken.lib.gui.GuiDraw.drawString;
import static codechicken.nei.LayoutManager.*;
public class LayoutStyleTMIOld extends LayoutStyleDefault
{
public static final Image stateOff = new Image(48, 0, 8, 12);
public static final Image stateOn = new Image(56, 0, 8, 12);
public static final Image stateDisabled = new Image(64, 0, 8, 12);
int stateButtonCount;
int clickButtonCount;
@Override
public String getName()
{
return "oldtmi";
}
@Override
public void init()
{
delete.icon = new Image(24, 12, 12, 12);
gamemode.icons[0] = new Image(12, 12, 12, 12);
gamemode.icons[1] = new Image(36, 12, 12, 12);
gamemode.icons[2] = new Image(48, 12, 12, 12);
rain.icon = new Image(0, 12, 12, 12);
magnet.icon = new Image(60, 24, 12, 12);
timeButtons[0].icon = new Image(12, 24, 12, 12);
timeButtons[1].icon = new Image(0, 24, 12, 12);
timeButtons[2].icon = new Image(24, 24, 12, 12);
timeButtons[3].icon = new Image(36, 24, 12, 12);
heal.icon = new Image(48, 24, 12, 12);
dropDown.x = 93;
}
@Override
public void reset()
{
stateButtonCount = clickButtonCount = 0;
}
@Override
public void layoutButton(Button button)
{
int offsetx = 2;
int offsety = 2;
if((button.state & 0x4) != 0)
{
button.x = offsetx + stateButtonCount*22;
button.y = offsety;
stateButtonCount++;
}
else
{
button.x = offsetx + (clickButtonCount%4)*22;
button.y = offsety + (1+clickButtonCount/4)*17;
clickButtonCount++;
}
button.height = 14;
button.width = button.contentWidth() + 2;
if((button.state & 0x4) != 0)
button.width += stateOff.width;
}
@Override
public void drawBackground(GuiContainerManager gui)
{
if(clickButtonCount == 0 && stateButtonCount == 0)
return;
int maxx = Math.max(stateButtonCount, clickButtonCount);
if(maxx > 4)maxx = 4;
int maxy = clickButtonCount == 0 ? 1 : (clickButtonCount / 4 + 2);
drawRect(0, 0, 2+22*maxx, 1+maxy*17, 0xFF000000);
}
@Override
public void drawButton(Button b, int mousex, int mousey)
{
int cwidth = b.contentWidth();
if((b.state & 0x4) != 0)
cwidth += stateOff.width;
int textx = b.x + (b.width - cwidth) / 2;
int texty = b.y + (b.height - 8) / 2;
drawRect(b.x, b.y, b.width, b.height, b.contains(mousex, mousey) ? 0xee401008 : 0xee000000);
Image icon = b.getRenderIcon();
if(icon == null)
{
drawString(b.getRenderLabel(), textx, texty, -1);
}
else
{
int icony = b.y + (b.height - icon.height) / 2;
LayoutManager.drawIcon(textx, icony, icon);
if((b.state & 0x3) == 2)
drawRect(textx, icony, icon.width, icon.height, 0x80000000);
if((b.state & 0x4) != 0)
{
Image stateimage;
if((b.state & 0x3) == 1)
stateimage = stateOn;
else if((b.state & 0x3) == 2)
stateimage = stateDisabled;
else
stateimage = stateOff;
LayoutManager.drawIcon(textx+icon.width, icony, stateimage);
}
}
}
@Override
public boolean texturedButtons()
{
return false;
}
}
+95
View File
@@ -0,0 +1,95 @@
package codechicken.nei;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
public class NEIActions
{
public static final int protocol = 0;
public static HashMap<String, NEIActions> nameActionMap = new HashMap<String, NEIActions>();
public static HashSet<String> canDisable = new HashSet<String>();
public static void addAction(String name, String base, boolean smpreq)
{
NEIActions action = new NEIActions(name, base, smpreq);
nameActionMap.put(name, action);
}
private static void addAction(String name, String base)
{
addAction(name, base, false);
}
public static void addAction(String name)
{
addAction(name, name);
}
private static void addAction(String name, boolean smpreq)
{
addAction(name, name, smpreq);
}
public static String base(String name)
{
NEIActions action = nameActionMap.get(name);
return action == null ? name : action.base;
}
public static boolean smpRequired(String name)
{
return nameActionMap.get(name).smpreq;
}
public static void init()
{
addAction("time");
addAction("dawn", "time");
addAction("noon", "time");
addAction("dusk", "time");
addAction("midnight", "time");
addAction("creative");
addAction("creative+", true);
addAction("adventure", "creative");
addAction("rain");
addAction("item");
addAction("heal");
addAction("delete", true);
addAction("magnet", true);
addAction("enchant", true);
addAction("potion", true);
addAction("itemnbt", "item", true);
canDisable.add("dawn");
canDisable.add("noon");
canDisable.add("dusk");
canDisable.add("midnight");
canDisable.add("rain");
}
public static final String[] timeZones = new String[]{"dawn", "noon", "dusk", "midnight"};
public static final String[] gameModes = new String[]{"survival", "creative", "creative+", "adventure"};
public String name;
public String base;
public boolean smpreq;
public NEIActions(String name, String base, boolean smpreq)
{
this.name = name;
this.base = base;
this.smpreq = smpreq;
}
public static List<String> baseActions()
{
List<String> list = new LinkedList<String>();
for(NEIActions a : nameActionMap.values())
if(a.base.equals(a.name))
list.add(a.name);
return list;
}
}
+249
View File
@@ -0,0 +1,249 @@
package codechicken.nei;
import codechicken.core.ClientUtils;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.lib.packet.PacketCustom;
import codechicken.lib.packet.PacketCustom.IClientPacketHandler;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.INetHandlerPlayClient;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World;
public class NEICPH implements IClientPacketHandler
{
public static final String channel = "NEI";
@Override
public void handlePacket(PacketCustom packet, Minecraft mc, INetHandlerPlayClient netHandler) {
switch (packet.getType()) {
case 1:
handleSMPCheck(packet.readUByte(), packet.readString(), mc.theWorld);
break;
case 10:
handleLoginState(packet);
break;
case 11:
handleActionDisabled(packet);
break;
case 12:
handleActionEnabled(packet);
break;
case 13:
ClientHandler.instance().addSMPMagneticItem(packet.readInt(), mc.theWorld);
break;
case 14:
handleGamemode(mc, packet.readUByte());
break;
case 21:
ClientUtils.openSMPGui(packet.readUByte(), new GuiEnchantmentModifier(mc.thePlayer.inventory, mc.theWorld, 0, 0, 0));
break;
case 23:
if (packet.readBoolean())
ClientUtils.openSMPGui(packet.readUByte(), new GuiExtendedCreativeInv(new ContainerCreativeInv(mc.thePlayer, new ExtendedCreativeInv(null, Side.CLIENT))));
else
mc.displayGuiScreen(new GuiInventory(mc.thePlayer));
break;
case 24:
ClientUtils.openSMPGui(packet.readUByte(), new GuiPotionCreator(mc.thePlayer.inventory));
break;
}
}
private void handleGamemode(Minecraft mc, int mode) {
mc.playerController.setGameType(NEIServerUtils.getGameType(mode));
}
private void handleActionEnabled(PacketCustom packet) {
String name = packet.readString();
if (packet.readBoolean())
NEIClientConfig.enabledActions.add(name);
else
NEIClientConfig.enabledActions.remove(name);
}
private void handleActionDisabled(PacketCustom packet) {
String name = packet.readString();
if (packet.readBoolean())
NEIClientConfig.disabledActions.add(name);
else
NEIClientConfig.disabledActions.remove(name);
}
private void handleLoginState(PacketCustom packet) {
NEIClientConfig.permissableActions.clear();
int num = packet.readUByte();
for (int i = 0; i < num; i++)
NEIClientConfig.permissableActions.add(packet.readString());
NEIClientConfig.disabledActions.clear();
num = packet.readUByte();
for (int i = 0; i < num; i++)
NEIClientConfig.disabledActions.add(packet.readString());
NEIClientConfig.enabledActions.clear();
num = packet.readUByte();
for (int i = 0; i < num; i++)
NEIClientConfig.enabledActions.add(packet.readString());
NEIClientConfig.bannedBlocks.clear();
num = packet.readInt();
for(int i = 0; i < num; i++)
NEIClientConfig.bannedBlocks.add(packet.readItemStack());
if (NEIClientUtils.getGuiContainer() != null)
LayoutManager.instance().refresh(NEIClientUtils.getGuiContainer());
}
private void handleSMPCheck(int serverprotocol, String worldName, World world) {
if (serverprotocol > NEIActions.protocol) {
NEIClientUtils.printChatMessage(new ChatComponentTranslation("nei.chat.mismatch.client"));
} else if (serverprotocol < NEIActions.protocol) {
NEIClientUtils.printChatMessage(new ChatComponentTranslation("nei.chat.mismatch.server"));
} else {
try {
ClientHandler.instance().loadWorld(world, true);
NEIClientConfig.loadWorld(getSaveName(worldName));
NEIClientConfig.setHasSMPCounterPart(true);
sendRequestLoginInfo();
} catch (Exception nce) {
nce.printStackTrace();
}
}
}
private static String getSaveName(String worldName) {
if (Minecraft.getMinecraft().isSingleplayer())
return "local/" + ClientUtils.getWorldSaveName();
return "remote/" + ClientUtils.getServerIP().replace(':', '~') + "/" + worldName;
}
public static void sendGiveItem(ItemStack spawnstack, boolean infinite, boolean doSpawn) {
PacketCustom packet = new PacketCustom(channel, 1);
packet.writeItemStack(spawnstack, true);
packet.writeBoolean(infinite);
packet.writeBoolean(doSpawn);
packet.sendToServer();
}
public static void sendDeleteAllItems() {
PacketCustom packet = new PacketCustom(channel, 4);
packet.sendToServer();
}
public static void sendStateLoad(ItemStack[] state) {
sendDeleteAllItems();
for (int slot = 0; slot < state.length; slot++) {
ItemStack item = state[slot];
if (item == null) {
continue;
}
sendSetSlot(slot, item, false);
}
PacketCustom packet = new PacketCustom(channel, 11);
packet.sendToServer();
}
public static void sendSetSlot(int slot, ItemStack stack, boolean container) {
PacketCustom packet = new PacketCustom(channel, 5);
packet.writeBoolean(container);
packet.writeShort(slot);
packet.writeItemStack(stack);
packet.sendToServer();
}
private static void sendRequestLoginInfo() {
PacketCustom packet = new PacketCustom(channel, 10);
packet.sendToServer();
}
public static void sendToggleMagnetMode() {
PacketCustom packet = new PacketCustom(channel, 6);
packet.sendToServer();
}
public static void sendSetTime(int hour) {
PacketCustom packet = new PacketCustom(channel, 7);
packet.writeByte(hour);
packet.sendToServer();
}
public static void sendHeal() {
PacketCustom packet = new PacketCustom(channel, 8);
packet.sendToServer();
}
public static void sendToggleRain() {
PacketCustom packet = new PacketCustom(channel, 9);
packet.sendToServer();
}
public static void sendOpenEnchantmentWindow() {
PacketCustom packet = new PacketCustom(channel, 21);
packet.sendToServer();
}
public static void sendModifyEnchantment(int enchID, int level, boolean add) {
PacketCustom packet = new PacketCustom(channel, 22);
packet.writeByte(enchID);
packet.writeByte(level);
packet.writeBoolean(add);
packet.sendToServer();
}
public static void sendSetPropertyDisabled(String name, boolean enable) {
PacketCustom packet = new PacketCustom(channel, 12);
packet.writeString(name);
packet.writeBoolean(enable);
packet.sendToServer();
}
public static void sendGamemode(int mode) {
new PacketCustom(channel, 13)
.writeByte(mode)
.sendToServer();
}
public static void sendCreativeInv(boolean open) {
PacketCustom packet = new PacketCustom(channel, 23);
packet.writeBoolean(open);
packet.sendToServer();
}
public static void sendCreativeScroll(int steps) {
PacketCustom packet = new PacketCustom(channel, 14);
packet.writeInt(steps);
packet.sendToServer();
}
public static void sendMobSpawnerID(int x, int y, int z, String mobtype) {
PacketCustom packet = new PacketCustom(channel, 15);
packet.writeCoord(x, y, z);
packet.writeString(mobtype);
packet.sendToServer();
}
public static PacketCustom createContainerPacket() {
return new PacketCustom(channel, 20);
}
public static void sendOpenPotionWindow() {
ItemStack[] potionStore = new ItemStack[9];
InventoryUtils.readItemStacksFromTag(potionStore, NEIClientConfig.global.nbt.getCompoundTag("potionStore").getTagList("items", 10));
PacketCustom packet = new PacketCustom(channel, 24);
for (ItemStack stack : potionStore)
packet.writeItemStack(stack);
packet.sendToServer();
}
public static void sendDummySlotSet(int slotNumber, ItemStack stack) {
PacketCustom packet = new PacketCustom(channel, 25);
packet.writeShort(slotNumber);
packet.writeItemStack(stack, true);
packet.sendToServer();
}
}
@@ -0,0 +1,29 @@
package codechicken.nei;
import codechicken.nei.api.INEIGuiAdapter;
import codechicken.nei.api.TaggedInventoryArea;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.item.ItemStack;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class NEIChestGuiHandler extends INEIGuiAdapter
{
public int chestSize(GuiContainer gui) {
return ((ContainerChest) gui.inventorySlots).getLowerChestInventory().getSizeInventory();
}
@Override
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
return gui instanceof GuiChest ? NEIServerUtils.getRange(0, chestSize(gui)) : Collections.<Integer>emptyList();
}
@Override
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
return gui instanceof GuiChest ? Arrays.asList(new TaggedInventoryArea("Chest", 0, chestSize(gui), gui.inventorySlots)) : null;
}
}
+527
View File
@@ -0,0 +1,527 @@
package codechicken.nei;
import codechicken.core.*;
import codechicken.lib.config.ConfigFile;
import codechicken.lib.config.ConfigTag;
import codechicken.lib.config.ConfigTagParent;
import codechicken.nei.api.*;
import codechicken.nei.config.*;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.obfuscator.ObfuscationRun;
import net.minecraft.client.AnvilConverterException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraft.world.storage.SaveFormatComparator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
public class NEIClientConfig
{
private static boolean configLoaded;
private static boolean enabledOverride;
public static Logger logger = LogManager.getLogger("NotEnoughItems");
public static File configDir = new File(CommonUtils.getMinecraftDir(), "config/NEI/");
public static ConfigSet global = new ConfigSet(
new File("saves/NEI/client.dat"),
new ConfigFile(new File(configDir, "client.cfg")));
public static ConfigSet world;
//public static ItemVisibilityHash vishash;
public static ItemStack creativeInv[];
private static boolean statesSaved[] = new boolean[7];
public static boolean hasSMPCounterpart;
public static HashSet<String> permissableActions = new HashSet<String>();
public static HashSet<String> disabledActions = new HashSet<String>();
public static HashSet<String> enabledActions = new HashSet<String>();
public static ItemStackSet bannedBlocks = new ItemStackSet();
static {
if (global.config.getTag("checkUpdates").getBooleanValue(true))
CCUpdateChecker.updateCheck("NotEnoughItems");
linkOptionList();
setDefaults();
}
private static void setDefaults() {
ConfigTagParent tag = global.config;
tag.setComment("Main configuration of NEI.\nMost of these options can be changed ingame.\nDeleting any element will restore it to it's default value");
tag.getTag("command").useBraces().setComment("Change these options if you have a different mod installed on the server that handles the commands differently, Eg. Bukkit Essentials");
tag.setNewLineMode(1);
tag.getTag("inventory.widgetsenabled").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.widgetsenabled"));
tag.getTag("inventory.hidden").getBooleanValue(false);
tag.getTag("inventory.cheatmode").getIntValue(2);
tag.getTag("inventory.lockmode").setComment("For those who can't help themselves.\nSet this to a mode and you will be unable to change it ingame").getIntValue(-1);
API.addOption(new OptionCycled("inventory.cheatmode", 3)
{
@Override
public boolean optionValid(int index) {
return getLockedMode() == -1 || getLockedMode() == index && NEIInfo.isValidMode(index);
}
});
checkCheatMode();
tag.getTag("inventory.utilities").setDefaultValue("delete, magnet");
API.addOption(new OptionUtilities("inventory.utilities"));
tag.getTag("inventory.gamemodes").setDefaultValue("creative, creative+, adventure");
API.addOption(new OptionGamemodes("inventory.gamemodes"));
tag.getTag("inventory.layoutstyle").getIntValue(0);
API.addOption(new OptionCycled("inventory.layoutstyle", 0)
{
@Override
public String getPrefix() {
return translateN(name);
}
@Override
public String getButtonText() {
return NEIClientUtils.translate("layoutstyle." +
LayoutManager.getLayoutStyle(renderTag().getIntValue()).getName());
}
@Override
public boolean cycle() {
LinkedList<Integer> list = new LinkedList<Integer>();
for (Entry<Integer, LayoutStyle> entry : LayoutManager.layoutStyles.entrySet())
list.add(entry.getKey());
Collections.sort(list);
int nextLayout = getTag().getIntValue();
if (nextLayout == list.getLast())//loop list
nextLayout = -1;
for (Integer i : list) {
if (i > nextLayout) {
nextLayout = i;
break;
}
}
getTag().setIntValue(nextLayout);
return true;
}
});
tag.getTag("inventory.itemIDs").getIntValue(1);
API.addOption(new OptionCycled("inventory.itemIDs", 3, true));
tag.getTag("world.highlight_tips").getBooleanValue(false);
tag.getTag("world.highlight_tips.x").getIntValue(5000);
tag.getTag("world.highlight_tips.y").getIntValue(100);
API.addOption(new OptionHighlightTips("world.highlight_tips"));
tag.getTag("inventory.profileRecipes").getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.profileRecipes", true));
tag.getTag("command.creative").setDefaultValue("/gamemode {0} {1}");
API.addOption(new OptionTextField("command.creative"));
tag.getTag("command.item").setDefaultValue("/give {0} {1} {2} {3}");
API.addOption(new OptionTextField("command.item"));
tag.getTag("command.time").setDefaultValue("/time set {0}");
API.addOption(new OptionTextField("command.time"));
tag.getTag("command.rain").setDefaultValue("/toggledownfall");
API.addOption(new OptionTextField("command.rain"));
tag.getTag("command.heal").setDefaultValue("");
API.addOption(new OptionTextField("command.heal"));
setDefaultKeyBindings();
}
private static void linkOptionList() {
getOptionList().bindConfig(new IConfigSetHolder()
{
@Override
public ConfigSet worldConfigSet() {
return world;
}
@Override
public ConfigSet globalConfigSet() {
return global;
}
});
}
private static void setDefaultKeyBindings() {
API.addKeyBind("gui.recipe", Keyboard.KEY_R);
API.addKeyBind("gui.usage", Keyboard.KEY_U);
API.addKeyBind("gui.back", Keyboard.KEY_BACK);
API.addKeyBind("gui.enchant", Keyboard.KEY_X);
API.addKeyBind("gui.potion", Keyboard.KEY_P);
API.addKeyBind("gui.prev", Keyboard.KEY_PRIOR);
API.addKeyBind("gui.next", Keyboard.KEY_NEXT);
API.addKeyBind("gui.hide", Keyboard.KEY_O);
API.addKeyBind("gui.search", Keyboard.KEY_F);
API.addKeyBind("world.chunkoverlay", Keyboard.KEY_F9);
API.addKeyBind("world.moboverlay", Keyboard.KEY_F7);
API.addKeyBind("world.highlight_tips", Keyboard.KEY_NUMPAD0);
API.addKeyBind("world.dawn", 0);
API.addKeyBind("world.noon", 0);
API.addKeyBind("world.dusk", 0);
API.addKeyBind("world.midnight", 0);
API.addKeyBind("world.rain", 0);
API.addKeyBind("world.heal", 0);
API.addKeyBind("world.creative", 0);
}
public static OptionList getOptionList() {
return OptionList.getOptionList("nei.options");
}
public static void loadWorld(String saveName) {
setInternalEnabled(true);
logger.debug("Loading "+(Minecraft.getMinecraft().isSingleplayer() ? "Local" : "Remote")+" World");
bootNEI(ClientUtils.getWorld());
File saveDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + saveName);
boolean newWorld = !saveDir.exists();
if (newWorld)
saveDir.mkdirs();
world = new ConfigSet(new File(saveDir, "NEI.dat"), new ConfigFile(new File(saveDir, "NEI.cfg")));
onWorldLoad(newWorld);
}
private static void onWorldLoad(boolean newWorld) {
world.config.setComment("World based configuration of NEI.\nMost of these options can be changed ingame.\nDeleting any element will restore it to it's default value");
setWorldDefaults();
creativeInv = new ItemStack[54];
LayoutManager.searchField.setText(getSearchExpression());
LayoutManager.quantity.setText(Integer.toString(getItemQuantity()));
if (newWorld && Minecraft.getMinecraft().isSingleplayer())
world.config.getTag("inventory.cheatmode").setIntValue(NEIClientUtils.getGamemode() == 1 ? 2 : 0);
NEIInfo.load(ClientUtils.getWorld());
}
private static void setWorldDefaults() {
NBTTagCompound nbt = world.nbt;
if (!nbt.hasKey("search")) nbt.setString("search", "");
if (!nbt.hasKey("quantity")) nbt.setInteger("quantity", 0);
if (!nbt.hasKey("validateenchantments")) nbt.setBoolean("validateenchantments", false);
world.saveNBT();
}
public static int getKeyBinding(String string) {
return getSetting("keys." + string).getIntValue();
}
public static void setDefaultKeyBinding(String string, int key) {
getSetting("keys." + string).getIntValue(key);
}
public static void bootNEI(World world) {
if (configLoaded)
return;
loadStates();
//ItemVisibilityHash.loadStates();
//vishash = new ItemVisibilityHash();
ItemInfo.load(world);
GuiInfo.load();
RecipeInfo.load();
LayoutManager.load();
NEIController.load();
configLoaded = true;
ClassDiscoverer classDiscoverer = new ClassDiscoverer(new IStringMatcher()
{
public boolean matches(String test) {
return test.startsWith("NEI") && test.endsWith("Config.class");
}
}, IConfigureNEI.class);
classDiscoverer.findClasses();
for (Class<?> class1 : classDiscoverer.classes) {
try {
IConfigureNEI config = (IConfigureNEI) class1.newInstance();
config.loadConfig();
NEIModContainer.plugins.add(config);
logger.debug("Loaded " + class1.getName());
} catch (Exception e) {
logger.error("Failed to Load " + class1.getName());
e.printStackTrace();
}
}
}
public static void loadStates() {
for (int state = 0; state < 7; state++)
statesSaved[state] = !global.nbt.getCompoundTag("save" + state).hasNoTags();
}
public static boolean isWorldSpecific(String setting) {
return world != null && world.config.containsTag(setting);
}
public static boolean isStateSaved(int i) {
return statesSaved[i];
}
public static ConfigTag getSetting(String s) {
return isWorldSpecific(s) ? world.config.getTag(s) : global.config.getTag(s);
}
public static boolean getBooleanSetting(String s) {
return getSetting(s).getBooleanValue();
}
public static boolean isHidden() {
return !enabledOverride || getBooleanSetting("inventory.hidden");
}
public static boolean isEnabled() {
return enabledOverride && getBooleanSetting("inventory.widgetsenabled");
}
public static void setEnabled(boolean flag) {
getSetting("inventory.widgetsenabled").setBooleanValue(flag);
}
public static int getItemQuantity() {
return world.nbt.getInteger("quantity");
}
public static int getCheatMode() {
return getIntSetting("inventory.cheatmode");
}
private static void checkCheatMode() {
if (getLockedMode() != -1)
setIntSetting("inventory.cheatmode", getLockedMode());
}
public static int getLockedMode() {
return getIntSetting("inventory.lockmode");
}
public static int getLayoutStyle() {
return getIntSetting("inventory.layoutstyle");
}
public static String getStringSetting(String s) {
return getSetting(s).getValue();
}
public static boolean canDump() {
return getBooleanSetting("ID dump.itemIDs") || getBooleanSetting("ID dump.blockIDs") || getBooleanSetting("ID dump.unused itemIDs") || getBooleanSetting("ID dump.unused blockIDs");
}
public static boolean showIDs() {
int i = getIntSetting("inventory.itemIDs");
return i == 2 || (i == 1 && isEnabled() && !isHidden());
}
public static void toggleBooleanSetting(String setting) {
ConfigTag tag = getSetting(setting);
tag.setBooleanValue(!tag.getBooleanValue());
}
public static void cycleSetting(String setting, int max) {
ConfigTag tag = getSetting(setting);
tag.setIntValue((tag.getIntValue() + 1) % max);
}
public static int getIntSetting(String setting) {
return getSetting(setting).getIntValue();
}
public static void setIntSetting(String setting, int val) {
getSetting(setting).setIntValue(val);
}
public static String getSearchExpression() {
return world.nbt.getString("search");
}
public static void setSearchExpression(String expression) {
world.nbt.setString("search", expression);
world.saveNBT();
}
public static boolean getMagnetMode() {
return enabledActions.contains("magnet");
}
public static boolean invCreativeMode() {
return enabledActions.contains("creative+") && canPerformAction("creative+");
}
public static boolean areDamageVariantsShown() {
return hasSMPCounterPart() || getSetting("command.item").getValue().contains("{3}");
}
public static void clearState(int state) {
statesSaved[state] = false;
global.nbt.setTag("save" + state, new NBTTagCompound());
global.saveNBT();
}
public static void loadState(int state) {
if (!statesSaved[state]) {
return;
}
NBTTagCompound statesave = global.nbt.getCompoundTag("save" + state);
GuiContainer currentContainer = NEIClientUtils.getGuiContainer();
LinkedList<TaggedInventoryArea> saveAreas = new LinkedList<TaggedInventoryArea>();
saveAreas.add(new TaggedInventoryArea(NEIClientUtils.mc().thePlayer.inventory));
for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
List<TaggedInventoryArea> areaList = handler.getInventoryAreas(currentContainer);
if (areaList != null)
saveAreas.addAll(areaList);
}
for (TaggedInventoryArea area : saveAreas) {
if (!statesave.hasKey(area.tagName))
continue;
for (int slot : area.slots) {
NEIClientUtils.setSlotContents(slot, null, area.isContainer());
}
NBTTagList areaTag = statesave.getTagList(area.tagName, 10);
for (int i = 0; i < areaTag.tagCount(); i++) {
NBTTagCompound stacksave = areaTag.getCompoundTagAt(i);
int slot = stacksave.getByte("Slot") & 0xFF;
if (!area.slots.contains(slot))
continue;
NEIClientUtils.setSlotContents(slot, ItemStack.loadItemStackFromNBT(stacksave), area.isContainer());
}
}
}
public static void saveState(int state) {
NBTTagCompound statesave = global.nbt.getCompoundTag("save" + state);
GuiContainer currentContainer = NEIClientUtils.getGuiContainer();
LinkedList<TaggedInventoryArea> saveAreas = new LinkedList<TaggedInventoryArea>();
saveAreas.add(new TaggedInventoryArea(NEIClientUtils.mc().thePlayer.inventory));
for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
List<TaggedInventoryArea> areaList = handler.getInventoryAreas(currentContainer);
if (areaList != null)
saveAreas.addAll(areaList);
}
for (TaggedInventoryArea area : saveAreas) {
NBTTagList areaTag = new NBTTagList();
for (int i : area.slots) {
ItemStack stack = area.getStackInSlot(i);
if (stack == null)
continue;
NBTTagCompound stacksave = new NBTTagCompound();
stacksave.setByte("Slot", (byte) i);
stack.writeToNBT(stacksave);
areaTag.appendTag(stacksave);
}
statesave.setTag(area.tagName, areaTag);
}
global.nbt.setTag("save" + state, statesave);
global.saveNBT();
statesSaved[state] = true;
}
public static boolean hasSMPCounterPart() {
return hasSMPCounterpart;
}
public static void setHasSMPCounterPart(boolean flag) {
hasSMPCounterpart = flag;
permissableActions.clear();
bannedBlocks.clear();
disabledActions.clear();
enabledActions.clear();
}
public static boolean canPerformAction(String name) {
if (!isEnabled())
return false;
if (!modePermitsAction(name))
return false;
String base = NEIActions.base(name);
if (hasSMPCounterpart)
return permissableActions.contains(base);
if (NEIActions.smpRequired(name))
return false;
String cmd = getStringSetting("command." + base);
if (cmd == null || !cmd.startsWith("/"))
return false;
return true;
}
private static boolean modePermitsAction(String name) {
if (getCheatMode() == 0) return false;
if (getCheatMode() == 2) return true;
String[] actions = getStringArrSetting("inventory.utilities");
for (String action : actions)
if (action.equalsIgnoreCase(name))
return true;
return false;
}
public static String[] getStringArrSetting(String s) {
return getStringSetting(s).replace(" ", "").split(",");
}
public static void setInternalEnabled(boolean b) {
enabledOverride = b;
}
public static void reloadSaves() {
File saveDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/local");
if (!saveDir.exists())
return;
List<SaveFormatComparator> saves;
try {
saves = Minecraft.getMinecraft().getSaveLoader().getSaveList();
} catch (Exception e) {
e.printStackTrace();
return;
}
HashSet<String> saveFileNames = new HashSet<String>();
for (SaveFormatComparator save : saves)
saveFileNames.add(save.getFileName());
for (File file : saveDir.listFiles()) {
if (file.isDirectory() && !saveFileNames.contains(file.getName()))
ObfuscationRun.deleteDir(file, true);
}
}
}
+371
View File
@@ -0,0 +1,371 @@
package codechicken.nei;
import codechicken.lib.inventory.InventoryRange;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.nei.api.GuiInfo;
import codechicken.nei.api.IInfiniteItemHandler;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.ItemInfo;
import com.google.common.collect.Iterables;
import net.minecraft.client.Minecraft;
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.ItemStack;
import net.minecraft.util.IChatComponent;
import org.lwjgl.input.Keyboard;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.*;
import static codechicken.nei.NEIClientConfig.*;
public class NEIClientUtils extends NEIServerUtils
{
public static LangProxy lang = new LangProxy("nei");
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) {
if (mc().ingameGUI != null)
mc().ingameGUI.getChatGUI().printChatMessage(msg);
}
public static void deleteHeldItem() {
deleteSlotStack(-999);
}
public static void dropHeldItem() {
mc().playerController.windowClick(((GuiContainer) mc().currentScreen).inventorySlots.windowId, -999, 0, 0, mc().thePlayer);
}
public static void deleteSlotStack(int slotNumber) {
setSlotContents(slotNumber, null, true);
}
public static void decreaseSlotStack(int slotNumber) {
ItemStack stack = slotNumber == -999 ? getHeldItem() : mc().thePlayer.openContainer.getSlot(slotNumber).getStack();
if (stack == null)
return;
if (stack.stackSize == 1)
deleteSlotStack(slotNumber);
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);
if (slot == null)
continue;
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);
if (slot == -999)
mc().thePlayer.inventory.setItemStack(item);
}
/**
* @param typeStack
* @param button
* @param mode -1 = normal cheats, 0 = no infinites, 1 = replenish stack
*/
public static void cheatItem(ItemStack typeStack, int button, int mode) {
if (!canPerformAction("item") || typeStack.hasTagCompound() && !canPerformAction("itemnbt"))
return;
if (mode == -1 && button == 0 && NEIClientUtils.shiftKey()) {
for (IInfiniteItemHandler handler : ItemInfo.infiniteHandlers) {
if (!handler.canHandleItem(typeStack))
continue;
ItemStack stack = handler.getInfiniteItem(typeStack);
if (stack != null) {
giveStack(stack, stack.stackSize, true);
return;
}
}
cheatItem(typeStack, button, 0);
} else if (button == 1) {
giveStack(typeStack, 1);
} else {
if (mode == 1 && typeStack.stackSize < typeStack.getMaxStackSize()) {
giveStack(typeStack, typeStack.getMaxStackSize() - typeStack.stackSize);
} else {
int amount = getItemQuantity();
if (amount == 0)
amount = typeStack.getMaxStackSize();
giveStack(typeStack, amount);
}
}
}
public static void giveStack(ItemStack itemstack) {
giveStack(itemstack, itemstack.stackSize);
}
public static void giveStack(ItemStack itemstack, int i) {
giveStack(itemstack, i, false);
}
public static void giveStack(ItemStack itemstack, int i, boolean infinite) {
ItemStack itemstack1 = copyStack(itemstack, i);
if (hasSMPCounterPart()) {
ItemStack typestack = copyStack(itemstack1, 1);
if (!infinite && !canItemFitInInventory(mc().thePlayer, itemstack1) && (mc().currentScreen instanceof GuiContainer)) {
GuiContainer gui = getGuiContainer();
List<Iterable<Integer>> handlerSlots = new LinkedList<Iterable<Integer>>();
for(INEIGuiHandler handler : GuiInfo.guiHandlers)
handlerSlots.add(handler.getItemSpawnSlots(gui, typestack));
int increment = typestack.getMaxStackSize();
int given = 0;
for(int slotNo : Iterables.concat(handlerSlots)) {
Slot slot = gui.inventorySlots.getSlot(slotNo);
if(!slot.isItemValid(typestack) || !InventoryUtils.canStack(slot.getStack(), typestack))
continue;
int qty = Math.min(itemstack1.stackSize - given, increment);
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;
if(given >= itemstack1.stackSize)
break;
}
if(given > 0)
NEICPH.sendGiveItem(copyStack(typestack, given), false, false);
} else
NEICPH.sendGiveItem(itemstack1, infinite, true);
} else {
for (int given = 0; given < itemstack1.stackSize; ) {
int qty = Math.min(itemstack1.stackSize - given, itemstack1.getMaxStackSize());
sendCommand(getStringSetting("command.item"), mc().thePlayer.getCommandSenderName(), itemstack1.getItem().getUnlocalizedName(), qty, itemstack1.getItemDamage());
given += qty;
}
}
}
public static void updateUnlimitedItems() {
ItemStack itemstack = getHeldItem();
if (itemstack != null && itemstack.stackSize > 64)
itemstack.stackSize = 1;
ItemStack aitemstack[] = mc().thePlayer.inventory.mainInventory;
for (int slot = 0; slot < aitemstack.length; slot++) {
ItemStack itemstack1 = aitemstack[slot];
if (itemstack1 == null)
continue;
if (itemstack1.stackSize < 0 || itemstack1.stackSize > 64)
itemstack1.stackSize = 111;
if (itemstack1.getItemDamage() > -32000 && itemstack1.getItemDamage() < -30000)
itemstack1.setItemDamage(-32000);
}
}
public static boolean itemListContains(ItemStack test) {
for (ItemStack stack : ItemList.itemMap.get(test.getItem()))
if (areStacksIdentical(stack, test))
return true;
return false;
}
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() {
return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
}
public static int getGamemode() {
if (invCreativeMode())
return 2;
else if (mc().playerController.isInCreativeMode())
return 1;
else if (mc().playerController.currentGameType.isAdventure())
return 3;
else
return 0;
}
public static boolean isValidGamemode(String s) {
return s.equals("survival") ||
canPerformAction(s) &&
Arrays.asList(getStringArrSetting("inventory.gamemodes")).contains(s);
}
public static int getNextGamemode() {
int mode = getGamemode();
int nmode = mode;
while (true) {
nmode = (nmode + 1) % NEIActions.gameModes.length;
if (nmode == mode || isValidGamemode(NEIActions.gameModes[nmode]))
break;
}
return nmode;
}
public static void cycleGamemode() {
int mode = getGamemode();
int nmode = getNextGamemode();
if (mode == nmode)
return;
if (hasSMPCounterPart())
NEICPH.sendGamemode(nmode);
else
sendCommand(getStringSetting("command.creative"), getGameType(nmode), mc().thePlayer.getCommandSenderName());
}
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;
if (hasSMPCounterPart())
NEICPH.sendSetTime(hour);
else
sendCommand(getStringSetting("command.time"), newTime);
}
public static void sendCommand(String command, Object... args) {
if (command.length() == 0)
return;
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() {
if (hasSMPCounterPart())
NEICPH.sendToggleRain();
else
sendCommand(getStringSetting("command.rain"), isRaining() ? 0 : 1);
}
public static void healPlayer() {
if (hasSMPCounterPart())
NEICPH.sendHeal();
else
sendCommand(getStringSetting("command.heal"), mc().thePlayer.getCommandSenderName());
}
public static void toggleMagnetMode() {
if (hasSMPCounterPart())
NEICPH.sendToggleMagnetMode();
}
public static ArrayList<int[]> concatIntegersToRanges(List<Integer> damages) {
ArrayList<int[]> ranges = new ArrayList<int[]>();
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) {
ranges.add(new int[]{start, next});
start = next = i;
continue;
}
next = i;
}
ranges.add(new int[]{start, next});
return ranges;
}
public static ArrayList<int[]> addIntegersToRanges(List<int[]> ranges, List<Integer> damages) {
for (int[] range : ranges)
for (int integer = range[0]; integer <= range[1]; integer++)
damages.add(integer);
return concatIntegersToRanges(damages);
}
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);
world.saveNBT();
LayoutManager.quantity.setText(Integer.toString(i));
}
public static GuiContainer getGuiContainer() {
if (mc().currentScreen instanceof GuiContainer)
return (GuiContainer) mc().currentScreen;
return null;
}
public static boolean altKey() {
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
}
}
@@ -0,0 +1,5 @@
package codechicken.nei;
public class NEICompatibility
{
}
+271
View File
@@ -0,0 +1,271 @@
package codechicken.nei;
import codechicken.nei.api.*;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;
import codechicken.nei.guihook.IContainerSlotClickHandler;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import java.awt.*;
import java.util.LinkedList;
import static codechicken.lib.gui.GuiDraw.getMousePosition;
public class NEIController implements IContainerSlotClickHandler, IContainerInputHandler
{
private static NEIController instance = new NEIController();
public static GuiContainerManager manager;
public static FastTransferManager fastTransferManager;
private static boolean deleteMode;
private static int pickedUpFromSlot;
private static IInfiniteItemHandler heldStackInfinite;
private static int selectedItem;
public static void load() {
GuiContainerManager.addSlotClickHandler(instance);
GuiContainerManager.addInputHandler(instance);
}
public static void load(GuiContainer gui) {
manager = GuiContainerManager.getManager(gui);
deleteMode = false;
GuiInfo.clearGuiHandlers();
fastTransferManager = null;
if (!NEIClientConfig.isEnabled())
return;
fastTransferManager = new FastTransferManager();
if (gui instanceof INEIGuiHandler)
API.registerNEIGuiHandler((INEIGuiHandler) gui);
}
ItemStack firstheld;
public static void updateUnlimitedItems(InventoryPlayer inventory) {
if (!NEIClientConfig.canPerformAction("item") || !NEIClientConfig.hasSMPCounterPart())
return;
LinkedList<ItemStack> beforeStacks = new LinkedList<ItemStack>();
for (int i = 0; i < inventory.getSizeInventory(); i++)
beforeStacks.add(NEIServerUtils.copyStack(inventory.getStackInSlot(i)));
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack == null)
continue;
for (IInfiniteItemHandler handler : ItemInfo.infiniteHandlers)
if (handler.canHandleItem(stack) && handler.isItemInfinite(stack))
handler.replenishInfiniteStack(inventory, i);
}
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack newstack = inventory.getStackInSlot(i);
if (!NEIServerUtils.areStacksIdentical(beforeStacks.get(i), newstack)) {
inventory.setInventorySlotContents(i, beforeStacks.get(i));//restore in case of SMP fail
NEIClientUtils.setSlotContents(i, newstack, false);//sends via SMP handler ;)
}
}
}
public static void processCreativeCycling(InventoryPlayer inventory) {
if (NEIClientConfig.invCreativeMode() && NEIClientUtils.controlKey()) {
if (selectedItem != inventory.currentItem) {
if (inventory.currentItem == selectedItem + 1 || (inventory.currentItem == 0 && selectedItem == 8))//foward
{
NEICPH.sendCreativeScroll(1);
inventory.currentItem = selectedItem;
} else if (inventory.currentItem == selectedItem - 1 || (inventory.currentItem == 8 && selectedItem == 0)) {
NEICPH.sendCreativeScroll(-1);
inventory.currentItem = selectedItem;
}
}
}
selectedItem = inventory.currentItem;
}
@Override
public void beforeSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier) {
if (!NEIClientConfig.isEnabled())
return;
firstheld = NEIClientUtils.getHeldItem();
}
@Override
public boolean handleSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier, boolean eventconsumed) {
if (eventconsumed || !NEIClientConfig.isEnabled())
return eventconsumed;
if (deleteMode && slotIndex >= 0 && slot != null) {
if (NEIClientUtils.shiftKey() && button == 0) {
ItemStack itemstack1 = slot.getStack();
if (itemstack1 != null)
NEIClientUtils.deleteItemsOfType(itemstack1);
} else if (button == 1)
NEIClientUtils.decreaseSlotStack(slot.slotNumber);
else
NEIClientUtils.deleteSlotStack(slot.slotNumber);
return true;
}
if (button == 1 && slot instanceof SlotCrafting)//right click
{
for (int i1 = 0; i1 < 64; i1++)//click this slot 64 times
manager.handleSlotClick(slot.slotNumber, button, 0);
return true;
}
if (slotIndex >= 0 && NEIClientUtils.shiftKey() && NEIClientUtils.getHeldItem() != null && !slot.getHasStack()) {
ItemStack held = NEIClientUtils.getHeldItem();
manager.handleSlotClick(slot.slotNumber, button, 0);
if (slot.isItemValid(held) && !ItemInfo.fastTransferExemptions.contains(slot.getClass()))
fastTransferManager.performMassTransfer(gui, pickedUpFromSlot, slotIndex, held);
return true;
}
if (NEIClientUtils.controlKey()
&& slot != null && slot.getStack() != null
&& NEIClientConfig.canPerformAction("item")
&& slot.isItemValid(slot.getStack())) {
NEIClientUtils.cheatItem(slot.getStack(), button, 1);
return true;
}
if (slotIndex == -999 && NEIClientUtils.shiftKey() && button == 0) {
fastTransferManager.throwAll(gui, pickedUpFromSlot);
return true;
}
return false;
}
@Override
public void afterSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier) {
if (!NEIClientConfig.isEnabled())
return;
ItemStack nowHeld = NEIClientUtils.getHeldItem();
if (firstheld != nowHeld)
pickedUpFromSlot = slotIndex;
if (NEIClientConfig.canPerformAction("item") && NEIClientConfig.hasSMPCounterPart()) {
if (heldStackInfinite != null && slot != null && slot.inventory == NEIClientUtils.mc().thePlayer.inventory) {
ItemStack stack = slot.getStack();
if (stack != null) {
heldStackInfinite.onPlaceInfinite(stack);
}
NEIClientUtils.setSlotContents(slotIndex, stack, true);
}
if (firstheld != nowHeld)
heldStackInfinite = null;
if (firstheld != nowHeld && nowHeld != null) {
for (IInfiniteItemHandler handler : ItemInfo.infiniteHandlers) {
if (handler.canHandleItem(nowHeld) && handler.isItemInfinite(nowHeld)) {
handler.onPickup(nowHeld);
NEIClientUtils.setSlotContents(-999, nowHeld, true);
heldStackInfinite = handler;
break;
}
}
}
}
}
@Override
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
if (!NEIClientConfig.isEnabled())
return false;
Slot slot = GuiContainerManager.getSlotMouseOver(gui);
if (slot == null)
return false;
int slotIndex = slot.slotNumber;
if (keyCode == NEIClientUtils.mc().gameSettings.keyBindDrop.getKeyCode() && NEIClientUtils.shiftKey()) {
FastTransferManager.clickSlot(gui, slotIndex);
fastTransferManager.throwAll(gui, slotIndex);
FastTransferManager.clickSlot(gui, slotIndex);
return true;
}
return false;
}
@Override
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
if (!NEIClientConfig.isEnabled())
return false;
Point mousePos = getMousePosition();
Slot mouseover = manager.window.getSlotAtPosition(mousePos.x, mousePos.y);
if (mouseover != null && mouseover.getHasStack()) {
if (scrolled > 0)
fastTransferManager.transferItem(manager.window, mouseover.slotNumber);
else
fastTransferManager.retrieveItem(manager.window, mouseover.slotNumber);
return true;
}
return false;
}
@Override
public boolean keyTyped(GuiContainer gui, char keyChar, int keyCode) {
return false;
}
@Override
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
return false;
}
@Override
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {
}
@Override
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
}
@Override
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {
}
@Override
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
}
@Override
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {
}
public static boolean canUseDeleteMode() {
return !(NEIClientUtils.getGuiContainer() instanceof GuiContainerCreative);
}
public static void toggleDeleteMode() {
if(canUseDeleteMode())
deleteMode = !deleteMode;
}
public static boolean getDeleteMode() {
return deleteMode;
}
}
@@ -0,0 +1,22 @@
package codechicken.nei;
import codechicken.nei.api.INEIGuiAdapter;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.creativetab.CreativeTabs;
public class NEICreativeGuiHandler extends INEIGuiAdapter
{
@Override
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility)
{
if(!(gui instanceof GuiContainerCreative))
return currentVisibility;
if(((GuiContainerCreative)gui).func_147056_g() != CreativeTabs.tabInventory.getTabIndex())
currentVisibility.showItemSection = currentVisibility.enableDeleteMode = false;
return currentVisibility;
}
}
@@ -0,0 +1,24 @@
package codechicken.nei;
import codechicken.core.inventory.ContainerExtended;
import codechicken.core.inventory.SlotDummy;
import codechicken.nei.api.INEIGuiAdapter;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class NEIDummySlotHandler extends INEIGuiAdapter
{
@Override
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button)
{
Slot slot = gui.getSlotAtPosition(mousex, mousey);
if(slot instanceof SlotDummy && slot.isItemValid(draggedStack) && gui.inventorySlots instanceof ContainerExtended)
{
((SlotDummy)slot).slotClick(draggedStack, button, NEIClientUtils.shiftKey());
NEICPH.sendDummySlotSet(slot.slotNumber, slot.getStack());
return true;
}
return false;
}
}
+94
View File
@@ -0,0 +1,94 @@
package codechicken.nei;
import codechicken.core.CommonUtils;
import codechicken.core.launch.CodeChickenCorePlugin;
import codechicken.nei.api.IConfigureNEI;
import codechicken.nei.asm.NEICorePlugin;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import cpw.mods.fml.client.FMLFileResourcePack;
import cpw.mods.fml.client.FMLFolderResourcePack;
import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.LoadController;
import cpw.mods.fml.common.MetadataCollection;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.versioning.ArtifactVersion;
import cpw.mods.fml.common.versioning.VersionParser;
import cpw.mods.fml.common.versioning.VersionRange;
import net.minecraft.util.EnumChatFormatting;
import java.io.File;
import java.util.*;
public class NEIModContainer extends DummyModContainer
{
public static LinkedList<IConfigureNEI> plugins = new LinkedList<IConfigureNEI>();
public NEIModContainer() {
super(MetadataCollection.from(MetadataCollection.class.getResourceAsStream("/neimod.info"), "NotEnoughItems").getMetadataForId("NotEnoughItems", null));
getMetadata();
}
@Override
public Set<ArtifactVersion> getRequirements() {
Set<ArtifactVersion> deps = new HashSet<ArtifactVersion>();
deps.add(VersionParser.parseVersionReference("CodeChickenCore@[0,)"));
return deps;
}
@Override
public List<ArtifactVersion> getDependencies() {
return new LinkedList<ArtifactVersion>(getRequirements());
}
@Override
public ModMetadata getMetadata() {
ModMetadata meta = super.getMetadata();
meta.description = "Recipe Viewer, Inventory Manager, Item Spawner, Cheats and more.\n"+ EnumChatFormatting.WHITE+"\n";
if (plugins.size() == 0) {
meta.description += EnumChatFormatting.RED+"No installed plugins.";
} else {
meta.description += EnumChatFormatting.GREEN+"Installed plugins: ";
for (int i = 0; i < plugins.size(); i++) {
if (i > 0)
meta.description += ", ";
IConfigureNEI plugin = plugins.get(i);
meta.description += plugin.getName() + " " + plugin.getVersion();
}
meta.description += ".";
}
return meta;
}
@Override
public boolean registerBus(EventBus bus, LoadController controller) {
bus.register(this);
return true;
}
@Subscribe
public void init(FMLInitializationEvent event) {
if (CommonUtils.isClient())
ClientHandler.load();
ServerHandler.load();
}
@Override
public VersionRange acceptableMinecraftVersionRange() {
return VersionParser.parseRange(CodeChickenCorePlugin.mcVersion);
}
/*@Override
public File getSource() {
return NEICorePlugin.location;
}
@Override
public Class<?> getCustomResourcePackClass() {
return getSource().isDirectory() ? FMLFolderResourcePack.class : FMLFileResourcePack.class;
}*/
}
+264
View File
@@ -0,0 +1,264 @@
package codechicken.nei;
import codechicken.core.CommonUtils;
import codechicken.core.IGuiPacketSender;
import codechicken.core.ServerUtils;
import codechicken.core.inventory.ContainerExtended;
import codechicken.core.inventory.SlotDummy;
import codechicken.lib.packet.PacketCustom;
import codechicken.lib.packet.PacketCustom.IServerPacketHandler;
import codechicken.lib.vec.BlockCoord;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.INetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.world.World;
import java.util.LinkedList;
import java.util.Set;
public class NEISPH implements IServerPacketHandler
{
@Override
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer netHandler) {
if (!NEIServerConfig.authenticatePacket(sender, packet))
return;
switch (packet.getType()) {
case 1:
handleGiveItem(sender, packet);
break;
case 4:
NEIServerUtils.deleteAllItems(sender);
break;
case 5:
setInventorySlot(sender, packet);
break;
case 6:
NEIServerUtils.toggleMagnetMode(sender);
break;
case 7:
NEIServerUtils.setHourForward(sender.worldObj, packet.readUByte(), true);
break;
case 8:
NEIServerUtils.healPlayer(sender);
break;
case 9:
NEIServerUtils.toggleRaining(sender.worldObj, true);
break;
case 10:
sendLoginState(sender);
break;
case 11:
sender.sendContainerAndContentsToPlayer(sender.openContainer, sender.openContainer.getInventory());
break;
case 12:
handlePropertyChange(sender, packet);
break;
case 13:
NEIServerUtils.setGamemode(sender, packet.readUByte());
break;
case 14:
NEIServerUtils.cycleCreativeInv(sender, packet.readInt());
break;
case 15:
handleMobSpawnerID(sender.worldObj, packet.readCoord(), packet.readString());
break;
case 20:
handleContainerPacket(sender, packet);
break;
case 21:
openEnchantmentGui(sender);
break;
case 22:
modifyEnchantment(sender, packet.readUByte(), packet.readUByte(), packet.readBoolean());
break;
case 23:
processCreativeInv(sender, packet.readBoolean());
break;
case 24:
openPotionGui(sender, packet);
break;
case 25:
handleDummySlotSet(sender, packet);
break;
}
}
private void handleDummySlotSet(EntityPlayerMP sender, PacketCustom packet) {
int slotNumber = packet.readShort();
ItemStack stack = packet.readItemStack(true);
Slot slot = sender.openContainer.getSlot(slotNumber);
if (slot instanceof SlotDummy)
slot.putStack(stack);
}
private void handleContainerPacket(EntityPlayerMP sender, PacketCustom packet) {
if (sender.openContainer instanceof ContainerExtended)
((ContainerExtended) sender.openContainer).handleInputPacket(packet);
}
private void handleMobSpawnerID(World world, BlockCoord coord, String mobtype) {
TileEntity tile = world.getTileEntity(coord.x, coord.y, coord.z);
if (tile instanceof TileEntityMobSpawner) {
((TileEntityMobSpawner) tile).func_145881_a().setEntityName(mobtype);
tile.markDirty();
world.markBlockForUpdate(coord.x, coord.y, coord.z);
}
}
private void handlePropertyChange(EntityPlayerMP sender, PacketCustom packet) {
String name = packet.readString();
if (NEIServerConfig.canPlayerPerformAction(sender.getCommandSenderName(), name))
NEIServerConfig.disableAction(sender.dimension, name, packet.readBoolean());
}
private void processCreativeInv(EntityPlayerMP sender, boolean open) {
if (open) {
ServerUtils.openSMPContainer(sender, new ContainerCreativeInv(sender, new ExtendedCreativeInv(NEIServerConfig.forPlayer(sender.getCommandSenderName()), Side.SERVER)), new IGuiPacketSender()
{
@Override
public void sendPacket(EntityPlayerMP player, int windowId) {
PacketCustom packet = new PacketCustom(channel, 23);
packet.writeBoolean(true);
packet.writeByte(windowId);
packet.sendToPlayer(player);
}
});
} else {
sender.closeContainer();
PacketCustom packet = new PacketCustom(channel, 23);
packet.writeBoolean(false);
packet.sendToPlayer(sender);
}
}
private void handleGiveItem(EntityPlayerMP player, PacketCustom packet) {
NEIServerUtils.givePlayerItem(player, packet.readItemStack(true), packet.readBoolean(), packet.readBoolean());
}
private void setInventorySlot(EntityPlayerMP player, PacketCustom packet) {
boolean container = packet.readBoolean();
int slot = packet.readShort();
ItemStack item = packet.readItemStack();
ItemStack old = NEIServerUtils.getSlotContents(player, slot, container);
boolean deleting = item == null || old != null && NEIServerUtils.areStacksSameType(item, old) && item.stackSize < old.stackSize;
if (NEIServerConfig.canPlayerPerformAction(player.getCommandSenderName(), deleting ? "delete" : "item"))
NEIServerUtils.setSlotContents(player, slot, item, container);
}
private void modifyEnchantment(EntityPlayerMP player, int e, int lvl, boolean add) {
ContainerEnchantmentModifier containerem = (ContainerEnchantmentModifier) player.openContainer;
if (add) {
containerem.addEnchantment(e, lvl);
} else {
containerem.removeEnchantment(e);
}
}
private void openEnchantmentGui(EntityPlayerMP player) {
ServerUtils.openSMPContainer(player, new ContainerEnchantmentModifier(player.inventory, player.worldObj, 0, 0, 0), new IGuiPacketSender()
{
@Override
public void sendPacket(EntityPlayerMP player, int windowId) {
PacketCustom packet = new PacketCustom(channel, 21);
packet.writeByte(windowId);
packet.sendToPlayer(player);
}
});
}
private void openPotionGui(EntityPlayerMP player, PacketCustom packet) {
InventoryBasic b = new InventoryBasic("potionStore", true, 9);
for (int i = 0; i < b.getSizeInventory(); i++)
b.setInventorySlotContents(i, packet.readItemStack());
ServerUtils.openSMPContainer(player, new ContainerPotionCreator(player.inventory, b), new IGuiPacketSender()
{
@Override
public void sendPacket(EntityPlayerMP player, int windowId) {
PacketCustom packet = new PacketCustom(channel, 24);
packet.writeByte(windowId);
packet.sendToPlayer(player);
}
});
}
public static void sendActionDisabled(int dim, String name, boolean disable) {
new PacketCustom(channel, 11)
.writeString(name)
.writeBoolean(disable)
.sendToDimension(dim);
}
public static void sendActionEnabled(EntityPlayerMP player, String name, boolean enable) {
new PacketCustom(channel, 12)
.writeString(name)
.writeBoolean(enable)
.sendToPlayer(player);
}
private void sendLoginState(EntityPlayerMP player) {
LinkedList<String> actions = new LinkedList<String>();
LinkedList<String> disabled = new LinkedList<String>();
LinkedList<String> enabled = new LinkedList<String>();
LinkedList<ItemStack> bannedItems = new LinkedList<ItemStack>();
PlayerSave playerSave = NEIServerConfig.forPlayer(player.getCommandSenderName());
for (String name : NEIActions.nameActionMap.keySet()) {
if (NEIServerConfig.canPlayerPerformAction(player.getCommandSenderName(), name))
actions.add(name);
if (NEIServerConfig.isActionDisabled(player.dimension, name))
disabled.add(name);
if (playerSave.isActionEnabled(name))
enabled.add(name);
}
for (ItemStackMap.Entry<Set<String>> entry : NEIServerConfig.bannedItems.entries())
if (!NEIServerConfig.isPlayerInList(player.getCommandSenderName(), entry.value, true))
bannedItems.add(entry.key);
PacketCustom packet = new PacketCustom(channel, 10);
packet.writeByte(actions.size());
for (String s : actions)
packet.writeString(s);
packet.writeByte(disabled.size());
for (String s : disabled)
packet.writeString(s);
packet.writeByte(enabled.size());
for (String s : enabled)
packet.writeString(s);
packet.writeInt(bannedItems.size());
for (ItemStack stack : bannedItems)
packet.writeItemStack(stack);
packet.sendToPlayer(player);
}
public static void sendHasServerSideTo(EntityPlayerMP player) {
NEIServerConfig.logger.debug("Sending serverside check to: " + player.getCommandSenderName());
PacketCustom packet = new PacketCustom(channel, 1);
packet.writeByte(NEIActions.protocol);
packet.writeString(CommonUtils.getWorldName(player.worldObj));
packet.sendToPlayer(player);
}
public static void sendAddMagneticItemTo(EntityPlayerMP player, EntityItem item) {
PacketCustom packet = new PacketCustom(channel, 13);
packet.writeInt(item.getEntityId());
packet.sendToPlayer(player);
}
public static final String channel = "NEI";
}
+285
View File
@@ -0,0 +1,285 @@
package codechicken.nei;
import codechicken.core.CommonUtils;
import codechicken.core.ServerUtils;
import codechicken.lib.config.ConfigFile;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.lib.packet.PacketCustom;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.*;
public class NEIServerConfig
{
private static MinecraftServer server;
public static Logger logger = LogManager.getLogger("NotEnoughItems");
public static File saveDir;
public static ConfigFile serverConfig;
public static Map<Integer, NBTTagCompound> dimTags = new HashMap<Integer, NBTTagCompound>();
public static HashMap<String, PlayerSave> playerSaves = new HashMap<String, PlayerSave>();
public static ItemStackMap<Set<String>> bannedItems = new ItemStackMap<Set<String>>();
public static void load(World world) {
if (MinecraftServer.getServer() != server) {
logger.debug("Loading NEI Server");
server = MinecraftServer.getServer();
saveDir = new File(DimensionManager.getCurrentSaveRootDirectory(), "NEI");
dimTags.clear();
loadConfig();
loadBannedItems();
}
loadWorld(world);
}
public static File getSaveDir(int dim) {
return new File(CommonUtils.getSaveLocation(dim), "NEI");
}
private static void loadWorld(World world) {
try {
File file = new File(getSaveDir(CommonUtils.getDimension(world)), "world.dat");
NBTTagCompound tag = CompressedStreamTools.read(file);
if(tag == null)
tag = new NBTTagCompound();
dimTags.put(CommonUtils.getDimension(world), tag);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static void loadConfig() {
File file = new File(saveDir, "server.cfg");
serverConfig = new ConfigFile(file);
serverConfig.setNewLineMode(1);
serverConfig.getTag("permissions").useBraces();
serverConfig.getTag("permissions").setComment("List of players who can use these features.\nEg. time=CodeChicken, Friend1");
setDefaultFeature("time");
setDefaultFeature("rain");
setDefaultFeature("heal");
setDefaultFeature("magnet");
setDefaultFeature("creative");
setDefaultFeature("creative+");
setDefaultFeature("adventure");
setDefaultFeature("enchant");
setDefaultFeature("potion");
setDefaultFeature("save-state");
setDefaultFeature("item");
setDefaultFeature("delete");
setDefaultFeature("notify-item", "CONSOLE, OP");
}
private static void setDefaultFeature(String featurename, String... names) {
if (names.length == 0)
names = new String[]{"OP"};
String list = "";
for (int i = 0; i < names.length; i++) {
if (i >= 1)
list += ", ";
list += names[i];
}
serverConfig.getTag("permissions." + featurename).setDefaultValue(list);
}
private static void saveWorld(int dim) {
try {
File file = new File(getSaveDir(dim), "world.dat");
CompressedStreamTools.write(dimTags.get(dim), file);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static boolean canPlayerPerformAction(String playername, String name) {
return isPlayerInList(playername, getPlayerList("permissions." + NEIActions.base(name)), true);
}
public static boolean isPlayerInList(String playername, Set<String> list, boolean allowCards) {
if (playername.equals("CONSOLE"))
return list.contains(playername);
playername = playername.toLowerCase();
if (allowCards) {
if (list.contains("ALL"))
return true;
if ((ServerUtils.isPlayerOP(playername) || ServerUtils.isPlayerOwner(playername)) && list.contains("OP"))
return true;
}
return list.contains(playername);
}
public static boolean isActionDisabled(int dim, String name) {
return dimTags.get(dim).getBoolean("disabled" + name);
}
public static void disableAction(int dim, String name, boolean disable) {
dimTags.get(dim).setBoolean("disabled" + name, disable);
NEISPH.sendActionDisabled(dim, name, disable);
saveWorld(dim);
}
public static HashSet<String> getPlayerList(String tag) {
String[] list = serverConfig.getTag(tag).getValue("").replace(" ", "").split(",");
return new HashSet<String>(Arrays.asList(list));
}
public static void addPlayerToList(String playername, String tag) {
HashSet<String> list = getPlayerList(tag);
if (!playername.equals("CONSOLE") && !playername.equals("ALL") && !playername.equals("OP"))
playername = playername.toLowerCase();
list.add(playername);
savePlayerList(tag, list);
}
public static void remPlayerFromList(String playername, String tag) {
HashSet<String> list = getPlayerList(tag);
if (!playername.equals("CONSOLE") && !playername.equals("ALL") && !playername.equals("OP"))
playername = playername.toLowerCase();
list.remove(playername);
savePlayerList(tag, list);
}
private static void savePlayerList(String tag, Collection<String> list) {
StringBuilder sb = new StringBuilder();
int i = 0;
for (Iterator<String> iterator = list.iterator(); iterator.hasNext(); i++) {
if (i != 0)
sb.append(", ");
sb.append(iterator.next());
}
serverConfig.getTag(tag).setValue(sb.toString());
}
private static void loadBannedItems() {
bannedItems.clear();
File file = new File(saveDir, "banneditems.cfg");
if(!file.exists()) {
bannedItems.put(new ItemStack(Blocks.bedrock), new HashSet<String>(Arrays.asList("NONE")));
saveBannedItems();
return;
}
try {
FileReader r = new FileReader(file);
int line = 0;
for(String s : IOUtils.readLines(r)) {
if(s.charAt(0) == '#' || s.trim().length() == 0)
continue;
int delim = s.lastIndexOf('=');
if(delim < 0) {
System.err.println("line "+line+": Missing =");
continue;
}
try {
NBTTagCompound key = (NBTTagCompound) JsonToNBT.func_150315_a(s.substring(0, delim));
Set<String> values = new HashSet<String>();
for(String s2 : s.substring(delim+1).split(","))
values.add(s2.trim());
bannedItems.put(InventoryUtils.loadPersistant(key), values);
} catch (Exception e) {
System.err.println("line "+line+": "+e.getMessage());
}
}
r.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void saveBannedItems() {
File file = new File(saveDir, "banneditems.cfg");
try {
if(!file.exists())
file.createNewFile();
PrintWriter p = new PrintWriter(file);
p.println("#Saved in this format for external editing. The format isn't that hard to figure out. If you think you're up to it, modify it here!");
for (ItemStackMap.Entry<Set<String>> entry : bannedItems.entries()) {
NBTTagCompound key = InventoryUtils.savePersistant(entry.key, new NBTTagCompound());
key.removeTag("Count");
if(key.getByte("Damage") == 0) key.removeTag("Damage");
p.print(key.toString());
p.print("=[");
int i = 0;
for (String s : entry.value) {
if(i++ != 0) p.print(", ");
p.print(s);
}
p.println("]");
}
p.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static PlayerSave forPlayer(String username) {
return playerSaves.get(username);
}
public static void loadPlayer(EntityPlayer player) {
logger.debug("Loading Player: " + player.getGameProfile().getName());
playerSaves.put(player.getCommandSenderName(), new PlayerSave(player.getCommandSenderName(), new File(saveDir, "players")));
}
public static void unloadPlayer(EntityPlayer player) {
logger.debug("Unloading Player: " + player.getCommandSenderName());
PlayerSave playerSave = playerSaves.remove(player.getCommandSenderName());
if (playerSave != null)
playerSave.save();
}
public static boolean authenticatePacket(EntityPlayerMP sender, PacketCustom packet) {
switch (packet.getType()) {
case 1:
return canPlayerPerformAction(sender.getCommandSenderName(), "item");
case 4:
return canPlayerPerformAction(sender.getCommandSenderName(), "delete");
case 6:
return canPlayerPerformAction(sender.getCommandSenderName(), "magnet");
case 7:
return canPlayerPerformAction(sender.getCommandSenderName(), "time");
case 8:
return canPlayerPerformAction(sender.getCommandSenderName(), "heal");
case 9:
return canPlayerPerformAction(sender.getCommandSenderName(), "rain");
case 14:
case 23:
return canPlayerPerformAction(sender.getCommandSenderName(), "creative+");
case 21:
case 22:
return canPlayerPerformAction(sender.getCommandSenderName(), "enchant");
case 24:
return canPlayerPerformAction(sender.getCommandSenderName(), "potion");
}
return true;
}
}
+363
View File
@@ -0,0 +1,363 @@
package codechicken.nei;
import codechicken.core.CommonUtils;
import codechicken.core.ServerUtils;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.lib.packet.PacketCustom;
import net.minecraft.command.ICommandSender;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.oredict.OreDictionary;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
public class NEIServerUtils
{
public static boolean isRaining(World world) {
return world.getWorldInfo().isRaining();
}
public static void toggleRaining(World world, boolean notify) {
boolean raining = !world.isRaining();
if (!raining)//turn off
((WorldServer) world).provider.resetRainAndThunder();
else
world.getWorldInfo().setRaining(!isRaining(world));
if (notify)
ServerUtils.sendChatToAll(new ChatComponentTranslation("nei.chat.rain." + (raining ? "on" : "off")));
}
public static void healPlayer(EntityPlayer player) {
player.heal(20);
player.getFoodStats().addStats(20, 1);
player.extinguish();
}
public static long getTime(World world) {
return world.getWorldInfo().getWorldTime();
}
public static void setTime(long l, World world) {
world.getWorldInfo().setWorldTime(l);
}
public static void setSlotContents(EntityPlayer player, int slot, ItemStack item, boolean containerInv) {
if (slot == -999)
player.inventory.setItemStack(item);
else if (containerInv)
player.openContainer.putStackInSlot(slot, item);
else
player.inventory.setInventorySlotContents(slot, item);
}
public static ItemStack getSlotContents(EntityPlayer player, int slot, boolean containerInv) {
if (slot == -999)
return player.inventory.getItemStack();
else if (containerInv)
return player.openContainer.getSlot(slot).getStack();
else
return player.inventory.getStackInSlot(slot);
}
@SuppressWarnings("unchecked")
public static void deleteAllItems(EntityPlayerMP player) {
for (Slot slot : (List<Slot>) player.openContainer.inventorySlots)
slot.putStack(null);
player.sendContainerAndContentsToPlayer(player.openContainer, player.openContainer.getInventory());
}
public static void setHourForward(World world, int hour, boolean notify) {
long day = (getTime(world) / 24000L) * 24000L;
long newTime = day + 24000L + hour * 1000;
setTime(newTime, world);
if (notify)
ServerUtils.sendChatToAll(new ChatComponentTranslation("nei.chat.time", getTime(world) / 24000L, hour));
}
public static void advanceDisabledTimes(World world) {
int dim = CommonUtils.getDimension(world);
int hour = (int) (getTime(world) % 24000) / 1000;
int newhour = hour;
while (NEIServerConfig.isActionDisabled(dim, NEIActions.timeZones[newhour / 6]))
newhour = ((newhour / 6 + 1) % 4) * 6;
if (newhour != hour)
setHourForward(world, newhour, false);
}
public static boolean canItemFitInInventory(EntityPlayer player, ItemStack itemstack) {
return InventoryUtils.insertItem(player.inventory, itemstack, true) == 0;
}
public static void sendNotice(ICommandSender sender, IChatComponent msg, String permission) {
ChatComponentTranslation notice = new ChatComponentTranslation("chat.type.admin", sender.getCommandSenderName(), msg.createCopy());
notice.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true);
if (NEIServerConfig.canPlayerPerformAction("CONSOLE", permission))
MinecraftServer.getServer().addChatMessage(notice);
for (EntityPlayer p : ServerUtils.getPlayers())
if(p == sender)
p.addChatComponentMessage(msg);
else if (NEIServerConfig.canPlayerPerformAction(p.getCommandSenderName(), permission))
p.addChatComponentMessage(notice);
}
/**
* @param stack1 The {@link ItemStack} being compared.
* @param stack2 The {@link ItemStack} to compare to.
* @return whether the two items are the same in terms of damage and itemID.
*/
public static boolean areStacksSameType(ItemStack stack1, ItemStack stack2) {
if (stack1 == null || stack2 == null)
return stack1 == stack2;
return InventoryUtils.canStack(stack1, stack2);
}
/**
* {@link ItemStack}s with damage -1 are wildcards allowing all damages. Eg all colours of wool are allowed to create Beds.
*
* @param stack1 The {@link ItemStack} being compared.
* @param stack2 The {@link ItemStack} to compare to.
* @return whether the two items are the same from the perspective of a crafting inventory.
*/
public static boolean areStacksSameTypeCrafting(ItemStack stack1, ItemStack stack2) {
if (stack1 == null || stack2 == null)
return false;
return stack1.getItem() == stack2.getItem() &&
(stack1.getItemDamage() == stack2.getItemDamage() || stack1.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack2.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack1.getItem().isDamageable());
}
/**
* A simple function for comparing ItemStacks in a compatible with comparators.
*
* @param stack1 The {@link ItemStack} being compared.
* @param stack2 The {@link ItemStack} to compare to.
* @return The ordering of stack1 relative to stack2.
*/
public static int compareStacks(ItemStack stack1, ItemStack stack2) {
if (stack1 == stack2) return 0;//catches both null
if (stack1 == null || stack2 == null) return stack1 == null ? -1 : 1;//null stack goes first
if (stack1.getItem() != stack2.getItem()) return Item.getIdFromItem(stack1.getItem()) - Item.getIdFromItem(stack2.getItem());
if (stack1.stackSize != stack2.stackSize) return stack1.stackSize - stack2.stackSize;
return stack1.getItemDamage() - stack2.getItemDamage();
}
public static boolean areStacksIdentical(ItemStack stack1, ItemStack stack2) {
return compareStacks(stack1, stack2) == 0;
}
public static IChatComponent setColour(IChatComponent msg, EnumChatFormatting colour) {
msg.getChatStyle().setColor(colour);
return msg;
}
public static void givePlayerItem(EntityPlayerMP player, ItemStack stack, boolean infinite, boolean doGive) {
if (stack.getItem() == null) {
player.addChatComponentMessage(setColour(new ChatComponentTranslation("nei.chat.give.noitem"), EnumChatFormatting.WHITE));
return;
}
int given = stack.stackSize;
if(doGive) {
if (infinite)
player.inventory.addItemStackToInventory(stack);
else
given -= InventoryUtils.insertItem(player.inventory, stack, false);
}
sendNotice(player, new ChatComponentTranslation("commands.give.success", stack.func_151000_E(), infinite ? "\u221E" : Integer.toString(given), player.getCommandSenderName()), "notify-item");
player.openContainer.detectAndSendChanges();
}
public static ItemStack copyStack(ItemStack itemstack, int i) {
if (itemstack == null)
return null;
itemstack.stackSize += i;
return itemstack.splitStack(i);
}
public static ItemStack copyStack(ItemStack itemstack) {
if (itemstack == null)
return null;
return copyStack(itemstack, itemstack.stackSize);
}
public static void toggleMagnetMode(EntityPlayerMP player) {
PlayerSave playerSave = NEIServerConfig.forPlayer(player.getCommandSenderName());
playerSave.enableAction("magnet", !playerSave.isActionEnabled("magnet"));
}
public static int getCreativeMode(EntityPlayerMP player) {
if (NEIServerConfig.forPlayer(player.getCommandSenderName()).isActionEnabled("creative+"))
return 2;
else if (player.theItemInWorldManager.isCreative())
return 1;
else if (player.theItemInWorldManager.getGameType().isAdventure())
return 3;
else
return 0;
}
public static GameType getGameType(int mode) {
switch (mode) {
case 0:
return GameType.SURVIVAL;
case 1:
case 2:
return GameType.CREATIVE;
case 3:
return GameType.ADVENTURE;
}
return null;
}
public static void setGamemode(EntityPlayerMP player, int mode) {
if (mode < 0 || mode >= NEIActions.gameModes.length ||
NEIActions.nameActionMap.containsKey(NEIActions.gameModes[mode]) &&
!NEIServerConfig.canPlayerPerformAction(player.getCommandSenderName(), NEIActions.gameModes[mode]))
return;
//change it on the server
player.theItemInWorldManager.setGameType(getGameType(mode));
NEIServerConfig.forPlayer(player.getCommandSenderName()).enableAction("creative+", mode == 2);
//tell the client to change it
new PacketCustom(NEISPH.channel, 14).writeByte(mode).sendToPlayer(player);
player.addChatMessage(new ChatComponentTranslation("nei.chat.gamemode." + mode));
}
public static void cycleCreativeInv(EntityPlayerMP player, int steps) {
InventoryPlayer inventory = player.inventory;
//top down [row][col]
ItemStack[][] slots = new ItemStack[10][9];
PlayerSave playerSave = NEIServerConfig.forPlayer(player.getCommandSenderName());
//get
System.arraycopy(inventory.mainInventory, 0, slots[9], 0, 9);
for (int row = 0; row < 3; row++)
System.arraycopy(inventory.mainInventory, (row + 1) * 9, slots[row + 6], 0, 9);
for (int row = 0; row < 6; row++)
System.arraycopy(playerSave.creativeInv, row * 9, slots[row], 0, 9);
ItemStack[][] newslots = new ItemStack[10][];
//put back
for (int row = 0; row < 10; row++)
newslots[(row + steps + 10) % 10] = slots[row];
System.arraycopy(newslots[9], 0, inventory.mainInventory, 0, 9);
for (int row = 0; row < 3; row++)
System.arraycopy(newslots[row + 6], 0, inventory.mainInventory, (row + 1) * 9, 9);
for (int row = 0; row < 6; row++)
System.arraycopy(newslots[row], 0, playerSave.creativeInv, row * 9, 9);
playerSave.setDirty();
}
public static List<int[]> getEnchantments(ItemStack itemstack) {
ArrayList<int[]> arraylist = new ArrayList<int[]>();
if (itemstack != null) {
NBTTagList nbttaglist = itemstack.getEnchantmentTagList();
if (nbttaglist != null)
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound tag = nbttaglist.getCompoundTagAt(i);
arraylist.add(new int[]{tag.getShort("id"), tag.getShort("lvl")});
}
}
return arraylist;
}
public static boolean stackHasEnchantment(ItemStack itemstack, int e) {
List<int[]> allenchantments = getEnchantments(itemstack);
for (int[] ai : allenchantments)
if (ai[0] == e)
return true;
return false;
}
public static int getEnchantmentLevel(ItemStack itemstack, int e) {
List<int[]> allenchantments = getEnchantments(itemstack);
for (int[] ai : allenchantments)
if (ai[0] == e)
return ai[1];
return -1;
}
public static boolean doesEnchantmentConflict(List<int[]> enchantments, Enchantment e) {
for (int[] ai : enchantments)
if (!e.canApplyTogether(Enchantment.enchantmentsList[ai[0]]))
return true;
return false;
}
public static RuntimeException throwCME(String msg) {
if (CommonUtils.isClient())
return ClientHandler.throwCME(msg);
throw new RuntimeException(msg);
}
@SuppressWarnings("unchecked")
public static ItemStack[] extractRecipeItems(Object obj) {
if (obj instanceof ItemStack)
return new ItemStack[]{(ItemStack) obj};
if (obj instanceof ItemStack[])
return (ItemStack[]) obj;
if (obj instanceof List)
return ((List<ItemStack>) obj).toArray(new ItemStack[0]);
throw new ClassCastException("not an ItemStack, ItemStack[] or List<ItemStack?");
}
public static List<Integer> getRange(final int start, final int end) {
return new AbstractList<Integer>()
{
@Override
public Integer get(int index) {
return start+index;
}
@Override
public int size() {
return end-start;
}
};
}
public static StringBuilder fixTrailingCommaList(StringBuilder sb) {
if(sb.charAt(sb.length()-1) == ',')
sb.deleteCharAt(sb.length()-1);
return sb;
}
}
+28
View File
@@ -0,0 +1,28 @@
package codechicken.nei;
import codechicken.nei.api.IStackPositioner;
import java.util.ArrayList;
public class OffsetPositioner implements IStackPositioner
{
public OffsetPositioner(int x, int y)
{
offsetx = x;
offsety = y;
}
@Override
public ArrayList<PositionedStack> positionStacks(ArrayList<PositionedStack> ai)
{
for(PositionedStack stack : ai)
{
stack.relx+=offsetx;
stack.rely+=offsety;
}
return ai;
}
public int offsetx;
public int offsety;
}
+111
View File
@@ -0,0 +1,111 @@
package codechicken.nei;
import codechicken.core.ServerUtils;
import codechicken.lib.inventory.InventoryUtils;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import java.io.File;
public class PlayerSave
{
public String username;
private File saveFile;
private NBTTagCompound nbt;
public ItemStack[] creativeInv;
private boolean creativeInvDirty;
private boolean isDirty;
private boolean wasOp;
public PlayerSave(String playername, File saveLocation) {
username = playername;
wasOp = ServerUtils.isPlayerOP(playername);
saveFile = new File(saveLocation, username + ".dat");
if (!saveFile.getParentFile().exists())
saveFile.getParentFile().mkdirs();
load();
}
private void load() {
nbt = new NBTTagCompound();
try {
if (!saveFile.exists())
saveFile.createNewFile();
if (saveFile.length() > 0)
nbt = CompressedStreamTools.read(saveFile);
} catch (Exception e) {
e.printStackTrace();
}
loadCreativeInv();
}
private void loadCreativeInv() {
creativeInv = new ItemStack[54];
NBTTagList itemList = nbt.getTagList("creativeitems", 10);
if (itemList != null)
InventoryUtils.readItemStacksFromTag(creativeInv, itemList);
}
public void save() {
if (!isDirty)
return;
if (creativeInvDirty)
saveCreativeInv();
try {
CompressedStreamTools.write(nbt, saveFile);
isDirty = false;
} catch (Exception e) {
e.printStackTrace();
}
}
private void saveCreativeInv() {
NBTTagList invsave = InventoryUtils.writeItemStacksToTag(creativeInv);
nbt.setTag("creativeitems", invsave);
creativeInvDirty = false;
}
public void setCreativeDirty() {
creativeInvDirty = isDirty = true;
}
public void setDirty() {
isDirty = true;
}
public void updateOpChange(EntityPlayerMP player) {
boolean isOp = ServerUtils.isPlayerOP(username);
if (isOp != wasOp) {
NEISPH.sendHasServerSideTo(player);
wasOp = isOp;
}
}
public boolean isActionEnabled(String name) {
return getEnabledActions().getBoolean(name);
}
private NBTTagCompound getEnabledActions() {
NBTTagCompound tag = nbt.getCompoundTag("enabledActions");
if (!nbt.hasKey("enabledActions"))
nbt.setTag("enabledActions", tag);
return tag;
}
public void enableAction(String name, boolean enabled) {
getEnabledActions().setBoolean(name, enabled);
NEISPH.sendActionEnabled(ServerUtils.getPlayer(username), name, enabled);
setDirty();
}
}
@@ -0,0 +1,69 @@
package codechicken.nei;
import codechicken.nei.guihook.IContainerInputHandler;
import net.minecraft.client.gui.inventory.GuiContainer;
import static codechicken.nei.NEIClientConfig.canPerformAction;
import static codechicken.nei.NEIClientConfig.getKeyBinding;
public class PopupInputHandler implements IContainerInputHandler
{
@Override
public boolean keyTyped(GuiContainer gui, char keyChar, int keyCode)
{
return false;
}
@Override
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button)
{
return false;
}
@Override
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID)
{
}
@Override
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyID)
{
if(keyID == getKeyBinding("gui.enchant") && canPerformAction("enchant"))
{
NEICPH.sendOpenEnchantmentWindow();
return true;
}
if(keyID == getKeyBinding("gui.potion") && canPerformAction("potion"))
{
NEICPH.sendOpenPotionWindow();
return true;
}
return false;
}
@Override
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button)
{
}
@Override
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button)
{
}
@Override
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled)
{
return false;
}
@Override
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled)
{
}
@Override
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime)
{
}
}
+119
View File
@@ -0,0 +1,119 @@
package codechicken.nei;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.List;
/**
* Simply an {@link ItemStack} with position.
* Mainly used in the recipe handlers.
*/
public class PositionedStack
{
public int relx;
public int rely;
public ItemStack items[];
//compatibility dummy
public ItemStack item;
private boolean permutated = false;
public PositionedStack(Object object, int x, int y, boolean genPerms)
{
items = NEIServerUtils.extractRecipeItems(object);
relx = x;
rely = y;
if(genPerms)
generatePermutations();
else
setPermutationToRender(0);
}
public PositionedStack(Object object, int x, int y)
{
this(object, x, y, true);
}
public void generatePermutations()
{
if(permutated)
return;
ArrayList<ItemStack> stacks = new ArrayList<ItemStack>();
for(ItemStack item : items)
{
if(item == null || item.getItem() == null)
continue;
if(item.getItemDamage() == Short.MAX_VALUE)
{
List<ItemStack> permutations = ItemList.itemMap.get(item.getItem());
if(!permutations.isEmpty())
{
for(ItemStack stack : permutations)
stacks.add(stack.copy());
}
else
{
ItemStack base = new ItemStack(item.getItem(), item.stackSize);
base.stackTagCompound = item.stackTagCompound;
stacks.add(base);
}
continue;
}
stacks.add(item.copy());
}
items = stacks.toArray(new ItemStack[0]);
if(items.length == 0)
items = new ItemStack[]{new ItemStack(Blocks.fire)};
permutated = true;
setPermutationToRender(0);
}
public void setMaxSize(int i)
{
for(ItemStack item : items)
if(item.stackSize > i)
item.stackSize = i;
}
public PositionedStack copy()
{
return new PositionedStack(items, relx, rely);
}
public void setPermutationToRender(int index)
{
item = items[index].copy();
if(item.getItem() == null)
item = new ItemStack(Blocks.fire);
else if(item.getItemDamage() == OreDictionary.WILDCARD_VALUE)
item.setItemDamage(0);
}
public boolean contains(ItemStack ingredient)
{
for(ItemStack item : items)
if(NEIServerUtils.areStacksSameTypeCrafting(item, ingredient))
return true;
return false;
}
public boolean contains(Item ingred)
{
for(ItemStack item : items)
if(item.getItem() == ingred)
return true;
return false;
}
}
+123
View File
@@ -0,0 +1,123 @@
package codechicken.nei;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import static codechicken.lib.gui.GuiDraw.drawString;
import static codechicken.lib.gui.GuiDraw.getStringWidth;
import static codechicken.nei.NEIClientUtils.translate;
public abstract class SaveLoadButton extends Button
{
public SaveLoadButton(String s)
{
super(s);
}
@Override
public boolean handleClick(int mousex, int mousey, int button)
{
if(button == 1)
{
label = "";
onTextChange();
focused = true;
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
return true;
}
return super.handleClick(mousex, mousey, button);
}
public abstract void onTextChange();
@Override
public void onGuiClick(int i, int j)
{
if(!contains(i, j))
focused = false;
}
@Override
public boolean handleKeyPress(int keyID, char keyChar)
{
if(!focused)
return false;
if(keyID == Keyboard.KEY_BACK)
{
if(label.length() > 0)
{
label = label.substring(0, label.length() - 1);
onTextChange();
backdowntime = System.currentTimeMillis();
}
}
else if(keyID == Keyboard.KEY_RETURN)
{
focused = false;
}
else if(keyChar == 22)//paste
{
String pastestring = GuiScreen.getClipboardString();
if(pastestring == null)
pastestring = "";
label = label + pastestring;
onTextChange();
}
else if(ChatAllowedCharacters.isAllowedCharacter(keyChar))
{
label = label + keyChar;
onTextChange();
}
return true;
}
@Override
public void update()
{
cursorCounter++;
if(backdowntime > 0)
{
if(Keyboard.isKeyDown(Keyboard.KEY_BACK) && label.length() > 5)
{
if(System.currentTimeMillis() - backdowntime > 200 / (1+backs * 0.3F))
{
label = label.substring(0, label.length() - 1);
onTextChange();
backdowntime = System.currentTimeMillis();
backs++;
}
}
else
{
backdowntime = 0;
backs = 0;
}
}
}
@Override
public void draw(int mousex, int mousey)
{
super.draw(mousex, mousey);
if(focused && (cursorCounter / 6) % 2 == 0)
drawString("_", x + (width + getStringWidth(getRenderLabel())) / 2, y + (height - 8) / 2, 0xFFFFFFFF);
}
@Override
public String getRenderLabel()
{
return translate(saved ? "load" : "save") + " " + label;
}
public boolean saved;
public long backdowntime;
public int backs;
public int cursorCounter;
public boolean focused;
}
+59
View File
@@ -0,0 +1,59 @@
package codechicken.nei;
import net.minecraft.util.EnumChatFormatting;
import static codechicken.lib.gui.GuiDraw.drawGradientRect;
import static codechicken.lib.gui.GuiDraw.drawRect;
import static codechicken.nei.NEIClientConfig.world;
public class SearchField extends TextField
{
public SearchField(String ident) {
super(ident);
}
public static boolean searchInventories() {
return world.nbt.getBoolean("searchinventories");
}
@Override
public void drawBox() {
if (searchInventories())
drawGradientRect(x, y, width, height, 0xFFFFFF00, 0xFFC0B000);
else
drawRect(x, y, width, height, 0xffA0A0A0);
drawRect(x + 1, y + 1, width - 2, height - 2, 0xFF000000);
}
@Override
public boolean handleClick(int mousex, int mousey, int button) {
if (button == 0) {
if (focused() && (System.currentTimeMillis() - lastclicktime < 500))//double click
{
world.nbt.setBoolean("searchinventories", !searchInventories());
world.saveNBT();
}
lastclicktime = System.currentTimeMillis();
}
return super.handleClick(mousex, mousey, button);
}
@Override
public void onTextChange(String oldText) {
NEIClientConfig.setSearchExpression(text());
ItemList.updateSearch();
}
@Override
public void lastKeyTyped(int keyID, char keyChar) {
if (keyID == NEIClientConfig.getKeyBinding("gui.search"))
setFocus(true);
}
@Override
public String filterText(String s) {
return EnumChatFormatting.getTextWithoutFormattingCodes(s);
}
long lastclicktime;
}
+149
View File
@@ -0,0 +1,149 @@
package codechicken.nei;
import codechicken.core.CommonUtils;
import codechicken.lib.packet.PacketCustom;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerChangedDimensionEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
import java.util.List;
public class ServerHandler
{
private static ServerHandler instance;
public static void load() {
instance = new ServerHandler();
PacketCustom.assignHandler(NEICPH.channel, new NEISPH());
FMLCommonHandler.instance().bus().register(instance);
MinecraftForge.EVENT_BUS.register(instance);
NEIActions.init();
}
@SubscribeEvent
public void tickEvent(TickEvent.WorldTickEvent event) {
if (event.phase == Phase.START)
processDisabledProperties(event.world);
}
@SubscribeEvent
public void loadEvent(WorldEvent.Load event) {
if(!event.world.isRemote)
NEIServerConfig.load(event.world);
}
@SubscribeEvent
public void tickEvent(TickEvent.PlayerTickEvent event) {
if (event.phase == Phase.START && event.player instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) event.player;
PlayerSave save = NEIServerConfig.forPlayer(player.getCommandSenderName());
if (save == null)
return;
updateMagneticPlayer(player, save);
save.updateOpChange(player);
save.save();
}
}
private void processDisabledProperties(World world) {
NEIServerUtils.advanceDisabledTimes(world);
if (NEIServerUtils.isRaining(world) && NEIServerConfig.isActionDisabled(CommonUtils.getDimension(world), "rain"))
NEIServerUtils.toggleRaining(world, false);
}
private void updateMagneticPlayer(EntityPlayerMP player, PlayerSave save) {
if (!save.isActionEnabled("magnet") || player.isDead)
return;
float distancexz = 16;
float distancey = 8;
double maxspeedxz = 0.5;
double maxspeedy = 0.5;
double speedxz = 0.05;
double speedy = 0.07;
List<EntityItem> items = player.worldObj.getEntitiesWithinAABB(EntityItem.class, player.boundingBox.expand(distancexz, distancey, distancexz));
for (EntityItem item : items) {
if (item.delayBeforeCanPickup > 0) continue;
if (!NEIServerUtils.canItemFitInInventory(player, item.getEntityItem())) continue;
if (item.delayBeforeCanPickup == 0) {
NEISPH.sendAddMagneticItemTo(player, item);
}
double dx = player.posX - item.posX;
double dy = player.posY + player.getEyeHeight() - item.posY;
double dz = player.posZ - item.posZ;
double absxz = Math.sqrt(dx * dx + dz * dz);
double absy = Math.abs(dy);
if (absxz > distancexz) {
continue;
}
if (absxz < 1) {
item.onCollideWithPlayer(player);
}
if (absxz > 1) {
dx /= absxz;
dz /= absxz;
}
if (absy > 1) {
dy /= absy;
}
double vx = item.motionX + speedxz * dx;
double vy = item.motionY + speedy * dy;
double vz = item.motionZ + speedxz * dz;
double absvxz = Math.sqrt(vx * vx + vz * vz);
double absvy = Math.abs(vy);
double rationspeedxz = absvxz / maxspeedxz;
if (rationspeedxz > 1) {
vx /= rationspeedxz;
vz /= rationspeedxz;
}
double rationspeedy = absvy / maxspeedy;
if (rationspeedy > 1) {
vy /= rationspeedy;
}
item.motionX = vx;
item.motionY = vy;
item.motionZ = vz;
}
}
@SubscribeEvent
public void loginEvent(PlayerLoggedInEvent event) {
NEIServerConfig.loadPlayer(event.player);
NEISPH.sendHasServerSideTo((EntityPlayerMP) event.player);
}
@SubscribeEvent
public void logoutEvent(PlayerLoggedOutEvent event) {
NEIServerConfig.unloadPlayer(event.player);
}
@SubscribeEvent
public void dimChangeEvent(PlayerChangedDimensionEvent event) {
NEISPH.sendHasServerSideTo((EntityPlayerMP) event.player);
}
@SubscribeEvent
public void loginEvent(PlayerRespawnEvent event) {
NEISPH.sendHasServerSideTo((EntityPlayerMP) event.player);
}
}
+10
View File
@@ -0,0 +1,10 @@
package codechicken.nei;
public abstract class SlotOP
{
public abstract String getDescription();
public abstract int[] getKeyBind();
public abstract void operate();
}
+97
View File
@@ -0,0 +1,97 @@
package codechicken.nei;
import codechicken.core.ClientUtils;
import codechicken.lib.render.TextureUtils;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.boss.BossStatus;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
public class SpawnerRenderer implements IItemRenderer
{
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type)
{
return true;
}
public void renderInventoryItem(RenderBlocks render, ItemStack item)
{
int meta = item.getItemDamage();
if(meta == 0)
{
meta = ItemMobSpawner.idPig;
}
String bossName = BossStatus.bossName;
int bossTimeout = BossStatus.statusBarTime;
try
{
World world = NEIClientUtils.mc().theWorld;
ItemMobSpawner.loadSpawners(world);
TextureUtils.bindAtlas(0);
render.renderBlockAsItem(Blocks.mob_spawner, 0, 1F);
GL11.glPushMatrix();
Entity entity = ItemMobSpawner.getEntity(meta);
if(entity != null)
{
entity.setWorld(world);
float f1 = 0.4375F;
if(entity.getShadowSize() > 1.5)
{
f1 = 0.1F;
}
GL11.glRotatef((float) (ClientUtils.getRenderTime()*10), 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-20F, 1.0F, 0.0F, 0.0F);
GL11.glTranslatef(0.0F, -0.4F, 0.0F);
GL11.glScalef(f1, f1, f1);
entity.setLocationAndAngles(0, 0, 0, 0.0F, 0.0F);
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 0);
}
GL11.glPopMatrix();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
catch(Exception e)
{
if(Tessellator.instance.isDrawing)
Tessellator.instance.draw();
}
BossStatus.bossName = bossName;
BossStatus.statusBarTime = bossTimeout;
}
@SuppressWarnings("incomplete-switch")
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
switch(type)
{
case EQUIPPED:
case EQUIPPED_FIRST_PERSON:
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
case INVENTORY:
case ENTITY:
renderInventoryItem((RenderBlocks)data[0], item);
break;
}
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
{
return true;
}
}
+279
View File
@@ -0,0 +1,279 @@
package codechicken.nei;
import net.minecraft.client.Minecraft;
import javax.swing.*;
import java.awt.*;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
public class TMIUninstaller
{
public static class InstallerGui extends JFrame
{
private static final long serialVersionUID = 1L;
private JTextField labelInfo;
private static final String PREFERRED_LOOK_AND_FEEL = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
public InstallerGui() {
setTitle("TMI Uninstaller");
initComponents();
}
private class ResizeListener implements LayoutManager
{
public void addLayoutComponent(String name, Component comp) {
}
public void layoutContainer(Container parent) {
int w = getContentPane().getWidth();
labelInfo.setBounds(10, 45, w - 20, 20);
labelInfo.setScrollOffset(1000);
labelInfo.update(getGraphics());
}
public Dimension minimumLayoutSize(Container parent) {
return new Dimension(150, 100);
}
public Dimension preferredLayoutSize(Container parent) {
return new Dimension(250, 120);
}
public void removeLayoutComponent(Component comp) {
}
}
private void initComponents() {
setLayout(new ResizeListener());
add(getLabelInfo());
setSize(358, 270);
}
public class InstallerListener implements ActionListener
{
public void actionPerformed(ActionEvent e) {
}
}
public JTextField getLabelInfo() {
if (labelInfo == null) {
labelInfo = new JTextField();
labelInfo.setFont(new Font("Tahoma", Font.PLAIN, 13));
labelInfo.setHorizontalAlignment(SwingConstants.CENTER);
labelInfo.setEditable(false);
labelInfo.setText("Uninstalling TMI");
}
return labelInfo;
}
public static void installLnF() {
try {
String lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lnfClassname);
} catch (Exception e) {
System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL + " on this platform:" + e.getMessage());
}
}
}
private static File jarFile;
public static InstallerGui mainframe;
public static void main(String[] args) {
jarFile = new File(args[0]);
InstallerGui.installLnF();
mainframe = new InstallerGui();
mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainframe.setLocationRelativeTo(null);
mainframe.pack();
mainframe.setVisible(true);
if (!jarFile.exists())
mainframe.getLabelInfo().setText("Invalid Minecraft.jar");
else
uninstall();
}
private static File getJarFile() {
URL url = Minecraft.class.getProtectionDomain().getCodeSource().getLocation();
try {
if (url.getProtocol().equals("jar"))
url = new URL(url.getPath().substring(0, url.getPath().indexOf('!')));
return new File(url.toURI());
} catch (URISyntaxException e) {
return new File(url.getPath());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
public static void deleteTMIUninstaller() throws IOException {
File file = new File(getJarFile().getParentFile(), "TMIUninstaller");
if (file.exists()) {
NEIClientConfig.logger.info("Removing TMI Uninstaller");
deleteDir(file, true);
}
}
public static boolean TMIInstalled() {
File jarFile = getJarFile();
if (!jarFile.getName().endsWith(".jar"))
return false;
try {
ZipFile zip = new ZipFile(jarFile);
ZipEntry tmi = zip.getEntry("mod_TooManyItems.class");
zip.close();
return tmi != null;
} catch (Exception e) {
return false;
}
}
public static void runTMIUninstaller() throws IOException {
File jarFile = getJarFile();
File uninstDir = new File(jarFile.getParentFile(), "TMIUninstaller");
if (!uninstDir.exists())
uninstDir.mkdirs();
NEIClientConfig.logger.info("Installing Uninstaller: " + uninstDir.getPath());
FileInputStream fileinputstream = new FileInputStream(jarFile);
ZipInputStream zipinputstream = new ZipInputStream(fileinputstream);
do {
ZipEntry zipentry = zipinputstream.getNextEntry();
if (zipentry == null) {
break;
}
String fullname = zipentry.getName().replace('\\', '/');
if (!zipentry.isDirectory() && fullname.replace('/', '.').startsWith(TMIUninstaller.class.getCanonicalName())) {
File outFile = new File(uninstDir, fullname);
NEIClientConfig.logger.info("Extracting File: " + outFile.getPath());
if (!outFile.getParentFile().exists())
outFile.getParentFile().mkdirs();
outFile.createNewFile();
FileOutputStream fout = new FileOutputStream(outFile);
byte[] buffer = new byte[65535];
int read = 0;
while ((read = zipinputstream.read(buffer)) != -1)//write loop
{
fout.write(buffer, 0, read);
}
fout.close();
}
}
while (true);
fileinputstream.close();
String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
String classpath = uninstDir.getAbsolutePath();
String className = TMIUninstaller.class.getCanonicalName();
String jarPath = jarFile.getPath();
NEIClientConfig.logger.info("Running Process: " + javaBin + " -cp \"" + classpath + "\" \"" + className + "\" \"" + jarPath + "\"");
ProcessBuilder builder = new ProcessBuilder(javaBin, "-cp", classpath, className, jarPath);
builder.start();
}
public static void deleteDir(File directory, boolean remove) throws IOException {
NEIClientConfig.logger.debug("Deleting Dir: " + directory.getPath());
if (!directory.exists()) {
if (!remove)
directory.mkdirs();
return;
}
for (File file : directory.listFiles()) {
if (file.isDirectory()) {
deleteDir(file, true);
} else {
if (!file.delete()) {
throw new IOException("Delete Failed: " + file);
}
}
}
if (remove) {
try {
if (!directory.delete()) {
throw new IOException("Delete Failed: " + directory);
}
} catch (SecurityException e) {
throw e;
}
}
}
public static void uninstall() {
File backupfile = new File(jarFile.getParentFile(), jarFile.getName() + ".bak");
try {
if (!backupfile.exists())
backupfile.createNewFile();
FileOutputStream backout = new FileOutputStream(backupfile);
FileInputStream jarin = new FileInputStream(jarFile);
backout.getChannel().transferFrom(jarin.getChannel(), 0, jarFile.length());
backout.close();
jarin.close();
ZipInputStream zipin = new ZipInputStream(new FileInputStream(backupfile));
ZipOutputStream zipout = new ZipOutputStream(new FileOutputStream(jarFile));
byte[] buffer = new byte[20000];
int read = 0;
while (true) {
ZipEntry entry = zipin.getNextEntry();
if (entry == null) {
break;
}
if (entry.isDirectory()) continue;
String name = entry.getName();
if (name.startsWith("TMI") || name.startsWith("_tmi") || name.startsWith("tmi.png") || name.startsWith("mod_TooManyItems")) {
continue;
}
zipout.putNextEntry(new ZipEntry(name));
InputStream in = zipin;
while ((read = in.read(buffer)) != -1) {
zipout.write(buffer, 0, read);
}
zipout.closeEntry();
zipin.closeEntry();
}
zipin.close();
zipout.close();
mainframe.getLabelInfo().setText("Uninstall Completed. Close this and restart minecraft.");
} catch (Exception e) {
e.printStackTrace();
mainframe.getLabelInfo().setText("Invalid Minecraft.jar");
try {
FileInputStream backin = new FileInputStream(backupfile);
FileOutputStream jarout = new FileOutputStream(jarFile);
jarout.getChannel().transferFrom(backin.getChannel(), 0, backupfile.length());
backin.close();
jarout.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
+182
View File
@@ -0,0 +1,182 @@
package codechicken.nei;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ChatAllowedCharacters;
import org.lwjgl.input.Keyboard;
import static codechicken.lib.gui.GuiDraw.*;
public abstract class TextField extends Widget
{
public TextField(String ident)
{
identifier = ident;
}
public int getTextColour()
{
return focused() ? 0xFFE0E0E0 : 0xFF909090;
}
public void drawBox()
{
drawRect(x, y, width, height, 0xffA0A0A0);
drawRect(x + 1, y + 1, width - 2, height - 2, 0xFF000000);
}
@Override
public void draw(int mousex, int mousey)
{
drawBox();
String drawtext = text;
if(text.length() > getMaxTextLength())
{
int startOffset = drawtext.length() - getMaxTextLength();
if(startOffset < 0 || startOffset > drawtext.length())
startOffset = 0;
drawtext = drawtext.substring(startOffset);
}
if(focused() && (cursorCounter / 6) % 2 == 0)
drawtext = drawtext + '_';
int textWidth = getStringWidth(text);
int textx = centered ? x+(width-textWidth)/2 : x + 4;
int texty = y + (height + 1) / 2 - 3;
drawString(drawtext, textx, texty, getTextColour());
}
@Override
public void onGuiClick(int mousex, int mousey)
{
if(!contains(mousex, mousey))
setFocus(false);
}
@Override
public boolean handleClick(int mousex, int mousey, int button)
{
if(button == 1)
setText("");
setFocus(true);
return true;
}
@Override
public boolean handleKeyPress(int keyID, char keyChar)
{
if(!focused())
return false;
if(keyID == Keyboard.KEY_BACK)
{
if(text.length() > 0)
{
setText(text.substring(0, text.length() - 1));
backdowntime = System.currentTimeMillis();
}
}
else if(keyID == Keyboard.KEY_RETURN || keyID == Keyboard.KEY_ESCAPE)
{
setFocus(false);
onExit();
}
else if(keyChar == 22)//paste
{
String pastestring = GuiScreen.getClipboardString();
if(pastestring == null)
pastestring = "";
if(isValid(text + pastestring))
setText(text + pastestring);
}
else if(isValid(text+keyChar))
setText(text+keyChar);
return true;
}
public void onExit()
{
}
public abstract void onTextChange(String oldText);
public boolean isValid(String string)
{
// Solve the problem that Minecraft can't post Chinese characters
return ChatAllowedCharacters.isAllowedCharacter(string.charAt(string.length()-1));
}
@Override
public void update()
{
cursorCounter++;
if(backdowntime > 0)
{
if(Keyboard.isKeyDown(Keyboard.KEY_BACK) && text.length() > 0)
{
if(System.currentTimeMillis() - backdowntime > 200 / (1+backs * 0.3F))
{
setText(text.substring(0, text.length() - 1));
backdowntime = System.currentTimeMillis();
backs++;
}
}
else
{
backdowntime = 0;
backs = 0;
}
}
}
public void setText(String s)
{
String oldText = text;
text = filterText(s);
onTextChange(oldText);
}
public String filterText(String s)
{
return s;
}
private int getMaxTextLength()
{
return width / 6 - 2;
}
public void setFocus(boolean focus)
{
if(focus)
{
LayoutManager.setInputFocused(this);
}
else if(focused())
{
LayoutManager.setInputFocused(null);
}
}
public boolean focused()
{
return LayoutManager.getInputFocused() == this;
}
public String text()
{
return text;
}
private String text = "";
public boolean centered;
public long backdowntime;
public int backs;
public String identifier;
public int cursorCounter;
}
+38
View File
@@ -0,0 +1,38 @@
package codechicken.nei;
public class VisiblityData
{
public boolean showUtilityButtons = true;
public boolean showStateButtons = true;
/**
* Item panel and associated buttons
*/
public boolean showItemPanel = true;
/**
* Item and search section
*/
public boolean showItemSection = true;
/**
* Dropdown and Item search field
*/
public boolean showSearchSection = true;
/**
* All widgets except options button
*/
public boolean showWidgets = true;
/**
* The entire NEI interface, aka hidden
*/
public boolean showNEI = true;
public boolean enableDeleteMode = true;
public void translateDependancies()
{
if(!showNEI)
showWidgets = false;
if(!showWidgets)
showItemSection = showUtilityButtons = showStateButtons = false;
if(!showItemSection)
showSearchSection = showItemPanel = false;
}
}
+72
View File
@@ -0,0 +1,72 @@
package codechicken.nei;
import net.minecraft.item.ItemStack;
import java.util.List;
public abstract class Widget
{
public Widget() {
}
public abstract void draw(int mousex, int mousey);
public void postDraw(int mousex, int mousey) {
}
public boolean handleClick(int mousex, int mousey, int button) {
return true;
}
public void onGuiClick(int mousex, int mousey) {
}
public void mouseUp(int mousex, int mousey, int button) {
}
public boolean handleKeyPress(int keyID, char keyChar) {
return false;
}
public void lastKeyTyped(int keyID, char keyChar) {
}
public boolean handleClickExt(int mousex, int mousey, int button) {
return false;
}
public boolean onMouseWheel(int i, int mousex, int mousey) {
return false;
}
public void update() {
}
public boolean contains(int posx, int posy) {
return posx >= x && posx < x + width && posy >= y && posy < y + height;
}
public ItemStack getStackMouseOver(int mousex, int mousey) {
return null;
}
public void mouseDragged(int mx, int my, int button, long heldTime) {
}
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
return tooltip;
}
public void loseFocus() {
}
public void gainFocus() {
}
public int x;
public int y;
public int z;
public int width;
public int height;
}
+18
View File
@@ -0,0 +1,18 @@
package codechicken.nei;
import java.util.Comparator;
public class WidgetZOrder
implements Comparator<Widget>
{
boolean topfirst;
public WidgetZOrder(boolean topfirst)
{
this.topfirst = topfirst;
}
public int compare(Widget w1, Widget w2)
{
return w1.z != w2.z ? ((topfirst ? w1.z > w2.z : w1.z < w2.z) ? 1 : -1) : 1;
}
}
@@ -0,0 +1,222 @@
package codechicken.nei;
import codechicken.lib.math.MathHelper;
import codechicken.lib.render.RenderUtils;
import codechicken.nei.KeyManager.IKeyStateTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.SpawnerAnimals;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import org.lwjgl.opengl.GL11;
public class WorldOverlayRenderer implements IKeyStateTracker
{
public static int mobOverlay = 0;
public static int chunkOverlay = 0;
public static void reset() {
mobOverlay = 0;
chunkOverlay = 0;
}
@Override
public void tickKeyStates() {
if (Minecraft.getMinecraft().currentScreen != null)
return;
if (KeyManager.keyStates.get("world.moboverlay").down)
mobOverlay = (mobOverlay + 1) % 2;
if (KeyManager.keyStates.get("world.chunkoverlay").down)
chunkOverlay = (chunkOverlay + 1) % 3;
}
public static void render(float frame) {
GL11.glPushMatrix();
Entity entity = Minecraft.getMinecraft().renderViewEntity;
RenderUtils.translateToWorldCoords(entity, frame);
renderChunkBounds(entity);
renderMobSpawnOverlay(entity);
GL11.glPopMatrix();
}
private static void renderMobSpawnOverlay(Entity entity) {
if (mobOverlay == 0)
return;
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glLineWidth(1.5F);
GL11.glBegin(GL11.GL_LINES);
GL11.glColor4f(1, 0, 0, 1);
int curSpawnMode = 2;
World world = entity.worldObj;
int x1 = (int) entity.posX;
int z1 = (int) entity.posZ;
int y1 = (int) MathHelper.clip(entity.posY, 16, world.getHeight() - 16);
for (int x = x1 - 16; x <= x1 + 16; x++)
for (int z = z1 - 16; z <= z1 + 16; z++) {
Chunk chunk = world.getChunkFromBlockCoords(x, z);
BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
if (biome.getSpawnableList(EnumCreatureType.monster).isEmpty() || biome.getSpawningChance() <= 0)
continue;
for (int y = y1 - 16; y < y1 + 16; y++) {
int spawnMode = getSpawnMode(chunk, x, y, z);
if (spawnMode == 0)
continue;
if (spawnMode != curSpawnMode) {
if (spawnMode == 1)
GL11.glColor4f(1, 1, 0, 1);
else
GL11.glColor4f(1, 0, 0, 1);
curSpawnMode = spawnMode;
}
GL11.glVertex3d(x, y + 0.004, z);
GL11.glVertex3d(x + 1, y + 0.004, z + 1);
GL11.glVertex3d(x + 1, y + 0.004, z);
GL11.glVertex3d(x, y + 0.004, z + 1);
}
}
GL11.glEnd();
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
private static Entity dummyEntity = new EntityPig(null);
private static AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
private static int getSpawnMode(Chunk chunk, int x, int y, int z) {
if (!SpawnerAnimals.canCreatureTypeSpawnAtLocation(EnumCreatureType.monster, chunk.worldObj, x, y, z) ||
chunk.getSavedLightValue(EnumSkyBlock.Block, x & 15, y, z & 15) >= 8)
return 0;
aabb.minX = x + 0.2;
aabb.maxX = x + 0.8;
aabb.minY = y + 0.01;
aabb.maxY = y + 1.8;
aabb.minZ = z + 0.2;
aabb.maxZ = z + 0.8;
if (!chunk.worldObj.checkNoEntityCollision(aabb) ||
!chunk.worldObj.getCollidingBoundingBoxes(dummyEntity, aabb).isEmpty() ||
chunk.worldObj.isAnyLiquid(aabb))
return 0;
if (chunk.getSavedLightValue(EnumSkyBlock.Sky, x & 15, y, z & 15) >= 8)
return 1;
return 2;
}
private static void renderChunkBounds(Entity entity) {
if (chunkOverlay == 0)
return;
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glLineWidth(1.5F);
GL11.glBegin(GL11.GL_LINES);
for (int cx = -4; cx <= 4; cx++)
for (int cz = -4; cz <= 4; cz++) {
double x1 = (entity.chunkCoordX + cx) << 4;
double z1 = (entity.chunkCoordZ + cz) << 4;
double x2 = x1 + 16;
double z2 = z1 + 16;
double dy = 128;
double y1 = Math.floor(entity.posY - dy / 2);
double y2 = y1 + dy;
if (y1 < 0) {
y1 = 0;
y2 = dy;
}
if (y1 > entity.worldObj.getHeight()) {
y2 = entity.worldObj.getHeight();
y1 = y2 - dy;
}
double dist = Math.pow(1.5, -(cx * cx + cz * cz));
GL11.glColor4d(0.9, 0, 0, dist);
if (cx >= 0 && cz >= 0) {
GL11.glVertex3d(x2, y1, z2);
GL11.glVertex3d(x2, y2, z2);
}
if (cx >= 0 && cz <= 0) {
GL11.glVertex3d(x2, y1, z1);
GL11.glVertex3d(x2, y2, z1);
}
if (cx <= 0 && cz >= 0) {
GL11.glVertex3d(x1, y1, z2);
GL11.glVertex3d(x1, y2, z2);
}
if (cx <= 0 && cz <= 0) {
GL11.glVertex3d(x1, y1, z1);
GL11.glVertex3d(x1, y2, z1);
}
if (chunkOverlay == 2 && cx == 0 && cz == 0) {
dy = 32;
y1 = Math.floor(entity.posY - dy / 2);
y2 = y1 + dy;
if (y1 < 0) {
y1 = 0;
y2 = dy;
}
if (y1 > entity.worldObj.getHeight()) {
y2 = entity.worldObj.getHeight();
y1 = y2 - dy;
}
GL11.glColor4d(0, 0.9, 0, 0.4);
for (double y = (int) y1; y <= y2; y++) {
GL11.glVertex3d(x2, y, z1);
GL11.glVertex3d(x2, y, z2);
GL11.glVertex3d(x1, y, z1);
GL11.glVertex3d(x1, y, z2);
GL11.glVertex3d(x1, y, z2);
GL11.glVertex3d(x2, y, z2);
GL11.glVertex3d(x1, y, z1);
GL11.glVertex3d(x2, y, z1);
}
for (double h = 1; h <= 15; h++) {
GL11.glVertex3d(x1 + h, y1, z1);
GL11.glVertex3d(x1 + h, y2, z1);
GL11.glVertex3d(x1 + h, y1, z2);
GL11.glVertex3d(x1 + h, y2, z2);
GL11.glVertex3d(x1, y1, z1 + h);
GL11.glVertex3d(x1, y2, z1 + h);
GL11.glVertex3d(x2, y1, z1 + h);
GL11.glVertex3d(x2, y2, z1 + h);
}
}
}
GL11.glEnd();
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
public static void load() {
KeyManager.trackers.add(new WorldOverlayRenderer());
}
}
+195
View File
@@ -0,0 +1,195 @@
package codechicken.nei.api;
import codechicken.nei.KeyManager;
import codechicken.nei.KeyManager.KeyState;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.OffsetPositioner;
import codechicken.nei.config.Option;
import codechicken.nei.config.OptionKeyBind;
import codechicken.nei.recipe.*;
import net.minecraft.block.Block;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
/**
* This is the main class that handles item property configuration.
* WARNING: DO NOT access this class until the world has been loaded
* These methods should be called from INEIConfig implementors
*/
public class API
{
/**
* Register a new Crafting Recipe handler;
*
* @param handler The handler to register
*/
public static void registerRecipeHandler(ICraftingHandler handler) {
GuiCraftingRecipe.registerRecipeHandler(handler);
}
/**
* Register a new Usage Recipe handler;
*
* @param handler The handler to register
*/
public static void registerUsageHandler(IUsageHandler handler) {
GuiUsageRecipe.registerUsageHandler(handler);
}
/**
* Add a gui to the default overlay renderer with the default position
*
* @param classz The class of your gui
* @param ident The identification string, currently
* {crafting, crafting2x2, smelting, fuel, brewing}
*/
public static void registerGuiOverlay(Class<? extends GuiContainer> classz, String ident) {
registerGuiOverlay(classz, ident, 5, 11);
}
/**
* Add a gui to the default overlay renderer with an offset
*
* @param classz The class of your gui
* @param ident The identification string, currently
* {crafting, crafting2x2, smelting, fuel, brewing}
* @param x x-offset
* @param y y-offset
*/
public static void registerGuiOverlay(Class<? extends GuiContainer> classz, String ident, int x, int y) {
registerGuiOverlay(classz, ident, new OffsetPositioner(x, y));
}
/**
* Add a gui to the default overlay renderer
*
* @param classz The class of your gui
* @param ident The identification string, currently
* {crafting, crafting2x2, smelting, fuel, brewing}
* @param positioner A Stack Repositioner for moving the items to the right place
*/
public static void registerGuiOverlay(Class<? extends GuiContainer> classz, String ident, IStackPositioner positioner) {
RecipeInfo.registerGuiOverlay(classz, ident, positioner);
}
/**
* @param classz The class of your gui
* @param handler The handler to register
* @param ident The recipe identification string
*/
public static void registerGuiOverlayHandler(Class<? extends GuiContainer> classz, IOverlayHandler handler, String ident) {
RecipeInfo.registerOverlayHandler(classz, handler, ident);
}
/**
* Set the offset to be added to items to translate them into recipe coords on the actual gui, default is 5, 11. Primarily RecipeTransferRects
*
* @param classz The class of your gui
* @param x
* @param y
*/
public static void setGuiOffset(Class<? extends GuiContainer> classz, int x, int y) {
RecipeInfo.setGuiOffset(classz, x, y);
}
public static void registerNEIGuiHandler(INEIGuiHandler handler) {
GuiInfo.guiHandlers.add(handler);
}
/**
* Hide an item from the item panel
* Damage values of OreDictionary.WILDCARD_VALUE and null NBT tags function as wildcards for their respective variables
*/
public static void hideItem(ItemStack item) {
ItemInfo.hiddenItems.add(item);
}
/**
* Add or replace the name normally shown on the item tooltip
*/
public static void setOverrideName(ItemStack item, String name) {
ItemInfo.nameOverrides.put(item, name);
}
/**
* Adds an item to the item panel. Any items added using this function will override the default search pattern.
* @param item an item with data
*/
public static void addItemListEntry(ItemStack item) {
ItemInfo.itemOverrides.put(item.getItem(), item);
}
/**
* Add a custom KeyBinding to be configured in the Controls menu.
* @param ident An identifier for your key, eg "shoot"
* @param defaultKey The default value, commonly obtained from {@link Keyboard}
*/
public static void addKeyBind(String ident, int defaultKey) {
NEIClientConfig.setDefaultKeyBinding(ident, defaultKey);
KeyManager.keyStates.put(ident, new KeyState());
addOption(new OptionKeyBind(ident));
}
public static void addOption(Option option) {
NEIClientConfig.getOptionList().addOption(option);
}
/**
* Add a new Layout Style for the NEI interface
* @param styleID The Unique ID to be used for storing your style in the config and cycling through avaliable styles
* @param style The style to add.
*/
public static void addLayoutStyle(int styleID, LayoutStyle style) {
LayoutManager.layoutStyles.put(styleID, style);
}
/**
* Registers a new Infinite Item Handler.
*
* @param handler The handler to be registered.
*/
public static void addInfiniteItemHandler(IInfiniteItemHandler handler) {
ItemInfo.infiniteHandlers.addFirst(handler);
}
/**
* Registers a new Infinite Item Handler.
*
* @param block The block to handle, null for all.
* @param handler The handler to be registered.
*/
public static void registerHighlightIdentifier(Block block, IHighlightHandler handler) {
ItemInfo.highlightIdentifiers.put(block, handler);
}
/**
* Tells NEI not to perform any Fast Transfer operations on slots of a particular class
*
* @param slotClass The class of slot to be exempted
*/
public static void addFastTransferExemptSlot(Class<? extends Slot> slotClass) {
ItemInfo.fastTransferExemptions.add(slotClass);
}
/**
* Register a new text handler for the block highlight tooltip with a layout specification (HEADER, BODY or FOOTER).
*
* @param handler
* @param layout A HUDAugmenterRegistry.Layout entry. HEADER is displayed before BODY which is displayed before FOOTER.
*/
public static void registerHighlightHandler(IHighlightHandler handler, ItemInfo.Layout... layout) {
ItemInfo.registerHighlightHandler(handler, layout);
}
/**
* Register a mode handler for overriding NEI recipe/utility/cheat mode settings.
*
* @param handler
*/
public static void registerModeHandler(INEIModeHandler handler) {
NEIInfo.modeHandlers.add(handler);
}
}
@@ -0,0 +1,44 @@
package codechicken.nei.api;
import codechicken.nei.PositionedStack;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.inventory.Slot;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.List;
public class DefaultOverlayRenderer implements IRecipeOverlayRenderer
{
public DefaultOverlayRenderer(List<PositionedStack> ai, IStackPositioner positioner)
{
positioner = this.positioner = positioner;
ingreds = new ArrayList<PositionedStack>();
for(PositionedStack stack : ai)
ingreds.add(stack.copy());
ingreds = positioner.positionStacks(ingreds);
}
@Override
public void renderOverlay(GuiContainerManager gui, Slot slot)
{
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(770, 1);
GL11.glColor4d(0.6, 0.6, 0.6, 0.7);
GuiContainerManager.setColouredItemRender(true);
for(PositionedStack stack : ingreds)
{
if(stack.relx == slot.xDisplayPosition && stack.rely == slot.yDisplayPosition)
GuiContainerManager.drawItem(stack.relx, stack.rely, stack.item);
}
GuiContainerManager.setColouredItemRender(false);
GL11.glColor4f(1, 1, 1, 1);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
}
IStackPositioner positioner;
ArrayList<PositionedStack> ingreds;
}
+26
View File
@@ -0,0 +1,26 @@
package codechicken.nei.api;
import codechicken.nei.NEIChestGuiHandler;
import codechicken.nei.NEICreativeGuiHandler;
import codechicken.nei.NEIDummySlotHandler;
import net.minecraft.client.gui.inventory.GuiContainer;
import java.util.Iterator;
import java.util.LinkedList;
public class GuiInfo
{
public static LinkedList<INEIGuiHandler> guiHandlers = new LinkedList<INEIGuiHandler>();
public static void load() {
API.registerNEIGuiHandler(new NEICreativeGuiHandler());
API.registerNEIGuiHandler(new NEIChestGuiHandler());
API.registerNEIGuiHandler(new NEIDummySlotHandler());
}
public static void clearGuiHandlers() {
for (Iterator<INEIGuiHandler> iterator = guiHandlers.iterator(); iterator.hasNext(); )
if (iterator.next() instanceof GuiContainer)
iterator.remove();
}
}
@@ -0,0 +1,13 @@
package codechicken.nei.api;
/**
* An nei configuration entry point should implement this class and have name "NEI<someting>Config"
* loadConfig will only be called when NEI is installed.
*/
public interface IConfigureNEI
{
public void loadConfig();
public String getName();
public String getVersion();
}
@@ -0,0 +1,8 @@
package codechicken.nei.api;
import net.minecraft.client.gui.inventory.GuiContainer;
public interface IGuiContainerOverlay
{
public GuiContainer getFirstScreen();
}
@@ -0,0 +1,15 @@
package codechicken.nei.api;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import java.util.List;
public interface IHighlightHandler
{
public ItemStack identifyHighlight(World world, EntityPlayer player, MovingObjectPosition mop);
public List<String> handleTextData(ItemStack itemStack, World world, EntityPlayer player, MovingObjectPosition mop, List<String> currenttip, ItemInfo.Layout layout);
}
@@ -0,0 +1,16 @@
package codechicken.nei.api;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public interface IInfiniteItemHandler
{
void onPickup(ItemStack heldItem);
void onPlaceInfinite(ItemStack heldItem);
boolean canHandleItem(ItemStack stack);
boolean isItemInfinite(ItemStack stack);
public void replenishInfiniteStack(InventoryPlayer inventory, int slotNo);
public ItemStack getInfiniteItem(ItemStack typeStack);
}
@@ -0,0 +1,43 @@
package codechicken.nei.api;
import codechicken.nei.VisiblityData;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import java.util.Collections;
import java.util.List;
/**
* Lets you just override those things you want to
*/
public class INEIGuiAdapter implements INEIGuiHandler
{
@Override
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility)
{
return currentVisibility;
}
@Override
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
return Collections.emptyList();
}
@Override
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui)
{
return null;
}
@Override
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button)
{
return false;
}
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h)
{
return false;
}
}
@@ -0,0 +1,48 @@
package codechicken.nei.api;
import codechicken.nei.VisiblityData;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import java.util.List;
/**
* If this is implemented on a gui, it will be automatically registered
*/
public interface INEIGuiHandler
{
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility);
/**
* NEI will give the specified item to the InventoryRange returned if the player's inventory is full.
* return null for no range
*/
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item);
/**
* @return A list of TaggedInventoryAreas that will be used with the savestates.
*/
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui);
/**
* Handles clicks while an itemstack has been dragged from the item panel. Use this to set configurable slots and the like.
* Changes made to the stackSize of the dragged stack will be kept
* @param gui The current gui instance
* @param mousex The x position of the mouse
* @param mousey The y position of the mouse
* @param draggedStack The stack being dragged from the item panel
* @param button The button presed
* @return True if the drag n drop was handled. False to resume processing through other routes. The held stack will be deleted if draggedStack.stackSize == 0
*/
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button);
/**
* Used to prevent the item panel from drawing on top of other gui elements.
* @param x The x coordinate of the rectangle bounding the slot
* @param y The y coordinate of the rectangle bounding the slot
* @param w The w coordinate of the rectangle bounding the slot
* @param h The h coordinate of the rectangle bounding the slot
* @return true if the item panel slot within the specified rectangle should not be rendered.
*/
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h);
}
@@ -0,0 +1,6 @@
package codechicken.nei.api;
public interface INEIModeHandler
{
public boolean isModeValid(int mode);
}
@@ -0,0 +1,9 @@
package codechicken.nei.api;
import codechicken.nei.recipe.IRecipeHandler;
import net.minecraft.client.gui.inventory.GuiContainer;
public interface IOverlayHandler
{
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift);
}
@@ -0,0 +1,9 @@
package codechicken.nei.api;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.inventory.Slot;
public interface IRecipeOverlayRenderer
{
public void renderOverlay(GuiContainerManager gui, Slot slot);
}
@@ -0,0 +1,14 @@
package codechicken.nei.api;
import codechicken.nei.PositionedStack;
import java.util.ArrayList;
/**
* For repositioning recipes in overlay renderers.
*
*/
public interface IStackPositioner
{
public ArrayList<PositionedStack> positionStacks(ArrayList<PositionedStack> ai);
}
+431
View File
@@ -0,0 +1,431 @@
package codechicken.nei.api;
import codechicken.core.featurehack.GameDataManipulator;
import codechicken.nei.*;
import codechicken.nei.config.ArrayDumper;
import codechicken.nei.config.ItemPanelDumper;
import codechicken.nei.config.RegistryDumper;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.RecipeItemInputHandler;
import com.google.common.collect.ArrayListMultimap;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityList.EntityEggInfo;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.entity.monster.EntitySnowman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.RegistryNamespaced;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.oredict.OreDictionary;
import java.util.*;
/**
* This is an internal class for storing information about items, to be accessed by the API
*/
public class ItemInfo
{
public static enum Layout
{
HEADER, BODY, FOOTER
}
public static final HashMap<Layout, ArrayList<IHighlightHandler>> highlightHandlers = new HashMap<Layout, ArrayList<IHighlightHandler>>();
public static final ItemStackMap<String> nameOverrides = new ItemStackMap<String>();
public static final ItemStackSet hiddenItems = new ItemStackSet();
public static final ItemStackSet finiteItems = new ItemStackSet();
public static final ArrayListMultimap<Item, ItemStack> itemOverrides = ArrayListMultimap.create();
public static final LinkedList<IInfiniteItemHandler> infiniteHandlers = new LinkedList<IInfiniteItemHandler>();
public static final ArrayListMultimap<Block, IHighlightHandler> highlightIdentifiers = ArrayListMultimap.create();
public static final HashSet<Class<? extends Slot>> fastTransferExemptions = new HashSet<Class<? extends Slot>>();
public static final HashMap<Item, String> itemOwners = new HashMap<Item, String>();
static {
for (Layout layout : Layout.values())
ItemInfo.highlightHandlers.put(layout, new ArrayList<IHighlightHandler>());
}
public static boolean isHidden(ItemStack stack) {
return hiddenItems.contains(stack);
}
public static boolean isHidden(Item item) {
return hiddenItems.containsAll(item);
}
public static String getNameOverride(ItemStack stack) {
return nameOverrides.get(stack);
}
public static boolean canBeInfinite(ItemStack stack) {
return !finiteItems.contains(stack);
}
public static List<ItemStack> getItemOverrides(Item item) {
return itemOverrides.get(item);
}
public static void load(World world) {
addVanillaBlockProperties();
addDefaultDropDowns();
searchItems();
parseModItems();
addMobSpawnerItem(world);
addSpawnEggs();
addInfiniteHandlers();
addInputHandlers();
addIDDumps();
}
private static void addIDDumps() {
API.addOption(new RegistryDumper<Item>("tools.dump.item")
{
@Override
public String[] header() {
return new String[]{"Name", "ID", "Has Block", "Mod", "Class"};
}
@Override
public String[] dump(Item item, int id, String name) {
return new String[]{
name,
Integer.toString(id),
Boolean.toString(Block.getBlockFromItem(item) != Blocks.air),
ItemInfo.itemOwners.get(item),
item.getClass().getCanonicalName()
};
}
@Override
public RegistryNamespaced registry() {
return Item.itemRegistry;
}
});
API.addOption(new RegistryDumper<Block>("tools.dump.block")
{
@Override
public String[] header() {
return new String[]{"Name", "ID", "Has Item", "Mod", "Class"};
}
@Override
public String[] dump(Block item, int id, String name) {
return new String[]{
name,
Integer.toString(id),
Boolean.toString(Item.getItemFromBlock(item) != null),
ItemInfo.itemOwners.get(item),
item.getClass().getCanonicalName()
};
}
@Override
public RegistryNamespaced registry() {
return Block.blockRegistry;
}
});
API.addOption(new ArrayDumper<Potion>("tools.dump.potion")
{
public String[] header() {
return new String[]{"ID", "Unlocalised name", "Class"};
}
@Override
public String[] dump(Potion potion, int id) {
return new String[]{
Integer.toString(id),
potion.getName(),
potion.getClass().getCanonicalName()
};
}
@Override
public Potion[] array() {
return Potion.potionTypes;
}
});
API.addOption(new ArrayDumper<Enchantment>("tools.dump.enchantment")
{
public String[] header() {
return new String[]{"ID", "Unlocalised name", "Type", "Min Level", "Max Level", "Class"};
}
@Override
public String[] dump(Enchantment ench, int id) {
return new String[]{
Integer.toString(id),
ench.getName(),
ench.type.toString(),
Integer.toString(ench.getMinLevel()),
Integer.toString(ench.getMaxLevel()),
ench.getClass().getCanonicalName()
};
}
@Override
public Enchantment[] array() {
return Enchantment.enchantmentsList;
}
});
API.addOption(new ArrayDumper<BiomeGenBase>("tools.dump.biome")
{
@Override
public String[] header() {
return new String[]{"ID", "Name", "Temperature", "Rainfall", "Spawn Chance", "Root Height", "Height Variation", "Types", "Class"};
}
@Override
public String[] dump(BiomeGenBase biome, int id) {
BiomeDictionary.Type[] types = BiomeDictionary.getTypesForBiome(biome);
StringBuilder s_types = new StringBuilder();
for (BiomeDictionary.Type t : types) {
if (s_types.length() > 0)
s_types.append(", ");
s_types.append(t.name());
}
return new String[]{
Integer.toString(id),
biome.biomeName,
Float.toString(biome.getFloatTemperature(0, 0, 0)),
Float.toString(biome.getFloatRainfall()),
Float.toString(biome.getSpawningChance()),
Float.toString(biome.rootHeight),
Float.toString(biome.heightVariation),
s_types.toString(),
biome.getClass().getCanonicalName()
};
}
@Override
public BiomeGenBase[] array() {
return BiomeGenBase.getBiomeGenArray();
}
});
API.addOption(new ItemPanelDumper("tools.dump.itempanel"));
}
private static void parseModItems() {
//TODO GameRegistry.findUniqueIdentifierFor()
}
private static void addInputHandlers() {
GuiContainerManager.addInputHandler(new RecipeItemInputHandler());
GuiContainerManager.addInputHandler(new PopupInputHandler());
}
private static void addMobSpawnerItem(World world) {
GameDataManipulator.replaceItem(Block.getIdFromBlock(Blocks.mob_spawner), new ItemMobSpawner(world));
}
private static void addInfiniteHandlers() {
API.addInfiniteItemHandler(new InfiniteStackSizeHandler());
API.addInfiniteItemHandler(new InfiniteToolHandler());
}
private static void addVanillaBlockProperties() {
API.setOverrideName(new ItemStack(Blocks.flowing_water), "Water Source");
API.setOverrideName(new ItemStack(Blocks.water), "Water Still");
API.setOverrideName(new ItemStack(Blocks.flowing_lava), "Lava Source");
API.setOverrideName(new ItemStack(Blocks.lava), "Lava Still");
API.setOverrideName(new ItemStack(Blocks.end_portal), "End Portal");
API.setOverrideName(new ItemStack(Blocks.end_portal_frame), "End Portal Frame");
API.hideItem(new ItemStack(Blocks.double_stone_slab, 1, OreDictionary.WILDCARD_VALUE));
API.hideItem(new ItemStack(Blocks.double_wooden_slab, 1, OreDictionary.WILDCARD_VALUE));
API.hideItem(new ItemStack(Blocks.carrots));
API.hideItem(new ItemStack(Blocks.potatoes));
API.hideItem(new ItemStack(Blocks.cocoa));
}
private static void addDefaultDropDowns() {
/*API.addSetRange("Blocks", new MultiItemRange("[0-32000]")
{
@Override
public void addItemIfInRange(int item, int damage, NBTTagCompound compound) {
if (item < Block.blocksList.length && (Block.blocksList[item] != null && Block.blocksList[item].blockMaterial != Material.air))
super.addItemIfInRange(item, damage, compound);
}
});
API.addSetRange("Items", new MultiItemRange("[0-32000]")
{
@Override
public void addItemIfInRange(int item, int damage, NBTTagCompound compound) {
if (item >= Block.blocksList.length || Block.blocksList[item] == null || Block.blocksList[item].blockMaterial == Material.air)
super.addItemIfInRange(item, damage, compound);
}
});
API.addSetRange("Blocks.MobSpawners", new MultiItemRange("[52]"));*/
}
//TODO
private static void searchItems() {
/*MultiItemRange tools = new MultiItemRange();
MultiItemRange picks = new MultiItemRange();
MultiItemRange shovels = new MultiItemRange();
MultiItemRange axes = new MultiItemRange();
MultiItemRange hoes = new MultiItemRange();
MultiItemRange swords = new MultiItemRange();
MultiItemRange chest = new MultiItemRange();
MultiItemRange helmets = new MultiItemRange();
MultiItemRange legs = new MultiItemRange();
MultiItemRange boots = new MultiItemRange();
MultiItemRange other = new MultiItemRange();
MultiItemRange ranged = new MultiItemRange();
MultiItemRange food = new MultiItemRange();
MultiItemRange potioningredients = new MultiItemRange();
MultiItemRange[] creativeTabRanges = new MultiItemRange[CreativeTabs.creativeTabArray.length];
for (CreativeTabs tab : CreativeTabs.creativeTabArray)
creativeTabRanges[tab.getTabIndex()] = new MultiItemRange();
for (Item item : (Iterable<Item>) Item.itemRegistry) {
if (item == null)
continue;
CreativeTabs itemTab = item.getCreativeTab();
if (itemTab != null)
creativeTabRanges[itemTab.getTabIndex()].add(item);
if (item.isDamageable()) {
tools.add(item);
if (item instanceof ItemPickaxe) {
picks.add(item);
} else if (item instanceof ItemSpade) {
shovels.add(item);
} else if (item instanceof ItemAxe) {
axes.add(item);
} else if (item instanceof ItemHoe) {
hoes.add(item);
} else if (item instanceof ItemSword) {
swords.add(item);
} else if (item instanceof ItemArmor) {
switch (((ItemArmor) item).armorType) {
case 0:
helmets.add(item);
break;
case 1:
chest.add(item);
break;
case 2:
legs.add(item);
break;
case 3:
boots.add(item);
break;
}
} else if (item == Items.arrow || item == Items.bow) {
ranged.add(item);
} else if (item == Items.fishing_rod || item == Items.flint_and_steel || item == Items.shears) {
other.add(item);
}
}
if (item instanceof ItemFood) {
food.add(item);
}
if (item.isPotionIngredient()) {
BrewingRecipeHandler.ingredients.add(item);
potioningredients.add(item);
}
}
API.addSetRange("Items.Tools.Pickaxes", picks);
API.addSetRange("Items.Tools.Shovels", shovels);
API.addSetRange("Items.Tools.Axes", axes);
API.addSetRange("Items.Tools.Hoes", hoes);
API.addSetRange("Items.Tools.Other", other);
API.addSetRange("Items.Weapons.Swords", swords);
API.addSetRange("Items.Weapons.Ranged", ranged);
API.addSetRange("Items.Armor.ChestPlates", chest);
API.addSetRange("Items.Armor.Leggings", legs);
API.addSetRange("Items.Armor.Helmets", helmets);
API.addSetRange("Items.Armor.Boots", boots);
API.addSetRange("Items.Food", food);
API.addSetRange("Items.Potions.Ingredients", potioningredients);
for (CreativeTabs tab : CreativeTabs.creativeTabArray) {
if (creativeTabRanges[tab.getTabIndex()].ranges.size() > 0)
API.addSetRange("CreativeTabs." + LangUtil.translateG(tab.getTranslatedTabLabel()), creativeTabRanges[tab.getTabIndex()]);
}*/
}
private static void addSpawnEggs()
{
addEntityEgg(EntitySnowman.class, 0xEEFFFF, 0xffa221);
addEntityEgg(EntityIronGolem.class, 0xC5C2C1, 0xffe1cc);
}
private static void addEntityEgg(Class<?> entity, int i, int j) {
int id = (Integer)EntityList.classToIDMapping.get(entity);
EntityList.entityEggs.put(id, new EntityEggInfo(id, i, j));
}
public static ArrayList<ItemStack> getIdentifierItems(World world, EntityPlayer player, MovingObjectPosition hit) {
int x = hit.blockX;
int y = hit.blockY;
int z = hit.blockZ;
Block mouseoverBlock = world.getBlock(x, y, z);
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
ArrayList<IHighlightHandler> handlers = new ArrayList<IHighlightHandler>();
if (highlightIdentifiers.containsKey(null))
handlers.addAll(highlightIdentifiers.get(null));
if (highlightIdentifiers.containsKey(mouseoverBlock))
handlers.addAll(highlightIdentifiers.get(mouseoverBlock));
for (IHighlightHandler ident : handlers) {
ItemStack item = ident.identifyHighlight(world, player, hit);
if (item != null)
items.add(item);
}
if (items.size() > 0)
return items;
ItemStack pick = mouseoverBlock.getPickBlock(hit, world, x, y, z);
if (pick != null)
items.add(pick);
try {
items.addAll(mouseoverBlock.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0));
} catch (Exception ignored) {}
if (mouseoverBlock instanceof IShearable) {
IShearable shearable = (IShearable) mouseoverBlock;
if (shearable.isShearable(new ItemStack(Items.shears), world, x, y, z))
items.addAll(shearable.onSheared(new ItemStack(Items.shears), world, x, y, z, 0));
}
if (items.size() == 0)
items.add(0, new ItemStack(mouseoverBlock, 1, world.getBlockMetadata(x, y, z)));
return items;
}
public static void registerHighlightHandler(IHighlightHandler handler, ItemInfo.Layout... layouts) {
for (ItemInfo.Layout layout : layouts)
ItemInfo.highlightHandlers.get(layout).add(handler);
}
public static List<String> getText(ItemStack itemStack, World world, EntityPlayer player, MovingObjectPosition mop) {
List<String> retString = new ArrayList<String>();
for (ItemInfo.Layout layout : ItemInfo.Layout.values())
for (IHighlightHandler handler : ItemInfo.highlightHandlers.get(layout))
retString = handler.handleTextData(itemStack, world, player, mop, retString, layout);
return retString;
}
}
+20
View File
@@ -0,0 +1,20 @@
package codechicken.nei.api;
import codechicken.nei.Button;
import codechicken.nei.VisiblityData;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.client.gui.inventory.GuiContainer;
public abstract class LayoutStyle
{
public abstract void init();
public abstract void reset();
public abstract void layout(GuiContainer gui, VisiblityData visibility);
public abstract String getName();
public void drawBackground(GuiContainerManager gui)
{
}
public abstract void drawButton(Button button, int mousex, int mousey);
public abstract boolean texturedButtons();
}
+29
View File
@@ -0,0 +1,29 @@
package codechicken.nei.api;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.config.OptionCycled;
import net.minecraft.world.World;
import java.util.LinkedList;
public class NEIInfo
{
public static final LinkedList<INEIModeHandler> modeHandlers = new LinkedList<INEIModeHandler>();
public static void load(World world) {
OptionCycled modeOption = (OptionCycled) NEIClientConfig.getOptionList().getOption("inventory.cheatmode");
modeOption.parent.synthesizeEnvironment();
if(!modeOption.optionValid(modeOption.value())) {
modeOption.copyGlobals();
modeOption.cycle();
}
}
public static boolean isValidMode(int mode) {
for(INEIModeHandler handler : modeHandlers)
if(!handler.isModeValid(mode))
return false;
return true;
}
}
@@ -0,0 +1,48 @@
package codechicken.nei.api;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import java.util.HashSet;
public class TaggedInventoryArea
{
public HashSet<Integer> slots = new HashSet<Integer>();
public String tagName;
/**
* Only for player inventories.
*/
private IInventory inventory;
/**
* Other inventories
*/
private Container container;
public TaggedInventoryArea(InventoryPlayer invPlayer)
{
this("InventoryPlayer", 0, 39, null);
inventory = invPlayer;
}
public TaggedInventoryArea(String name, int first, int last, Container container)
{
this.container = container;
tagName = name;
for(int i = first; i <= last; i++)
slots.add(i);
}
public ItemStack getStackInSlot(int i)
{
if(inventory != null)
return inventory.getStackInSlot(i);
return container.getSlot(i).getStack();
}
public boolean isContainer()
{
return inventory == null;
}
}
@@ -0,0 +1,42 @@
package codechicken.nei.asm;
import codechicken.core.launch.CodeChickenCorePlugin;
import cpw.mods.fml.relauncher.IFMLCallHook;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions;
import java.util.Map;
@TransformerExclusions(value = {"codechicken.nei.asm"})
public class NEICorePlugin implements IFMLLoadingPlugin, IFMLCallHook
{
@Override
public String[] getASMTransformerClass() {
CodeChickenCorePlugin.versionCheck(CodeChickenCorePlugin.mcVersion, "NotEnoughItems");
return new String[]{"codechicken.nei.asm.NEITransformer"};
}
@Override
public String getModContainerClass() {
return "codechicken.nei.NEIModContainer";
}
@Override
public String getSetupClass() {
return "codechicken.nei.asm.NEICorePlugin";
}
@Override
public void injectData(Map<String, Object> data) {
}
@Override
public String getAccessTransformerClass() {
return null;
}
@Override
public Void call() {
return null;
}
}
+180
View File
@@ -0,0 +1,180 @@
package codechicken.nei.asm;
import codechicken.lib.asm.*;
import codechicken.lib.asm.ModularASMTransformer.*;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.tree.*;
import org.objectweb.asm.util.TraceClassVisitor;
import java.io.*;
import java.util.Map;
import static codechicken.lib.asm.InsnComparator.*;
import static org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
import static org.objectweb.asm.ClassWriter.COMPUTE_MAXS;
import static org.objectweb.asm.Opcodes.*;
public class NEITransformer implements IClassTransformer
{
private ModularASMTransformer transformer = new ModularASMTransformer();
private Map<String, ASMBlock> asmblocks = ASMReader.loadResource("/assets/nei/asm/blocks.asm");
public NEITransformer() {
//Generates method to set the placed position of a mob spawner for the item callback. More portable than copying vanilla placement code
transformer.add(new MethodWriter(ACC_PUBLIC,
new ObfMapping("net/minecraft/block/BlockMobSpawner", "func_149689_a", "(Lnet/minecraft/world/World;IIILnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;)V"),
asmblocks.get("spawnerPlaced")));
//Make MobSpawnerBaseLogic use getSpawnerWorld when creating new entities
transformer.add(new MethodReplacer(new ObfMapping("net/minecraft/tileentity/MobSpawnerBaseLogic", "func_98281_h", "()Lnet/minecraft/entity/Entity;"),
asmblocks.get("d_spawnerWorld"), asmblocks.get("spawnerWorld")));
//Removes trailing seperators from NBTTagList/Compound.toString because OCD
transformer.add(new MethodInjector(new ObfMapping("net/minecraft/nbt/NBTTagCompound", "toString", "()Ljava/lang/String;"),
asmblocks.get("n_commaFix"), asmblocks.get("commaFix"), true));
transformer.add(new MethodInjector(new ObfMapping("net/minecraft/nbt/NBTTagList", "toString", "()Ljava/lang/String;"),
asmblocks.get("n_commaFix"), asmblocks.get("commaFix"), true));
String GuiContainer = "net/minecraft/client/gui/inventory/GuiContainer";
//add manager field
transformer.add(new FieldWriter(ACC_PUBLIC, new ObfMapping(GuiContainer, "manager", "Lcodechicken/nei/guihook/GuiContainerManager;")));
//Fill out getManager in GuiContainerManager
transformer.add(new MethodWriter(ACC_PUBLIC | ACC_STATIC,
new ObfMapping("codechicken/nei/guihook/GuiContainerManager", "getManager", "(Lnet/minecraft/client/gui/inventory/GuiContainer;)Lcodechicken/nei/guihook/GuiContainerManager;"),
asmblocks.get("m_getManager")));
//Generate load method
transformer.add(new MethodWriter(ACC_PUBLIC, new ObfMapping(GuiContainer, "func_146280_a", "(Lnet/minecraft/client/Minecraft;II)V"), asmblocks.get("m_setWorldAndResolution")));
//Generate handleKeyboardInput method
transformer.add(new MethodWriter(ACC_PUBLIC, new ObfMapping(GuiContainer, "func_146282_l", "()V"), asmblocks.get("m_handleKeyboardInput")));
//Generate handleKeyboardInput method
transformer.add(new MethodWriter(ACC_PUBLIC, new ObfMapping(GuiContainer, "func_146282_l", "()V"), asmblocks.get("m_handleKeyboardInput")));
//Generate handleKeyboardInput method
transformer.add(new MethodWriter(ACC_PUBLIC, new ObfMapping(GuiContainer, "func_146282_l", "()V"), asmblocks.get("m_handleKeyboardInput")));
//Generate handleMouseInput method
transformer.add(new MethodWriter(ACC_PUBLIC, new ObfMapping(GuiContainer, "func_146274_d", "()V"), asmblocks.get("m_handleMouseInput")));
//Generate public accessor for keyTyped
transformer.add(new MethodWriter(ACC_PUBLIC, new ObfMapping(GuiContainer, "publicKeyTyped", "(CI)V"), asmblocks.get("m_publicKeyTyped")));
//Fill out callKeyTyped in GuiContainerManager
transformer.add(new MethodWriter(ACC_PUBLIC | ACC_STATIC,
new ObfMapping("codechicken/nei/guihook/GuiContainerManager", "callKeyTyped", "(Lnet/minecraft/client/gui/inventory/GuiContainer;CI)V"),
asmblocks.get("m_callKeyTyped")));
//Inject preDraw at the start of drawScreen
transformer.add(new MethodInjector(new ObfMapping(GuiContainer, "func_73863_a", "(IIF)V"), asmblocks.get("preDraw"), true));
//Inject objectUnderMouse check before drawing slot highlights
transformer.add(new MethodInjector(new ObfMapping(GuiContainer, "func_73863_a", "(IIF)V"), asmblocks.get("n_objectUnderMouse"), asmblocks.get("objectUnderMouse"), false));
//Inject renderObjects after drawGuiContainerForegroundLayer
transformer.add(new MethodInjector(new ObfMapping(GuiContainer, "func_73863_a", "(IIF)V"), asmblocks.get("n_renderObjects"), asmblocks.get("renderObjects"), false));
//Replace default renderToolTip with delegate
transformer.add(new MethodReplacer(new ObfMapping(GuiContainer, "func_73863_a", "(IIF)V"), asmblocks.get("d_renderToolTip"), asmblocks.get("renderTooltips")));
//Replace zLevel = 200 with zLevel = 500 in drawItemStack
transformer.add(new MethodReplacer(new ObfMapping(GuiContainer, "func_146982_a", "(Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V"),
asmblocks.get("d_zLevel"), asmblocks.get("zLevel")));
//Replace default renderItem with delegate and slot overlay/underlay
transformer.add(new MethodReplacer(new ObfMapping(GuiContainer, "func_146977_a", "(Lnet/minecraft/inventory/Slot;)V"), asmblocks.get("d_drawSlot"), asmblocks.get("drawSlot")));
//Inject mouseClicked hook after super call in mouseClicked
transformer.add(new MethodInjector(new ObfMapping(GuiContainer, "func_73864_a", "(III)V"), asmblocks.get("n_mouseClicked"), asmblocks.get("mouseClicked"), false));
//Replace general handleMouseClicked call with delegate
transformer.add(new MethodReplacer(new ObfMapping(GuiContainer, "func_73864_a", "(III)V"), asmblocks.get("d_handleMouseClick"), asmblocks.get("handleMouseClick")));
//Inject mouseDragged hook after super call in mouseDragged
transformer.add(new MethodInjector(new ObfMapping(GuiContainer, "func_146273_a", "(IIIJ)V"), asmblocks.get("n_mouseDragged"), asmblocks.get("mouseDragged"), false));
//Inject overrideMouseUp at the start of mouseMovedOrUp
transformer.add(new MethodInjector(new ObfMapping(GuiContainer, "func_146286_b", "(III)V"), asmblocks.get("overrideMouseUp"), true));
//Replace general handleMouseClicked call with delegate
transformer.add(new MethodReplacer(new ObfMapping(GuiContainer, "func_146286_b", "(III)V"), asmblocks.get("d_handleMouseClick2"), asmblocks.get("handleMouseClick2")));
transformer.add(new MethodTransformer(new ObfMapping(GuiContainer, "func_146286_b", "(III)V"))
{
@Override
public void transform(MethodNode mv) {
ASMBlock gotoBlock = asmblocks.get("n_mouseUpGoto");
ASMBlock needleBlock = asmblocks.get("n_mouseUp");
ASMBlock injectionBlock = asmblocks.get("mouseUp");
gotoBlock.mergeLabels(injectionBlock);
findOnce(mv.instructions, gotoBlock.list).replace(gotoBlock.list.list);
InsnListSection needle = findOnce(mv.instructions, needleBlock.list);
injectionBlock.mergeLabels(needleBlock.applyLabels(needle));
needle.insertBefore(injectionBlock.list.list);
}
});
//Replace general handleSlotClick call with delegate
transformer.add(new MethodReplacer(new ObfMapping(GuiContainer, "func_146984_a", "(Lnet/minecraft/inventory/Slot;III)V"),
asmblocks.get("d_handleSlotClick"), asmblocks.get("handleSlotClick")));
//Inject lastKeyTyped at the start of keyTyped
transformer.add(new MethodInjector(new ObfMapping(GuiContainer, "func_73869_a", "(CI)V"), asmblocks.get("lastKeyTyped"), true));
//Inject updateScreen hook after super call
transformer.add(new MethodInjector(new ObfMapping(GuiContainer, "func_73876_c", "()V"), asmblocks.get("n_updateScreen"), asmblocks.get("updateScreen"), false));
}
private ObfMapping c_GuiContainer = new ObfMapping("net/minecraft/client/gui/inventory/GuiContainer").toClassloading();
/**
* Adds super.updateScreen() to non implementing GuiContainer subclasses
*/
public byte[] transformSubclasses(String name, byte[] bytes) {
if (ClassHeirachyManager.classExtends(name, c_GuiContainer.javaClass())) {
ClassNode cnode = ASMHelper.createClassNode(bytes);
ObfMapping methodmap = new ObfMapping(cnode.superName, "func_73876_c", "()V").toClassloading();
InsnListSection supercall = new InsnListSection();
supercall.add(new VarInsnNode(ALOAD, 0));
supercall.add(methodmap.toInsn(INVOKESPECIAL));
boolean changed = false;
for (MethodNode mv : cnode.methods) {
if (methodmap.matches(mv)) {
if (matches(new InsnListSection(mv.instructions), supercall, getControlFlowLabels(mv.instructions)) == null) {
mv.instructions.insert(supercall.list);
ASMHelper.logger.debug("Inserted super call into " + methodmap);
changed = true;
}
}
}
if (changed)
bytes = ASMHelper.createBytes(cnode, COMPUTE_MAXS | COMPUTE_FRAMES);
}
return bytes;
}
@Override
public byte[] transform(String name, String tname, byte[] bytes) {
if (bytes == null) return null;
try {
if (FMLLaunchHandler.side().isClient())
bytes = transformSubclasses(name, bytes);
bytes = transformer.transform(name, bytes);
} catch (Exception e) {
throw new RuntimeException(e);
}
return bytes;
}
}
@@ -0,0 +1,31 @@
package codechicken.nei.config;
import java.util.LinkedList;
public abstract class ArrayDumper<T> extends DataDumper
{
public ArrayDumper(String name) {
super(name);
}
@Override
public Iterable<String[]> dump(int mode) {
LinkedList<String[]> list = new LinkedList<String[]>();
T[] array = array();
for (int i = 0; i < array.length; i++) {
T obj = array[i];
if (obj == null) {
if (mode == 1 || mode == 2)
list.add(new String[]{Integer.toString(i), null, null, null, null});
} else {
if (mode == 0 || mode == 2)
list.add(dump(obj, i));
}
}
return list;
}
public abstract T[] array();
public abstract String[] dump(T obj, int id);
}
+42
View File
@@ -0,0 +1,42 @@
package codechicken.nei.config;
import codechicken.lib.config.ConfigTagParent;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import java.io.File;
public class ConfigSet
{
private File nbtFile;
public NBTTagCompound nbt;
public ConfigTagParent config;
public ConfigSet(File nbtFile, ConfigTagParent config) {
this.nbtFile = nbtFile;
this.config = config;
loadNBT();
}
public void loadNBT() {
nbt = new NBTTagCompound();
try {
if (!nbtFile.getParentFile().exists())
nbtFile.getParentFile().mkdirs();
if (!nbtFile.exists())
nbtFile.createNewFile();
if (nbtFile.length() > 0)
nbt = CompressedStreamTools.read(nbtFile);
} catch (Exception e) {
e.printStackTrace();
}
}
public void saveNBT() {
try {
CompressedStreamTools.write(nbt, nbtFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
+160
View File
@@ -0,0 +1,160 @@
package codechicken.nei.config;
import codechicken.core.CommonUtils;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import static codechicken.lib.gui.GuiDraw.drawString;
import static codechicken.lib.gui.GuiDraw.drawStringC;
public abstract class DataDumper extends Option
{
public DataDumper(String name) {
super(name);
}
public abstract String[] header();
public abstract Iterable<String[]> dump(int mode);
public String renderName() {
return translateN(name + "s");
}
public void dumpFile() {
try {
File file = new File(CommonUtils.getMinecraftDir(), "dumps/" + getFileName(name.replaceFirst(".+\\.", "")));
if (!file.getParentFile().exists())
file.getParentFile().mkdirs();
if (!file.exists())
file.createNewFile();
dumpTo(file);
NEIClientUtils.printChatMessage(dumpMessage(file));
} catch (Exception e) {
System.err.println("Error dumping " + renderName() + " mode: " + getMode());
e.printStackTrace();
}
}
public String getFileName(String prefix) {
return prefix + getFileExtension();
}
public String getFileExtension() {
return ".csv";
}
public IChatComponent dumpMessage(File file) {
return new ChatComponentTranslation("nei.options.tools.dump.dumped",
translateN(name), "dumps/" + file.getName());
}
public void dumpTo(File file) throws IOException {
int mode = getMode();
PrintWriter w = new PrintWriter(file);
w.println(concat(header()));
for (String[] line : dump(mode))
w.println(concat(line));
w.close();
}
public static String concat(String[] header) {
StringBuilder sb = new StringBuilder();
for (String s : header) {
if (sb.length() > 0)
sb.append(',');
if (s == null)
s = "null";
if (s.indexOf(',') > 0 || s.indexOf('\"') > 0)
s = '\"' + s.replace("\"", "\"\"") + '\"';
sb.append(s);
}
return sb.toString();
}
@Override
public void draw(int mousex, int mousey, float frame) {
drawPrefix();
if(modeCount() > 1)
drawModeButton(mousex, mousey);
drawDumpButton(mousex, mousey);
}
public void drawPrefix() {
drawString(renderName(), 10, 8, -1);
}
public Rectangle4i dumpButtonSize() {
int width = 80;
return new Rectangle4i(slot.contentWidth() - width, 2, width, 20);
}
public Rectangle4i modeButtonSize() {
int width = 60;
return new Rectangle4i(slot.contentWidth() - width - 10 - dumpButtonSize().w, 2, width, 20);
}
public String dumpButtonText() {
return NEIClientUtils.lang.translate("options.tools.dump.dump");
}
public String modeButtonText() {
return NEIClientUtils.lang.translate("options.tools.dump.mode." + getMode());
}
public int getMode() {
return getTag().getIntValue(0);
}
public void drawModeButton(int mousex, int mousey) {
GL11.glColor4f(1, 1, 1, 1);
Rectangle4i b = modeButtonSize();
boolean hover = b.contains(mousex, mousey);
LayoutManager.drawButtonBackground(b.x, b.y, b.w, b.h, true, getButtonTex(hover));
drawStringC(modeButtonText(), b.x, b.y, b.w, b.h, getTextColour(hover));
}
public void drawDumpButton(int mousex, int mousey) {
GL11.glColor4f(1, 1, 1, 1);
Rectangle4i b = dumpButtonSize();
boolean hover = b.contains(mousex, mousey);
LayoutManager.drawButtonBackground(b.x, b.y, b.w, b.h, true, getButtonTex(hover));
drawStringC(dumpButtonText(), b.x, b.y, b.w, b.h, getTextColour(hover));
}
public int getButtonTex(boolean hover) {
return hover ? 2 : 1;
}
public int getTextColour(boolean hover) {
return hover ? 0xFFFFFFA0 : 0xFFE0E0E0;
}
@Override
public void mouseClicked(int mousex, int mousey, int button) {
if (modeCount() > 1 && modeButtonSize().contains(mousex, mousey)) {
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
getTag().setIntValue((getMode() + 1) % modeCount());
} else if (dumpButtonSize().contains(mousex, mousey)) {
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
dumpFile();
}
}
public int modeCount() {
return 3;
}
}
@@ -0,0 +1,149 @@
package codechicken.nei.config;
import codechicken.core.gui.GuiCCButton;
import codechicken.core.gui.GuiScreenWidget;
import codechicken.lib.math.MathHelper;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.HUDRenderer;
import codechicken.nei.NEIClientUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.input.Keyboard;
import java.awt.*;
import java.util.Arrays;
import static codechicken.lib.gui.GuiDraw.displaySize;
import static codechicken.lib.gui.GuiDraw.getMousePosition;
public class GuiHighlightTips extends GuiScreenWidget
{
private String name;
private GuiCCButton toggleButton;
private OptionHighlightTips opt;
private Point dragDown;
public GuiHighlightTips(OptionHighlightTips opt) {
super(80, 20);
this.opt = opt;
name = opt.name;
}
@Override
public boolean doesGuiPauseGame() {
return true;
}
public void addWidgets() {
add(toggleButton = new GuiCCButton(0, 0, 80, 20, "").setActionCommand("show"));
updateNames();
}
@Override
public void actionPerformed(String ident, Object... params) {
if (ident.equals("show")) {
opt.getTag(name).setBooleanValue(!show());
updateNames();
}
}
private void updateNames() {
toggleButton.text = NEIClientUtils.translate("options." + name + "." + (show() ? "show" : "hide"));
}
private boolean show() {
return opt.getTag(name).getBooleanValue();
}
@Override
public void keyTyped(char c, int keycode) {
if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) {
Minecraft.getMinecraft().displayGuiScreen(opt.slot.getGui());
return;
}
super.keyTyped(c, keycode);
}
@Override
public void drawScreen(int mousex, int mousey, float f) {
super.drawScreen(mousex, mousey, f);
if (show())
HUDRenderer.renderOverlay(new ItemStack(Blocks.redstone_block), Arrays.asList("RedstoneBlock", EnumChatFormatting.RED+"Sample"), renderPos());
}
public Point getPos() {
return new Point(opt.getTag(name + ".x").getIntValue(), opt.getTag(name + ".y").getIntValue());
}
public Dimension sampleSize()//copied from HUDManager when running with the sample for this gui
{
return new Dimension(101, 30);
}
public Point getDrag() {
Point mouse = getMousePosition();
Point drag = new Point(mouse.x - dragDown.x, mouse.y - dragDown.y);
Dimension size = displaySize();
Dimension sample = sampleSize();
drag.x *= 10000;
drag.y *= 10000;
drag.x /= (size.width - sample.width);
drag.y /= (size.height - sample.height);
Point pos = getPos();
drag.x = (int) MathHelper.clip(drag.x, -pos.x, 10000 - pos.x);
drag.y = (int) MathHelper.clip(drag.y, -pos.y, 10000 - pos.y);
return drag;
}
public Point renderPos() {
Point pos = getPos();
if (dragDown != null) {
Point drag = getDrag();
pos.x += drag.x;
pos.y += drag.y;
}
for (int i = 25; i < 100; i += 25)//snapping
{
if (pos.x / 100 == i)
pos.x = i * 100;
if (pos.y / 100 == i)
pos.y = i * 100;
}
return pos;
}
@Override
protected void mouseMovedOrUp(int x, int y, int button) {
if (button == 0 && dragDown != null) {
setPos(renderPos());
dragDown = null;
}
}
public Rectangle4i selectionBox() {
Point pos = renderPos();
Dimension size = displaySize();
Dimension rect = sampleSize();
return new Rectangle4i(
(size.width - rect.width) * pos.x / 10000,
(size.height - rect.height) * pos.y / 10000,
rect.width, rect.height);
}
@Override
protected void mouseClicked(int x, int y, int button) {
if (button == 0 && selectionBox().contains(x, y))
dragDown = getMousePosition();
else
super.mouseClicked(x, y, button);
}
private void setPos(Point p) {
opt.getTag(name + ".x").setIntValue(p.x);
opt.getTag(name + ".y").setIntValue(p.y);
}
}
@@ -0,0 +1,378 @@
package codechicken.nei.config;
import codechicken.core.gui.GuiCCButton;
import codechicken.core.gui.GuiScreenWidget;
import codechicken.core.gui.GuiScrollSlot;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.LayoutManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import static codechicken.lib.gui.GuiDraw.*;
import static net.minecraft.util.StatCollector.translateToLocal;
public class GuiOptionList extends GuiScreenWidget
{
public class OptionScrollSlot extends GuiScrollSlot
{
public ArrayList<Option> options = new ArrayList<Option>();
public OptionScrollSlot()
{
super(0, 0, 0, 0);
}
@Override
public void onAdded(GuiScreen s)
{
super.onAdded(s);
for(Option o : optionList.optionList)
options.add(o);
for(Option o : options)
o.onAdded(this);
}
@Override
public int getSlotHeight()
{
return 24;
}
public int contentWidth()
{
return width-20;
}
@Override
protected int getNumSlots()
{
return options.size();
}
@Override
public void selectNext()
{
}
@Override
public void selectPrev()
{
}
@Override
protected boolean isSlotSelected(int slot)
{
return false;
}
@Override
protected void drawSlot(int slot, int x, int y, int mousex, int mousey, boolean selected, float frame)
{
GL11.glTranslatef(x, y, 0);
Option o = options.get(slot);
if(o.showWorldSelector() && world)
drawWorldSelector(o, mousex, mousey);
o.draw(mousex, mousey, frame);
GL11.glTranslatef(-x, -y, 0);
}
public Rectangle4i worldButtonSize()
{
return new Rectangle4i(-24, 2, 20, 20);
}
private void drawWorldSelector(Option o, int mousex, int mousey)
{
Rectangle4i b = worldButtonSize();
boolean set = o.hasWorldOverride();
boolean mouseover = b.contains(mousex, mousey);
GL11.glColor4f(1, 1, 1, 1);
LayoutManager.drawButtonBackground(b.x, b.y, b.w, b.h, true, !set ? 0 : mouseover ? 2 : 1);
drawStringC("W", b.x, b.y, b.w, b.h, -1);
}
@Override
public void drawOverlay(float frame)
{
drawOverlayTex(0, 0, parentScreen.width, y);
drawOverlayTex(0, y+height, parentScreen.width, parentScreen.height-y-height);
drawOverlayGrad(0, parentScreen.width, y, y+4);
drawOverlayGrad(0, parentScreen.width, y+height, y+height-4);
}
public void drawOverlayTex(int x, int y, int w, int h)
{
GL11.glColor4f(1, 1, 1, 1);
renderEngine.bindTexture(Gui.optionsBackground);
Tessellator t = Tessellator.instance;
t.startDrawingQuads();
t.addVertexWithUV(x, y, zLevel, 0, 0);
t.addVertexWithUV(x, y+h, zLevel, 0, h/16D);
t.addVertexWithUV(x+w, y+h, zLevel, w/16D, h/16D);
t.addVertexWithUV(x+w, y, zLevel, w/16D, 0);
t.draw();
}
public void drawOverlayGrad(int x1, int x2, int y1, int y2)
{
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glShadeModel(GL11.GL_SMOOTH);
Tessellator t = Tessellator.instance;
t.startDrawingQuads();
t.setColorRGBA_I(0, 255);
t.addVertex(x2, y1, zLevel);
t.addVertex(x1, y1, zLevel);
t.setColorRGBA_I(0, 0);
t.addVertex(x1, y2, zLevel);
t.addVertex(x2, y2, zLevel);
t.draw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
@Override
public void drawSlotBox(float frame)
{
}
@Override
public boolean drawLineGuide()
{
return false;
}
@Override
public int getScrollBarWidth()
{
return 6;
}
@Override
public void drawScrollBar(float frame)
{
int sbarw = getScrollBarWidth();
int sbarx = x + width - sbarw;
drawRect(sbarx, y, sbarx+sbarw, y+height, 0xFF000000);
super.drawScrollBar(frame);
}
@Override
public void update()
{
super.update();
for(Option o : options)
o.update();
}
@Override
protected void slotClicked(int slot, int button, int mousex, int mousey, boolean doubleclick)
{
options.get(slot).mouseClicked(mousex, mousey, button);
}
@Override
public void mouseClicked(int mousex, int mousey, int button)
{
for(Option o : options)
o.onMouseClicked(mousex, mousey, button);
super.mouseClicked(mousex, mousey, button);
int slot = getClickedSlot(mousey);
if(slot >= 0)
{
Option o = options.get(slot);
if(world && o.showWorldSelector() && worldButtonSize().contains(mousex-contentx, mousey-getSlotY(slot)))
{
if(button == 1 && o.hasWorldOverride())
{
o.useGlobals();
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
else if(button == 0 && !o.hasWorldOverride())
{
o.copyGlobals();
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
}
}
}
@Override
public void keyTyped(char c, int keycode)
{
super.keyTyped(c, keycode);
for(Option o : options)
o.keyTyped(c, keycode);
}
public void resize()
{
int width = Math.min(parentScreen.width-80, 320);
setSize((parentScreen.width-width)/2, 20, width, parentScreen.height-50);
setContentSize(x, y+4, height-8);
}
@Override
public void mouseScrolled(int x, int y, int scroll)
{
scroll(-scroll);
}
public GuiOptionList getGui()
{
return ((GuiOptionList)parentScreen);
}
public List<String> handleTooltip(int mousex, int mousey, List<String> tooltip)
{
for(int slot = 0; slot < getNumSlots(); slot++)
{
int sloty = getSlotY(slot);
if(sloty > contenty - getSlotHeight() && sloty < contenty + contentheight)
tooltip = handleTooltip(slot, mousex-contentx, mousey-sloty, tooltip);
}
return tooltip;
}
private List<String> handleTooltip(int slot, int mousex, int mousey, List<String> tooltip)
{
Option o = options.get(slot);
if(world && o.showWorldSelector() && worldButtonSize().contains(mousex, mousey))
tooltip.add(translateToLocal("nei.options.wbutton.tip."+(o.hasWorldOverride() ? "1" : "0")));
return o.handleTooltip(mousex, mousey, tooltip);
}
}
private final GuiScreen parent;
private final OptionList optionList;
private boolean world;
private OptionScrollSlot slot;
private GuiCCButton backButton;
private GuiCCButton worldButton;
public GuiOptionList(GuiScreen parent, OptionList optionList, boolean world)
{
this.parent = parent;
this.optionList = optionList;
this.world = world;
}
@Override
public void initGui()
{
xSize = width;
ySize = height;
super.initGui();
if(slot != null)
{
slot.resize();
backButton.width = Math.min(200, width-40);
backButton.x = (width-backButton.width)/2;
backButton.y = height-25;
worldButton.width = 60;
worldButton.x = width-worldButton.width-15;
}
}
@Override
public void addWidgets()
{
add(slot = new OptionScrollSlot());
add(backButton = new GuiCCButton(0, 0, 0, 20, translateToLocal("nei.options.back")).setActionCommand("back"));
add(worldButton = new GuiCCButton(0, 2, 0, 16, worldButtonName()).setActionCommand("world"));
initGui();
}
private String worldButtonName()
{
return translateToLocal("nei.options." + (world ? "world" : "global"));
}
@Override
public void actionPerformed(String ident, Object... params)
{
if(ident.equals("back"))
{
if(parent instanceof GuiOptionList)
((GuiOptionList)parent).world = world;
Minecraft.getMinecraft().displayGuiScreen(parent);
}
else if(ident.equals("world"))
{
world = !world;
worldButton.text = worldButtonName();
}
}
@Override
public void drawBackground()
{
drawDefaultBackground();
}
@Override
public void drawForeground()
{
drawCenteredString(fontRenderer, translateToLocal(optionList.fullName()), width/2, 6, -1);
drawTooltip();
}
private void drawTooltip()
{
List<String> tooltip = new LinkedList<String>();
Point mouse = getMousePosition();
if(worldButton.pointInside(mouse.x, mouse.y))
tooltip.addAll(Arrays.asList(translateToLocal("nei.options.global.tip." + (world ? "1" : "0")).split(":")));
tooltip = slot.handleTooltip(mouse.x, mouse.y, tooltip);
drawMultilineTip(mouse.x+12, mouse.y-12, tooltip);
}
@Override
public boolean doesGuiPauseGame()
{
return false;
}
@Override
public void keyTyped(char c, int keycode)
{
if (keycode == 1)//esc
{
GuiScreen p = parent;
while(p instanceof GuiOptionList)
p = ((GuiOptionList)p).parent;
Minecraft.getMinecraft().displayGuiScreen(p);
}
else
{
super.keyTyped(c, keycode);
}
}
public boolean worldConfig()
{
return world;
}
}
@@ -0,0 +1,7 @@
package codechicken.nei.config;
public interface IConfigSetHolder
{
public ConfigSet worldConfigSet();
public ConfigSet globalConfigSet();
}
@@ -0,0 +1,114 @@
package codechicken.nei.config;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.nei.ItemPanel;
import codechicken.nei.ItemPanel.ItemPanelObject;
import codechicken.nei.ItemPanelStack;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;
public class ItemPanelDumper extends DataDumper
{
public ItemPanelDumper(String name) {
super(name);
}
@Override
public String[] header() {
return new String[]{"Item Name", "Item ID", "Item meta", "Has NBT", "Display Name"};
}
@Override
public Iterable<String[]> dump(int mode) {
LinkedList<String[]> list = new LinkedList<String[]>();
for (ItemPanelObject obj : ItemPanel.visibleitems)
if (obj instanceof ItemPanelStack) {
ItemStack stack = ((ItemPanelStack) obj).item;
list.add(new String[]{
Item.itemRegistry.getNameForObject(stack.getItem()),
Integer.toString(Item.getIdFromItem(stack.getItem())),
Integer.toString(InventoryUtils.actualDamage(stack)),
stack.stackTagCompound == null ? "false" : "true",
EnumChatFormatting.getTextWithoutFormattingCodes(GuiContainerManager.itemDisplayNameShort(stack))
});
}
return list;
}
@Override
public String renderName() {
return translateN(name);
}
@Override
public String getFileExtension() {
switch(getMode()) {
case 0: return ".csv";
case 1: return ".nbt";
case 2: return ".json";
}
return null;
}
@Override
public ChatComponentTranslation dumpMessage(File file) {
return new ChatComponentTranslation(namespaced(name + ".dumped"), "dumps/" + file.getName());
}
@Override
public String modeButtonText() {
return translateN(name + ".mode." + getMode());
}
@Override
public void dumpTo(File file) throws IOException {
if (getMode() == 0)
super.dumpTo(file);
else if (getMode() == 1)
dumpNBT(file);
else
dumpJson(file);
}
public void dumpNBT(File file) throws IOException {
NBTTagList list = new NBTTagList();
for (ItemPanelObject obj : ItemPanel.visibleitems)
if (obj instanceof ItemPanelStack)
list.appendTag(((ItemPanelStack) obj).item.writeToNBT(new NBTTagCompound()));
NBTTagCompound tag = new NBTTagCompound();
tag.setTag("list", list);
CompressedStreamTools.writeCompressed(tag, new FileOutputStream(file));
}
public void dumpJson(File file) throws IOException {
PrintWriter p = new PrintWriter(file);
for (ItemPanelObject obj : ItemPanel.visibleitems)
if (obj instanceof ItemPanelStack) {
NBTTagCompound tag = ((ItemPanelStack) obj).item.writeToNBT(new NBTTagCompound());
tag.removeTag("Count");
p.println(tag);
}
p.close();
}
@Override
public int modeCount() {
return 3;
}
}
+183
View File
@@ -0,0 +1,183 @@
package codechicken.nei.config;
import codechicken.lib.config.ConfigTag;
import codechicken.nei.config.GuiOptionList.OptionScrollSlot;
import net.minecraft.util.StatCollector;
import java.util.List;
public abstract class Option
{
public OptionScrollSlot slot;
public String namespace = null;
public final String name;
public OptionList parent;
public Option(String name)
{
this.name = name;
}
public String fullName()
{
return namespaced(name);
}
public String configName()
{
return fullName().substring(configBase().fullName().length()+1);
}
public String namespaced(String name)
{
return namespace == null ? name : (namespace+"."+name);
}
public String translateN(String s, Object... args)
{
return StatCollector.translateToLocalFormatted(namespaced(s), args);
}
public ConfigSet globalConfigSet()
{
return parent.globalConfigSet();
}
public ConfigSet worldConfigSet()
{
return parent.worldConfigSet();
}
public OptionList configBase()
{
return parent.configBase();
}
public boolean worldSpecific()
{
return worldSpecific(configName());
}
public boolean worldSpecific(String s)
{
return worldConfigSet().config.containsTag(s);
}
public ConfigSet configSet()
{
return worldConfig() ? worldConfigSet() : globalConfigSet();
}
public ConfigTag renderTag()
{
return renderTag(configName());
}
public ConfigTag renderTag(String s)
{
return (worldConfig() && worldSpecific(s) ? worldConfigSet() : globalConfigSet()).config.getTag(s);
}
public ConfigTag getTag()
{
return getTag(configName());
}
public ConfigTag getTag(String s)
{
return configSet().config.getTag(s);
}
public boolean worldConfig()
{
return slot.getGui().worldConfig();
}
public boolean renderDefault()
{
return renderDefault(configName());
}
public boolean renderDefault(String s)
{
return worldConfig() && !worldSpecific(s);
}
public void useGlobal()
{
useGlobal(configName());
}
public void useGlobal(String s)
{
if(worldConfig())
worldConfigSet().config.removeTag(s);
}
public void copyGlobal()
{
copyGlobal(configName());
}
public void copyGlobal(String s)
{
if(worldConfig())
worldConfigSet().config.getTag(s).setValue(globalConfigSet().config.getTag(s).getValue());
}
public void onAdded(OptionScrollSlot slot)
{
this.slot = slot;
}
public void onAdded(OptionList list)
{
parent = list;
}
public void onMouseClicked(int mousex, int mousey, int button)
{
}
public void mouseClicked(int mousex, int mousey, int button)
{
}
public void update()
{
}
public void draw(int mousex, int mousey, float frame)
{
}
public void keyTyped(char c, int keycode)
{
}
public List<String> handleTooltip(int mousex, int mousey, List<String> currenttip)
{
return currenttip;
}
public boolean showWorldSelector()
{
return true;
}
public void copyGlobals()
{
copyGlobal();
}
public void useGlobals()
{
useGlobal();
}
public boolean hasWorldOverride()
{
return worldSpecific();
}
}
@@ -0,0 +1,146 @@
package codechicken.nei.config;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.LayoutManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import java.util.List;
import static codechicken.lib.gui.GuiDraw.*;
public abstract class OptionButton extends Option
{
protected static ResourceLocation guiTex = new ResourceLocation("textures/gui/widgets.png");
public final String prefix;
public final String text;
public final String tooltip;
private boolean isEnabled = true;
public OptionButton(String name, String prefix, String text, String tooltip)
{
super(name);
this.prefix = prefix;
this.text = text;
this.tooltip = tooltip;
}
public OptionButton(String prefix, String text, String tooltip)
{
this(text, prefix, text, tooltip);
}
public OptionButton(String name)
{
this(null, name, name+".tip");
}
public boolean isEnabled()
{
return isEnabled;
}
public void setEnabled(boolean b)
{
isEnabled = b;
}
@Override
public void draw(int mousex, int mousey, float frame)
{
changeTexture(guiTex);
GL11.glColor4f(1, 1, 1, 1);
drawPrefix();
drawButton(mousex, mousey);
}
public Rectangle4i buttonSize()
{
int width;
int x;
if(getPrefix() == null)
{
width = slot.contentWidth();
x = (slot.contentWidth()-width)/2;
}
else
{
width = Math.max(60, getStringWidth(getButtonText()));
x = slot.contentWidth()-width;
}
return new Rectangle4i(x, 2, width, 20);
}
public String getPrefix()
{
if(prefix == null) return null;
String s = translateN(prefix);
if(s.equals(namespaced(prefix))) return null;
return s;
}
public String getButtonText()
{
return translateN(name);
}
public String getTooltip()
{
if(tooltip == null) return null;
String s = translateN(tooltip);
if(s.equals(namespaced(tooltip))) return null;
return s;
}
public void drawPrefix()
{
if(getPrefix() != null)
drawString(getPrefix(), 10, 8, -1);
}
public void drawButton(int mousex, int mousey)
{
Rectangle4i b = buttonSize();
LayoutManager.drawButtonBackground(b.x, b.y, b.w, b.h, true, getButtonTex(mousex, mousey));
drawStringC(getButtonText(), b.x, b.y, b.w, b.h, getTextColour(mousex, mousey));
}
public int getButtonTex(int mousex, int mousey)
{
return !isEnabled() ? 0 : pointInside(mousex, mousey) ? 2 : 1;
}
public int getTextColour(int mousex, int mousey)
{
return !isEnabled() ? 0xFFA0A0A0 : pointInside(mousex, mousey) ? 0xFFFFFFA0 : 0xFFE0E0E0;
}
public boolean pointInside(int mousex, int mousey)
{
return buttonSize().contains(mousex, mousey);
}
@Override
public void mouseClicked(int x, int y, int button)
{
if(pointInside(x, y))
if(onClick(button))
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
public boolean onClick(int button)
{
return false;
}
@Override
public List<String> handleTooltip(int mousex, int mousey, List<String> currenttip)
{
if(new Rectangle4i(0, 2, slot.contentWidth(), 20).contains(mousex, mousey) && getTooltip() != null)
currenttip.add(getTooltip());
return currenttip;
}
}
@@ -0,0 +1,66 @@
package codechicken.nei.config;
public class OptionCycled extends OptionButton
{
public final int count;
public final boolean prefixed;
public OptionCycled(String name, int count, boolean prefixed)
{
super(name);
this.count = count;
this.prefixed = prefixed;
}
public OptionCycled(String name, int count)
{
this(name, count, false);
}
public int value()
{
return renderTag().getIntValue();
}
@Override
public String getButtonText()
{
return translateN(name+"."+value());
}
@Override
public String getPrefix()
{
return prefixed ? translateN(name) : null;
}
@Override
public boolean onClick(int button)
{
if(renderDefault())
return false;
return cycle();
}
public boolean cycle()
{
int next = value();
do
{
next=(next+1)%count;
}
while(!optionValid(next));
if(next == value())
return false;
getTag().setIntValue(next);
return true;
}
public boolean optionValid(int index)
{
return true;
}
}
@@ -0,0 +1,25 @@
package codechicken.nei.config;
import codechicken.nei.Image;
import codechicken.nei.LayoutManager;
public class OptionGamemodes extends OptionStringSet
{
public OptionGamemodes(String name)
{
super(name);
options.add("creative");
options.add("creative+");
options.add("adventure");
}
@Override
public void drawIcons()
{
int x = buttonX();
LayoutManager.drawIcon(x+4, 6, new Image(132, 12, 12, 12)); x+=24;
LayoutManager.drawIcon(x+4, 6, new Image(156, 12, 12, 12)); x+=24;
LayoutManager.drawIcon(x+4, 6, new Image(168, 12, 12, 12)); x+=24;
}
}
@@ -0,0 +1,29 @@
package codechicken.nei.config;
import net.minecraft.client.Minecraft;
public class OptionHighlightTips extends OptionButton
{
public OptionHighlightTips(String name)
{
super(name, null, name, null);
}
@Override
public void copyGlobals()
{
copyGlobal(name);
copyGlobal(name+".x");
copyGlobal(name+".y");
}
@Override
public boolean onClick(int button)
{
if(renderDefault())
return false;
Minecraft.getMinecraft().displayGuiScreen(new GuiHighlightTips(this));
return true;
}
}
@@ -0,0 +1,95 @@
package codechicken.nei.config;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.input.Keyboard;
public class OptionKeyBind extends OptionButton
{
private boolean hasFocus = false;
public OptionKeyBind(String name)
{
super("keys."+name);
}
@Override
public void onMouseClicked(int mousex, int mousey, int button)
{
hasFocus = false;
}
@Override
public void keyTyped(char c, int keycode)
{
if(hasFocus)
{
setValue(keycode);
hasFocus = false;
}
}
@Override
public boolean onClick(int button)
{
if(renderDefault())
return false;
if(button == 0)
{
hasFocus = true;
return true;
}
if(button == 1 && getValue() != 0)
{
setValue(0);
return true;
}
return false;
}
public boolean conflicted()
{
if(getValue() == 0)
return false;
for(Option o : slot.options)
if(o instanceof OptionKeyBind && o != this && ((OptionKeyBind)o).getValue() == getValue())
return true;
return false;
}
public void setValue(int keycode)
{
getTag().setIntValue(keycode);
}
public int getValue()
{
return renderTag().getIntValue();
}
@Override
public String getPrefix()
{
return translateN(name);
}
@Override
public String getButtonText()
{
if(hasFocus)
return EnumChatFormatting.WHITE+"> "+EnumChatFormatting.YELLOW+"??? "+EnumChatFormatting.WHITE+"<";
if(conflicted())
return EnumChatFormatting.RED + Keyboard.getKeyName(getValue());
return Keyboard.getKeyName(getValue());
}
@Override
public int getTextColour(int mousex, int mousey)
{
return -1;
}
}
+155
View File
@@ -0,0 +1,155 @@
package codechicken.nei.config;
import codechicken.nei.config.GuiOptionList.OptionScrollSlot;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import java.util.ArrayList;
import java.util.HashMap;
public class OptionList extends OptionButton
{
public static final OptionList top = new OptionList(null);
public static OptionList getOptionList(String fullName)
{
Option o = top.getOption(fullName);
if(o == null)
top.addOption(o = new OptionList(fullName));
return (OptionList) o;
}
public static String parent(String fullName)
{
int i = fullName.indexOf('.');
if(i < 0)
return fullName;
return fullName.substring(0, i);
}
public static String child(String fullName)
{
int i = fullName.indexOf('.');
return fullName.substring(i+1);
}
public ArrayList<Option> optionList = new ArrayList<Option>();
public HashMap<String, Option> options = new HashMap<String, Option>();
public IConfigSetHolder config;
public OptionList(String name)
{
super(name);
}
public OptionList bindConfig(IConfigSetHolder config)
{
this.config = config;
return this;
}
private OptionList subList(String fullName)
{
OptionList o = (OptionList) getOption(fullName);
if(o == null)
addOption(o = new OptionList(fullName));
return o;
}
public Option getOption(String fullName)
{
if(fullName.contains("."))
return subList(parent(fullName)).getOption(child(fullName));
return options.get(fullName);
}
public void addOption(Option o)
{
o.namespace = fullName();
addOption(o, o.fullName(), o.name);
}
private void addOption(Option o, String fullName, String subName)
{
if(subName.contains("."))
{
subList(parent(subName)).addOption(o, fullName, child(subName));
return;
}
if(options.containsKey(subName))
System.err.println("Warning, replacing option: "+fullName);
options.put(subName, o);
addSorted(o);
o.onAdded(this);
}
public void addSorted(Option o)
{
optionList.add(o);
}
public void expandOptionList(OptionList replacement)
{
addOption(replacement);
OptionList base = (OptionList) getOption(replacement.name);
replacement.options = base.options;
replacement.optionList = base.optionList;
options.remove(base.name);
optionList.remove(base);
}
public void showGui(GuiScreen parent)
{
Minecraft.getMinecraft().displayGuiScreen(new GuiOptionList(parent, this, false));
}
public void synthesizeEnvironment()
{
new GuiOptionList(null, this, false).addWidgets();
}
@Override
public boolean onClick(int button)
{
Minecraft.getMinecraft().displayGuiScreen(new GuiOptionList(slot.getGui(), OptionList.this, slot.getGui().worldConfig()));
return true;
}
@Override
public boolean showWorldSelector()
{
return false;
}
@Override
public void onAdded(OptionScrollSlot slot)
{
super.onAdded(slot);
globalConfigSet().config.getTag(configName()).useBraces();
worldConfigSet().config.getTag(configName()).useBraces();
}
@Override
public ConfigSet worldConfigSet()
{
return config != null ? config.worldConfigSet() : super.worldConfigSet();
}
@Override
public ConfigSet globalConfigSet()
{
return config != null ? config.globalConfigSet() : super.globalConfigSet();
}
@Override
public OptionList configBase()
{
return config != null ? this : super.configBase();
}
}
@@ -0,0 +1,173 @@
package codechicken.nei.config;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.LayoutManager;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation;
import java.util.*;
import static codechicken.lib.gui.GuiDraw.drawString;
public abstract class OptionStringSet extends Option
{
public LinkedList<String> options = new LinkedList<String>();
public Multimap<String, String> dependants = ArrayListMultimap.create();
public Map<String, String> dependancies = new HashMap<String, String>();
public Multimap<String, String> groups = ArrayListMultimap.create();
public OptionStringSet(String name)
{
super(name);
}
public void addDep(String base, String dep)
{
dependants.put(dep, base);
dependancies.put(base, dep);
}
@Override
public void draw(int mousex, int mousey, float frame)
{
drawPrefix();
drawButtons();
drawIcons();
}
public void drawPrefix()
{
drawString(translateN(name), 10, 8, -1);
}
public void drawButtons()
{
int x = buttonX();
List<String> values = values();
for(int i = 0; i < options.size(); i++)
{
LayoutManager.drawButtonBackground(x, 2, 20, 20, true, values.contains(options.get(i)) ? 1 : 0);
x+=24;
}
}
public abstract void drawIcons();
@Override
public List<String> handleTooltip(int mousex, int mousey, List<String> currenttip)
{
if(new Rectangle4i(4, 4, 50, 20).contains(mousex, mousey))
currenttip.add(translateN(name+".tip"));
int x = buttonX();
for(int i = 0; i < options.size(); i++)
{
if(new Rectangle4i(x, 2, 20, 20).contains(mousex, mousey))
currenttip.add(translateN(name+"."+options.get(i)));
x+=24;
}
return currenttip;
}
@Override
public void mouseClicked(int x, int y, int button)
{
if(renderDefault())
return;
if(clickButton(x, y, button))
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
public boolean clickButton(int mousex, int mousey, int button)
{
int x = buttonX();
List<String> values = values();
for(int i = 0; i < options.size(); i++)
{
if(new Rectangle4i(x, 2, 20, 20).contains(mousex, mousey))
{
String s = options.get(i);
boolean set = values.contains(s);
if(button == 0 && !set)
{
setValue(s);
return true;
}
if(button == 1 && set)
{
remValue(s);
return true;
}
return false;
}
x+=24;
}
return false;
}
public void setValue(String s)
{
if(values().contains(s))
return;
String dep = dependancies.get(s);
if(dep != null)
setValue(dep);
if(groups.containsKey(s))
{
for(String grp : groups.get(s))
setValue(grp);
}
else
{
List<String> setUtils = new LinkedList<String>(values());
setUtils.add(s);
setValues(setUtils);
}
}
public void remValue(String s)
{
for(String dep : dependants.get(s))
remValue(dep);
if(groups.containsKey(s))
{
for(String grp : groups.get(s))
remValue(grp);
}
else
{
List<String> values = new LinkedList<String>(values());
values.remove(s);
setValues(values);
}
}
public void setValues(List<String> values)
{
StringBuilder sb = new StringBuilder();
for(String s : values)
{
if(sb.length() > 0)
sb.append(", ");
sb.append(s);
}
getTag().setValue(sb.toString());
}
public List<String> values()
{
return Arrays.asList(renderTag().getValue().replace(" ", "").split(","));
}
public int buttonX()
{
return slot.contentWidth()-(24*options.size()-4);
}
}
@@ -0,0 +1,110 @@
package codechicken.nei.config;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.TextField;
import codechicken.nei.config.GuiOptionList.OptionScrollSlot;
import java.util.List;
import static codechicken.lib.gui.GuiDraw.drawString;
import static codechicken.lib.gui.GuiDraw.getStringWidth;
public class OptionTextField extends Option
{
private boolean focused = false;
private TextField textField = new TextField("")
{
@Override
public void onTextChange(String oldText)
{
if(!text().equals(renderTag().getValue()))
getTag().setValue(text());
}
@Override
public boolean focused()
{
return focused;
}
@Override
public void setFocus(boolean focus)
{
if(focus == true && renderDefault())
return;
focused = focus;
}
};
public OptionTextField(String name)
{
super(name);
textField.height = 20;
textField.y = 2;
}
@Override
public void onAdded(OptionScrollSlot slot)
{
super.onAdded(slot);
}
@Override
public void update()
{
textField.setText(renderText());
}
public String getPrefix()
{
return translateN(name);
}
@Override
public void draw(int mousex, int mousey, float frame)
{
drawString(getPrefix(), 10, 8, -1);
textField.setText(renderText());
textField.width = slot.contentWidth()-getStringWidth(getPrefix())-16;
textField.x = slot.contentWidth()-textField.width;
textField.draw(mousex, mousey);
}
public String renderText()
{
return renderTag().getValue();
}
@Override
public void keyTyped(char c, int keycode)
{
textField.handleKeyPress(keycode, c);
}
@Override
public void mouseClicked(int mousex, int mousey, int button)
{
if(textField.contains(mousex, mousey))
textField.handleClick(mousex, mousey, button);
}
@Override
public void onMouseClicked(int mousex, int mousey, int button)
{
textField.onGuiClick(mousex, mousey);
}
@Override
public List<String> handleTooltip(int mousex, int mousey, List<String> currenttip)
{
if(new Rectangle4i(10, 2, textField.x-10, 20).contains(mousex, mousey))
{
String tip = translateN(name+".tip");
if(!tip.equals(name+".tip"))
currenttip.add(tip);
}
return currenttip;
}
}
@@ -0,0 +1,43 @@
package codechicken.nei.config;
public class OptionToggleButton extends OptionButton
{
public final boolean prefixed;
public OptionToggleButton(String name, boolean prefixed)
{
super(name);
this.prefixed = prefixed;
}
public OptionToggleButton(String name)
{
this(name, false);
}
public boolean state()
{
return renderTag().getBooleanValue();
}
public String getButtonText()
{
return translateN(name+(state() ? ".true" : ".false"));
}
@Override
public String getPrefix()
{
return prefixed ? translateN(name) : null;
}
@Override
public boolean onClick(int button)
{
if(renderDefault())
return false;
getTag().setBooleanValue(!state());
return true;
}
}
@@ -0,0 +1,51 @@
package codechicken.nei.config;
import codechicken.nei.Image;
import codechicken.nei.LayoutManager;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
public class OptionUtilities extends OptionStringSet
{
public OptionUtilities(String name)
{
super(name);
options.add("time");
options.add("rain");
options.add("heal");
options.add("delete");
options.add("magnet");
options.add("gamemode");
options.add("enchant");
options.add("potion");
options.add("item");
groups.put("gamemode", "creative");
groups.put("gamemode", "creative+");
groups.put("gamemode", "adventure");
}
@Override
public void drawIcons()
{
int x = buttonX();
LayoutManager.drawIcon(x+4, 6, new Image(120, 24, 12, 12)); x+=24;
LayoutManager.drawIcon(x+4, 6, new Image(120, 12, 12, 12)); x+=24;
LayoutManager.drawIcon(x+4, 6, new Image(168, 24, 12, 12)); x+=24;
LayoutManager.drawIcon(x+4, 6, new Image(144, 12, 12, 12)); x+=24;
LayoutManager.drawIcon(x+4, 6, new Image(180, 24, 12, 12)); x+=24;
LayoutManager.drawIcon(x+4, 6, new Image(132, 12, 12, 12)); x+=24;
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
ItemStack sword = new ItemStack(Items.diamond_sword);
sword.addEnchantment(Enchantment.sharpness, 1);
GuiContainerManager.drawItem(x+2, 4, sword); x+=24;
GuiContainerManager.drawItem(x+2, 4, new ItemStack(Items.potionitem)); x+=24;
GuiContainerManager.drawItem(x+2, 4, new ItemStack(Blocks.stone)); x+=24;
}
}
@@ -0,0 +1,31 @@
package codechicken.nei.config;
import net.minecraft.util.RegistryNamespaced;
import java.util.LinkedList;
public abstract class RegistryDumper <T> extends DataDumper
{
public RegistryDumper(String name) {
super(name);
}
@Override
public Iterable<String[]> dump(int mode) {
LinkedList<String[]> list = new LinkedList<String[]>();
RegistryNamespaced registry = registry();
for(T obj : (Iterable<T>)registry)
list.add(dump(obj, registry.getIDForObject(obj), registry.getNameForObject(obj)));
return list;
}
public abstract RegistryNamespaced registry();
public abstract String[] dump(T obj, int id, String name);
@Override
public int modeCount() {
return 1;
}
}
@@ -0,0 +1,28 @@
package codechicken.nei.guihook;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
public class DefaultSlotClickHandler implements IContainerSlotClickHandler
{
@Override
public void beforeSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier)
{
}
@Override
public boolean handleSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier, boolean eventconsumed)
{
if(!eventconsumed) {
if(slot != null)
slotIndex = slot.slotNumber;
GuiContainerManager.getManager(gui).handleSlotClick(slotIndex, button, slotIndex != -999 ? modifier : 0);
}
return true;
}
@Override
public void afterSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier)
{
}
}
@@ -0,0 +1,545 @@
package codechicken.nei.guihook;
import codechicken.lib.gui.GuiDraw;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
import static codechicken.lib.gui.GuiDraw.*;
public class GuiContainerManager
{
public GuiContainer window;
public static RenderItem drawItems = new RenderItem();
public static final LinkedList<IContainerTooltipHandler> tooltipHandlers = new LinkedList<IContainerTooltipHandler>();
public static final LinkedList<IContainerInputHandler> inputHandlers = new LinkedList<IContainerInputHandler>();
public static final LinkedList<IContainerDrawHandler> drawHandlers = new LinkedList<IContainerDrawHandler>();
public static final LinkedList<IContainerObjectHandler> objectHandlers = new LinkedList<IContainerObjectHandler>();
public static final LinkedList<IContainerSlotClickHandler> slotClickHandlers = new LinkedList<IContainerSlotClickHandler>();
// Check the version of LWGJL, if it is 2.9.0, then it solves the multi input problem by itself
private static boolean multiInputLWJGL;
static {
try {
multiInputLWJGL = "2.9.0".equals(Sys.getVersion());
} catch (Throwable t) {
System.err.println(String.format("Error getting lwjgl version: %s", t.toString()));
multiInputLWJGL = false;
}
}
static {
addSlotClickHandler(new DefaultSlotClickHandler());
}
public static GuiContainerManager getManager() {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
return gui instanceof GuiContainer ? getManager((GuiContainer) gui) : null;
}
public static GuiContainerManager getManager(GuiContainer gui) {
//gets GuiContainer.manager using ASM
return null;
}
/**
* Register a new Tooltip render handler;
*
* @param handler The handler to register
*/
public static void addTooltipHandler(IContainerTooltipHandler handler) {
tooltipHandlers.add(handler);
}
/**
* Register a new Input handler;
*
* @param handler The handler to register
*/
public static void addInputHandler(IContainerInputHandler handler) {
inputHandlers.add(handler);
}
/**
* Register a new Drawing handler;
*
* @param handler The handler to register
*/
public static void addDrawHandler(IContainerDrawHandler handler) {
drawHandlers.add(handler);
}
/**
* Register a new Object handler;
*
* @param handler The handler to register
*/
public static void addObjectHandler(IContainerObjectHandler handler) {
objectHandlers.add(handler);
}
/**
* Care needs to be taken with this method. It will insert your handler at the start of the list to be called first. You may need to simply edit the list yourself.
*
* @param handler The handler to register.
*/
public static void addSlotClickHandler(IContainerSlotClickHandler handler) {
slotClickHandlers.addFirst(handler);
}
public static FontRenderer getFontRenderer(ItemStack stack) {
if (stack != null && stack.getItem() != null) {
FontRenderer f = stack.getItem().getFontRenderer(stack);
if (f != null)
return f;
}
return fontRenderer;
}
/**
* Extra lines are often used for more information. For example enchantments, potion effects and mob spawner contents.
*
* @param itemstack The item to get the name for.
* @param gui An instance of the currentscreen passed to tooltip handlers. If null, only gui inspecific handlers should respond
* @param includeHandlers If true tooltip handlers will add to the item tip
* @return A list of Strings representing the text to be displayed on each line of the tool tip.
*/
public static List<String> itemDisplayNameMultiline(ItemStack itemstack, GuiContainer gui, boolean includeHandlers) {
List<String> namelist = null;
try {
namelist = itemstack.getTooltip(Minecraft.getMinecraft().thePlayer, includeHandlers && Minecraft.getMinecraft().gameSettings.advancedItemTooltips);
} catch (Throwable ignored) {}
if (namelist == null)
namelist = new ArrayList<String>();
if (namelist.size() == 0)
namelist.add("Unnamed");
if (namelist.get(0) == null || namelist.get(0).equals(""))
namelist.set(0, "Unnamed");
if (includeHandlers) {
for (IContainerTooltipHandler handler : tooltipHandlers) {
namelist = handler.handleItemDisplayName(gui, itemstack, namelist);
}
}
namelist.set(0, itemstack.getRarity().rarityColor.toString() + namelist.get(0));
for (int i = 1; i < namelist.size(); i++)
namelist.set(i, "\u00a77" + namelist.get(i));
return namelist;
}
/**
* The general name of this item.
*
* @param itemstack The {@link ItemStack} to get the name for.
* @return The first line of the multiline display name.
*/
public static String itemDisplayNameShort(ItemStack itemstack) {
List<String> list = itemDisplayNameMultiline(itemstack, null, false);
return list.get(0);
}
/**
* Concatenates the multiline display name into one line for easy searching using string and {@link Pattern} functions.
*
* @param itemstack The stack to get the name for
* @return The multiline display name of this item separated by '#'
*/
public static String concatenatedDisplayName(ItemStack itemstack, boolean includeHandlers) {
List<String> list = itemDisplayNameMultiline(itemstack, null, includeHandlers);
StringBuilder sb = new StringBuilder();
boolean first = true;
for (String name : list) {
if (first) {
first = false;
} else {
sb.append("#");
}
sb.append(name);
}
return EnumChatFormatting.getTextWithoutFormattingCodes(sb.toString());
}
public static void drawItem(int i, int j, ItemStack itemstack) {
drawItem(i, j, itemstack, getFontRenderer(itemstack));
}
private static int modelviewDepth = -1;
private static HashSet<String> stackTraces = new HashSet<String>();
public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer fontRenderer) {
enable3DRender();
float zLevel = drawItems.zLevel += 100F;
try {
drawItems.renderItemAndEffectIntoGUI(fontRenderer, renderEngine, itemstack, i, j);
drawItems.renderItemOverlayIntoGUI(fontRenderer, renderEngine, itemstack, i, j);
if (!checkMatrixStack())
throw new IllegalStateException("Modelview matrix stack too deep");
if (Tessellator.instance.isDrawing)
throw new IllegalStateException("Still drawing");
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String stackTrace = itemstack + sw.toString();
if (!stackTraces.contains(stackTrace)) {
System.err.println("Error while rendering: " + itemstack);
e.printStackTrace();
stackTraces.add(stackTrace);
}
restoreMatrixStack();
if (Tessellator.instance.isDrawing)
Tessellator.instance.draw();
drawItems.zLevel = zLevel;
drawItems.renderItemIntoGUI(fontRenderer, renderEngine, new ItemStack(Blocks.fire), i, j);
}
enable2DRender();
drawItems.zLevel = zLevel - 100;
}
public static void enableMatrixStackLogging() {
modelviewDepth = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH);
}
public static void disableMatrixStackLogging() {
modelviewDepth = -1;
}
public static boolean checkMatrixStack() {
return modelviewDepth < 0 || GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH) == modelviewDepth;
}
public static void restoreMatrixStack() {
if (modelviewDepth >= 0)
for (int i = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH); i > modelviewDepth; i--)
GL11.glPopMatrix();
}
public static void setColouredItemRender(boolean enable) {
drawItems.renderWithColor = !enable;
}
public static void enable3DRender() {
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
public static void enable2DRender() {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
}
private int clickHandled = 0;
private List<IContainerTooltipHandler> instanceTooltipHandlers;
public GuiContainerManager(GuiContainer screen) {
window = screen;
if (screen instanceof IContainerTooltipHandler) {
instanceTooltipHandlers = new LinkedList<IContainerTooltipHandler>();
instanceTooltipHandlers.add((IContainerTooltipHandler) screen);
instanceTooltipHandlers.addAll(tooltipHandlers);
} else
instanceTooltipHandlers = tooltipHandlers;
}
public static ItemStack getStackMouseOver(GuiContainer window) {
Point mousePos = getMousePosition();
for (IContainerObjectHandler objectHandler : objectHandlers) {
ItemStack item = objectHandler.getStackUnderMouse(window, mousePos.x, mousePos.y);
if (item != null)
return item;
}
Slot slot = getSlotMouseOver(window);
if (slot != null)
return slot.getStack();
return null;
}
public static Slot getSlotMouseOver(GuiContainer window) {
Point mousePos = getMousePosition();
if (getManager(window).objectUnderMouse(mousePos.x, mousePos.y))
return null;
return window.getSlotAtPosition(mousePos.x, mousePos.y);
}
public void load() {
clickHandled = 0;
for (IContainerObjectHandler objectHandler : objectHandlers)
objectHandler.load(window);
}
/**
* Called from updateScreen
*/
public void updateScreen() {
for (IContainerObjectHandler objectHandler : objectHandlers)
objectHandler.guiTick(window);
}
/**
* Override for keyTyped
*/
public boolean lastKeyTyped(int keyID, char keyChar) {
if (keyID == 1)
return false;
for (IContainerInputHandler inputhander : inputHandlers)
if (inputhander.lastKeyTyped(window, keyChar, keyID))
return true;
return false;
}
public boolean firstKeyTyped(char keyChar, int keyID) {
for (IContainerInputHandler inputhander : inputHandlers)
inputhander.onKeyTyped(window, keyChar, keyID);
for (IContainerInputHandler inputhander : inputHandlers)
if (inputhander.keyTyped(window, keyChar, keyID))
return true;
return false;
}
public boolean mouseClicked(int mousex, int mousey, int button) {
for (IContainerInputHandler inputhander : inputHandlers)
inputhander.onMouseClicked(window, mousex, mousey, button);
for (IContainerInputHandler inputhander : inputHandlers)
if (inputhander.mouseClicked(window, mousex, mousey, button)) {
clickHandled |= 1 << button;
return true;
}
return false;
}
public void mouseScrolled(int scrolled) {
Point mousepos = getMousePosition();
for (IContainerInputHandler inputHandler : inputHandlers)
inputHandler.onMouseScrolled(window, mousepos.x, mousepos.y, scrolled);
for (IContainerInputHandler inputHandler : inputHandlers)
if (inputHandler.mouseScrolled(window, mousepos.x, mousepos.y, scrolled))
return;
if (window instanceof IGuiHandleMouseWheel)
((IGuiHandleMouseWheel) window).mouseScrolled(scrolled);
}
/**
* Override for mouseMovedOrUp
*/
public boolean overrideMouseUp(int mousex, int mousey, int button) {
if (button >= 0 && (clickHandled & 1 << button) != 0) {
clickHandled &= ~(1 << button);
mouseUp(mousex, mousey, button);
return true;
}
return false;
}
public void mouseUp(int mousex, int mousey, int button) {
for (IContainerInputHandler inputhander : inputHandlers)
inputhander.onMouseUp(window, mousex, mousey, button);
}
/**
* Called from mouseClickMove
*/
public void mouseDragged(int mousex, int mousey, int button, long heldTime) {
for (IContainerInputHandler inputhander : inputHandlers)
inputhander.onMouseDragged(window, mousex, mousey, button, heldTime);
}
/**
* Called at the start of drawScreen
*/
public void preDraw() {
for (IContainerDrawHandler drawHandler : drawHandlers)
drawHandler.onPreDraw(window);
}
public void renderObjects(int mousex, int mousey) {
GL11.glTranslatef(-window.guiLeft, -window.guiTop, 200F);
for (IContainerDrawHandler drawHandler : drawHandlers)
drawHandler.renderObjects(window, mousex, mousey);
for (IContainerDrawHandler drawHandler : drawHandlers)
drawHandler.postRenderObjects(window, mousex, mousey);
GL11.glTranslatef(window.guiLeft, window.guiTop, -200F);
}
public void renderToolTips(int mousex, int mousey) {
List<String> tooltip = new LinkedList<String>();
for (IContainerTooltipHandler handler : instanceTooltipHandlers)
tooltip = handler.handleTooltip(window, mousex, mousey, tooltip);
if (tooltip.isEmpty() && shouldShowTooltip(window))//mouseover tip, not holding an item
{
ItemStack stack = getStackMouseOver(window);
if (stack != null)
tooltip = itemDisplayNameMultiline(stack, window, true);
for (IContainerTooltipHandler handler : instanceTooltipHandlers)
tooltip = handler.handleItemTooltip(window, stack, mousex, mousey, tooltip);
}
if (tooltip.size() > 0)
tooltip.set(0, tooltip.get(0) + GuiDraw.TOOLTIP_LINESPACE);//add space after 'title'
drawMultilineTip(mousex + 12, mousey - 12, tooltip);
}
public static boolean shouldShowTooltip(GuiContainer window) {
for (IContainerObjectHandler handler : objectHandlers)
if (!handler.shouldShowTooltip(window))
return false;
return window.mc.thePlayer.inventory.getItemStack() == null;
}
public void renderSlotUnderlay(Slot slot) {
for (IContainerDrawHandler drawHandler : drawHandlers)
drawHandler.renderSlotUnderlay(window, slot);
}
public void renderSlotOverlay(Slot slot) {
for (IContainerDrawHandler drawHandler : drawHandlers)
drawHandler.renderSlotOverlay(window, slot);
}
/**
* Returns true if there is an object of yours obscuring the slot that the mouse would otherwise be hovering over.
*/
public boolean objectUnderMouse(int mousex, int mousey) {
for (IContainerObjectHandler objectHandler : objectHandlers)
if (objectHandler.objectUnderMouse(window, mousex, mousey))
return true;
return false;
}
public void handleMouseClick(Slot slot, int slotIndex, int button, int modifier) {
for (IContainerSlotClickHandler handler : slotClickHandlers)
handler.beforeSlotClick(window, slotIndex, button, slot, modifier);
boolean eventHandled = false;
for (IContainerSlotClickHandler handler : slotClickHandlers)
eventHandled = handler.handleSlotClick(window, slotIndex, button, slot, modifier, eventHandled);
for (IContainerSlotClickHandler handler : slotClickHandlers)
handler.afterSlotClick(window, slotIndex, button, slot, modifier);
}
// Enable inputting Chinese characters
public void handleKeyboardInput() {
// if it's LWGJL 2.9.0
if (multiInputLWJGL) {
int k = Keyboard.getEventKey();
char c = Keyboard.getEventCharacter();
if (k == 0 && Character.isDefined(c) || Keyboard.getEventKeyState())
keyTyped(c, k);
}
// if it isn't LWJGL 2.9.0, then make the Chinese input method to split the characters
else if (Keyboard.getEventKeyState()) {
int k = Keyboard.getEventKey();
char c = Keyboard.getEventCharacter();
if (c > 0x7F && c <= 0xFF && Keyboard.next()) {
int k2 = Keyboard.getEventKey();
char c2 = Keyboard.getEventCharacter();
try {
c2 = new String(new byte[]{(byte) c, (byte) c2}).charAt(0);
keyTyped(c2, k);
} catch (Throwable t) {
keyTyped(c, k);
keyTyped(c2, k2);
}
} else {
keyTyped(c, k);
}
}
}
public void keyTyped(char c, int k) {
if (firstKeyTyped(c, k))
return;
callKeyTyped(window, c, k);
}
private static void callKeyTyped(GuiContainer window, char c, int k) {
//calls GuiContainer.keyTyped using ASM generated forwarder
}
/**
* Delegate for changing item rendering for certain slots. Eg. Shrinking text for large itemstacks
*/
public void drawSlotItem(Slot slot, ItemStack stack, int x, int y, String quantity) {
if(window instanceof IGuiSlotDraw)
((IGuiSlotDraw)window).drawSlotItem(slot, stack, x, y, quantity);
else {
drawItems.renderItemAndEffectIntoGUI(fontRenderer, window.mc.getTextureManager(), stack, x, y);
drawItems.renderItemOverlayIntoGUI(fontRenderer, window.mc.getTextureManager(), stack, x, y, quantity);
}
}
/**
* Implementation for handleMouseClick
*/
public void handleSlotClick(int slotIndex, int button, int modifiers) {
if (slotIndex == -1)
return;
if (window instanceof IGuiClientSide)//send the calls directly to the container bypassing the MPController window send
window.mc.thePlayer.openContainer.slotClick(slotIndex, button, modifiers, window.mc.thePlayer);
else
window.mc.playerController.windowClick(window.inventorySlots.windowId, slotIndex, button, modifiers, window.mc.thePlayer);
}
/**
* Called from handleMouseInput
*/
public void handleMouseWheel() {
int i = Mouse.getEventDWheel();
if (i != 0)
mouseScrolled(i > 0 ? 1 : -1);
}
}
Loaded 100 of 149 files, more files were not shown because too many files have changed in this diff. Show more