Added effects to the Cloaks.

This commit is contained in:
Lizbeth Rika committed 2014-12-05 17:09:50 +00:00
1 parent 58c09a69b5
commit 3fb7f9bc2b
6 files changed
+119 -18

No files matched your search

@@ -11,46 +11,111 @@
*/
package vazkii.botania.common.item.equipment.bauble;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderPlayerEvent;
import baubles.api.BaubleType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.item.IBaubleRender;
import vazkii.botania.api.item.IBaubleRender.Helper;
import vazkii.botania.api.item.IBaubleRender.RenderType;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.Botania;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibItemNames;
import baubles.api.BaubleType;
import baubles.common.container.InventoryBaubles;
import baubles.common.lib.PlayerHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemHolyCloak extends ItemBauble implements IBaubleRender {
private static final ResourceLocation texture = new ResourceLocation(LibResources.MODEL_HOLY_CLOAK);
@SideOnly(Side.CLIENT)
private static ModelBiped model;
private static final String TAG_COOLDOWN = "cooldown";
public ItemHolyCloak() {
this(LibItemNames.HOLY_CLOAK);
MinecraftForge.EVENT_BUS.register(this);
}
public ItemHolyCloak(String name) {
super(name);
}
@SubscribeEvent
public void onPlayerDamage(LivingHurtEvent event) {
if(event.entityLiving instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.entityLiving;
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
ItemStack belt = baubles.getStackInSlot(3);
if(belt != null && belt.getItem() instanceof ItemHolyCloak) {
ItemHolyCloak cloak = (ItemHolyCloak) belt.getItem();
int cooldown = getCooldown(belt);
if(cooldown == 0 && cloak.effectOnDamage(event, player, belt))
setCooldown(belt, cloak.getCooldownTime(belt));
}
}
}
@Override
public void onWornTick(ItemStack stack, EntityLivingBase player) {
int cooldown = getCooldown(stack);
if(cooldown > 0)
setCooldown(stack, cooldown - 1);
}
public boolean effectOnDamage(LivingHurtEvent event, EntityPlayer player, ItemStack stack) {
if(!event.source.isMagicDamage()) {
event.setCanceled(true);
player.worldObj.playSoundAtEntity(player, "botania:holyCloak", 1F, 1F);
for(int i = 0; i < 30; i++) {
double x = player.posX + Math.random() * player.width * 2 - player.width;
double y = player.posY + Math.random() * player.height;
double z = player.posZ + Math.random() * player.width * 2 - player.width;
boolean yellow = Math.random() > 0.5;
Botania.proxy.sparkleFX(player.worldObj, x, y, z, yellow ? 1F : 0.3F, yellow ? 1F : 0.3F, yellow ? 0.3F : 1F, 0.8F + (float) Math.random() * 0.4F, 3);
}
return true;
}
return false;
}
public int getCooldownTime(ItemStack stack) {
return 200;
}
@Override
public BaubleType getBaubleType(ItemStack arg0) {
return BaubleType.AMULET;
return BaubleType.BELT;
}
public static int getCooldown(ItemStack stack) {
return ItemNBTHelper.getInt(stack, TAG_COOLDOWN, 0);
}
public static void setCooldown(ItemStack stack, int cooldown) {
ItemNBTHelper.setInt(stack, TAG_COOLDOWN, cooldown);
}
@SideOnly(Side.CLIENT)
ResourceLocation getRenderTexture() {
return texture;
}
@Override
@SideOnly(Side.CLIENT)
public void onPlayerBaubleRender(ItemStack stack, RenderPlayerEvent event, RenderType type) {
@@ -63,11 +128,11 @@ public class ItemHolyCloak extends ItemBauble implements IBaubleRender {
float s = 0.1F;
GL11.glScalef(s, s, s);
if(model == null)
model = new ModelBiped();
model = new ModelBiped();
model.bipedBody.render(1F);
}
}
}
@@ -11,10 +11,19 @@
*/
package vazkii.botania.common.item.equipment.bauble;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.Botania;
import vazkii.botania.common.lib.LibItemNames;
public class ItemUnholyCloak extends ItemHolyCloak {
@@ -25,6 +34,31 @@ public class ItemUnholyCloak extends ItemHolyCloak {
super(LibItemNames.UNHOLY_CLOAK);
}
@Override
public boolean effectOnDamage(LivingHurtEvent event, EntityPlayer player, ItemStack stack) {
if(!event.source.isUnblockable()) {
int range = 6;
List<IMob> mobs = player.worldObj.getEntitiesWithinAABB(IMob.class, AxisAlignedBB.getBoundingBox(player.posX - range, player.posY - range, player.posZ - range, player.posX + range, player.posY + range, player.posZ + range));
for(IMob mob : mobs)
if(mob instanceof EntityLiving) {
EntityLiving entity = (EntityLiving) mob;
entity.attackEntityFrom(DamageSource.causePlayerDamage(player), event.ammount);
}
player.worldObj.playSoundAtEntity(player, "botania:unholyCloak", 1F, 1F);
for(int i = 0; i < 90; i++) {
float rad = (float) i * 4F * (float) Math.PI / 180F;
float xMotion = (float) Math.cos(rad) * 0.2F;
float zMotion = (float) Math.sin(rad) * 0.2F;
Botania.proxy.wispFX(player.worldObj, player.posX, player.posY + 0.5, player.posZ, 0.4F + (float) Math.random() + 0.25F, 0F, 0F, 0.6F + (float) Math.random() * 0.2F, xMotion, 0F, zMotion);
}
return true;
}
return false;
}
@Override
ResourceLocation getRenderTexture() {
return texture;