-
Notifications
You must be signed in to change notification settings - Fork 497
/
EntityMechanicalArm.java
154 lines (132 loc) · 3.91 KB
/
EntityMechanicalArm.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.factory;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import buildcraft.core.EntityBlock;
public class EntityMechanicalArm extends Entity {
EntityBlock xArm, yArm, zArm, head;
boolean inProgressionXZ = false;
boolean inProgressionY = false;
protected TileQuarry parent;
private double armSizeX;
private double armSizeZ;
private double xRoot;
private double yRoot;
private double zRoot;
private int headX, headY, headZ;
public EntityMechanicalArm(World world) {
super(world);
makeParts(world);
noClip = true;
}
public EntityMechanicalArm(World world, double x, double y, double z, double width, double height, TileQuarry parent) {
this(world);
setPositionAndRotation(parent.xCoord, parent.yCoord, parent.zCoord, 0, 0);
this.xRoot = x;
this.yRoot = y;
this.zRoot = z;
this.motionX = 0.0;
this.motionY = 0.0;
this.motionZ = 0.0;
setArmSize(width, height);
setHead(x, y - 2, z);
this.parent = parent;
parent.setArm(this);
updatePosition();
}
void setHead(double x, double y, double z) {
this.headX = (int) (x * 32D);
this.headY = (int) (y * 32D);
this.headZ = (int) (z * 32D);
}
private void setArmSize(double x, double z) {
armSizeX = x;
xArm.iSize = x;
armSizeZ = z;
zArm.kSize = z;
updatePosition();
}
private void makeParts(World world) {
xArm = FactoryProxy.proxy.newDrill(world, 0, 0, 0, 1, 0.5, 0.5);
yArm = FactoryProxy.proxy.newDrill(world, 0, 0, 0, 0.5, 1, 0.5);
zArm = FactoryProxy.proxy.newDrill(world, 0, 0, 0, 0.5, 0.5, 1);
head = FactoryProxy.proxy.newDrillHead(world, 0, 0, 0, 0.2, 1, 0.2);
head.shadowSize = 1.0F;
world.spawnEntityInWorld(xArm);
world.spawnEntityInWorld(yArm);
world.spawnEntityInWorld(zArm);
world.spawnEntityInWorld(head);
}
@Override
protected void entityInit() {
}
@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
xRoot = nbttagcompound.getDouble("xRoot");
yRoot = nbttagcompound.getDouble("yRoot");
zRoot = nbttagcompound.getDouble("zRoot");
armSizeX = nbttagcompound.getDouble("armSizeX");
armSizeZ = nbttagcompound.getDouble("armSizeZ");
setArmSize(armSizeX, armSizeZ);
updatePosition();
}
private void findAndJoinQuarry() {
TileEntity te = worldObj.getTileEntity((int) posX, (int) posY, (int) posZ);
if (te != null && te instanceof TileQuarry) {
parent = (TileQuarry) te;
parent.setArm(this);
} else {
setDead();
}
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setDouble("xRoot", xRoot);
nbttagcompound.setDouble("yRoot", yRoot);
nbttagcompound.setDouble("zRoot", zRoot);
nbttagcompound.setDouble("armSizeX", armSizeX);
nbttagcompound.setDouble("armSizeZ", armSizeZ);
}
@Override
public void onUpdate() {
super.onUpdate();
updatePosition();
if (parent == null) {
findAndJoinQuarry();
}
if (parent == null) {
setDead();
return;
}
}
public void updatePosition() {
double[] head = getHead();
this.xArm.setPosition(xRoot, yRoot, head[2] + 0.25);
this.yArm.jSize = yRoot - head[1] - 1;
this.yArm.setPosition(head[0] + 0.25, head[1] + 1, head[2] + 0.25);
this.zArm.setPosition(head[0] + 0.25, yRoot, zRoot);
this.head.setPosition(head[0] + 0.4, head[1], head[2] + 0.4);
}
@Override
public void setDead() {
if (worldObj != null && worldObj.isRemote) {
xArm.setDead();
yArm.setDead();
zArm.setDead();
head.setDead();
}
super.setDead();
}
private double[] getHead() {
return new double[] { this.headX / 32D, this.headY / 32D, this.headZ / 32D };
}
}