aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/EnchantmentTableEntity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Minecraft.World/EnchantmentTableEntity.cpp')
-rw-r--r--Minecraft.World/EnchantmentTableEntity.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/Minecraft.World/EnchantmentTableEntity.cpp b/Minecraft.World/EnchantmentTableEntity.cpp
new file mode 100644
index 00000000..31da3c49
--- /dev/null
+++ b/Minecraft.World/EnchantmentTableEntity.cpp
@@ -0,0 +1,109 @@
+#include "stdafx.h"
+#include "EnchantmentTableEntity.h"
+#include "net.minecraft.world.entity.player.h"
+#include "net.minecraft.world.level.h"
+
+
+
+EnchantmentTableEntity::EnchantmentTableEntity()
+{
+ random = new Random();
+
+ time = 0;
+ flip = 0.0f;
+ oFlip = 0.0f;
+ flipT = 0.0f;
+ flipA = 0.0f;
+ open = 0.0f;
+ oOpen = 0.0f;
+ rot = 0.0f;
+ oRot = 0.0f;
+ tRot = 0.0f;
+}
+
+EnchantmentTableEntity::~EnchantmentTableEntity()
+{
+ delete random;
+}
+
+void EnchantmentTableEntity::tick()
+{
+ TileEntity::tick();
+ oOpen = open;
+ oRot = rot;
+
+ shared_ptr<Player> player = level->getNearestPlayer(x + 0.5f, y + 0.5f, z + 0.5f, 3);
+ if (player != NULL)
+ {
+ double xd = player->x - (x + 0.5f);
+ double zd = player->z - (z + 0.5f);
+
+ tRot = (float) atan2(zd, xd);
+
+ open += 0.1f;
+
+ if (open < 0.5f || random->nextInt(40) == 0)
+ {
+ float old = flipT;
+ do
+ {
+ flipT += random->nextInt(4) - random->nextInt(4);
+ } while (old == flipT);
+ }
+
+ }
+ else
+ {
+ tRot += 0.02f;
+ open -= 0.1f;
+ }
+
+ while (rot >= PI)
+ rot -= PI * 2;
+ while (rot < -PI)
+ rot += PI * 2;
+ while (tRot >= PI)
+ tRot -= PI * 2;
+ while (tRot < -PI)
+ tRot += PI * 2;
+ float rotDir = tRot - rot;
+ while (rotDir >= PI)
+ rotDir -= PI * 2;
+ while (rotDir < -PI)
+ rotDir += PI * 2;
+
+ rot += rotDir * 0.4f;
+
+ if (open < 0) open = 0;
+ if (open > 1) open = 1;
+
+ time++;
+ oFlip = flip;
+
+ float diff = (flipT - flip) * 0.4f;
+ float max = 0.2f;
+ if (diff < -max) diff = -max;
+ if (diff > +max) diff = +max;
+ flipA += (diff - flipA) * 0.9f;
+
+ flip = flip + flipA;
+}
+
+shared_ptr<TileEntity> EnchantmentTableEntity::clone()
+{
+ shared_ptr<EnchantmentTableEntity> result = shared_ptr<EnchantmentTableEntity>( new EnchantmentTableEntity() );
+ TileEntity::clone(result);
+
+ result->time = time;
+ result->flip = flip;
+ result->oFlip = oFlip;
+ result->flipT = flipT;
+ result->flipA = flipA;
+ result->open = open;
+ result->oOpen = oOpen;
+ result->rot = rot;
+ result->oRot = oRot;
+ result->tRot = tRot;
+
+ return result;
+} \ No newline at end of file