168 lines
4.7 KiB
Java
Executable file
168 lines
4.7 KiB
Java
Executable file
package game.tileentity;
|
|
|
|
import game.entity.npc.EntityNPC;
|
|
import game.inventory.Container;
|
|
import game.inventory.ContainerEnchantment;
|
|
import game.inventory.InventoryPlayer;
|
|
import game.nbt.NBTTagCompound;
|
|
import game.rng.Random;
|
|
import game.util.ExtMath;
|
|
|
|
public class TileEntityEnchantmentTable extends TileEntity implements ITickable, IInteractionObject
|
|
{
|
|
public int tickCount;
|
|
public float pageFlip;
|
|
public float pageFlipPrev;
|
|
public float field_145932_k;
|
|
public float field_145929_l;
|
|
public float bookSpread;
|
|
public float bookSpreadPrev;
|
|
public float bookRotation;
|
|
public float bookRotationPrev;
|
|
public float field_145924_q;
|
|
private static Random rand = new Random();
|
|
private String customName;
|
|
|
|
public void writeToNBT(NBTTagCompound compound)
|
|
{
|
|
super.writeToNBT(compound);
|
|
|
|
if (this.hasCustomName())
|
|
{
|
|
compound.setString("CustomName", this.customName);
|
|
}
|
|
}
|
|
|
|
public void readFromNBT(NBTTagCompound compound)
|
|
{
|
|
super.readFromNBT(compound);
|
|
|
|
if (compound.hasKey("CustomName", 8))
|
|
{
|
|
this.customName = compound.getString("CustomName");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Like the old updateEntity(), except more generic.
|
|
*/
|
|
public void update()
|
|
{
|
|
this.bookSpreadPrev = this.bookSpread;
|
|
this.bookRotationPrev = this.bookRotation;
|
|
EntityNPC entityplayer = this.worldObj.getClosestPlayer((double)((float)this.pos.getX() + 0.5F), (double)((float)this.pos.getY() + 0.5F), (double)((float)this.pos.getZ() + 0.5F), 3.0D);
|
|
|
|
if (entityplayer != null)
|
|
{
|
|
double d0 = entityplayer.posX - (double)((float)this.pos.getX() + 0.5F);
|
|
double d1 = entityplayer.posZ - (double)((float)this.pos.getZ() + 0.5F);
|
|
this.field_145924_q = (float)ExtMath.atan2(d1, d0);
|
|
this.bookSpread += 0.1F;
|
|
|
|
if (this.bookSpread < 0.5F || rand.zrange(40) == 0)
|
|
{
|
|
float f1 = this.field_145932_k;
|
|
|
|
while (true)
|
|
{
|
|
this.field_145932_k += (float)(rand.zrange(4) - rand.zrange(4));
|
|
|
|
if (f1 != this.field_145932_k)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.field_145924_q += 0.02F;
|
|
this.bookSpread -= 0.1F;
|
|
}
|
|
|
|
while (this.bookRotation >= (float)Math.PI)
|
|
{
|
|
this.bookRotation -= ((float)Math.PI * 2F);
|
|
}
|
|
|
|
while (this.bookRotation < -(float)Math.PI)
|
|
{
|
|
this.bookRotation += ((float)Math.PI * 2F);
|
|
}
|
|
|
|
while (this.field_145924_q >= (float)Math.PI)
|
|
{
|
|
this.field_145924_q -= ((float)Math.PI * 2F);
|
|
}
|
|
|
|
while (this.field_145924_q < -(float)Math.PI)
|
|
{
|
|
this.field_145924_q += ((float)Math.PI * 2F);
|
|
}
|
|
|
|
float f2;
|
|
|
|
for (f2 = this.field_145924_q - this.bookRotation; f2 >= (float)Math.PI; f2 -= ((float)Math.PI * 2F))
|
|
{
|
|
;
|
|
}
|
|
|
|
while (f2 < -(float)Math.PI)
|
|
{
|
|
f2 += ((float)Math.PI * 2F);
|
|
}
|
|
|
|
this.bookRotation += f2 * 0.4F;
|
|
this.bookSpread = ExtMath.clampf(this.bookSpread, 0.0F, 1.0F);
|
|
++this.tickCount;
|
|
this.pageFlipPrev = this.pageFlip;
|
|
float f = (this.field_145932_k - this.pageFlip) * 0.4F;
|
|
float f3 = 0.2F;
|
|
f = ExtMath.clampf(f, -f3, f3);
|
|
this.field_145929_l += (f - this.field_145929_l) * 0.9F;
|
|
this.pageFlip += this.field_145929_l;
|
|
}
|
|
|
|
/**
|
|
* Get the name of this object. For players this returns their username
|
|
*/
|
|
public String getName()
|
|
{
|
|
return this.hasCustomName() ? this.customName : "Verzaubern";
|
|
}
|
|
|
|
/**
|
|
* Returns true if this thing is named
|
|
*/
|
|
public boolean hasCustomName()
|
|
{
|
|
return this.customName != null && this.customName.length() > 0;
|
|
}
|
|
|
|
public void setCustomName(String customNameIn)
|
|
{
|
|
this.customName = customNameIn;
|
|
}
|
|
|
|
/**
|
|
* Get the formatted ChatComponent that will be used for the sender's username in chat
|
|
*/
|
|
public String getCommandName()
|
|
{
|
|
return this.getName(); // (TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName()));
|
|
}
|
|
|
|
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
|
|
{
|
|
return new ContainerEnchantment(playerInventory, this.worldObj, this.pos);
|
|
}
|
|
|
|
public String getGuiID()
|
|
{
|
|
return "enchanting_table";
|
|
}
|
|
|
|
public int getColor() {
|
|
return 0xbf00ff;
|
|
}
|
|
}
|