Added infrastructure and rendering for the Soul Arrow.

This commit is contained in:
WayofTime 2016-01-08 22:20:31 -05:00
parent 22a0e2b8a9
commit 1d6edae50e
11 changed files with 300 additions and 0 deletions
src/main
java/WayofTime/bloodmagic
resources/assets/bloodmagic/textures/entities

View file

@ -24,6 +24,8 @@ public interface ISoulGem
*/
public double getSouls(ItemStack soulGemStack);
public void setSouls(ItemStack soulGemStack, double amount);
public int getMaxSouls(ItemStack soulGemStack);
public double drainSouls(ItemStack stack, double drainAmount);

View file

@ -112,4 +112,32 @@ public class PlayerSoulHandler
return soulStack;
}
public static double addSouls(EntityPlayer player, double amount)
{
ItemStack[] inventory = player.inventory.mainInventory;
double remaining = amount;
for (int i = 0; i < inventory.length; i++)
{
ItemStack stack = inventory[i];
if (stack != null)
{
if (stack.getItem() instanceof ISoulGem)
{
double souls = ((ISoulGem) stack.getItem()).getSouls(stack);
double fill = Math.min(((ISoulGem) stack.getItem()).getMaxSouls(stack) - souls, remaining);
((ISoulGem) stack.getItem()).setSouls(stack, fill + souls);
remaining -= fill;
if (remaining <= 0)
{
break;
}
}
}
}
return amount - remaining;
}
}

View file

