Katana rework

This commit is contained in:
John Yorke committed 2021-02-08 14:02:44 -04:00
1 parent 6877cf922d
commit 8788ea9354
2 files changed
+293 -222

No files matched your search

@@ -1,7 +1,7 @@
package taintedmagic.common.items.tools;
import java.awt.Color;
import java.util.List;
import java.util.Random;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
@@ -14,12 +14,14 @@ import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
@@ -44,12 +46,22 @@ import thaumcraft.api.IRepairable;
import thaumcraft.api.IWarpingGear;
import thaumcraft.client.lib.UtilsFX;
import thaumcraft.codechicken.lib.vec.Vector3;
import thaumcraft.common.Thaumcraft;
import thaumcraft.common.config.Config;
import thaumcraft.common.entities.projectile.EntityExplosiveOrb;
public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRenderInventoryItem, IHeldItemHUD
{
public static final int SUBTYPES = 3;
final int SUBTYPES = 3;
// NBT tags
public static final String TAG_INSCRIPTION = "inscription";
public static final String TAG_COOLDOWN = "cooldown";
// ticks to fully charge (20 ticks = 1 second)
public static final int CHARGE_TICKS = 20;
// inscription attack cooldown
public static final int COOLDOWN = 140;
public static final ResourceLocation TEXTURE_THAUMIUM =
new ResourceLocation("taintedmagic:textures/models/ModelKatanaThaumium.png");
@@ -71,79 +83,6 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
this.setMaxStackSize(1);
}
@Override
public boolean hitEntity (ItemStack stack, EntityLivingBase entity, EntityLivingBase player)
{
if (!entity.worldObj.isRemote && (! (entity instanceof EntityPlayer) || ! (player instanceof EntityPlayer)
|| MinecraftServer.getServer().isPVPEnabled()))
{
try
{
if (stack.getItemDamage() == 1)
{
entity.addPotionEffect(new PotionEffect(Potion.weakness.getId(), 60));
entity.addPotionEffect(new PotionEffect(Potion.hunger.getId(), 120));
}
if (stack.getItemDamage() == 2)
{
entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.getId(), 120, 2));
entity.addPotionEffect(new PotionEffect(Config.potionBlurredID, 120));
}
}
catch (Exception e)
{
}
if (hasAnyInscription(stack))
{
switch (getInscription(stack))
{
case 0 :
{
entity.attackEntityFrom(
DamageSource.causePlayerDamage((EntityPlayer) player).setFireDamage().setDamageBypassesArmor(),
getAttackDamage(stack));
entity.setFire(5);
break;
}
case 1 :
{
entity.attackEntityFrom(
DamageSource.causePlayerDamage((EntityPlayer) player).setMagicDamage().setDamageBypassesArmor(),
getAttackDamage(stack));
try
{
entity.addPotionEffect(new PotionEffect(Potion.weakness.id, 160));
}
catch (Exception e)
{
}
break;
}
case 2 :
{
entity.attackEntityFrom(DamageSource.wither.setMagicDamage().setDamageBypassesArmor(),
getAttackDamage(stack));
try
{
entity.addPotionEffect(new PotionEffect(Potion.wither.id, 60));
}
catch (Exception ex)
{
}
break;
}
}
}
else entity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) player), getAttackDamage(stack));
}
player.worldObj.playSoundAtEntity(player, "thaumcraft:swing", 0.5F + (float) Math.random(),
0.5F + (float) Math.random());
return super.hitEntity(stack, entity, player);
}
@Override
public boolean isFull3D ()
{
@@ -163,12 +102,14 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
}
@SideOnly (Side.CLIENT)
@Override
public void getSubItems (Item item, CreativeTabs tab, List list)
{
for (int a = 0; a < SUBTYPES; a++)
list.add(new ItemStack(this, 1, a));
}
@Override
public String getUnlocalizedName (ItemStack stack)
{
return super.getUnlocalizedName() + "." + stack.getItemDamage();
@@ -178,13 +119,17 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
public void addInformation (ItemStack stack, EntityPlayer player, List list, boolean b)
{
if (stack.getItemDamage() == 1)
list.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("enchantment.special.sapless"));
if (stack.getItemDamage() == 2)
list.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("enchantment.special.sapgreat"));
list.add(" ");
list.add("\u00A79+" + getAttackDamage(stack) + " " + StatCollector.translateToLocal("text.attackdamage"));
if (stack.hasTagCompound() && stack.stackTagCompound.hasKey("inscription"))
if (stack.hasTagCompound() && stack.stackTagCompound.hasKey(TAG_INSCRIPTION))
list.add(EnumChatFormatting.GOLD + StatCollector
.translateToLocal("text.katana.inscription." + stack.stackTagCompound.getInteger("inscription")));
.translateToLocal("text.katana.inscription." + stack.stackTagCompound.getInteger(TAG_INSCRIPTION)));
}
@Override
@@ -193,7 +138,248 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
return EnumRarity.uncommon;
}
public float getAttackDamage (ItemStack stack)
@Override
public int getWarp (ItemStack stack, EntityPlayer player)
{
return stack.getItemDamage() == 0 ? 0 : stack.getItemDamage() == 1 ? 3 : 7;
}
@Override
public boolean hitEntity (ItemStack stack, EntityLivingBase entity, EntityLivingBase player)
{
if (!entity.worldObj.isRemote && (! (entity instanceof EntityPlayer) || ! (player instanceof EntityPlayer)
|| MinecraftServer.getServer().isPVPEnabled()))
{
// Sapping effects
if (stack.getItemDamage() == 1)
{
entity.addPotionEffect(new PotionEffect(Potion.weakness.id, 60)); // lesser sapping
}
if (stack.getItemDamage() == 2)
{
entity.addPotionEffect(new PotionEffect(Potion.weakness.id, 60)); // greater sapping
entity.addPotionEffect(new PotionEffect(Potion.hunger.id, 120));
}
// Inscription effects
if (hasAnyInscription(stack)) switch (getInscription(stack))
{
case 0 :
{
entity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) player).setFireDamage(),
getAttackDamage(stack));
entity.setFire(3);
break;
}
case 1 :
{
entity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) player).setMagicDamage(),
getAttackDamage(stack));
entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 140));
break;
}
case 2 :
{
entity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) player).setMagicDamage(),
getAttackDamage(stack));
entity.addPotionEffect(new PotionEffect(Potion.wither.id, 60));
break;
}
default :
break;
}
else entity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) player), getAttackDamage(stack));
}
// Sound effect
player.worldObj.playSoundAtEntity(player, "thaumcraft:swing", 0.5F + (float) Math.random(),
0.5F + (float) Math.random());
return super.hitEntity(stack, entity, player);
}
@Override
public int getMaxItemUseDuration (ItemStack stack)
{
return 72000;
}
@Override
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
{
if (!hasCooldown(stack)) player.setItemInUse(stack, getMaxItemUseDuration(stack));
return stack;
}
@Override
public void onUsingTick (ItemStack stack, EntityPlayer player, int i)
{
super.onUsingTick(stack, player, i);
this.ticksInUse = getMaxItemUseDuration(stack) - i;
float j = 0.75F + ((float) Math.random() * 0.25F);
if (player.ticksExisted % 5 == 0) player.worldObj.playSoundAtEntity(player, "thaumcraft:wind", j * 0.1F, j);
}
@Override
public void onPlayerStoppedUsing (ItemStack stack, World world, EntityPlayer player, int i)
{
super.onPlayerStoppedUsing(stack, world, player, i);
if (isFullyCharged(player))
{
if (!hasAnyInscription(stack) || player.isSneaking())
{
if (world.isRemote)
{
MovingObjectPosition mop = Minecraft.getMinecraft().objectMouseOver;
// charged strike damage multiplier
float mul = 1.5F;
if (world.rand.nextInt(10) == 0) mul += 1.0F; // crit
if (mop.entityHit != null) PacketHandler.INSTANCE
.sendToServer(new PacketKatanaAttack(mop.entityHit, player, this.getAttackDamage(stack) * mul));
}
player.worldObj.playSoundAtEntity(player, "thaumcraft:swing", 0.5F + (float) Math.random(),
0.5F + (float) Math.random());
player.swingItem();
}
else
{
switch (getInscription(stack))
{
case 0 : // fireball
{
EntityExplosiveOrb proj = new EntityExplosiveOrb(world, player);
proj.strength = getAttackDamage(stack) * .25F;
proj.posX += proj.motionX;
proj.posY += proj.motionY;
proj.posZ += proj.motionZ;
if (!world.isRemote) world.spawnEntityInWorld(proj);
player.swingItem();
break;
}
case 1 : // thunder
{
// get entities within 10 block radius
List<EntityLivingBase> ents = world.getEntitiesWithinAABB(EntityLivingBase.class,
AxisAlignedBB.getBoundingBox(player.posX, player.posY, player.posZ, player.posX + 1,
player.posY + 1, player.posZ + 1).expand(10.0D, 10.0D, 10.0D));
if (ents != null && ents.size() > 0) for (EntityLivingBase entity : ents)
{
if (entity != player && entity.isEntityAlive() && !entity.isEntityInvulnerable())
{
entity.attackEntityFrom(DamageSource.magic, getAttackDamage(stack) * 0.25F);
Vector3 movement = TaintedMagicHelper.getVectorBetweenEntities(entity, player);
entity.addVelocity(movement.x * 5.0D, 1.5D, movement.z * 5.0D);
if (world.isRemote) ItemFocusShockwave.spawnParticles(world, player, entity);
}
}
world.playSoundAtEntity(player, "taintedmagic:shockwave", 5.0F, 1.5F * (float) Math.random());
player.swingItem();
break;
}
case 2 : // heal
{
// heal 50% of missing health
player.heal( (player.getMaxHealth() - player.getHealth()) * 0.5F);
// get entities within 5 blocks
List<EntityLivingBase> ents = world.getEntitiesWithinAABB(EntityLivingBase.class,
AxisAlignedBB.getBoundingBox(player.posX, player.posY, player.posZ, player.posX + 1,
player.posY + 1, player.posZ + 1).expand(5.0D, 5.0D, 5.0D));
// add wither to all entities in range
if (ents != null && ents.size() > 0) for (EntityLivingBase entity : ents)
if (entity != player && entity.isEntityAlive() && !entity.isEntityInvulnerable())
entity.addPotionEffect(new PotionEffect(Potion.wither.id, 100, 1));
// beneficial effects on the player
player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 60, 1));
player.addPotionEffect(new PotionEffect(Potion.resistance.id, 120, 1));
// particles similar to pech focus
if (world.isRemote)
{
for (int a = 0; a < 18; a++)
{
Thaumcraft.proxy.wispFX2(world, player.posX + world.rand.nextGaussian() * 0.25F,
player.boundingBox.minY + 1.0F + world.rand.nextGaussian() * 0.5F,
player.posZ + world.rand.nextGaussian() * 0.25F, 0.25F + (float) Math.random() * 0.25F, 3,
true, false, 0.02F);
Thaumcraft.proxy.sparkle((float) player.posX + (float) world.rand.nextGaussian() * 0.25F,
(float) player.boundingBox.minY + 1.0F + (float) world.rand.nextGaussian() * 0.5F,
(float) player.posZ + (float) world.rand.nextGaussian() * 0.25F, 5);
}
}
world.playSoundAtEntity(player, "thaumcraft:wand", 1.0F, 0.9F + (float) Math.random() * 0.1F);
player.swingItem();
break;
}
default :
break;
}
setCooldown(stack, COOLDOWN);
}
}
}
@Override
public void onUpdate (ItemStack stack, World world, Entity entity, int i, boolean b)
{
// update the cooldown every tick
if (hasCooldown(stack)) setCooldown(stack, getCooldown(stack) - 1);
}
private boolean isFullyCharged (EntityPlayer player)
{
float f = Math.min((float) this.ticksInUse / (float) CHARGE_TICKS, 1.0F);
return f == 1.0F;
}
public static boolean hasAnyInscription (ItemStack stack)
{
return stack.hasTagCompound() && stack.stackTagCompound.hasKey(TAG_INSCRIPTION);
}
private int getInscription (ItemStack stack)
{
if (stack.hasTagCompound() && stack.stackTagCompound.hasKey(TAG_INSCRIPTION))
return stack.stackTagCompound.getInteger(TAG_INSCRIPTION);
else return 0;
}
private boolean hasCooldown (ItemStack stack)
{
return stack.hasTagCompound() && stack.stackTagCompound.getInteger(TAG_COOLDOWN) > 0;
}
private void setCooldown (ItemStack stack, int cooldown)
{
if (!stack.hasTagCompound()) stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setInteger(TAG_COOLDOWN, cooldown);
}
private int getCooldown (ItemStack stack)
{
if (stack.hasTagCompound() && stack.stackTagCompound.hasKey(TAG_COOLDOWN))
return stack.stackTagCompound.getInteger(TAG_COOLDOWN);
else return 0;
}
private float getAttackDamage (ItemStack stack)
{
switch (stack.getItemDamage())
{
@@ -207,104 +393,19 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
return 0;
}
@Override
public int getMaxItemUseDuration (ItemStack stack)
// get texture based on the item damage
public static ResourceLocation getTexture (ItemStack stack)
{
return 72000;
}
@Override
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
{
player.setItemInUse(stack, getMaxItemUseDuration(stack));
return stack;
}
@Override
public void onUsingTick (ItemStack stack, EntityPlayer player, int i)
{
super.onUsingTick(stack, player, i);
this.ticksInUse = getMaxItemUseDuration(stack) - i;
float j = 1.0F + ((float) Math.random() * 0.25F);
if (player.ticksExisted % 5 == 0) player.worldObj.playSoundAtEntity(player, "thaumcraft:wind", j * 0.1F, j);
}
@Override
public void onPlayerStoppedUsing (ItemStack stack, World world, EntityPlayer player, int i)
{
super.onPlayerStoppedUsing(stack, world, player, i);
Random random = new Random();
if (isFullyCharged(player) && (!hasAnyInscription(stack) || player.isSneaking() || getInscription(stack) == 2))
switch (stack.getItemDamage())
{
boolean leech = (getInscription(stack) == 2 && isFullyCharged(player));
if (world.isRemote)
{
MovingObjectPosition mop = Minecraft.getMinecraft().objectMouseOver;
float mul = 2.0F;
if (mop.entityHit != null) PacketHandler.INSTANCE
.sendToServer(new PacketKatanaAttack(mop.entityHit, player, this.getAttackDamage(stack) * mul, leech));
player.swingItem();
}
player.worldObj.playSoundAtEntity(player, "thaumcraft:swing", 0.5F + (float) Math.random(),
0.5F + (float) Math.random());
case 0 :
return TEXTURE_THAUMIUM;
case 1 :
return TEXTURE_VOIDMETAL;
case 2 :
return TEXTURE_SHADOWMETAL;
}
else if (hasAnyInscription(stack) && isFullyCharged(player) && !player.isSneaking())
{
switch (getInscription(stack))
{
case 0 :
{
EntityExplosiveOrb proj = new EntityExplosiveOrb(world, player);
proj.strength = getAttackDamage(stack) * .25F;
proj.posX += proj.motionX;
proj.posY += proj.motionY;
proj.posZ += proj.motionZ;
if (!world.isRemote) world.spawnEntityInWorld(proj);
player.swingItem();
break;
}
case 1 :
{
List<EntityLivingBase> ents = world.getEntitiesWithinAABB(EntityLivingBase.class,
AxisAlignedBB.getBoundingBox(player.posX, player.posY, player.posZ, player.posX + 1, player.posY + 1,
player.posZ + 1).expand(10.0D, 10.0D, 10.0D));
if (ents != null && ents.size() > 0)
{
for (EntityLivingBase entity : ents)
{
if (entity != player && entity.isEntityAlive() && !entity.isEntityInvulnerable())
{
entity.attackEntityFrom(DamageSource.magic, getAttackDamage(stack) * 0.25F);
Vector3 movement = TaintedMagicHelper.getVectorBetweenEntities(entity, player);
entity.addVelocity(movement.x * 5.0D, 1.5D, movement.z * 5.0D);
if (world.isRemote) ItemFocusShockwave.spawnParticles(world, player, entity);
}
}
}
world.playSoundAtEntity(player, "taintedmagic:shockwave", 5.0F, 1.5F * (float) Math.random());
player.swingItem();
break;
}
default :
break;
}
}
}
private boolean isFullyCharged (EntityPlayer player)
{
float f = Math.min((float) this.ticksInUse / 10.0F, 1.0F);
return f == 1.0F;
return null;
}
@Override
@@ -312,7 +413,8 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
{
Tessellator t = Tessellator.instance;
float tickFract = Math.min((float) player.getItemInUseDuration() / 10.0F, 1.0F);
float overlay = Math.min(hasCooldown(stack) ? ((float) getCooldown(stack) / (float) COOLDOWN)
: (float) player.getItemInUseDuration() / (float) CHARGE_TICKS, 1.0F);
int x = res.getScaledWidth() / 2 + 725;
int x2 = x + 16;
@@ -333,6 +435,7 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
{
float red = MathHelper.sin( (player.ticksExisted + rune * 5) / 5.0F) * 0.1F + 0.8F;
float green = MathHelper.sin( (player.ticksExisted + rune * 5) / 7.0F) * 0.1F + 0.7F;
float blue = 0.4F;
float alpha = MathHelper.sin( (player.ticksExisted + rune * 5) / 10.0F) * 0.3F;
float f = 0.0625F * rune;
@@ -343,7 +446,7 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
t.startDrawingQuads();
t.setBrightness(240);
t.setColorRGBA_F(red, green, 0.4F, (alpha + 0.7F) * fract);
t.setColorRGBA_F(red, green, blue, (alpha + 0.7F) * fract);
t.addVertexWithUV(x + (rune * 16) - alpha, y2 + alpha, 0, f, f3);
t.addVertexWithUV(x2 + (rune * 16) + alpha, y2 + alpha, 0, f1, f3);
t.addVertexWithUV(x2 + (rune * 16) + alpha, y - alpha, 0, f1, f2);
@@ -351,12 +454,21 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
t.draw();
if ((int) (16 * tickFract) > rune)
if (Math.ceil(16 * overlay) > rune)
{
// red to green gradient
Color color = new Color(Color.HSBtoRGB((float) rune / 16F * 0.3F, 1.0F, 1.0F));
// flip the gradient when cooling down
if (hasCooldown(stack)) color = new Color(Color.HSBtoRGB( (16F - (float) rune) / 16F * 0.3F, 1.0F, 1.0F));
// convert to float rgb
red = (float) color.getRed() / 255F;
green = (float) color.getGreen() / 255F;
blue = (float) color.getBlue() / 255F;
t.startDrawingQuads();
t.setBrightness(240);
t.setColorRGBA_F(1.0F - (0.0625F * rune), 0.0F + (0.0625F * rune), 0.0F, 0.9F + alpha);
t.setColorRGBA_F(red, green, blue, 0.9F + alpha);
t.addVertexWithUV(x + (rune * 16) - alpha, y2 + alpha, 0, f, f3);
t.addVertexWithUV(x2 + (rune * 16) + alpha, y2 + alpha, 0, f1, f3);
t.addVertexWithUV(x2 + (rune * 16) + alpha, y - alpha, 0, f1, f2);
@@ -370,38 +482,7 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable, IRend
GL11.glPopMatrix();
}
public static boolean hasAnyInscription (ItemStack stack)
{
return stack.hasTagCompound() && stack.stackTagCompound.hasKey("inscription");
}
public static int getInscription (ItemStack stack)
{
if (stack.hasTagCompound() && stack.stackTagCompound.hasKey("inscription"))
return stack.stackTagCompound.getInteger("inscription");
else return 0;
}
public static ResourceLocation getTexture (ItemStack stack)
{
switch (stack.getItemDamage())
{
case 0 :
return TEXTURE_THAUMIUM;
case 1 :
return TEXTURE_VOIDMETAL;
case 2 :
return TEXTURE_SHADOWMETAL;
}
return null;
}
@Override
public int getWarp (ItemStack stack, EntityPlayer player)
{
return stack.getItemDamage() == 0 ? 0 : stack.getItemDamage() == 1 ? 3 : 7;
}
// render katana on hip
@Override
public void render (EntityPlayer player, ItemStack stack, float partialTicks)
{
@@ -17,19 +17,17 @@ public class PacketKatanaAttack implements IMessage, IMessageHandler<PacketKatan
private int playerID;
private int dimensionID;
private float dmg;
private boolean leech;
public PacketKatanaAttack ()
{
}
public PacketKatanaAttack (Entity entity, EntityPlayer player, float dmg, boolean leech)
public PacketKatanaAttack (Entity entity, EntityPlayer player, float dmg)
{
this.entityID = entity.getEntityId();
this.playerID = player.getEntityId();
this.dimensionID = entity.dimension;
this.dmg = dmg;
this.leech = leech;
}
@Override
@@ -41,14 +39,8 @@ public class PacketKatanaAttack implements IMessage, IMessageHandler<PacketKatan
Entity entity = world.getEntityByID(message.entityID);
Entity player = world.getEntityByID(message.playerID);
if (entity != null && entity instanceof EntityLivingBase && player != null && player instanceof EntityPlayer)
entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(player, entity), message.dmg);
if (message.leech && player instanceof EntityPlayer)
{
((EntityPlayer) player).heal(message.dmg * 0.25F);
world.playSoundAtEntity(player, "thaumcraft:runicShieldEffect", 0.5F, 0.5F + ((float) Math.random() * 0.5F));
}
if (entity != null && entity instanceof EntityLivingBase && player != null && player instanceof EntityPlayer) entity
.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) player).setDamageBypassesArmor(), message.dmg);
return null;
}
@@ -60,7 +52,6 @@ public class PacketKatanaAttack implements IMessage, IMessageHandler<PacketKatan
this.playerID = buf.readInt();
this.dimensionID = buf.readInt();
this.dmg = buf.readFloat();
this.leech = buf.readBoolean();
}
@Override
@@ -70,6 +61,5 @@ public class PacketKatanaAttack implements IMessage, IMessageHandler<PacketKatan
buf.writeInt(this.playerID);
buf.writeInt(this.dimensionID);
buf.writeFloat(this.dmg);
buf.writeBoolean(this.leech);
}
}