-
Notifications
You must be signed in to change notification settings - Fork 497
/
FillerPattern.java
128 lines (109 loc) · 3.32 KB
/
FillerPattern.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
/**
* Copyright (c) SpaceToad, 2011
* 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.builders;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.core.IBox;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BlockUtil;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class FillerPattern implements IFillerPattern {
protected int id;
/**
* stackToPlace contains the next item that can be place in the world. Null if there is none. IteratePattern is responsible to decrementing the stack size
* if needed. Return true when the iteration process is finished.
*/
@Override
public abstract boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace);
@SideOnly(Side.CLIENT)
@Override
public abstract Icon getTexture();
@Override
public void setId(int id) {
this.id = id;
}
@Override
public int getId() {
return this.id;
}
/**
* Attempt to fill blocks in the area.
*
* Return false if the process failed.
*
*/
public boolean fill(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, ItemStack stackToPlace, World world) {
boolean found = false;
int xSlot = 0, ySlot = 0, zSlot = 0;
for (int y = yMin; y <= yMax && !found; ++y) {
for (int x = xMin; x <= xMax && !found; ++x) {
for (int z = zMin; z <= zMax && !found; ++z) {
if (!BlockUtil.canChangeBlock(world, x, y, z))
return false;
if (BlockUtil.isSoftBlock(world, x, y, z)) {
xSlot = x;
ySlot = y;
zSlot = z;
found = true;
}
}
}
}
if (found && stackToPlace != null) {
BlockUtil.breakBlock(world, xSlot, ySlot, zSlot);
stackToPlace.getItem().onItemUse(stackToPlace, CoreProxy.proxy.getBuildCraftPlayer(world), world, xSlot, ySlot - 1, zSlot, 1, 0.0f, 0.0f, 0.0f);
}
return found;
}
/**
* Attempt to remove the blocks in the area.
*
* Return false if is the process failed.
*
*/
public boolean empty(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, World world) {
boolean found = false;
int lastX = Integer.MAX_VALUE, lastY = Integer.MAX_VALUE, lastZ = Integer.MAX_VALUE;
for (int y = yMax; y >= yMin; y--) {
found = false;
for (int x = xMin; x <= xMax; ++x) {
for (int z = zMin; z <= zMax; ++z) {
if (!BlockUtil.canChangeBlock(world, x, y, z))
return false;
if (!BlockUtil.isSoftBlock(world, x, y, z)) {
found = true;
lastX = x;
lastY = y;
lastZ = z;
}
}
}
if (found) {
break;
}
}
if (lastX != Integer.MAX_VALUE) {
if (BuildCraftBuilders.fillerDestroy) {
world.setBlock(lastX, lastY, lastZ, 0);
} else {
if(BlockUtil.isToughBlock(world, lastX, lastY, lastZ))
BlockUtil.breakBlock(world, lastX, lastY, lastZ, BuildCraftBuilders.fillerLifespanTough);
else
BlockUtil.breakBlock(world, lastX, lastY, lastZ, BuildCraftBuilders.fillerLifespanNormal);
}
return true;
}
return false;
}
}