From 1d6edae50e9f626369f82996cb9e88e747aa271b Mon Sep 17 00:00:00 2001 From: WayofTime Date: Fri, 8 Jan 2016 22:20:31 -0500 Subject: [PATCH] Added infrastructure and rendering for the Soul Arrow. --- .../bloodmagic/api/soul/ISoulGem.java | 2 + .../api/soul/PlayerSoulHandler.java | 28 +++++ .../render/entity/RenderEntitySoulArrow.java | 100 ++++++++++++++++++ .../render/entity/SoulArrowRenderFactory.java | 15 +++ .../entity/projectile/EntitySoulArrow.java | 59 +++++++++++ .../bloodmagic/item/soul/ItemSoulBow.java | 79 ++++++++++++++ .../bloodmagic/item/soul/ItemSoulGem.java | 1 + .../bloodmagic/proxy/ClientProxy.java | 3 + .../bloodmagic/registry/ModEntities.java | 2 + .../bloodmagic/util/handler/EventHandler.java | 11 ++ .../textures/entities/soulArrow.png | Bin 0 -> 279 bytes 11 files changed, 300 insertions(+) create mode 100644 src/main/java/WayofTime/bloodmagic/client/render/entity/RenderEntitySoulArrow.java create mode 100644 src/main/java/WayofTime/bloodmagic/client/render/entity/SoulArrowRenderFactory.java create mode 100644 src/main/java/WayofTime/bloodmagic/entity/projectile/EntitySoulArrow.java create mode 100644 src/main/resources/assets/bloodmagic/textures/entities/soulArrow.png diff --git a/src/main/java/WayofTime/bloodmagic/api/soul/ISoulGem.java b/src/main/java/WayofTime/bloodmagic/api/soul/ISoulGem.java index 456e0c8d..14d6c9d7 100644 --- a/src/main/java/WayofTime/bloodmagic/api/soul/ISoulGem.java +++ b/src/main/java/WayofTime/bloodmagic/api/soul/ISoulGem.java @@ -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); diff --git a/src/main/java/WayofTime/bloodmagic/api/soul/PlayerSoulHandler.java b/src/main/java/WayofTime/bloodmagic/api/soul/PlayerSoulHandler.java index 91bc9d9e..8a4ba2bf 100644 --- a/src/main/java/WayofTime/bloodmagic/api/soul/PlayerSoulHandler.java +++ b/src/main/java/WayofTime/bloodmagic/api/soul/PlayerSoulHandler.java @@ -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; + } } diff --git a/src/main/java/WayofTime/bloodmagic/client/render/entity/RenderEntitySoulArrow.java b/src/main/java/WayofTime/bloodmagic/client/render/entity/RenderEntitySoulArrow.java new file mode 100644 index 00000000..58c7345d --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/render/entity/RenderEntitySoulArrow.java @@ -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 +{ + 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; + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/client/render/entity/SoulArrowRenderFactory.java b/src/main/java/WayofTime/bloodmagic/client/render/entity/SoulArrowRenderFactory.java new file mode 100644 index 00000000..3445254f --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/render/entity/SoulArrowRenderFactory.java @@ -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 +{ + @Override + public Render createRenderFor(RenderManager manager) + { + return new RenderEntitySoulArrow(manager); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/entity/projectile/EntitySoulArrow.java b/src/main/java/WayofTime/bloodmagic/entity/projectile/EntitySoulArrow.java new file mode 100644 index 00000000..2738ae1c --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/entity/projectile/EntitySoulArrow.java @@ -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"); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulBow.java b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulBow.java index c8d4887d..1fa01176 100644 --- a/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulBow.java +++ b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulBow.java @@ -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) { diff --git a/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulGem.java b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulGem.java index 23aff38d..86612f72 100644 --- a/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulGem.java +++ b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulGem.java @@ -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); diff --git a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java index f996a5ef..a1cc5d4e 100644 --- a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java +++ b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java @@ -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 diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModEntities.java b/src/main/java/WayofTime/bloodmagic/registry/ModEntities.java index 7c7f11a8..a467175c 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModEntities.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModEntities.java @@ -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); } } diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java index 4fc81594..22bf7e91 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/EventHandler.java @@ -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++) { diff --git a/src/main/resources/assets/bloodmagic/textures/entities/soulArrow.png b/src/main/resources/assets/bloodmagic/textures/entities/soulArrow.png new file mode 100644 index 0000000000000000000000000000000000000000..2d55e539f385294cf15d8a75810f2effdf0fda4f GIT binary patch literal 279 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oVGw3ym^DWND9B#o z>Fdh=fRU3)jaNnZ&wHTIHcuDFkch*{K5u9Ii+4Rgq0!%?<>8&iyFEN5Y(6|ZJU!)l zbJKr(dB@v4vH5j3`DCpa0>%l37AB<@M7V8j3b literal 0 HcmV?d00001