mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-13 16:54:06 +00:00
Added the Lens Clip.
This commit is contained in:
1 parent
238a68548c
commit
62c87bfdb9
11 files changed
+239
-20
No files matched your search
@@ -35,7 +35,7 @@ public final class ItemsRemainingRenderHandler {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void render(ScaledResolution resolution, float partTicks) {
|
||||
if(ticks > 0) {
|
||||
if(ticks > 0 && stack != null) {
|
||||
int pos = maxTicks - ticks;
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
int x = resolution.getScaledWidth() / 2 + 10 + Math.max(0, pos - leaveTicks);
|
||||
@@ -57,17 +57,23 @@ public final class ItemsRemainingRenderHandler {
|
||||
GL11.glScalef(1F / alpha,1F, 1F);
|
||||
GL11.glTranslatef(-xp, -y, 0F);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
|
||||
int max = stack.getMaxStackSize();
|
||||
int stacks = count / max;
|
||||
int rem = count % max;
|
||||
String text = EnumChatFormatting.GREEN + stack.getDisplayName();
|
||||
if(count >= 0) {
|
||||
int max = stack.getMaxStackSize();
|
||||
int stacks = count / max;
|
||||
int rem = count % max;
|
||||
|
||||
if(stacks == 0)
|
||||
text = "" + count;
|
||||
else text = count + " (" + stacks + "*" + max + "+" + rem + ")";
|
||||
}
|
||||
|
||||
int color = 0x00FFFFFF | ((int) (alpha * 0xFF) << 24);
|
||||
if(stacks == 0)
|
||||
mc.fontRenderer.drawStringWithShadow("" + count, x + 20, y + 6, color);
|
||||
else mc.fontRenderer.drawStringWithShadow(count + " (" + stacks + "*" + max + "+" + rem + ")", x + 20, y + 6, color);
|
||||
mc.fontRenderer.drawStringWithShadow(text, x + 20, y + 6, color);
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
@@ -82,7 +88,7 @@ public final class ItemsRemainingRenderHandler {
|
||||
public static void set(ItemStack stack, int count) {
|
||||
ItemsRemainingRenderHandler.stack = stack;
|
||||
ItemsRemainingRenderHandler.count = count;
|
||||
ticks = maxTicks;
|
||||
ticks = stack == null ? 0 : maxTicks;
|
||||
}
|
||||
|
||||
public static void set(EntityPlayer player, ItemStack displayStack, Pattern pattern) {
|
||||
|
||||
@@ -272,6 +272,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
|
||||
addItem(ModItems.spark);
|
||||
addItem(ModItems.sparkUpgrade);
|
||||
addItem(ModItems.manaGun);
|
||||
addItem(ModItems.clip);
|
||||
addItem(ModItems.lens);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under a
|
||||
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
|
||||
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
|
||||
*
|
||||
* File Created @ [Jan 24, 2015, 8:37:33 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.crafting.recipe;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.common.item.ItemManaGun;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.item.equipment.tool.ItemTerraPick;
|
||||
|
||||
public class ManaGunClipRecipe implements IRecipe {
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting var1, World var2) {
|
||||
boolean foundGun = false;
|
||||
boolean foundClip = false;
|
||||
|
||||
for(int i = 0; i < var1.getSizeInventory(); i++) {
|
||||
ItemStack stack = var1.getStackInSlot(i);
|
||||
if(stack != null) {
|
||||
if(stack.getItem() instanceof ItemManaGun && !ItemManaGun.hasClip(stack))
|
||||
foundGun = true;
|
||||
|
||||
else if(stack.getItem() == ModItems.clip)
|
||||
foundClip = true;
|
||||
|
||||
else return false; // Found an invalid item, breaking the recipe
|
||||
}
|
||||
}
|
||||
|
||||
return foundGun && foundClip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting var1) {
|
||||
ItemStack gun = null;
|
||||
|
||||
for(int i = 0; i < var1.getSizeInventory(); i++) {
|
||||
ItemStack stack = var1.getStackInSlot(i);
|
||||
if(stack != null && stack.getItem() instanceof ItemManaGun)
|
||||
gun = stack;
|
||||
}
|
||||
|
||||
if(gun == null)
|
||||
return null;
|
||||
|
||||
ItemStack lens = ItemManaGun.getLens(gun);
|
||||
ItemManaGun.setLens(gun, null);
|
||||
ItemStack gunCopy = gun.copy();
|
||||
ItemManaGun.setClip(gunCopy, true);
|
||||
ItemManaGun.setLensAtPos(gunCopy, lens, 0);
|
||||
return gunCopy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under a
|
||||
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
|
||||
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
|
||||
*
|
||||
* File Created @ [Jan 24, 2015, 7:56:38 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.item;
|
||||
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
public class ItemClip extends ItemMod {
|
||||
|
||||
public ItemClip() {
|
||||
setMaxStackSize(1);
|
||||
setUnlocalizedName(LibItemNames.CLIP);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,9 +12,11 @@
|
||||
package vazkii.botania.common.item;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -22,16 +24,22 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
import net.minecraftforge.oredict.RecipeSorter.Category;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.lexicon.KnowledgeType;
|
||||
import vazkii.botania.api.mana.BurstProperties;
|
||||
import vazkii.botania.api.mana.ILens;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.client.core.handler.ClientTickHandler;
|
||||
import vazkii.botania.client.core.handler.ItemsRemainingRenderHandler;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.crafting.recipe.ManaGunClipRecipe;
|
||||
import vazkii.botania.common.crafting.recipe.ManaGunLensRecipe;
|
||||
import vazkii.botania.common.crafting.recipe.ManaGunRemoveLensRecipe;
|
||||
import vazkii.botania.common.entity.EntityManaBurst;
|
||||
@@ -43,6 +51,10 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
public class ItemManaGun extends ItemMod implements IManaUsingItem {
|
||||
|
||||
private static final String TAG_LENS = "lens";
|
||||
private static final String TAG_CLIP = "clip";
|
||||
private static final String TAG_CLIP_POS = "clipPos";
|
||||
|
||||
private static final int CLIP_SLOTS = 6;
|
||||
private static final int COOLDOWN = 30;
|
||||
|
||||
IIcon[] icons;
|
||||
@@ -56,13 +68,23 @@ public class ItemManaGun extends ItemMod implements IManaUsingItem {
|
||||
|
||||
GameRegistry.addRecipe(new ManaGunLensRecipe());
|
||||
GameRegistry.addRecipe(new ManaGunRemoveLensRecipe());
|
||||
GameRegistry.addRecipe(new ManaGunClipRecipe());
|
||||
RecipeSorter.register("botania:manaGunLens", ManaGunLensRecipe.class, Category.SHAPELESS, "");
|
||||
RecipeSorter.register("botania:manaGunRemoveLens", ManaGunRemoveLensRecipe.class, Category.SHAPELESS, "");
|
||||
RecipeSorter.register("botania:manaGunClip", ManaGunClipRecipe.class, Category.SHAPELESS, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
|
||||
if(par1ItemStack.getItemDamage() == 0) {
|
||||
if(par3EntityPlayer.isSneaking()) {
|
||||
rotatePos(par1ItemStack);
|
||||
par2World.playSoundAtEntity(par3EntityPlayer, "random.click", 0.6F, (1.0F + (par2World.rand.nextFloat() - par2World.rand.nextFloat()) * 0.2F) * 0.7F);
|
||||
if(par2World.isRemote)
|
||||
par3EntityPlayer.swingItem();
|
||||
ItemStack lens = getLens(par1ItemStack);
|
||||
ItemsRemainingRenderHandler.set(lens, -1);
|
||||
par1ItemStack.setItemDamage(COOLDOWN);
|
||||
} else if(par1ItemStack.getItemDamage() == 0) {
|
||||
EntityManaBurst burst = getBurst(par3EntityPlayer, par1ItemStack, true);
|
||||
if(burst != null && ManaItemHandler.requestManaExact(par1ItemStack, par3EntityPlayer, burst.getMana(), true)) {
|
||||
if(!par2World.isRemote) {
|
||||
@@ -77,33 +99,35 @@ public class ItemManaGun extends ItemMod implements IManaUsingItem {
|
||||
par1ItemStack.setItemDamage(COOLDOWN);
|
||||
} else if(!par2World.isRemote)
|
||||
par2World.playSoundAtEntity(par3EntityPlayer, "random.click", 0.6F, (1.0F + (par2World.rand.nextFloat() - par2World.rand.nextFloat()) * 0.2F) * 0.7F);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister par1IconRegister) {
|
||||
int states = 2;
|
||||
int states = 3;
|
||||
icons = new IIcon[states * 2];
|
||||
|
||||
for(int i = 0; i < states; i++)
|
||||
for(int i = 0; i < states; i++) {
|
||||
icons[i] = IconHelper.forItem(par1IconRegister, this, i);
|
||||
icons[states] = IconHelper.forName(par1IconRegister, "desuGun0");
|
||||
icons[states + 1] = IconHelper.forName(par1IconRegister, "desuGun1");
|
||||
icons[states + i] = IconHelper.forName(par1IconRegister, "desuGun" + i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresMultipleRenderPasses() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(ItemStack stack, int pass) {
|
||||
boolean desu = isSugoiKawaiiDesuNe(stack);
|
||||
return icons[Math.min(1, pass) + (desu ? 2 : 0)];
|
||||
int index = pass;
|
||||
if(index == 0 && hasClip(stack))
|
||||
index = 2;
|
||||
|
||||
return icons[Math.min(2, index) + (desu ? 3 : 0)];
|
||||
}
|
||||
|
||||
// ASADA-SAN ASADA-SAN ASADA-SAN ASADA-SAN ASADA-SAN ASADA-SAN ASADA-SAN ASADA-SAN
|
||||
@@ -187,21 +211,100 @@ public class ItemManaGun extends ItemMod implements IManaUsingItem {
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
|
||||
boolean clip = hasClip(par1ItemStack);
|
||||
if(clip && !GuiScreen.isShiftKeyDown()) {
|
||||
addStringToTooltip(StatCollector.translateToLocal("botaniamisc.shiftinfo"), par3List);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack lens = getLens(par1ItemStack);
|
||||
if(lens != null) {
|
||||
List<String> tooltip = lens.getTooltip(par2EntityPlayer, false);
|
||||
if(tooltip.size() > 1)
|
||||
par3List.addAll(tooltip.subList(1, tooltip.size()));
|
||||
}
|
||||
|
||||
if(clip) {
|
||||
int pos = getClipPos(par1ItemStack);
|
||||
addStringToTooltip(StatCollector.translateToLocal("botaniamisc.hasClip"), par3List);
|
||||
for(int i = 0; i < CLIP_SLOTS; i++) {
|
||||
String name = "";
|
||||
EnumChatFormatting formatting = i == pos ? EnumChatFormatting.GREEN : EnumChatFormatting.GRAY;
|
||||
ItemStack lensAt = getLensAtPos(par1ItemStack, i);
|
||||
if(lensAt == null)
|
||||
name = StatCollector.translateToLocal("botaniamisc.clipEmpty");
|
||||
else name = lensAt.getDisplayName();
|
||||
addStringToTooltip(formatting + " - " + name, par3List);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addStringToTooltip(String s, List<String> tooltip) {
|
||||
tooltip.add(s.replaceAll("&", "\u00a7"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack par1ItemStack) {
|
||||
ItemStack lens = getLens(par1ItemStack);
|
||||
return super.getItemStackDisplayName(par1ItemStack) + (lens == null ? "" : " (" + EnumChatFormatting.GREEN + lens.getDisplayName() + EnumChatFormatting.RESET + ")");
|
||||
}
|
||||
|
||||
public static boolean hasClip(ItemStack stack) {
|
||||
return ItemNBTHelper.getBoolean(stack, TAG_CLIP, false);
|
||||
}
|
||||
|
||||
public static void setClip(ItemStack stack, boolean clip) {
|
||||
ItemNBTHelper.setBoolean(stack, TAG_CLIP, clip);
|
||||
}
|
||||
|
||||
public static int getClipPos(ItemStack stack) {
|
||||
return ItemNBTHelper.getInt(stack, TAG_CLIP_POS, 0);
|
||||
}
|
||||
|
||||
public static void setClipPos(ItemStack stack, int pos) {
|
||||
ItemNBTHelper.setInt(stack, TAG_CLIP_POS, pos);
|
||||
}
|
||||
|
||||
public static void rotatePos(ItemStack stack) {
|
||||
int currPos = getClipPos(stack);
|
||||
boolean acceptEmpty = getLensAtPos(stack, currPos) != null;
|
||||
int[] slots = new int[CLIP_SLOTS - 1];
|
||||
|
||||
int index = 0;
|
||||
for(int i = currPos + 1; i < CLIP_SLOTS; i++, index++)
|
||||
slots[index] = i;
|
||||
for(int i = 0; i < currPos; i++, index++)
|
||||
slots[index] = i;
|
||||
|
||||
for(int i : slots) {
|
||||
ItemStack lensAt = getLensAtPos(stack, i);
|
||||
if(acceptEmpty || lensAt != null) {
|
||||
setClipPos(stack, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getLensAtPos(ItemStack stack, int pos) {
|
||||
NBTTagCompound cmp = ItemNBTHelper.getCompound(stack, TAG_LENS + pos, true);
|
||||
if(cmp != null) {
|
||||
ItemStack lens = ItemStack.loadItemStackFromNBT(cmp);
|
||||
return lens;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setLensAtPos(ItemStack stack, ItemStack lens, int pos) {
|
||||
NBTTagCompound cmp = new NBTTagCompound();
|
||||
if(lens != null)
|
||||
lens.writeToNBT(cmp);
|
||||
ItemNBTHelper.setCompound(stack, TAG_LENS + pos, cmp);
|
||||
}
|
||||
|
||||
public static void setLens(ItemStack stack, ItemStack lens) {
|
||||
if(hasClip(stack))
|
||||
setLensAtPos(stack, lens, getClipPos(stack));
|
||||
|
||||
NBTTagCompound cmp = new NBTTagCompound();
|
||||
if(lens != null)
|
||||
lens.writeToNBT(cmp);
|
||||
@@ -209,6 +312,9 @@ public class ItemManaGun extends ItemMod implements IManaUsingItem {
|
||||
}
|
||||
|
||||
public static ItemStack getLens(ItemStack stack) {
|
||||
if(hasClip(stack))
|
||||
return getLensAtPos(stack, getClipPos(stack));
|
||||
|
||||
NBTTagCompound cmp = ItemNBTHelper.getCompound(stack, TAG_LENS, true);
|
||||
if(cmp != null) {
|
||||
ItemStack lens = ItemStack.loadItemStackFromNBT(cmp);
|
||||
|
||||
@@ -191,7 +191,8 @@ public final class ModItems {
|
||||
public static Item craftingHalo;
|
||||
public static Item blackLotus;
|
||||
public static Item monocle;
|
||||
|
||||
public static Item clip;
|
||||
|
||||
public static void init() {
|
||||
lexicon = new ItemLexicon();
|
||||
petal = new ItemPetal();
|
||||
@@ -291,6 +292,7 @@ public final class ModItems {
|
||||
craftingHalo = new ItemCraftingHalo();
|
||||
blackLotus = new ItemBlackLotus();
|
||||
monocle = new ItemMonocle();
|
||||
clip = new ItemClip();
|
||||
|
||||
OreDictionary.registerOre(LibOreDict.LEXICON, lexicon);
|
||||
for(int i = 0; i < 16; i++) {
|
||||
|
||||
@@ -112,7 +112,8 @@ public final class LibItemNames {
|
||||
public static final String CRAFTING_HALO = "craftingHalo";
|
||||
public static final String BLACK_LOTUS = "blackLotus";
|
||||
public static final String MONOCLE = "monocle";
|
||||
|
||||
public static final String CLIP = "clip";
|
||||
|
||||
public static final String[] LENS_NAMES = new String[] {
|
||||
"lensNormal",
|
||||
"lensSpeed",
|
||||
|
||||
Reference in new issue
Block a user