mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Key of the King's Law, part 1.
This commit is contained in:
1 parent
05601999dc
commit
c20db40564
5 files changed
+635
No files matched your search
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [Aug 16, 2015, 3:56:14 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.core.helper.Vector3;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.item.equipment.tool.ToolCommons;
|
||||
import vazkii.botania.common.item.relic.ItemKingKey;
|
||||
|
||||
public class EntityBabylonWeapon extends EntityThrowableCopy {
|
||||
|
||||
// TODO NBT
|
||||
|
||||
public EntityBabylonWeapon(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntityBabylonWeapon(World world, EntityLivingBase thrower) {
|
||||
super(world, thrower);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
setSize(0F, 0F);
|
||||
|
||||
dataWatcher.addObject(20, (byte) 0);
|
||||
dataWatcher.addObject(21, 0);
|
||||
dataWatcher.addObject(22, 0);
|
||||
dataWatcher.addObject(23, 0);
|
||||
dataWatcher.addObject(24, 0);
|
||||
|
||||
dataWatcher.setObjectWatched(20);
|
||||
dataWatcher.setObjectWatched(21);
|
||||
dataWatcher.setObjectWatched(22);
|
||||
dataWatcher.setObjectWatched(23);
|
||||
dataWatcher.setObjectWatched(24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
EntityLivingBase thrower = getThrower();
|
||||
if(!worldObj.isRemote && (thrower == null || !(thrower instanceof EntityPlayer))) {
|
||||
setDead();
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) thrower;
|
||||
boolean charging = isCharging();
|
||||
if(!worldObj.isRemote) {
|
||||
ItemStack stack = player == null ? null : player.getCurrentEquippedItem();
|
||||
boolean newCharging = stack != null && stack.getItem() == ModItems.kingKey && ItemKingKey.isCharging(stack);
|
||||
if(charging != newCharging) {
|
||||
setCharging(newCharging);
|
||||
charging = newCharging;
|
||||
}
|
||||
}
|
||||
|
||||
double x = motionX;
|
||||
double y = motionY;
|
||||
double z = motionZ;
|
||||
|
||||
int liveTime = getLiveTicks();
|
||||
int delay = getDelay();
|
||||
charging &= liveTime == 0;
|
||||
|
||||
if(charging) {
|
||||
motionX = 0;
|
||||
motionY = 0;
|
||||
motionZ = 0;
|
||||
|
||||
int chargeTime = getChargeTicks();
|
||||
setChargeTicks(chargeTime + 1);
|
||||
} else {
|
||||
if(liveTime < delay) {
|
||||
motionX = 0;
|
||||
motionY = 0;
|
||||
motionZ = 0;
|
||||
} else if(liveTime == delay && !worldObj.isRemote && player != null) {
|
||||
Vector3 playerLook = null;
|
||||
MovingObjectPosition lookat = ToolCommons.raytraceFromEntity(worldObj, player, true, 64);
|
||||
if(lookat == null)
|
||||
playerLook = new Vector3(player.getLookVec()).multiply(64).add(Vector3.fromEntity(player));
|
||||
else playerLook = new Vector3(lookat.blockX + 0.5, lookat.blockY + 0.5, lookat.blockZ + 0.5);
|
||||
|
||||
Vector3 thisVec = Vector3.fromEntityCenter(this);
|
||||
Vector3 motionVec = playerLook.sub(thisVec).normalize().multiply(2);
|
||||
|
||||
x = motionVec.x;
|
||||
y = motionVec.y;
|
||||
z = motionVec.z;
|
||||
}
|
||||
|
||||
setLiveTicks(liveTime + 1);
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
AxisAlignedBB axis = AxisAlignedBB.getBoundingBox(posX, posY, posZ, lastTickPosX, lastTickPosY, lastTickPosZ).expand(2, 2, 2);
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axis);
|
||||
for(EntityLivingBase living : entities) {
|
||||
if(living != thrower)
|
||||
continue;
|
||||
|
||||
if(living.hurtTime == 0) {
|
||||
if(player != null)
|
||||
living.attackEntityFrom(DamageSource.causePlayerDamage(player), 14);
|
||||
else living.attackEntityFrom(DamageSource.generic, 14);
|
||||
onImpact(new MovingObjectPosition(living));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.onUpdate();
|
||||
|
||||
motionX = x;
|
||||
motionY = y;
|
||||
motionZ = z;
|
||||
|
||||
Botania.proxy.wispFX(worldObj, posX, posY, posZ, 1F, 1F, 0F, 0.3F, 0F);
|
||||
|
||||
if(liveTime > (200 + delay))
|
||||
setDead();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onImpact(MovingObjectPosition pos) {
|
||||
EntityLivingBase thrower = getThrower();
|
||||
if(pos.entityHit == null || pos.entityHit != thrower) {
|
||||
worldObj.createExplosion(this, posX, posY, posZ, 3F, false);
|
||||
setDead();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCharging() {
|
||||
return dataWatcher.getWatchableObjectByte(20) == 1;
|
||||
}
|
||||
|
||||
public void setCharging(boolean charging) {
|
||||
dataWatcher.updateObject(20, (byte) (charging ? 1 : 0));
|
||||
}
|
||||
|
||||
public int getVariety() {
|
||||
return dataWatcher.getWatchableObjectInt(21);
|
||||
}
|
||||
|
||||
public void setVariety(int var) {
|
||||
dataWatcher.updateObject(21, var);
|
||||
}
|
||||
|
||||
public int getChargeTicks() {
|
||||
return dataWatcher.getWatchableObjectInt(22);
|
||||
}
|
||||
|
||||
public void setChargeTicks(int ticks) {
|
||||
dataWatcher.updateObject(22, ticks);
|
||||
}
|
||||
|
||||
public int getLiveTicks() {
|
||||
return dataWatcher.getWatchableObjectInt(23);
|
||||
}
|
||||
|
||||
public void setLiveTicks(int ticks) {
|
||||
dataWatcher.updateObject(23, ticks);
|
||||
}
|
||||
|
||||
public int getDelay() {
|
||||
return dataWatcher.getWatchableObjectInt(24);
|
||||
}
|
||||
|
||||
public void setDelay(int delay) {
|
||||
dataWatcher.updateObject(24, delay);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [Aug 16, 2015, 4:01:43 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.IProjectile;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
// A copy of the vanilla EntityThrowable class
|
||||
// Doing this because if I didn't do this it'd be an EntityThrowable
|
||||
// And we all know how much mods like deflecting EntityThrowables
|
||||
public abstract class EntityThrowableCopy extends Entity implements IProjectile {
|
||||
private int field_145788_c = -1;
|
||||
private int field_145786_d = -1;
|
||||
private int field_145787_e = -1;
|
||||
private Block field_145785_f;
|
||||
protected boolean inGround;
|
||||
public int throwableShake;
|
||||
/** The entity that threw this throwable item. */
|
||||
private EntityLivingBase thrower;
|
||||
private String throwerName;
|
||||
private int ticksInGround;
|
||||
private int ticksInAir;
|
||||
private static final String __OBFID = "CL_00001723";
|
||||
|
||||
public EntityThrowableCopy(World p_i1776_1_)
|
||||
{
|
||||
super(p_i1776_1_);
|
||||
this.setSize(0.25F, 0.25F);
|
||||
}
|
||||
|
||||
protected void entityInit() {}
|
||||
|
||||
/**
|
||||
* Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
|
||||
* length * 64 * renderDistanceWeight Args: distance
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isInRangeToRenderDist(double p_70112_1_)
|
||||
{
|
||||
double d1 = this.boundingBox.getAverageEdgeLength() * 4.0D;
|
||||
d1 *= 64.0D;
|
||||
return p_70112_1_ < d1 * d1;
|
||||
}
|
||||
|
||||
public EntityThrowableCopy(World p_i1777_1_, EntityLivingBase p_i1777_2_)
|
||||
{
|
||||
super(p_i1777_1_);
|
||||
this.thrower = p_i1777_2_;
|
||||
this.setSize(0.25F, 0.25F);
|
||||
this.setLocationAndAngles(p_i1777_2_.posX, p_i1777_2_.posY + (double)p_i1777_2_.getEyeHeight(), p_i1777_2_.posZ, p_i1777_2_.rotationYaw, p_i1777_2_.rotationPitch);
|
||||
this.posX -= (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
|
||||
this.posY -= 0.10000000149011612D;
|
||||
this.posZ -= (double)(MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
|
||||
this.setPosition(this.posX, this.posY, this.posZ);
|
||||
this.yOffset = 0.0F;
|
||||
float f = 0.4F;
|
||||
this.motionX = (double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f);
|
||||
this.motionZ = (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f);
|
||||
this.motionY = (double)(-MathHelper.sin((this.rotationPitch + this.func_70183_g()) / 180.0F * (float)Math.PI) * f);
|
||||
this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, this.func_70182_d(), 1.0F);
|
||||
}
|
||||
|
||||
public EntityThrowableCopy(World p_i1778_1_, double p_i1778_2_, double p_i1778_4_, double p_i1778_6_)
|
||||
{
|
||||
super(p_i1778_1_);
|
||||
this.ticksInGround = 0;
|
||||
this.setSize(0.25F, 0.25F);
|
||||
this.setPosition(p_i1778_2_, p_i1778_4_, p_i1778_6_);
|
||||
this.yOffset = 0.0F;
|
||||
}
|
||||
|
||||
protected float func_70182_d()
|
||||
{
|
||||
return 1.5F;
|
||||
}
|
||||
|
||||
protected float func_70183_g()
|
||||
{
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
|
||||
*/
|
||||
public void setThrowableHeading(double p_70186_1_, double p_70186_3_, double p_70186_5_, float p_70186_7_, float p_70186_8_)
|
||||
{
|
||||
float f2 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_3_ * p_70186_3_ + p_70186_5_ * p_70186_5_);
|
||||
p_70186_1_ /= (double)f2;
|
||||
p_70186_3_ /= (double)f2;
|
||||
p_70186_5_ /= (double)f2;
|
||||
p_70186_1_ += this.rand.nextGaussian() * 0.007499999832361937D * (double)p_70186_8_;
|
||||
p_70186_3_ += this.rand.nextGaussian() * 0.007499999832361937D * (double)p_70186_8_;
|
||||
p_70186_5_ += this.rand.nextGaussian() * 0.007499999832361937D * (double)p_70186_8_;
|
||||
p_70186_1_ *= (double)p_70186_7_;
|
||||
p_70186_3_ *= (double)p_70186_7_;
|
||||
p_70186_5_ *= (double)p_70186_7_;
|
||||
this.motionX = p_70186_1_;
|
||||
this.motionY = p_70186_3_;
|
||||
this.motionZ = p_70186_5_;
|
||||
float f3 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_5_ * p_70186_5_);
|
||||
this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(p_70186_1_, p_70186_5_) * 180.0D / Math.PI);
|
||||
this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(p_70186_3_, (double)f3) * 180.0D / Math.PI);
|
||||
this.ticksInGround = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the velocity to the args. Args: x, y, z
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_)
|
||||
{
|
||||
this.motionX = p_70016_1_;
|
||||
this.motionY = p_70016_3_;
|
||||
this.motionZ = p_70016_5_;
|
||||
|
||||
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
|
||||
{
|
||||
float f = MathHelper.sqrt_double(p_70016_1_ * p_70016_1_ + p_70016_5_ * p_70016_5_);
|
||||
this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(p_70016_1_, p_70016_5_) * 180.0D / Math.PI);
|
||||
this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(p_70016_3_, (double)f) * 180.0D / Math.PI);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to update the entity's position/logic.
|
||||
*/
|
||||
public void onUpdate()
|
||||
{
|
||||
this.lastTickPosX = this.posX;
|
||||
this.lastTickPosY = this.posY;
|
||||
this.lastTickPosZ = this.posZ;
|
||||
super.onUpdate();
|
||||
|
||||
if (this.throwableShake > 0)
|
||||
{
|
||||
--this.throwableShake;
|
||||
}
|
||||
|
||||
if (this.inGround)
|
||||
{
|
||||
if (this.worldObj.getBlock(this.field_145788_c, this.field_145786_d, this.field_145787_e) == this.field_145785_f)
|
||||
{
|
||||
++this.ticksInGround;
|
||||
|
||||
if (this.ticksInGround == 1200)
|
||||
{
|
||||
this.setDead();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
++this.ticksInAir;
|
||||
}
|
||||
|
||||
Vec3 vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
||||
Vec3 vec31 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
||||
MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
|
||||
vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
||||
vec31 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
||||
|
||||
if (movingobjectposition != null)
|
||||
{
|
||||
vec31 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
|
||||
}
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
Entity entity = null;
|
||||
List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
|
||||
double d0 = 0.0D;
|
||||
EntityLivingBase entitylivingbase = this.getThrower();
|
||||
|
||||
for (int j = 0; j < list.size(); ++j)
|
||||
{
|
||||
Entity entity1 = (Entity)list.get(j);
|
||||
|
||||
if (entity1.canBeCollidedWith() && (entity1 != entitylivingbase || this.ticksInAir >= 5))
|
||||
{
|
||||
float f = 0.3F;
|
||||
AxisAlignedBB axisalignedbb = entity1.boundingBox.expand((double)f, (double)f, (double)f);
|
||||
MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);
|
||||
|
||||
if (movingobjectposition1 != null)
|
||||
{
|
||||
double d1 = vec3.distanceTo(movingobjectposition1.hitVec);
|
||||
|
||||
if (d1 < d0 || d0 == 0.0D)
|
||||
{
|
||||
entity = entity1;
|
||||
d0 = d1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
movingobjectposition = new MovingObjectPosition(entity);
|
||||
}
|
||||
}
|
||||
|
||||
if (movingobjectposition != null)
|
||||
{
|
||||
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.worldObj.getBlock(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ) == Blocks.portal)
|
||||
{
|
||||
this.setInPortal();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.onImpact(movingobjectposition);
|
||||
}
|
||||
}
|
||||
|
||||
this.posX += this.motionX;
|
||||
this.posY += this.motionY;
|
||||
this.posZ += this.motionZ;
|
||||
float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
||||
this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
|
||||
|
||||
for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f1) * 180.0D / Math.PI); 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;
|
||||
float f2 = 0.99F;
|
||||
float f3 = this.getGravityVelocity();
|
||||
|
||||
if (this.isInWater())
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
f2 = 0.8F;
|
||||
}
|
||||
|
||||
this.motionX *= (double)f2;
|
||||
this.motionY *= (double)f2;
|
||||
this.motionZ *= (double)f2;
|
||||
this.motionY -= (double)f3;
|
||||
this.setPosition(this.posX, this.posY, this.posZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of gravity to apply to the thrown entity with each tick.
|
||||
*/
|
||||
protected float getGravityVelocity()
|
||||
{
|
||||
return 0.03F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this EntityThrowable hits a block or entity.
|
||||
*/
|
||||
protected abstract void onImpact(MovingObjectPosition p_70184_1_);
|
||||
|
||||
/**
|
||||
* (abstract) Protected helper method to write subclass entity data to NBT.
|
||||
*/
|
||||
public void writeEntityToNBT(NBTTagCompound p_70014_1_)
|
||||
{
|
||||
p_70014_1_.setShort("xTile", (short)this.field_145788_c);
|
||||
p_70014_1_.setShort("yTile", (short)this.field_145786_d);
|
||||
p_70014_1_.setShort("zTile", (short)this.field_145787_e);
|
||||
p_70014_1_.setByte("inTile", (byte)Block.getIdFromBlock(this.field_145785_f));
|
||||
p_70014_1_.setByte("shake", (byte)this.throwableShake);
|
||||
p_70014_1_.setByte("inGround", (byte)(this.inGround ? 1 : 0));
|
||||
|
||||
if ((this.throwerName == null || this.throwerName.length() == 0) && this.thrower != null && this.thrower instanceof EntityPlayer)
|
||||
{
|
||||
this.throwerName = this.thrower.getCommandSenderName();
|
||||
}
|
||||
|
||||
p_70014_1_.setString("ownerName", this.throwerName == null ? "" : this.throwerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* (abstract) Protected helper method to read subclass entity data from NBT.
|
||||
*/
|
||||
public void readEntityFromNBT(NBTTagCompound p_70037_1_)
|
||||
{
|
||||
this.field_145788_c = p_70037_1_.getShort("xTile");
|
||||
this.field_145786_d = p_70037_1_.getShort("yTile");
|
||||
this.field_145787_e = p_70037_1_.getShort("zTile");
|
||||
this.field_145785_f = Block.getBlockById(p_70037_1_.getByte("inTile") & 255);
|
||||
this.throwableShake = p_70037_1_.getByte("shake") & 255;
|
||||
this.inGround = p_70037_1_.getByte("inGround") == 1;
|
||||
this.throwerName = p_70037_1_.getString("ownerName");
|
||||
|
||||
if (this.throwerName != null && this.throwerName.length() == 0)
|
||||
{
|
||||
this.throwerName = null;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getShadowSize()
|
||||
{
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
public EntityLivingBase getThrower()
|
||||
{
|
||||
if (this.thrower == null && this.throwerName != null && this.throwerName.length() > 0)
|
||||
{
|
||||
this.thrower = this.worldObj.getPlayerEntityByName(this.throwerName);
|
||||
}
|
||||
|
||||
return this.thrower;
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ public final class ModEntities {
|
||||
EntityRegistry.registerModEntity(EntityPinkWither.class, LibEntityNames.PINK_WITHER, id++, Botania.instance, 80, 3, false);
|
||||
EntityRegistry.registerModEntity(EntityPlayerMover.class, LibEntityNames.PLAYER_MOVER, id++, Botania.instance, 40, 3, true);
|
||||
EntityRegistry.registerModEntity(EntityManaStorm.class, LibEntityNames.MANA_STORM, id++, Botania.instance, 64, 10, false);
|
||||
EntityRegistry.registerModEntity(EntityBabylonWeapon.class, LibEntityNames.BABYLON_WEAPON, id++, Botania.instance, 64, 10, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,14 +10,94 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.relic;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.core.helper.Vector3;
|
||||
import vazkii.botania.common.entity.EntityBabylonWeapon;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
public class ItemKingKey extends ItemRelic {
|
||||
|
||||
private static final String TAG_WEAPONS_SPAWNED = "weaponsSpawned";
|
||||
private static final String TAG_CHARGING = "charging";
|
||||
|
||||
public ItemKingKey() {
|
||||
super(LibItemNames.KING_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
|
||||
par3EntityPlayer.setItemInUse(par1ItemStack, getMaxItemUseDuration(par1ItemStack));
|
||||
setCharging(par1ItemStack, true);
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int time) {
|
||||
setCharging(stack, false);
|
||||
setWeaponsSpawned(stack, 0); // TODO probably move this to a ticker
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUsingTick(ItemStack stack, EntityPlayer player, int count) {
|
||||
int spawned = getWeaponsSpawned(stack);
|
||||
if(count != getMaxItemUseDuration(stack) && spawned < 20 && !player.worldObj.isRemote) {
|
||||
Vector3 look = new Vector3(player.getLookVec());
|
||||
look.y = 0;
|
||||
look.normalize().negate().multiply(2);
|
||||
Vector3 pl = look.copy().add(Vector3.fromEntityCenter(player));
|
||||
|
||||
Random rand = player.worldObj.rand;
|
||||
Vector3 axis = pl.copy().crossProduct(new Vector3(-1, 0, -1)).normalize();
|
||||
Vector3 axis1 = axis.copy();
|
||||
axis1.multiply(rand.nextDouble() * 22 + 3).rotate((rand.nextDouble() - 0.5) * Math.PI / 2.0, look);
|
||||
Vector3 end = pl.copy().add(axis1);
|
||||
|
||||
EntityBabylonWeapon weapon = new EntityBabylonWeapon(player.worldObj, player);
|
||||
weapon.posX = end.x;
|
||||
weapon.posY = end.y;
|
||||
weapon.posZ = end.z;
|
||||
weapon.setVariety(rand.nextInt(12));
|
||||
weapon.setDelay(spawned);
|
||||
|
||||
player.worldObj.spawnEntityInWorld(weapon);
|
||||
setWeaponsSpawned(stack, spawned + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAction getItemUseAction(ItemStack par1ItemStack) {
|
||||
return EnumAction.bow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration(ItemStack par1ItemStack) {
|
||||
return 72000;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isCharging(ItemStack stack) {
|
||||
return ItemNBTHelper.getBoolean(stack, TAG_CHARGING, false);
|
||||
}
|
||||
|
||||
public static int getWeaponsSpawned(ItemStack stack) {
|
||||
return ItemNBTHelper.getInt(stack, TAG_WEAPONS_SPAWNED, 0);
|
||||
}
|
||||
|
||||
public static void setCharging(ItemStack stack, boolean charging) {
|
||||
ItemNBTHelper.setBoolean(stack, TAG_CHARGING, charging);
|
||||
}
|
||||
|
||||
public static void setWeaponsSpawned(ItemStack stack, int count) {
|
||||
ItemNBTHelper.setInt(stack, TAG_WEAPONS_SPAWNED, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull3D() {
|
||||
return true;
|
||||
|
||||
@@ -31,5 +31,6 @@ public final class LibEntityNames {
|
||||
public static final String PINK_WITHER = LibResources.PREFIX_MOD + "pinkWither";
|
||||
public static final String PLAYER_MOVER = LibResources.PREFIX_MOD + "playerMover";
|
||||
public static final String MANA_STORM = LibResources.PREFIX_MOD + "manaStorm";
|
||||
public static final String BABYLON_WEAPON = LibResources.PREFIX_MOD + "babylonWeapon";
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user