@ -0,0 +1,100 @@
package WayofTime.bloodmagic.client.render.entity;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import WayofTime.bloodmagic.entity.projectile.EntitySoulArrow;
@SideOnly(Side.CLIENT)
public class RenderEntitySoulArrow extends Render<EntitySoulArrow>
{
private static final ResourceLocation arrowTextures = new ResourceLocation("bloodmagic:textures/entities/soulArrow.png");
public RenderEntitySoulArrow(RenderManager renderManagerIn)
{
super(renderManagerIn);
}
public void doRender(EntitySoulArrow entity, double x, double y, double z, float entityYaw, float partialTicks)
{
this.bindEntityTexture(entity);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.pushMatrix();
GlStateManager.translate((float) x, (float) y, (float) z);
GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks - 90.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, 0.0F, 0.0F, 1.0F);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
int i = 0;
float f = 0.0F;
float f1 = 0.5F;
float f2 = (float) (0 + i * 10) / 32.0F;
float f3 = (float) (5 + i * 10) / 32.0F;
float f4 = 0.0F;
float f5 = 0.15625F;
float f6 = (float) (5 + i * 10) / 32.0F;
float f7 = (float) (10 + i * 10) / 32.0F;
float f8 = 0.05625F;
GlStateManager.enableRescaleNormal();
float f9 = (float) entity.arrowShake - partialTicks;
if (f9 > 0.0F)
{
float f10 = -MathHelper.sin(f9 * 3.0F) * f9;
GlStateManager.rotate(f10, 0.0F, 0.0F, 1.0F);
}
GlStateManager.rotate(45.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.scale(f8, f8, f8);
GlStateManager.translate(-4.0F, 0.0F, 0.0F);
GL11.glNormal3f(f8, 0.0F, 0.0F);
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
worldrenderer.pos(-7.0D, -2.0D, -2.0D).tex((double) f4, (double) f6).endVertex();
worldrenderer.pos(-7.0D, -2.0D, 2.0D).tex((double) f5, (double) f6).endVertex();
worldrenderer.pos(-7.0D, 2.0D, 2.0D).tex((double) f5, (double) f7).endVertex();
worldrenderer.pos(-7.0D, 2.0D, -2.0D).tex((double) f4, (double) f7).endVertex();
tessellator.draw();
GL11.glNormal3f(-f8, 0.0F, 0.0F);
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
worldrenderer.pos(-7.0D, 2.0D, -2.0D).tex((double) f4, (double) f6).endVertex();
worldrenderer.pos(-7.0D, 2.0D, 2.0D).tex((double) f5, (double) f6).endVertex();
worldrenderer.pos(-7.0D, -2.0D, 2.0D).tex((double) f5, (double) f7).endVertex();
worldrenderer.pos(-7.0D, -2.0D, -2.0D).tex((double) f4, (double) f7).endVertex();
tessellator.draw();
for (int j = 0; j < 4; ++j)
{
GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
GL11.glNormal3f(0.0F, 0.0F, f8);
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
worldrenderer.pos(-8.0D, -2.0D, 0.0D).tex((double) f, (double) f2).endVertex();
worldrenderer.pos(8.0D, -2.0D, 0.0D).tex((double) f1, (double) f2).endVertex();
worldrenderer.pos(8.0D, 2.0D, 0.0D).tex((double) f1, (double) f3).endVertex();
worldrenderer.pos(-8.0D, 2.0D, 0.0D).tex((double) f, (double) f3).endVertex();
tessellator.draw();
}
GlStateManager.disableRescaleNormal();
GlStateManager.popMatrix();
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called
* unless you call Render.bindEntityTexture.
*/
protected ResourceLocation getEntityTexture(EntitySoulArrow entity)
{
return arrowTextures;
}
}

View file

@ -0,0 +1,15 @@
package WayofTime.bloodmagic.client.render.entity;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import WayofTime.bloodmagic.entity.projectile.EntitySoulArrow;
public class SoulArrowRenderFactory implements IRenderFactory<EntitySoulArrow>
{
@Override
public Render<? super EntitySoulArrow> createRenderFor(RenderManager manager)
{
return new RenderEntitySoulArrow(manager);
}
}

View file

@ -0,0 +1,59 @@
package WayofTime.bloodmagic.entity.projectile;
import WayofTime.bloodmagic.api.soul.PlayerSoulHandler;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class EntitySoulArrow extends EntityArrow
{
public double reimbursedAmountOnHit = 0;
public EntitySoulArrow(World worldIn)
{
super(worldIn);
}
public EntitySoulArrow(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
public EntitySoulArrow(World worldIn, EntityLivingBase shooter, EntityLivingBase p_i1755_3_, float p_i1755_4_, float p_i1755_5_)
{
super(worldIn, shooter, p_i1755_3_, p_i1755_4_, p_i1755_5_);
}
public EntitySoulArrow(World worldIn, EntityLivingBase shooter, float velocity, double reimbursement)
{
super(worldIn, shooter, velocity);
this.reimbursedAmountOnHit = reimbursement;
}
public void reimbursePlayer()
{
if (this.shootingEntity instanceof EntityPlayer)
{
PlayerSoulHandler.addSouls((EntityPlayer) this.shootingEntity, reimbursedAmountOnHit);
}
}
@Override
public void writeEntityToNBT(NBTTagCompound tag)
{
super.writeEntityToNBT(tag);
tag.setDouble("reimbursement", reimbursedAmountOnHit);
}
@Override
public void readEntityFromNBT(NBTTagCompound tag)
{
super.readEntityFromNBT(tag);
reimbursedAmountOnHit = tag.getDouble("reimbursement");
}
}

View file

@ -1,13 +1,21 @@
package WayofTime.bloodmagic.item.soul;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.entity.projectile.EntitySoulArrow;
public class ItemSoulBow extends ItemBow
{
@ -18,6 +26,77 @@ public class ItemSoulBow extends ItemBow
this.setCreativeTab(BloodMagic.tabBloodMagic);
}
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)
{
boolean flag = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
if (flag || playerIn.inventory.hasItem(Items.arrow))
{
int i = this.getMaxItemUseDuration(stack) - timeLeft;
net.minecraftforge.event.entity.player.ArrowLooseEvent event = new net.minecraftforge.event.entity.player.ArrowLooseEvent(playerIn, stack, i);
if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event))
return;
i = event.charge;
float f = (float) i / 20.0F;
f = (f * f + f * 2.0F) / 3.0F;
if ((double) f < 0.1D)
{
return;
}
if (f > 1.0F)
{
f = 1.0F;
}
EntityArrow entityarrow = new EntitySoulArrow(worldIn, playerIn, f * 2.0F, 0);
if (f == 1.0F)
{
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
if (j > 0)
{
entityarrow.setDamage(entityarrow.getDamage() + (double) j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
if (k > 0)
{
entityarrow.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
{
entityarrow.setFire(100);
}
stack.damageItem(1, playerIn);
worldIn.playSoundAtEntity(playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (flag)
{
entityarrow.canBePickedUp = 2;
} else
{
playerIn.inventory.consumeInventoryItem(Items.arrow);
}
playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
if (!worldIn.isRemote)
{
worldIn.spawnEntityInWorld(entityarrow);
}
}
}
@SideOnly(Side.CLIENT)
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining)
{

View file

@ -98,6 +98,7 @@ public class ItemSoulGem extends Item implements ISoulGem
return tag.getDouble(Constants.NBT.SOULS);
}
@Override
public void setSouls(ItemStack soulGemStack, double souls)
{
NBTHelper.checkNBT(soulGemStack);

View file

@ -10,7 +10,9 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.client.render.RenderAlchemyArray;
import WayofTime.bloodmagic.client.render.RenderAltar;
import WayofTime.bloodmagic.client.render.entity.SoulArrowRenderFactory;
import WayofTime.bloodmagic.client.render.entity.SoulSnareRenderFactory;
import WayofTime.bloodmagic.entity.projectile.EntitySoulArrow;
import WayofTime.bloodmagic.entity.projectile.EntitySoulSnare;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.registry.ModItems;
@ -52,6 +54,7 @@ public class ClientProxy extends CommonProxy
public void registerRenderers()
{
RenderingRegistry.registerEntityRenderingHandler(EntitySoulSnare.class, new SoulSnareRenderFactory());
RenderingRegistry.registerEntityRenderingHandler(EntitySoulArrow.class, new SoulArrowRenderFactory());
}
@Override

View file

@ -3,6 +3,7 @@ package WayofTime.bloodmagic.registry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.entity.projectile.EntityBloodLight;
import WayofTime.bloodmagic.entity.projectile.EntitySoulArrow;
import WayofTime.bloodmagic.entity.projectile.EntitySoulSnare;
public class ModEntities
@ -13,5 +14,6 @@ public class ModEntities
EntityRegistry.registerModEntity(EntityBloodLight.class, "BloodLight", id++, BloodMagic.instance, 64, 20, true);
EntityRegistry.registerModEntity(EntitySoulSnare.class, "SoulSnare", id++, BloodMagic.instance, 64, 1, true);
EntityRegistry.registerModEntity(EntitySoulArrow.class, "SoulArrow", id++, BloodMagic.instance, 64, 1, true);
}
}

View file

@ -41,6 +41,7 @@ import WayofTime.bloodmagic.api.soul.ISoulWeapon;
import WayofTime.bloodmagic.api.soul.PlayerSoulHandler;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
import WayofTime.bloodmagic.block.BlockAltar;
import WayofTime.bloodmagic.entity.projectile.EntitySoulArrow;
import WayofTime.bloodmagic.item.ItemAltarMaker;
import WayofTime.bloodmagic.item.armour.ItemLivingArmour;
import WayofTime.bloodmagic.item.gear.ItemPackSacrifice;
@ -241,6 +242,8 @@ public class EventHandler
{
EntityPlayer attackedPlayer = (EntityPlayer) attackedEntity;
// Living Armour handling
boolean hasFullSet = true;
for (int i = 0; i < 4; i++)
{
@ -269,10 +272,18 @@ public class EventHandler
}
}
if (sourceEntity instanceof EntitySoulArrow)
{
// Soul Weapon handling
((EntitySoulArrow) sourceEntity).reimbursePlayer();
}
if (sourceEntity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) sourceEntity;
// Living Armour handling
boolean hasFullSet = true;
for (int i = 0; i < 4; i++)
{

Binary file not shown.

After

(image error) Size: 279 B