Added the effect for the Mana Blaster, next off, lenses.

This commit is contained in:
Vasco Lavos committed 2014-03-13 22:53:50 +00:00
1 parent dd18027d94
commit d94b6f3937
9 files changed
+315 -33

No files matched your search

@@ -61,10 +61,4 @@ public interface IManaItem {
*/
public boolean canExportManaToItem(ItemStack stack, ItemStack otherStack);
/**
* Should the mana in this item be prioritized over the mana in
* other items? Generally set to false for generic containers
* and true for tools and the like.
*/
public boolean isPriorityItem(ItemStack stack);
}
@@ -0,0 +1,87 @@
/**
* 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 @ [Mar 13, 2014, 5:32:24 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public final class ManaItemHandler {
/**
* Requests mana from items in a given player's inventory. Note that stack.getItem()
* must be instanceof IManaItem.
* @param manaToGet How much mana is to be requested, if less mana exists than this amount,
* the amount of mana existent will be returned instead, if you want exact values use requestManaExact.
* @param remove If true, the mana will be removed from the target item. Set to false to just check.
* @return The amount of mana received from the request.
*/
public static int requestMana(ItemStack stack, EntityPlayer player, int manaToGet, boolean remove) {
if(stack == null)
return 0;
for(ItemStack stackInSlot : player.inventory.mainInventory) {
if(stackInSlot == stack)
continue;
if(stackInSlot != null && stackInSlot.getItem() instanceof IManaItem) {
IManaItem manaItem = (IManaItem) stackInSlot.getItem();
if(manaItem.canExportManaToItem(stackInSlot, stack) && manaItem.getMana(stackInSlot) > 0) {
if(stack.getItem() instanceof IManaItem && !((IManaItem) stack.getItem()).canReceiveManaFromItem(stack, stackInSlot))
continue;
int mana = Math.min(manaToGet, manaItem.getMana(stackInSlot));
if(remove)
manaItem.addMana(stackInSlot, -mana);
return mana;
}
}
}
return 0;
}
/**
* Requests an exact amount of mana from items in a given player's inventory.
* Note that stack.getItem() must be instanceof IManaItem.
* @param manaToGet How much mana is to be requested, if less mana exists than this amount,
* false will be returned instead, and nothing will happen.
* @param remove If true, the mana will be removed from the target item. Set to false to just check.
* @return If the request was succesful.
*/
public static boolean requestManaExact(ItemStack stack, EntityPlayer player, int manaToGet, boolean remove) {
if(stack == null)
return false;
for(ItemStack stackInSlot : player.inventory.mainInventory) {
if(stackInSlot == stack)
continue;
if(stackInSlot != null && stackInSlot.getItem() instanceof IManaItem) {
IManaItem manaItemSlot = (IManaItem) stackInSlot.getItem();
if(manaItemSlot.canExportManaToItem(stackInSlot, stack) && manaItemSlot.getMana(stackInSlot) > manaToGet) {
if(stack.getItem() instanceof IManaItem && !((IManaItem) stack.getItem()).canReceiveManaFromItem(stack, stackInSlot))
continue;
if(remove)
manaItemSlot.addMana(stackInSlot, -manaToGet);
return true;
}
}
}
return false;
}
}
@@ -231,7 +231,7 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector
}
public EntityManaBurst getBurst(boolean fake) {
EntityManaBurst burst = new EntityManaBurst(worldObj, this, fake);
EntityManaBurst burst = new EntityManaBurst(this, fake);
int maxMana = 160;
int color = 0x00FF00;
@@ -18,6 +18,7 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -60,7 +61,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
final int dataWatcherStart = 32 - dataWatcherEntries;
List<String> alreadyCollidedAt = new ArrayList();
boolean fullManaLastTick = true;
public EntityManaBurst(World world) {
@@ -78,8 +79,8 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
}
}
public EntityManaBurst(World par1World, TileSpreader spreader, boolean fake) {
this(par1World);
public EntityManaBurst(TileSpreader spreader, boolean fake) {
this(spreader.worldObj);
this.fake = fake;
setBurstSourceCoords(spreader.xCoord, spreader.yCoord, spreader.zCoord);
@@ -94,6 +95,25 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
setMotion(mx, my, mz);
}
public EntityManaBurst(EntityPlayer player) {
this(player.worldObj);
setBurstSourceCoords(0, -1, 0);
setLocationAndAngles(player.posX, player.posY + player.getEyeHeight(), player.posZ, player.rotationYaw + 180, -player.rotationPitch);
posX -= (double)(MathHelper.cos((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F);
posY -= 0.10000000149011612D;
posZ -= (double)(MathHelper.sin((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F);
setPosition(posX, posY, posZ);
yOffset = 0.0F;
float f = 0.4F;
double mx = MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f / 2D;
double mz = -(MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f) / 2D;
double my = MathHelper.sin((rotationPitch + func_70183_g()) / 180.0F * (float) Math.PI) * f / 2D;
setMotion(mx, my, mz);
}
float accumulatedManaLoss = 0;
private int ticksInAir;
@@ -331,11 +351,11 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
if(getMana() <= 0)
setDead();
}
particles();
setMotion(motionX, motionY, motionZ);
fullManaLastTick = getMana() == getStartingMana();
}
@@ -354,7 +374,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
++ticksExisted;
onUpdate();
}
if(fake)
incrementFakeParticleTick();
@@ -464,7 +484,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
if(tile instanceof IManaCollisionGhost && ((IManaCollisionGhost) tile).isGhost())
return;
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
if(tile != null && (tile.xCoord != coords.posX || tile.yCoord != coords.posY || tile.zCoord != coords.posZ))
collidedTile = tile;
@@ -650,18 +670,18 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
private String getCollisionLocString(int x, int y, int z) {
return x + ":" + y + ":" + z;
}
private boolean shouldDoFakeParticles() {
if(ConfigHandler.staticWandBeam)
return true;
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
TileEntity tile = worldObj.getBlockTileEntity(coords.posX, coords.posY, coords.posZ);
if(tile != null && tile instanceof TileSpreader)
return (getMana() != getStartingMana() && fullManaLastTick) || Math.abs(((TileSpreader) tile).burstParticleTick - ticksExisted) < 3;
return false;
}
private void incrementFakeParticleTick() {
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
TileEntity tile = worldObj.getBlockTileEntity(coords.posX, coords.posY, coords.posZ);
@@ -672,7 +692,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
spreader.burstParticleTick = 0;
}
}
private void setDeathTicksForFakeParticle() {
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
TileEntity tile = worldObj.getBlockTileEntity(coords.posX, coords.posY, coords.posZ);
@@ -190,10 +190,8 @@ public class ItemLens extends ItemMod implements ILens {
for(ItemStack stack_ : items)
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stack_));
burst.setMana(mana - 16);
}
if(!burst.isFake())
burst.setMana(mana - 64);
}
dead = false;
@@ -206,7 +204,7 @@ public class ItemLens extends ItemMod implements ILens {
if(living.hurtTime == 0) {
int mana = burst.getMana();
if(mana >= 32) {
burst.setMana(mana - 32);
burst.setMana(mana - 16);
if(!burst.isFake() && !entity.worldObj.isRemote)
living.attackEntityFrom(DamageSource.magic, 1);
}
@@ -219,11 +217,11 @@ public class ItemLens extends ItemMod implements ILens {
burst.setMinManaLoss(Math.max(0, burst.getMinManaLoss() - 4));
}
}
case 11 : { // Explosive
case 11 : { // Entropic
if(!burst.isFake()) {
ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates();
if(!entity.worldObj.isRemote && pos.entityHit == null && !isManaBlock && (pos.blockX != coords.posX || pos.blockY != coords.posY || pos.blockZ != coords.posZ))
entity.worldObj.createExplosion(entity, entity.posX, entity.posY, entity.posZ, (float) burst.getMana() / 100F, true);
entity.worldObj.createExplosion(entity, entity.posX, entity.posY, entity.posZ, (float) burst.getMana() / 50F, true);
} else dead = false;
}
}
@@ -11,34 +11,136 @@
*/
package vazkii.botania.common.item;
import java.util.List;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import vazkii.botania.api.mana.BurstProperties;
import vazkii.botania.api.mana.ILens;
import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.entity.EntityManaBurst;
import vazkii.botania.common.item.recipe.ManaGunLensRecipe;
import vazkii.botania.common.lib.LibItemIDs;
import vazkii.botania.common.lib.LibItemNames;
public class ItemManaGun extends ItemMod {
private static final String TAG_LENS = "lens";
private static final int COOLDOWN = 30;
public ItemManaGun() {
super(LibItemIDs.idManaGun);
setMaxDamage(10);
setMaxDamage(COOLDOWN);
setMaxStackSize(1);
setNoRepair();
setUnlocalizedName(LibItemNames.MANA_GUN);
GameRegistry.addRecipe(new ManaGunLensRecipe());
}
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
par1ItemStack.setItemDamage(10);
if(!par3EntityPlayer.isSneaking()) {
if(par1ItemStack.getItemDamage() == 0) {
EntityManaBurst burst = getBurst(par3EntityPlayer, par1ItemStack);
if(burst != null && ManaItemHandler.requestManaExact(par1ItemStack, par3EntityPlayer, burst.getMana(), true)) {
if(!par2World.isRemote) {
par2World.playSoundAtEntity(par3EntityPlayer, "random.explode", 0.9F, 3F);
par2World.spawnEntityInWorld(burst);
} else par3EntityPlayer.swingItem();
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);
}
} else {
ItemStack lens = getLens(par1ItemStack);
if(lens != null) {
if(!par3EntityPlayer.inventory.addItemStackToInventory(lens.copy()))
par3EntityPlayer.addChatMessage("botaniamisc.invFull");
else setLens(par1ItemStack, null);
}
}
return par1ItemStack;
}
public EntityManaBurst getBurst(EntityPlayer player, ItemStack stack) {
EntityManaBurst burst = new EntityManaBurst(player);
int maxMana = 120;
int color = 0x00FF00;
int ticksBeforeManaLoss = 60;
float manaLossPerTick = 4F;
float motionModifier = 5F;
float gravity = 0F;
BurstProperties props = new BurstProperties(maxMana, ticksBeforeManaLoss, manaLossPerTick, gravity, motionModifier, color);
ItemStack lens = getLens(stack);
if(lens != null)
((ILens) lens.getItem()).apply(lens, props);
burst.setSourceLens(lens);
if(ManaItemHandler.requestManaExact(stack, player, props.maxMana, false)) {
burst.setColor(props.color);
burst.setMana(props.maxMana);
burst.setStartingMana(props.maxMana);
burst.setMinManaLoss(props.ticksBeforeManaLoss);
burst.setManaLossPerTick(props.manaLossPerTick);
burst.setGravity(props.gravity);
burst.setMotion(burst.motionX * props.motionModifier, burst.motionY * props.motionModifier, burst.motionZ * props.motionModifier);
return burst;
}
return null;
}
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
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()));
}
}
@Override
public String getItemDisplayName(ItemStack par1ItemStack) {
ItemStack lens = getLens(par1ItemStack);
return super.getItemDisplayName(par1ItemStack) + (lens == null ? "" : " (" + EnumChatFormatting.GREEN + lens.getDisplayName() + EnumChatFormatting.RESET + ")");
}
public static void setLens(ItemStack stack, ItemStack lens) {
NBTTagCompound cmp = new NBTTagCompound();
if(lens != null)
lens.writeToNBT(cmp);
ItemNBTHelper.setCompound(stack, TAG_LENS, cmp);
}
public static ItemStack getLens(ItemStack stack) {
NBTTagCompound cmp = ItemNBTHelper.getCompound(stack, TAG_LENS, true);
if(cmp != null) {
ItemStack lens = ItemStack.loadItemStackFromNBT(cmp);
return lens;
}
return null;
}
@Override
public boolean isFull3D() {
return true;
}
@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
if(par1ItemStack.isItemDamaged())
@@ -151,10 +151,4 @@ public class ItemManaTablet extends ItemMod implements IManaItem {
public boolean canExportManaToItem(ItemStack stack, ItemStack otherStack) {
return true;
}
@Override
public boolean isPriorityItem(ItemStack stack) {
return false;
}
}
@@ -0,0 +1,79 @@
/**
* 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 @ [Mar 13, 2014, 8:01:14 PM (GMT)]
*/
package vazkii.botania.common.item.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.api.mana.ILens;
import vazkii.botania.common.item.ItemManaGun;
public class ManaGunLensRecipe implements IRecipe {
@Override
public boolean matches(InventoryCrafting var1, World var2) {
boolean foundLens = false;
boolean foundGun = false;
for(int i = 0; i < var1.getSizeInventory(); i++) {
ItemStack stack = var1.getStackInSlot(i);
if(stack != null) {
if(stack.getItem() instanceof ItemManaGun && ItemManaGun.getLens(stack) == null)
foundGun = true;
else if(stack.getItem() instanceof ILens)
foundLens = true;
else return false; // Found an invalid item, breaking the recipe
}
}
return foundLens && foundGun;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting var1) {
ItemStack lens = null;
ItemStack gun = null;
for(int i = 0; i < var1.getSizeInventory(); i++) {
ItemStack stack = var1.getStackInSlot(i);
if(stack != null) {
if(stack.getItem() instanceof ItemManaGun)
gun = stack;
else if(stack.getItem() instanceof ILens)
lens = stack;
}
}
if(lens == null || gun == null)
return null;
ItemStack gunCopy = gun.copy();
ItemManaGun.setLens(gunCopy, lens);
return gunCopy;
}
@Override
public int getRecipeSize() {
return 10;
}
@Override
public ItemStack getRecipeOutput() {
return null;
}
}
+8
View File
@@ -16,6 +16,7 @@ botaniamisc.flareColor=%s Rounds
botaniamisc.outputtingPower=Sparing Power to Items
botaniamisc.inputtingPower=Accepting Power from Items
botaniamisc.creative=Creative
botaniamisc.invFull=Your inventory is full.
# COLORS
botania.color0=White
@@ -217,6 +218,7 @@ item.botania:rune14.name=Rune of Envy
item.botania:rune15.name=Rune of Pride
item.botania:signalFlare.name=Signal Flare
item.botania:manaTablet.name=Mana Tablet
item.botania:manaGun.name=Mana Blaster
# GUI TEXT
botania.gui.lexicon.header=Lexica Botania Index - Pick which category you would like to study:
@@ -468,6 +470,12 @@ botania.page.pylon0=A &1Mana Pylon&0 is a structure that can pull energies from
botania.page.pylon1=&oYou must construct additional pylons!&r
# - MYSTICAL INSTRUMENTS
# -- MANA BLASTER
botania.entry.manaBlaster=Mana Blaster
botania.page.manaBlaster0=The &1Mana Blaster&0 is like a portable &1Mana Spreader&0, while shaped like a pistol for easy handling, it's not exactly a firearm, as much as it is just a portable spreader.<br>By utilizing &4Mana&0 from &4Mana carrying items&0 in the holder's inventory, it can shoot a mana burst when one is looking at.
botania.page.manaBlaster1=This burst is a bit different from the one fired from speaders, as it's faster, but carries only three quarters of the mana a spreader burst would. There's also a short cooldown period after firing the blaster until another burst can be shot.
botania.page.manaBlaster2=&1Mana Lenses&0 also function with the blaster, to attach one to it, put them side by side on a crafting table, to remove it, simply shift-right click the blaster.
botania.page.manaBlaster3=Crafting the blaster
# - MISCLANEOUS
# -- UNSTABLE CUBE