mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-26 15:03:01 +00:00
Lots of integration. Graphics n stuff. Items. Everything.
This commit is contained in:
1 parent
4bb32da4c8
commit
0bdf31912b
48 files changed
+119
-384
No files matched your search
@@ -26,6 +26,7 @@ public class TConstructRegistry
|
||||
public static TConstructCreativeTab materialTab;
|
||||
public static TConstructCreativeTab blockTab;
|
||||
public static TConstructCreativeTab equipableTab;
|
||||
public static TConstructCreativeTab weaponryTab;
|
||||
|
||||
/* Items */
|
||||
|
||||
|
||||
@@ -0,0 +1,627 @@
|
||||
package tconstruct.library.entity;
|
||||
|
||||
import tconstruct.library.weaponry.AmmoItem;
|
||||
import tconstruct.util.Reference;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.projectile.EntityArrow;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.play.server.S2BPacketChangeGameState;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.library.ActiveToolMod;
|
||||
import tconstruct.library.TConstructRegistry;
|
||||
import tconstruct.library.tools.AbilityHelper;
|
||||
import tconstruct.library.tools.ToolCore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// have to base this on EntityArrow, otherwise minecraft does derp things because everything is handled based on class.
|
||||
public abstract class ProjectileBase extends EntityArrow implements IEntityAdditionalSpawnData {
|
||||
public final static String woodSound = Reference.resource("woodHit");
|
||||
public final static String stoneSound = Reference.resource("stoneHit");
|
||||
|
||||
public ItemStack returnStack;
|
||||
public int returnStackSlot;
|
||||
|
||||
public boolean bounceOnNoDamage = true;
|
||||
|
||||
public ProjectileBase(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public ProjectileBase(World world, double d, double d1, double d2) {
|
||||
this(world);
|
||||
this.setPosition(d, d1, d2);
|
||||
}
|
||||
|
||||
public ProjectileBase(World world, EntityPlayer player, float speed, float accuracy, ItemStack stack) {
|
||||
this(world);
|
||||
|
||||
this.shootingEntity = player;
|
||||
|
||||
canBePickedUp = 1;
|
||||
|
||||
// stuff from the arrow
|
||||
this.setLocationAndAngles(player.posX, player.posY + (double)player.getEyeHeight(), player.posZ, player.rotationYaw, player.rotationPitch);
|
||||
this.posX -= MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F;
|
||||
this.posY -= 0.10000000149011612D;
|
||||
this.posZ -= MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F;
|
||||
this.setPosition(this.posX, this.posY, this.posZ);
|
||||
this.yOffset = 0.0F;
|
||||
this.motionX = -MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI);
|
||||
this.motionZ = +MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI);
|
||||
this.motionY = -MathHelper.sin(this.rotationPitch / 180.0F * (float)Math.PI);
|
||||
this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, speed, accuracy);
|
||||
|
||||
// our stuff
|
||||
returnStackSlot = player.inventory.currentItem;
|
||||
returnStack = stack;
|
||||
|
||||
/*
|
||||
// fix upward default angle
|
||||
motionY = -MathHelper.sin((rotationPitch / 180F) * 3.141593F - 0.2f);
|
||||
setArrowHeading(motionX, motionY, motionZ, speed, 0.0f);
|
||||
|
||||
// set better position and move it a tad so we don't hit ourselves.
|
||||
this.setPosition(player.posX, player.posY + player.getEyeHeight(), player.posZ);
|
||||
*/
|
||||
/*
|
||||
double l = Math.sqrt(motionX*motionX + motionY*motionY + motionZ*motionZ);
|
||||
double vx = motionX/l;
|
||||
double vy = motionY/l;
|
||||
double vz = motionZ/l;
|
||||
|
||||
posX += vx*1.5f;
|
||||
posY += vy*1.5f;
|
||||
posZ += vz*1.5f;
|
||||
*/
|
||||
|
||||
//init();
|
||||
}
|
||||
|
||||
public ItemStack getEntityItem ()
|
||||
{
|
||||
return returnStack;
|
||||
}
|
||||
|
||||
protected void playHitBlockSound(int x, int y, int z)
|
||||
{
|
||||
Block block = worldObj.getBlock(x,y,z);
|
||||
if(block != null && block.blockMaterial == Material.wood)
|
||||
worldObj.playSoundAtEntity(this, woodSound, 1.0f, 1.0f);
|
||||
else {
|
||||
worldObj.playSoundAtEntity(this, stoneSound, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
if(block != null)
|
||||
worldObj.playSoundAtEntity(this, block.stepSound.getBreakSound(), 0.7f, 1.0f);
|
||||
}
|
||||
|
||||
protected void playHitEntitySound()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* How deep the item enters stuff it hits. Should be bigger for bigger objects, and smaller for smaller objects.
|
||||
* 1.0f is exactly halfway in.
|
||||
*/
|
||||
protected double getStuckDepth() { return 0.5f; }
|
||||
|
||||
protected void doLivingHit(EntityLivingBase entityHit)
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
entityHit.setArrowCountInEntity(entityHit.getArrowCountInEntity() + 1);
|
||||
}
|
||||
|
||||
if (this.knockbackStrength > 0)
|
||||
{
|
||||
double horizontalSpeed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
||||
|
||||
if (horizontalSpeed > 0.0F)
|
||||
{
|
||||
entityHit.addVelocity(this.motionX * (double) this.knockbackStrength * 0.6000000238418579D / (double) horizontalSpeed, 0.1D, this.motionZ * (double) this.knockbackStrength * 0.6000000238418579D / (double) horizontalSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.shootingEntity != null && this.shootingEntity instanceof EntityLivingBase)
|
||||
{
|
||||
EnchantmentHelper.func_151384_a(entityHit, this.shootingEntity);
|
||||
EnchantmentHelper.func_151385_b((EntityLivingBase)this.shootingEntity, entityHit);
|
||||
}
|
||||
|
||||
if (this.shootingEntity != null && entityHit != this.shootingEntity && entityHit instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP)
|
||||
{
|
||||
((EntityPlayerMP)this.shootingEntity).playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
|
||||
}
|
||||
}
|
||||
|
||||
public void onHitBlock(MovingObjectPosition movingobjectposition) {
|
||||
this.field_145791_d = movingobjectposition.blockX;
|
||||
this.field_145792_e = movingobjectposition.blockY;
|
||||
this.field_145789_f = movingobjectposition.blockZ;
|
||||
this.field_145790_g = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);
|
||||
this.inData = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f);
|
||||
this.motionX = movingobjectposition.hitVec.xCoord - this.posX;
|
||||
this.motionY = movingobjectposition.hitVec.yCoord - this.posY;
|
||||
this.motionZ = movingobjectposition.hitVec.zCoord - this.posZ;
|
||||
double speed = getStuckDepth() * MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
|
||||
this.posX -= this.motionX / speed * 0.05000000074505806D;
|
||||
this.posY -= this.motionY / speed * 0.05000000074505806D;
|
||||
this.posZ -= this.motionZ / speed * 0.05000000074505806D;
|
||||
|
||||
playHitBlockSound(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
|
||||
|
||||
this.inGround = true;
|
||||
this.arrowShake = 7;
|
||||
this.setIsCritical(false);
|
||||
|
||||
if (this.field_145790_g.getMaterial() != Material.air)
|
||||
{
|
||||
this.field_145790_g.onEntityCollidedWithBlock(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void onHitEntity(MovingObjectPosition movingobjectposition) {
|
||||
NBTTagCompound tags = returnStack.getTagCompound().getCompoundTag("InfiTool");
|
||||
double speed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
|
||||
int damage = MathHelper.ceiling_double_int(speed * tags.getInteger("Attack"));
|
||||
|
||||
// Damage calculations and stuff. For reference see AbilityHelper.onLeftClickEntity
|
||||
ToolCore ammo = (ToolCore)returnStack.getItem();
|
||||
|
||||
// factor in modified stuff for base damage
|
||||
// basically we pass the base damage to all modifiers and take the highest one
|
||||
int baseDamage = 0;
|
||||
for(ActiveToolMod toolmod : TConstructRegistry.activeModifiers) {
|
||||
int dmg = toolmod.baseAttackDamage(baseDamage, damage, ammo, returnStack.getTagCompound(), tags, returnStack, (EntityPlayer)this.shootingEntity, movingobjectposition.entityHit);
|
||||
if(dmg > baseDamage)
|
||||
baseDamage = dmg;
|
||||
}
|
||||
damage += baseDamage;
|
||||
|
||||
// damage modification from the weapon itself
|
||||
damage *= ammo.getDamageModifier();
|
||||
|
||||
// unlike the regular weapons, we do no gain more damage from potion of strength/weakness since we don't hit stuff directly
|
||||
|
||||
// stonebound decreases, jagged increases damage too
|
||||
float bonusDamage = -AbilityHelper.calcStoneboundBonus(ammo, tags);
|
||||
// enchantments might add too
|
||||
if(shootingEntity != null)
|
||||
bonusDamage += EnchantmentHelper.getEnchantmentModifierLiving((EntityLivingBase)this.shootingEntity, (EntityLivingBase)movingobjectposition.entityHit);
|
||||
damage += bonusDamage;
|
||||
|
||||
// ensure we still have damage
|
||||
if(damage < 1)
|
||||
damage = 1;
|
||||
|
||||
// the regular tool modifier damage stuff
|
||||
int modDamage = 0;
|
||||
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
|
||||
{
|
||||
modDamage += mod.attackDamage(modDamage, damage, ammo, returnStack.getTagCompound(), tags, returnStack, (EntityPlayer)this.shootingEntity, movingobjectposition.entityHit);
|
||||
}
|
||||
damage += modDamage;
|
||||
|
||||
// calculate critical damaaage
|
||||
if (this.getIsCritical())
|
||||
damage += this.rand.nextInt(damage / 2 + 2);
|
||||
|
||||
// and now we come to the part where we actually deal the damage!
|
||||
if(!dealDamage(damage, ammo, tags, movingobjectposition.entityHit))
|
||||
{
|
||||
if(!bounceOnNoDamage)
|
||||
this.setDead();
|
||||
|
||||
// bounce off if we didn't deal damage
|
||||
this.motionX *= -0.10000000149011612D;
|
||||
this.motionY *= -0.10000000149011612D;
|
||||
this.motionZ *= -0.10000000149011612D;
|
||||
this.rotationYaw += 180.0F;
|
||||
this.prevRotationYaw += 180.0F;
|
||||
this.ticksInAir = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (movingobjectposition.entityHit instanceof EntityLivingBase)
|
||||
doLivingHit((EntityLivingBase)movingobjectposition.entityHit);
|
||||
|
||||
playHitEntitySound();
|
||||
|
||||
if (!(movingobjectposition.entityHit instanceof EntityEnderman))
|
||||
{
|
||||
this.setDead();
|
||||
}
|
||||
}
|
||||
|
||||
// returns true if it was successful
|
||||
public boolean dealDamage(float damage, ToolCore ammo, NBTTagCompound tags, Entity entityHit)
|
||||
{
|
||||
boolean dealtDamage = false;
|
||||
|
||||
// deal regular damage
|
||||
DamageSource damagesource;
|
||||
if (this.shootingEntity == null)
|
||||
damagesource = DamageSource.causeArrowDamage(this, this);
|
||||
else
|
||||
damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity);
|
||||
dealtDamage = entityHit.attackEntityFrom(damagesource, damage);
|
||||
|
||||
return dealtDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
// this function is the same as the vanilla EntityArrow
|
||||
public void onUpdate() {
|
||||
// call the entity update routine
|
||||
// luckily we can call this directly and take the arrow-code, since we'd have to call super.onUpdate otherwise. Which would not work.
|
||||
onEntityUpdate();
|
||||
|
||||
// boioioiooioing
|
||||
if (this.arrowShake > 0)
|
||||
--this.arrowShake;
|
||||
|
||||
// If we don't have our rotation set correctly, infer it from our motion direction
|
||||
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
|
||||
{
|
||||
float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
||||
this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
|
||||
this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f) * 180.0D / Math.PI);
|
||||
}
|
||||
|
||||
// we previously hit something. Check if the block is still there.
|
||||
Block block = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);
|
||||
if (block.getMaterial() != Material.air)
|
||||
{
|
||||
block.setBlockBoundsBasedOnState(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f);
|
||||
AxisAlignedBB axisalignedbb = block.getCollisionBoundingBoxFromPool(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f);
|
||||
|
||||
// we are stuck in a block. yay.
|
||||
if (axisalignedbb != null && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ)))
|
||||
this.inGround = true;
|
||||
}
|
||||
|
||||
if (this.inGround)
|
||||
updateInGround();
|
||||
else
|
||||
updateInAir();
|
||||
}
|
||||
|
||||
// Update while we're stuck in a block
|
||||
protected void updateInGround()
|
||||
{
|
||||
Block block = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);
|
||||
int j = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f);
|
||||
|
||||
// check if it's still the same block
|
||||
if (block == this.field_145790_g && j == this.inData)
|
||||
{
|
||||
++this.ticksInGround;
|
||||
|
||||
if (this.ticksInGround == 1200)
|
||||
{
|
||||
this.setDead();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.inGround = false;
|
||||
this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
|
||||
this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
|
||||
this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
|
||||
this.ticksInGround = 0;
|
||||
this.ticksInAir = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// update while traveling
|
||||
protected void updateInAir()
|
||||
{
|
||||
// tick tock
|
||||
++this.ticksInAir;
|
||||
|
||||
// do a raytrace from old to new position
|
||||
Vec3 curPos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
||||
Vec3 newPos = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
||||
MovingObjectPosition movingobjectposition = this.worldObj.func_147447_a(curPos, newPos, false, true, false);
|
||||
|
||||
// raytrace messes with the positions. get new ones!
|
||||
curPos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
||||
|
||||
// if we hit something, the collision point is our new position
|
||||
if (movingobjectposition != null)
|
||||
newPos = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
|
||||
else
|
||||
newPos = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
||||
|
||||
|
||||
// Check all the entities we on our way
|
||||
Entity entity = null;
|
||||
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
|
||||
double distance = 0.0D;
|
||||
float f1;
|
||||
|
||||
for(Entity ent : list)
|
||||
{
|
||||
if(!ent.canBeCollidedWith())
|
||||
continue;
|
||||
// we don't shoot ourselves into the foot.
|
||||
if(ent == this.shootingEntity && this.ticksInAir < 5)
|
||||
continue;
|
||||
|
||||
f1 = 0.3F;
|
||||
AxisAlignedBB axisalignedbb1 = ent.boundingBox.expand((double)f1, (double)f1, (double)f1);
|
||||
MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(curPos, newPos);
|
||||
|
||||
// did we actually collide with the entity, or was it just really close nearby?
|
||||
if (movingobjectposition1 != null)
|
||||
{
|
||||
// check if this entity is closer than the other one we already hit
|
||||
double otherDistance = curPos.distanceTo(movingobjectposition1.hitVec);
|
||||
|
||||
if (otherDistance < distance || distance == 0.0D)
|
||||
{
|
||||
entity = ent;
|
||||
distance = otherDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we hit something, new collision point!
|
||||
if (entity != null)
|
||||
movingobjectposition = new MovingObjectPosition(entity);
|
||||
|
||||
// did we hit a player?
|
||||
if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayer entityplayer = (EntityPlayer)movingobjectposition.entityHit;
|
||||
|
||||
// can we attack said player?
|
||||
if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer))
|
||||
movingobjectposition = null;
|
||||
|
||||
// this check should probably done inside of the loop for accuracy..
|
||||
}
|
||||
|
||||
|
||||
// time to hit the object
|
||||
if (movingobjectposition != null)
|
||||
{
|
||||
if (movingobjectposition.entityHit != null)
|
||||
onHitEntity(movingobjectposition);
|
||||
else
|
||||
onHitBlock(movingobjectposition);
|
||||
}
|
||||
|
||||
// crithit particles
|
||||
if (this.getIsCritical())
|
||||
drawCritParticles();
|
||||
|
||||
// MOVEMENT! yay.
|
||||
doMoveUpdate();
|
||||
double slowdown = 1.0d - getSlowdown();
|
||||
|
||||
// bubblez
|
||||
if (this.isInWater())
|
||||
{
|
||||
for (int l = 0; l < 4; ++l)
|
||||
{
|
||||
float f4 = 0.25F;
|
||||
this.worldObj.spawnParticle("bubble", this.posX - this.motionX * (double)f4, this.posY - this.motionY * (double)f4, this.posZ - this.motionZ * (double)f4, this.motionX, this.motionY, this.motionZ);
|
||||
}
|
||||
|
||||
// more slowdown in water
|
||||
slowdown = 1d - 20d*getSlowdown();
|
||||
}
|
||||
|
||||
// phshshshshshs
|
||||
if (this.isWet())
|
||||
this.extinguish();
|
||||
|
||||
// minimalistic slowdown!
|
||||
this.motionX *= slowdown;
|
||||
this.motionY *= slowdown;
|
||||
this.motionZ *= slowdown;
|
||||
// gravity
|
||||
this.motionY -= getGravity();
|
||||
this.setPosition(this.posX, this.posY, this.posZ);
|
||||
|
||||
// tell blocks we collided with, that we collided with them!
|
||||
this.func_145775_I();
|
||||
}
|
||||
|
||||
public void drawCritParticles()
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
this.worldObj.spawnParticle("crit", this.posX + this.motionX * (double)i / 4.0D, this.posY + this.motionY * (double)i / 4.0D, this.posZ + this.motionZ * (double)i / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doMoveUpdate()
|
||||
{
|
||||
this.posX += this.motionX;
|
||||
this.posY += this.motionY;
|
||||
this.posZ += this.motionZ;
|
||||
double f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
||||
this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
|
||||
this.rotationPitch = (float)(Math.atan2(this.motionY, f2) * 180.0D / Math.PI);
|
||||
|
||||
// normalize rotations
|
||||
while (this.rotationPitch - this.prevRotationPitch < -180.0F)
|
||||
this.prevRotationPitch -= 360.0F;
|
||||
|
||||
while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
|
||||
this.prevRotationPitch += 360.0F;
|
||||
|
||||
while (this.rotationYaw - this.prevRotationYaw < -180.0F)
|
||||
this.prevRotationYaw -= 360.0F;
|
||||
|
||||
while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
|
||||
this.prevRotationYaw += 360.0F;
|
||||
|
||||
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
|
||||
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factor for the slowdown. 0 = no slowdown, >0 = (1-slowdown)*speed slowdown, <0 = speedup
|
||||
*/
|
||||
protected double getSlowdown() { return 0.01; }
|
||||
|
||||
/**
|
||||
* Added to the y-velocity as gravitational pull. Otherwise stuff would simply float midair.
|
||||
*/
|
||||
protected double getGravity() { return 0.05; }
|
||||
|
||||
/**
|
||||
* Called by a player entity when they collide with an entity
|
||||
*/
|
||||
public void onCollideWithPlayer(EntityPlayer player)
|
||||
{
|
||||
if (!this.worldObj.isRemote && this.inGround && this.arrowShake <= 0)
|
||||
{
|
||||
boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && player.capabilities.isCreativeMode;
|
||||
|
||||
if (this.canBePickedUp == 1)
|
||||
{
|
||||
// ammo pickup
|
||||
if(this.returnStack != null && this.returnStack.getItem() instanceof AmmoItem)
|
||||
{
|
||||
if(!((AmmoItem) this.returnStack.getItem()).pickupAmmo(returnStack, null, player))
|
||||
flag = false;
|
||||
}
|
||||
// regular pickup.
|
||||
// Note that you can't pick up ammo items without the proper itemstack in your inventory to prevent dupes
|
||||
else if(!player.inventory.addItemStackToInventory(new ItemStack(Items.arrow, 1)))
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
|
||||
player.onItemPickup(this, 1);
|
||||
this.setDead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** NBT stuff **/
|
||||
|
||||
@Override
|
||||
public void writeEntityToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeEntityToNBT(tags);
|
||||
|
||||
tags.setTag("Throwable", this.returnStack.writeToNBT(new NBTTagCompound()));
|
||||
tags.setByte("onGround", (byte) (onGround ? 1 : 0));
|
||||
//tags.setBoolean("Retrieval", doNotRetrieve);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readEntityFromNBT(NBTTagCompound tags) {
|
||||
super.readEntityFromNBT(tags);
|
||||
|
||||
this.returnStack = ItemStack.loadItemStackFromNBT(tags.getCompoundTag("Throwable"));
|
||||
onGround = tags.getByte("onGround") == 1;
|
||||
//doNotRetrieve = tags.getBoolean("Retrieval");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(ByteBuf data) {
|
||||
NBTTagCompound tags = returnStack.getTagCompound().getCompoundTag("InfiTool");
|
||||
ByteBufUtils.writeItemStack(data, returnStack);
|
||||
data.writeFloat(rotationYaw);
|
||||
/*
|
||||
data.writeInt(tags.getInteger("RenderHandle"));
|
||||
data.writeInt(tags.getInteger("RenderHead"));
|
||||
data.writeInt(tags.getInteger("RenderAccessory"));
|
||||
data.writeInt(tags.getInteger("RenderExtra"));
|
||||
|
||||
int effects = 0;
|
||||
if (tags.hasKey("Effect1"))
|
||||
effects++;
|
||||
if (tags.hasKey("Effect2"))
|
||||
effects++;
|
||||
if (tags.hasKey("Effect3"))
|
||||
effects++;
|
||||
if (tags.hasKey("Effect4"))
|
||||
effects++;
|
||||
if (tags.hasKey("Effect5"))
|
||||
effects++;
|
||||
if (tags.hasKey("Effect6"))
|
||||
effects++;
|
||||
data.writeInt(effects);
|
||||
|
||||
switch (effects)
|
||||
{
|
||||
case 6:
|
||||
data.writeInt(tags.getInteger("Effect6"));
|
||||
case 5:
|
||||
data.writeInt(tags.getInteger("Effect5"));
|
||||
case 4:
|
||||
data.writeInt(tags.getInteger("Effect4"));
|
||||
case 3:
|
||||
data.writeInt(tags.getInteger("Effect3"));
|
||||
case 2:
|
||||
data.writeInt(tags.getInteger("Effect2"));
|
||||
case 1:
|
||||
data.writeInt(tags.getInteger("Effect1"));
|
||||
}
|
||||
*/
|
||||
// shooting entity
|
||||
int id = shootingEntity == null ? this.getEntityId() : shootingEntity.getEntityId();
|
||||
data.writeInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(ByteBuf data) {
|
||||
returnStack = ByteBufUtils.readItemStack(data);
|
||||
rotationYaw = data.readFloat();
|
||||
/*
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagCompound toolTag = new NBTTagCompound();
|
||||
toolTag.setInteger("RenderHandle", data.readInt());
|
||||
toolTag.setInteger("RenderHead", data.readInt());
|
||||
toolTag.setInteger("RenderAccessory", data.readInt());
|
||||
toolTag.setInteger("RenderExtra", data.readInt());
|
||||
|
||||
switch (data.readInt())
|
||||
{
|
||||
case 6:
|
||||
toolTag.setInteger("Effect6", data.readInt());
|
||||
case 5:
|
||||
toolTag.setInteger("Effect5", data.readInt());
|
||||
case 4:
|
||||
toolTag.setInteger("Effect4", data.readInt());
|
||||
case 3:
|
||||
toolTag.setInteger("Effect3", data.readInt());
|
||||
case 2:
|
||||
toolTag.setInteger("Effect2", data.readInt());
|
||||
case 1:
|
||||
toolTag.setInteger("Effect1", data.readInt());
|
||||
}
|
||||
compound.setTag("InfiTool", toolTag);
|
||||
returnStack.setTagCompound(compound);
|
||||
*/
|
||||
shootingEntity = worldObj.getEntityByID(data.readInt());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package tconstruct.library.tools;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import tconstruct.library.TConstructRegistry;
|
||||
import tconstruct.library.tools.DynamicToolPart;
|
||||
import tconstruct.library.util.TextureHelper;
|
||||
import tconstruct.tools.TinkerTools;
|
||||
import tconstruct.util.config.PHConstruct;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DualMaterialToolPart extends DynamicToolPart {
|
||||
public IIcon defaultIcon2;
|
||||
public IIcon[] icons2;
|
||||
|
||||
public DualMaterialToolPart(String textureType, String name) {
|
||||
super(textureType, name);
|
||||
}
|
||||
|
||||
public static ItemStack createDualMaterial(Item item, int mat1, int mat2)
|
||||
{
|
||||
ItemStack stack = new ItemStack(item, 1, mat1);
|
||||
NBTTagCompound tags = new NBTTagCompound();
|
||||
NBTTagCompound subtag = new NBTTagCompound();
|
||||
subtag.setInteger("Material2", mat2);
|
||||
|
||||
tags.setTag("DualMat", subtag);
|
||||
stack.setTagCompound(tags);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int getMaterialID2(ItemStack stack)
|
||||
{
|
||||
if(!stack.hasTagCompound())
|
||||
return -1;
|
||||
|
||||
int id = stack.getTagCompound().getCompoundTag("DualMat").getInteger("Material2");
|
||||
|
||||
if (TConstructRegistry.toolMaterials.keySet().contains(id))
|
||||
return id;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems (Item item, CreativeTabs tab, List list)
|
||||
{
|
||||
// material id == metadata
|
||||
for(Integer matID : TConstructRegistry.toolMaterials.keySet())
|
||||
list.add(createDualMaterial(item, matID, TinkerTools.MaterialID.Iron));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderPasses(int metadata) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresMultipleRenderPasses() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IIconRegister iconRegister) {
|
||||
super.registerIcons(iconRegister);
|
||||
|
||||
// same as in super, secondary icon :I
|
||||
this.icons2 = new IIcon[icons.length];
|
||||
|
||||
// register icon for each material that has one
|
||||
if(!PHConstruct.minimalTextures)
|
||||
for(Map.Entry<Integer, tconstruct.library.tools.ToolMaterial> entry : TConstructRegistry.toolMaterials.entrySet())
|
||||
{
|
||||
String tex = modTexPrefix + ":" + folder + entry.getValue().materialName.toLowerCase() + texture + "_2";
|
||||
if(TextureHelper.itemTextureExists(tex))
|
||||
this.icons2[entry.getKey()] = iconRegister.registerIcon(tex);
|
||||
}
|
||||
|
||||
this.defaultIcon2 = iconRegister.registerIcon(modTexPrefix + ":" + folder + texture + "_2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconFromDamageForRenderPass(int meta, int pass) {
|
||||
// secondary item
|
||||
if(pass > 0) {
|
||||
if(meta > icons.length)
|
||||
return defaultIcon2;
|
||||
|
||||
if(icons2[meta] == null)
|
||||
return defaultIcon2;
|
||||
|
||||
return icons2[meta];
|
||||
}
|
||||
return super.getIconFromDamageForRenderPass(meta, pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorFromItemStack(ItemStack stack, int renderpass) {
|
||||
if(renderpass > 0)
|
||||
{
|
||||
int matId = getMaterialID2(stack);
|
||||
if(matId > icons2.length)
|
||||
return super.getColorFromItemStack(stack, renderpass);
|
||||
|
||||
if(icons[matId] == null)
|
||||
return TConstructRegistry.getMaterial(matId).primaryColor();
|
||||
|
||||
return super.getColorFromItemStack(stack, renderpass);
|
||||
}
|
||||
return super.getColorFromItemStack(stack, renderpass);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package tconstruct.library.util;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.EntityDamageSourceIndirect;
|
||||
|
||||
public class PiercingArrowDamage extends EntityDamageSourceIndirect {
|
||||
public PiercingArrowDamage(String p_i1568_1_, Entity p_i1568_2_, Entity p_i1568_3_) {
|
||||
super(p_i1568_1_, p_i1568_2_, p_i1568_3_);
|
||||
this.setDamageBypassesArmor();
|
||||
this.setProjectile();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package tconstruct.library.weaponry;
|
||||
|
||||
import tconstruct.library.TConstructRegistry;
|
||||
import tconstruct.weaponry.TinkerWeaponry;
|
||||
import tconstruct.util.Reference;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import tconstruct.library.tools.ToolCore;
|
||||
|
||||
public abstract class AmmoItem extends ToolCore implements IAmmo {
|
||||
public AmmoItem(int baseDamage, String name) {
|
||||
super(baseDamage);
|
||||
this.setCreativeTab(TConstructRegistry.weaponryTab);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmmoCount(ItemStack stack) {
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
return tags.getInteger("Ammo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxAmmo(ItemStack stack) {
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
return getMaxAmmo(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxAmmo(NBTTagCompound tags) {
|
||||
float dur = tags.getInteger("TotalDurability");
|
||||
return (int)Math.ceil(dur*getAmmoModifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addAmmo(int toAdd, ItemStack stack) {
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
int oldCount = tags.getInteger("Ammo");
|
||||
int newCount = Math.min(oldCount + toAdd, getMaxAmmo(stack));
|
||||
tags.setInteger("Ammo", newCount);
|
||||
return toAdd - (newCount - oldCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int consumeAmmo(int toUse, ItemStack stack) {
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
int oldCount = tags.getInteger("Ammo");
|
||||
int newCount = Math.max(oldCount - toUse, 0);
|
||||
tags.setInteger("Ammo", newCount);
|
||||
return toUse - (oldCount - newCount);
|
||||
}
|
||||
|
||||
public float getAmmoModifier() { return 0.1f; }
|
||||
|
||||
public boolean pickupAmmo(ItemStack stack, ItemStack candidate, EntityPlayer player)
|
||||
{
|
||||
if(stack.getItem() == null || !(stack.getItem() instanceof IAmmo))
|
||||
return false;
|
||||
|
||||
// check if our candidate fits
|
||||
if(candidate != null)
|
||||
{
|
||||
// same item
|
||||
if(testIfAmmoMatches(stack, candidate)) {
|
||||
IAmmo pickedup = ((IAmmo) stack.getItem());
|
||||
IAmmo ininventory = ((IAmmo) candidate.getItem());
|
||||
// we can be sure that it's ammo, since stack is ammo and they're equal
|
||||
ininventory.addAmmo(pickedup.getAmmoCount(stack), candidate);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// search the players inventory
|
||||
for(ItemStack invItem : player.inventory.mainInventory) {
|
||||
if (testIfAmmoMatches(stack, invItem)) {
|
||||
IAmmo pickedup = ((IAmmo) stack.getItem());
|
||||
IAmmo ininventory = ((IAmmo) invItem.getItem());
|
||||
// we can be sure that it's ammo, since stack is ammo and they're equal
|
||||
ininventory.addAmmo(pickedup.getAmmoCount(stack), invItem);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// couldn't find a matching thing.
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean testIfAmmoMatches(ItemStack reference, ItemStack candidate)
|
||||
{
|
||||
if(candidate == null)
|
||||
return false;
|
||||
if(!candidate.hasTagCompound() || !candidate.getTagCompound().hasKey("InfiTool"))
|
||||
return false;
|
||||
|
||||
// create a stack to test against
|
||||
ItemStack testsubject = candidate.copy();
|
||||
// all NBT has to match, but the ammo-count obviously differs. So we set our testsubject to the same
|
||||
// this ensures that it's the one to collect and the one we have matches.
|
||||
testsubject.getTagCompound().getCompoundTag("InfiTool").setInteger("Ammo", getAmmoCount(reference));
|
||||
|
||||
return ItemStack.areItemStacksEqual(reference, testsubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLeftClickEntity (ItemStack stack, EntityPlayer player, Entity entity)
|
||||
{
|
||||
// ammo doesn't hurt on smacking stuff with it
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package tconstruct.library.weaponry;
|
||||
|
||||
import tconstruct.weaponry.client.CrosshairType;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Throwing weapons that utilize the ammo system on themselves.
|
||||
* Throwing knifes etc.
|
||||
*/
|
||||
public abstract class AmmoWeapon extends AmmoItem implements IAccuracy, IWindup {
|
||||
public AmmoWeapon(int baseDamage, String name) {
|
||||
super(baseDamage, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAction getItemUseAction(ItemStack par1ItemStack) {
|
||||
return EnumAction.none;
|
||||
} // we use custom animation renderiiing!
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration(ItemStack par1ItemStack) {
|
||||
return 72000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float clickX, float clickY, float clickZ)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to "ready" the weapon. To reach the point, where holding the right mouse button any longer doesn't have an impact.
|
||||
*/
|
||||
@Override
|
||||
public int getWindupTime(ItemStack itemStack) { return 0; }
|
||||
|
||||
@Override
|
||||
public float getMinWindupProgress(ItemStack itemStack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float getWindupProgress(ItemStack itemStack, int timeInUse)
|
||||
{
|
||||
float time = (float) timeInUse;
|
||||
float windup = getWindupTime(itemStack);
|
||||
if(time > windup)
|
||||
time = windup;
|
||||
|
||||
return time/windup;
|
||||
}
|
||||
|
||||
|
||||
public float minAccuracy(ItemStack itemStack) { return 0.5f; }
|
||||
public float maxAccuracy(ItemStack itemStack) { return 0.5f; }
|
||||
|
||||
public float getWindupProgress(ItemStack itemStack, EntityPlayer player)
|
||||
{
|
||||
// what are you doing!
|
||||
if(player.inventory.getCurrentItem() != itemStack)
|
||||
return 0f;
|
||||
|
||||
// are we using it?
|
||||
if(player.getItemInUse() == null)
|
||||
return 0f;
|
||||
|
||||
return getWindupProgress(itemStack, getMaxItemUseDuration(itemStack) - player.getItemInUseCount());
|
||||
}
|
||||
|
||||
public float getAccuracy(ItemStack itemStack, EntityPlayer player)
|
||||
{
|
||||
float dif = minAccuracy(itemStack) - maxAccuracy(itemStack);
|
||||
|
||||
return minAccuracy(itemStack) - dif * getWindupProgress(itemStack, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTraits() {
|
||||
return new String[] {"weapon", "throwing", "ammo"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int durationLeft) {
|
||||
int time = this.getMaxItemUseDuration(stack) - durationLeft;
|
||||
if(getWindupProgress(stack, time) >= getMinWindupProgress(stack))
|
||||
launchProjectile(stack, world, player);
|
||||
}
|
||||
|
||||
protected void launchProjectile(ItemStack stack, World world, EntityPlayer player) {
|
||||
// spawn projectile on server
|
||||
if(!world.isRemote) {
|
||||
ItemStack reference = stack.copy();
|
||||
reference.stackSize = 1;
|
||||
reference.getTagCompound().getCompoundTag("InfiTool").setInteger("Ammo", 1);
|
||||
Entity projectile = createProjectile(reference, world, player, getAccuracy(stack, player));
|
||||
world.spawnEntityInWorld(projectile);
|
||||
}
|
||||
|
||||
// reduce ammo
|
||||
this.consumeAmmo(1, stack);
|
||||
}
|
||||
|
||||
protected abstract Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy);
|
||||
|
||||
@Override
|
||||
public void registerPartPaths(int index, String[] location) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAlternatePartPaths(int index, String[] location) {
|
||||
headStrings.put(index, location[0]);
|
||||
brokenPartStrings.put(index, location[1]);
|
||||
handleStrings.put(index, location[2]);
|
||||
if (location.length > 3)
|
||||
accessoryStrings.put(index, location[3]);
|
||||
if (location.length > 4)
|
||||
extraStrings.put(index, location[4]);
|
||||
}
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public CrosshairType getCrosshairType() { return CrosshairType.SQUARE; }
|
||||
|
||||
@Override
|
||||
public boolean zoomOnWindup(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZoom(ItemStack itemStack) {
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package tconstruct.library.weaponry;
|
||||
|
||||
import tconstruct.weaponry.TinkerWeaponry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import tconstruct.library.tools.CustomMaterial;
|
||||
|
||||
public class ArrowShaftMaterial extends CustomMaterial {
|
||||
public final float durabilityModifier; // like the durability modifier of handles, but for arrows!
|
||||
public final float fragility; // 1.0 = breaks 100%, 0.0 = never breaks
|
||||
public final float weight; // baseline: 1.0 = default, smaller = lighter, higher = heavier
|
||||
|
||||
public ArrowShaftMaterial(int materialID, int value, ItemStack input, ItemStack craftingItem, float durabilityModifier, float weight, float fragility, int color) {
|
||||
super(materialID, value, input, craftingItem, color);
|
||||
this.durabilityModifier = durabilityModifier;
|
||||
this.fragility = fragility;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public static ArrowShaftMaterial createMaterial(int id, Item input, float durabilityModifier, float weight, float fragility, int color)
|
||||
{
|
||||
return createMaterial(id, input, 0, durabilityModifier, weight, fragility, color);
|
||||
}
|
||||
|
||||
public static ArrowShaftMaterial createMaterial(int id, Item input, int inputMeta, float durabilityModifier, float weight, float fragility, int color)
|
||||
{
|
||||
return new ArrowShaftMaterial(id, 2, new ItemStack(input, 1, inputMeta), new ItemStack(TinkerWeaponry.partArrowShaft, 0, id), durabilityModifier, weight, fragility, color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package tconstruct.library.weaponry;
|
||||
|
||||
import tconstruct.weaponry.ammo.ArrowAmmo;
|
||||
import tconstruct.weaponry.entity.ArrowEntity;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.entity.projectile.EntityArrow;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.library.crafting.ToolBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BowBaseAmmo extends ProjectileWeapon {
|
||||
public BowBaseAmmo(int baseDamage, String name) {
|
||||
super(baseDamage, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int durabilityTypeAccessory() {
|
||||
return 2; // head-type
|
||||
}
|
||||
|
||||
@Override
|
||||
public int durabilityTypeExtra() {
|
||||
return 1; // handle-type
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoomOnWindup(ItemStack itemStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZoom(ItemStack itemStack) {
|
||||
return 1.2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMinWindupProgress(ItemStack itemStack) {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon)
|
||||
{
|
||||
// arrow priority: hotbar > inventory, tinker arrows > regular arrows
|
||||
ItemStack[] inventory = player.inventory.mainInventory;
|
||||
|
||||
// check hotbar for tinker arrows
|
||||
for(int i = 0; i < InventoryPlayer.getHotbarSize(); i++)
|
||||
if(checkTinkerArrow(inventory[i]))
|
||||
return inventory[i];
|
||||
|
||||
// check hotbar for vanilla arrows
|
||||
for(int i = 0; i < InventoryPlayer.getHotbarSize(); i++)
|
||||
if(checkVanillaArrow(inventory[i]))
|
||||
return inventory[i];
|
||||
|
||||
// check the rest of the inventory for tinker arrows
|
||||
for(int i = InventoryPlayer.getHotbarSize(); i < inventory.length; i++)
|
||||
if(checkTinkerArrow(inventory[i]))
|
||||
return inventory[i];
|
||||
|
||||
// check the rest of the inventory for vanilla arrows
|
||||
for(int i = InventoryPlayer.getHotbarSize(); i < inventory.length; i++)
|
||||
if(checkVanillaArrow(inventory[i]))
|
||||
return inventory[i];
|
||||
|
||||
// creative mode
|
||||
if(player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, weapon) > 0)
|
||||
return new ItemStack(Items.arrow);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean checkTinkerArrow(ItemStack stack)
|
||||
{
|
||||
// null
|
||||
if(stack == null)
|
||||
return false;
|
||||
// no tinker arrow
|
||||
if(!(stack.getItem() instanceof ArrowAmmo))
|
||||
return false;
|
||||
// no ammo left
|
||||
if(((IAmmo) stack.getItem()).getAmmoCount(stack) <= 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkVanillaArrow(ItemStack stack)
|
||||
{
|
||||
// null
|
||||
if(stack == null)
|
||||
return false;
|
||||
// no arrow
|
||||
if(!(stack.getItem() == Items.arrow))
|
||||
return false;
|
||||
// inventory shouldn't contain stacksize 0 items so we don't have to check that.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Entity createProjectile(ItemStack arrows, World world, EntityPlayer player, float speed, float accuracy) {
|
||||
EntityArrow arrow;
|
||||
|
||||
if(arrows.getItem() == Items.arrow) {
|
||||
arrow = new EntityArrow(world, player, speed/1.5f); // vanilla arrows internally do x1.5
|
||||
}
|
||||
else {
|
||||
ItemStack reference = arrows.copy();
|
||||
reference.stackSize = 1;
|
||||
reference.getTagCompound().getCompoundTag("InfiTool").setInteger("Ammo", 1);
|
||||
arrow = new ArrowEntity(world, player, speed, accuracy, reference);
|
||||
}
|
||||
|
||||
if(player.capabilities.isCreativeMode)
|
||||
arrow.canBePickedUp = 2;
|
||||
|
||||
return arrow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playFiringSound(World world, EntityPlayer player, ItemStack weapon, ItemStack ammo, float speed, float accuracy) {
|
||||
world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + speed * 0.5F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildTool (int id, String name, List list)
|
||||
{
|
||||
// all creative bows use regular bowstring
|
||||
ItemStack handleStack = new ItemStack(getHandleItem(), 1, 0); // regular bowstring
|
||||
ItemStack accessoryStack = getPartAmount() > 2 ? new ItemStack(getAccessoryItem(), 1, id) : null;
|
||||
ItemStack extraStack = getPartAmount() > 3 ? new ItemStack(getExtraItem(), 1, id) : null;
|
||||
|
||||
ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, id), handleStack, accessoryStack, extraStack, "");
|
||||
if (tool != null)
|
||||
{
|
||||
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
|
||||
list.add(tool);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass) {
|
||||
if(renderPass != 0 || !stack.hasTagCompound())
|
||||
return super.getColorFromItemStack(stack, renderPass);
|
||||
|
||||
// bowstring: custom material -> custom coloring
|
||||
// todo: move this into the custom material itself
|
||||
int mat = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Handle");
|
||||
switch(mat)
|
||||
{
|
||||
case 0: return 0xffffffff; // string = white
|
||||
case 1: return 0xffccccff; // macig string = light blue
|
||||
case 2: return 0xffffcccc; // flamestring = light red
|
||||
}
|
||||
return super.getColorFromItemStack(stack, renderPass);
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package tconstruct.library.weaponry;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IAccuracy {
|
||||
public float minAccuracy(ItemStack itemStack);
|
||||
public float maxAccuracy(ItemStack itemStack);
|
||||
public float getAccuracy(ItemStack itemStack, EntityPlayer player);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package tconstruct.library.weaponry;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface IAmmo {
|
||||
/**
|
||||
* Returns the current ammo amount of the item.
|
||||
*/
|
||||
int getAmmoCount(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of ammo the item can have
|
||||
*/
|
||||
int getMaxAmmo(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of ammo the item can have
|
||||
* @param tags InfiTool tag compound of the item
|
||||
*/
|
||||
int getMaxAmmo(NBTTagCompound tags);
|
||||
|
||||
/**
|
||||
* Adds the given amount of ammo cache. Will not go over max-ammo.
|
||||
* @param count How much to add
|
||||
* @param stack The itemstack to add the ammo to. Has to have the proper NBT.
|
||||
* @return The amount of ammo that couldn't be added.
|
||||
*/
|
||||
int addAmmo(int count, ItemStack stack);
|
||||
|
||||
/**
|
||||
* Removes the given amount fro the ammo cache. Will not go below zero.
|
||||
* @param count How much to remove
|
||||
* @param stack The itemstack to add the ammo to. Has to have the proper NBT.
|
||||
* @return The amount of ammo that couldn't be removed. If you try to remove 5, but only 3 are left, it'll return 2.
|
||||
*/
|
||||
int consumeAmmo(int count, ItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package tconstruct.library.weaponry;
|
||||
|
||||
import tconstruct.weaponry.client.CrosshairType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This class has a windup time, meaning it takes some time to reach full potency.
|
||||
* Windup progress is visualized with a special crosshair.
|
||||
*/
|
||||
public interface IWindup {
|
||||
public int getWindupTime(ItemStack itemStack); // how long it takes to fully wind up
|
||||
public float getWindupProgress(ItemStack itemStack, EntityPlayer player); // how far we've winded up, 0.0-1.0
|
||||
public float getMinWindupProgress(ItemStack itemStack); // how long it has been winded up at least to fire (0.0-1.0)
|
||||
|
||||
public CrosshairType getCrosshairType();
|
||||
|
||||
public boolean zoomOnWindup(ItemStack itemStack);
|
||||
public float getZoom(ItemStack itemStack);
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
package tconstruct.library.weaponry;
|
||||
|
||||
import tconstruct.library.TConstructRegistry;
|
||||
import tconstruct.weaponry.TinkerWeaponry;
|
||||
import tconstruct.weaponry.client.CrosshairType;
|
||||
import tconstruct.util.Reference;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
|
||||
import tconstruct.library.tools.AbilityHelper;
|
||||
import tconstruct.library.tools.ToolCore;
|
||||
import tconstruct.library.util.TextureHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Weapons that utilize ammo that uses the ammo system to shoot projectiles.
|
||||
* Bows,...
|
||||
*/
|
||||
public abstract class ProjectileWeapon extends ToolCore implements IAccuracy, IWindup {
|
||||
public ProjectileWeapon(int baseDamage, String name) {
|
||||
super(baseDamage);
|
||||
|
||||
this.setCreativeTab(TConstructRegistry.weaponryTab);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public CrosshairType getCrosshairType() {
|
||||
return CrosshairType.SQUARE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoomOnWindup(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZoom(ItemStack itemStack) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the player for ammo to use
|
||||
* @param player the player
|
||||
* @return the itemstack found to be ammo
|
||||
*/
|
||||
public abstract ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon);
|
||||
|
||||
/**
|
||||
* Creates the projectile to be fired.
|
||||
* @param ammo The ammo used
|
||||
* @param world world.
|
||||
* @param player player.
|
||||
* @param speed the speed calculated for the projectile
|
||||
* @param accuracy the accuracy calculated for the projectile
|
||||
* @return A banana.
|
||||
*/
|
||||
protected abstract Entity createProjectile(ItemStack ammo, World world, EntityPlayer player, float speed, float accuracy);
|
||||
|
||||
|
||||
/* Accuracy */
|
||||
public abstract float minAccuracy(ItemStack itemStack);
|
||||
public abstract float maxAccuracy(ItemStack itemStack);
|
||||
|
||||
public float getAccuracy(ItemStack itemStack, EntityPlayer player)
|
||||
{
|
||||
return getAccuracy(itemStack, getMaxItemUseDuration(itemStack) - player.getItemInUseCount());
|
||||
}
|
||||
|
||||
public float getAccuracy(ItemStack itemStack, int time)
|
||||
{
|
||||
float dif = minAccuracy(itemStack) - maxAccuracy(itemStack);
|
||||
|
||||
return minAccuracy(itemStack) - dif * getWindupProgress(itemStack, time);
|
||||
}
|
||||
|
||||
/* Windup */
|
||||
public int getWindupTime(ItemStack itemStack) {
|
||||
NBTTagCompound toolTag = itemStack.getTagCompound().getCompoundTag("InfiTool");
|
||||
return (int)((float)toolTag.getInteger("DrawSpeed")*windupModifier(itemStack));
|
||||
}
|
||||
|
||||
protected float windupModifier(ItemStack itemStack) { return 1.0f; }
|
||||
|
||||
public float getWindupProgress(ItemStack itemStack, EntityPlayer player)
|
||||
{
|
||||
// what are you doing!
|
||||
if(player.inventory.getCurrentItem() != itemStack)
|
||||
return 0f;
|
||||
|
||||
// are we using it?
|
||||
if(player.getItemInUse() == null)
|
||||
return 0f;
|
||||
|
||||
return getWindupProgress(itemStack, getMaxItemUseDuration(itemStack) - player.getItemInUseCount());
|
||||
}
|
||||
|
||||
public float getWindupProgress(ItemStack itemStack, int timeInUse)
|
||||
{
|
||||
float time = (float) timeInUse;
|
||||
float windup = getWindupTime(itemStack);
|
||||
if(time > windup)
|
||||
return 1.0f;
|
||||
|
||||
return time/windup;
|
||||
}
|
||||
|
||||
public float getProjectileSpeed(ItemStack itemStack)
|
||||
{
|
||||
NBTTagCompound toolTag = itemStack.getTagCompound().getCompoundTag("InfiTool");
|
||||
return toolTag.getFloat("FlightSpeed") * projectileSpeedModifier(itemStack);
|
||||
}
|
||||
|
||||
protected float projectileSpeedModifier(ItemStack itemStack) { return 1.0f; }
|
||||
|
||||
/* Bow usage */
|
||||
@Override
|
||||
public EnumAction getItemUseAction(ItemStack par1ItemStack) {
|
||||
return EnumAction.none;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration(ItemStack par1ItemStack) {
|
||||
return 72000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
if(getWindupTime(stack) == 0.0f)
|
||||
return stack;
|
||||
|
||||
// only if ammo is present
|
||||
if(searchForAmmo(player, stack) != null)
|
||||
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStoppedUsing (ItemStack weapon, World world, EntityPlayer player, int useRemaining)
|
||||
{
|
||||
int time = this.getMaxItemUseDuration(weapon) - useRemaining;
|
||||
|
||||
// we abuse the arrowLooseEvent for all projectiles
|
||||
ArrowLooseEvent event = new ArrowLooseEvent(player, weapon, time);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
if (event.isCanceled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
time = event.charge;
|
||||
|
||||
// find ammo
|
||||
ItemStack ammo = searchForAmmo(player, weapon);
|
||||
|
||||
// no ammo found. :(
|
||||
if(ammo == null)
|
||||
return;
|
||||
|
||||
NBTTagCompound toolTag = weapon.getTagCompound().getCompoundTag("InfiTool");
|
||||
float projectileSpeed = getProjectileSpeed(weapon);
|
||||
float windup = getWindupProgress(weapon, time);
|
||||
float accuracy = getAccuracy(weapon, time);
|
||||
|
||||
// needs a minimum windup
|
||||
if(windup < this.getMinWindupProgress(weapon))
|
||||
return;
|
||||
|
||||
// take windup time into account
|
||||
projectileSpeed *= windup;
|
||||
|
||||
Entity projectile = createProjectile(ammo, world, player, projectileSpeed, accuracy);
|
||||
|
||||
|
||||
int reinforced = 0;
|
||||
if (toolTag.hasKey("Unbreaking"))
|
||||
reinforced = toolTag.getInteger("Unbreaking");
|
||||
|
||||
if (random.nextInt(10) < 10 - reinforced)
|
||||
AbilityHelper.damageTool(weapon, 1, player, false);
|
||||
|
||||
playFiringSound(world, player, weapon, ammo, projectileSpeed, accuracy);
|
||||
|
||||
|
||||
// use up ammo
|
||||
if(ammo.getItem() instanceof IAmmo)
|
||||
((IAmmo) ammo.getItem()).consumeAmmo(1, ammo);
|
||||
else
|
||||
player.inventory.consumeInventoryItem(ammo.getItem());
|
||||
|
||||
// FIREEEEEEE
|
||||
if (!world.isRemote)
|
||||
world.spawnEntityInWorld(projectile);
|
||||
}
|
||||
|
||||
public abstract void playFiringSound(World world, EntityPlayer player, ItemStack weapon, ItemStack ammo, float speed, float accuracy);
|
||||
|
||||
public HashMap<Integer, IIcon[]> animationHeadIcons = new HashMap<Integer, IIcon[]>();
|
||||
public HashMap<Integer, IIcon[]> animationHandleIcons = new HashMap<Integer, IIcon[]>();
|
||||
public HashMap<Integer, IIcon[]> animationAccessoryIcons = new HashMap<Integer, IIcon[]>();
|
||||
public HashMap<Integer, IIcon[]> animationExtraIcons = new HashMap<Integer, IIcon[]>();
|
||||
|
||||
// todo: animated effects
|
||||
|
||||
/**
|
||||
* return true if the current renderpass should use animations.
|
||||
* 0 == handle
|
||||
* 1 == head
|
||||
* 2 == accessory
|
||||
* 3 == extra
|
||||
*/
|
||||
protected boolean animateLayer(int renderPass)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
|
||||
// animate?
|
||||
if(!animateLayer(renderPass))
|
||||
return super.getIcon(stack, renderPass, player, usingItem, useRemaining);
|
||||
|
||||
if(usingItem == null || stack != usingItem || !stack.hasTagCompound())
|
||||
return super.getIcon(stack, renderPass, player, usingItem, useRemaining);
|
||||
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
|
||||
// effects aren't animated
|
||||
// todo: make effects animated
|
||||
if(renderPass >= getPartAmount() || tags == null)
|
||||
return super.getIcon(stack, renderPass, player, usingItem, useRemaining);
|
||||
|
||||
float progress = getWindupProgress(usingItem, getMaxItemUseDuration(usingItem) - useRemaining);
|
||||
// get the correct icon
|
||||
switch (renderPass)
|
||||
{
|
||||
case 0: return getCorrectAnimationIcon(animationHandleIcons, tags.getInteger("RenderHandle"), progress);
|
||||
case 1: return getCorrectAnimationIcon(animationHeadIcons, tags.getInteger("renderHead"), progress);
|
||||
case 2: return getCorrectAnimationIcon(animationAccessoryIcons, tags.getInteger("renderAccessory"), progress);
|
||||
case 3: return getCorrectAnimationIcon(animationExtraIcons, tags.getInteger("renderExtra"), progress);
|
||||
}
|
||||
|
||||
return emptyIcon;
|
||||
}
|
||||
|
||||
protected IIcon getCorrectAnimationIcon(Map<Integer, IIcon[]> icons, int id, float progress)
|
||||
{
|
||||
// animation count, standard texture as reference
|
||||
float count = icons.get(-1).length - 1;
|
||||
int step = Math.round(progress * count);
|
||||
|
||||
if(icons.containsKey(id))
|
||||
return icons.get(id)[step];
|
||||
|
||||
// default icon
|
||||
return icons.get(-1)[step];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister iconRegister) {
|
||||
super.registerIcons(iconRegister);
|
||||
|
||||
addAnimationIcons(headStrings, animationHeadIcons, iconRegister, getIconSuffix(0));
|
||||
addAnimationIcons(handleStrings, animationHandleIcons, iconRegister, getIconSuffix(2));
|
||||
addAnimationIcons(accessoryStrings, animationAccessoryIcons, iconRegister, getIconSuffix(3));
|
||||
addAnimationIcons(extraStrings, animationExtraIcons, iconRegister, getIconSuffix(4));
|
||||
}
|
||||
|
||||
private void addAnimationIcons(HashMap<Integer, String> textures, HashMap<Integer, IIcon[]> icons, IIconRegister iconRegister, String standard)
|
||||
{
|
||||
icons.clear();
|
||||
|
||||
// we use the standard to determine how many animations there are
|
||||
if(standard == null || standard.isEmpty())
|
||||
return;
|
||||
|
||||
int count = 1;
|
||||
standard = getDefaultTexturePath() + "/" + standard;
|
||||
while(TextureHelper.itemTextureExists(standard + "_" + count))
|
||||
count++;
|
||||
|
||||
count--;
|
||||
|
||||
// add the standard icons
|
||||
IIcon[] anims = new IIcon[count];
|
||||
for(int i = 0; i < count; i++)
|
||||
anims[i] = iconRegister.registerIcon(standard + "_" + (i+1));
|
||||
icons.put(-1, anims);
|
||||
|
||||
// now do the same for each entry
|
||||
for(Map.Entry<Integer, String> entry : textures.entrySet())
|
||||
{
|
||||
anims = new IIcon[count];
|
||||
boolean empty = true;
|
||||
for(int i = 0; i < count; i++) {
|
||||
String tex = entry.getValue() + "_" + (i+1);
|
||||
if (TextureHelper.itemTextureExists(tex)) {
|
||||
anims[i] = iconRegister.registerIcon(tex);
|
||||
empty = false;
|
||||
}
|
||||
}
|
||||
if(!empty)
|
||||
icons.put(entry.getKey(), anims);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user