-
Notifications
You must be signed in to change notification settings - Fork 497
/
EntityRobotBuilder.java
178 lines (142 loc) · 3.9 KB
/
EntityRobotBuilder.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* 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.core.robots;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import buildcraft.builders.blueprints.IBlueprintBuilderAgent;
import buildcraft.builders.urbanism.TaskBuildSchematic;
import buildcraft.core.DefaultProps;
import buildcraft.core.proxy.CoreProxy;
public class EntityRobotBuilder extends EntityRobot implements
IEntityAdditionalSpawnData, IBlueprintBuilderAgent, IInventory {
private static ResourceLocation texture = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_builder.png");
ItemStack buildingStack = null;
float curBlockDamage = 0;
float buildEnergy = 0;
public EntityRobotBuilder(World par1World) {
super (par1World);
}
/**
* Operate a block break. Return true is the block has indeed been broken.
*/
@Override
public boolean breakBlock (int x, int y, int z) {
Block block = worldObj.getBlock(x, y, z);
if (block != null) {
curBlockDamage += 1 / (block.getBlockHardness(worldObj, x, y, z) * 20);
}
if (block != null && curBlockDamage < 1) {
worldObj.destroyBlockInWorldPartially(getEntityId(), x, y, z,
(int) (this.curBlockDamage * 10.0F) - 1);
setLaserDestination(x + 0.5F, y + 0.5F, z + 0.5F);
showLaser();
return false;
} else {
worldObj.destroyBlockInWorldPartially(getEntityId(), x, y, z, -1);
worldObj.setBlock(x, y, z, Blocks.air);
curBlockDamage = 0;
hideLaser();
return true;
}
}
@Override
public boolean buildBlock(int x, int y, int z) {
if (buildingStack == null) {
if (worldObj.getBlock(x, y, z) != Blocks.air) {
breakBlock(x, y, z);
} else {
setLaserDestination(x + 0.5F, y + 0.5F, z + 0.5F);
showLaser();
buildingStack = getInventory().decrStackSize(0, 1);
buildEnergy = 0;
}
return false;
} else {
buildEnergy++;
if (buildEnergy >= 25) {
buildingStack.getItem().onItemUse(buildingStack,
CoreProxy.proxy.getBuildCraftPlayer(worldObj),
worldObj, x, y - 1, z, 1, 0.0f, 0.0f, 0.0f);
buildingStack = null;
hideLaser();
return true;
} else {
return false;
}
}
}
@Override
public IInventory getInventory() {
return this;
}
@Override
public int getSizeInventory() {
return 1;
}
@Override
public ItemStack getStackInSlot(int i) {
// Fake inventory filled with bricks
return new ItemStack(Blocks.brick_block);
}
@Override
public ItemStack decrStackSize(int i, int j) {
// Fake inventory filled with bricks
return new ItemStack(Blocks.brick_block);
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
}
@Override
public int getInventoryStackLimit() {
return 0;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return false;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return false;
}
@Override
public String getInventoryName() {
return null;
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public void markDirty() {
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
@Override
public boolean acceptTask (IRobotTask task) {
return task instanceof TaskBuildSchematic;
}
@Override
public ResourceLocation getTexture () {
return texture;
}
}