-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockQuarry.java
214 lines (177 loc) · 6.21 KB
/
BlockQuarry.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
* 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 buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory;
import buildcraft.api.core.Position;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.Box;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockQuarry extends BlockBuildCraft {
IIcon textureTop;
IIcon textureFront;
IIcon textureSide;
public BlockQuarry() {
super(Material.iron);
setHardness(10F);
setResistance(10F);
// TODO: set proper sound
//setStepSound(soundAnvilFootstep);
}
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack stack) {
super.onBlockPlacedBy(world, i, j, k, entityliving, stack);
if (entityliving instanceof EntityPlayer){
EntityPlayer p=(EntityPlayer) entityliving;
p.addStat(BuildCraftCore.chunkDestroyerAchievement, 1);
}
ForgeDirection orientation = Utils.get2dOrientation(entityliving);
world.setBlockMetadataWithNotify(i, j, k, orientation.getOpposite().ordinal(), 1);
if (entityliving instanceof EntityPlayer) {
TileQuarry tq = (TileQuarry) world.getTileEntity(i, j, k);
tq.placedBy = (EntityPlayer) entityliving;
}
}
@Override
public IIcon getIcon(int i, int j) {
// If no metadata is set, then this is an icon.
if (j == 0 && i == 3)
return textureFront;
if (i == j && i > 1) // Front can't be top or bottom.
return textureFront;
switch (i) {
case 1:
return textureTop;
default:
return textureSide;
}
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileQuarry();
}
public void searchFrames(World world, int i, int j, int k) {
int width2 = 1;
if (!world.checkChunksExist(i - width2, j - width2, k - width2, i + width2, j + width2, k + width2))
return;
Block block = world.getBlock(i, j, k);
if (block != BuildCraftFactory.frameBlock)
return;
int meta = world.getBlockMetadata(i, j, k);
if ((meta & 8) == 0) {
world.setBlockMetadataWithNotify(i, j, k, meta | 8, 0);
ForgeDirection[] dirs = ForgeDirection.VALID_DIRECTIONS;
for (ForgeDirection dir : dirs) {
switch (dir) {
case UP:
searchFrames(world, i, j + 1, k);
case DOWN:
searchFrames(world, i, j - 1, k);
case SOUTH:
searchFrames(world, i, j, k + 1);
case NORTH:
searchFrames(world, i, j, k - 1);
case EAST:
searchFrames(world, i + 1, j, k);
case WEST:
default:
searchFrames(world, i - 1, j, k);
}
}
}
}
private void markFrameForDecay(World world, int x, int y, int z) {
if (world.getBlock(x, y, z) == BuildCraftFactory.frameBlock) {
world.setBlockMetadataWithNotify(x, y, z, 1, 0);
}
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
if (BuildCraftFactory.quarryOneTimeUse) {
return new ArrayList<ItemStack>();
}
return super.getDrops(world, x, y, z, metadata, fortune);
}
@Override
public void breakBlock(World world, int i, int j, int k, Block block, int par6) {
if (world.isRemote) {
return;
}
TileEntity tile = world.getTileEntity(i, j, k);
if (tile instanceof TileQuarry) {
TileQuarry quarry = (TileQuarry) tile;
Box box = quarry.box;
if (box.isInitialized() && Integer.MAX_VALUE != box.xMax) {
// X - Axis
for (int x = box.xMin; x <= box.xMax; x++) {
markFrameForDecay(world, x, box.yMin, box.zMin);
markFrameForDecay(world, x, box.yMax, box.zMin);
markFrameForDecay(world, x, box.yMin, box.zMax);
markFrameForDecay(world, x, box.yMax, box.zMax);
}
// Z - Axis
for (int z = box.zMin + 1; z <= box.zMax - 1; z++) {
markFrameForDecay(world, box.xMin, box.yMin, z);
markFrameForDecay(world, box.xMax, box.yMin, z);
markFrameForDecay(world, box.xMin, box.yMax, z);
markFrameForDecay(world, box.xMax, box.yMax, z);
}
// Y - Axis
for (int y = box.yMin + 1; y <= box.yMax - 1; y++) {
markFrameForDecay(world, box.xMin, y, box.zMin);
markFrameForDecay(world, box.xMax, y, box.zMin);
markFrameForDecay(world, box.xMin, y, box.zMax);
markFrameForDecay(world, box.xMax, y, box.zMax);
}
}
quarry.destroy();
}
Utils.preDestroyBlock(world, i, j, k);
super.breakBlock(world, i, j, k, block, par6);
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
TileQuarry tile = (TileQuarry) world.getTileEntity(i, j, k);
// Drop through if the player is sneaking
if (entityplayer.isSneaking())
return false;
// Restart the quarry if its a wrench
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, i, j, k)) {
tile.reinitalize();
((IToolWrench) equipped).wrenchUsed(entityplayer, i, j, k);
return true;
}
return false;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister) {
textureSide = par1IconRegister.registerIcon("buildcraft:quarry_side");
textureTop = par1IconRegister.registerIcon("buildcraft:quarry_top");
textureFront = par1IconRegister.registerIcon("buildcraft:quarry_front");
}
}