-
Notifications
You must be signed in to change notification settings - Fork 497
/
TileBuffer.java
107 lines (82 loc) · 2.93 KB
/
TileBuffer.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
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
* <p/>
* 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.lib;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import buildcraft.api.core.SafeTimeTracker;
public final class TileBuffer {
private IBlockState state = null;
private TileEntity tile;
private final SafeTimeTracker tracker = new SafeTimeTracker(20, 5);
private final World world;
private final BlockPos pos;
private final boolean loadUnloaded;
public TileBuffer(World world, BlockPos pos, boolean loadUnloaded) {
if (world == null) throw new NullPointerException("world");
this.world = world;
this.pos = pos;
this.loadUnloaded = loadUnloaded;
refresh();
}
public void refresh() {
tile = null;
state = null;
// if (!loadUnloaded && world.isAirBlock(pos)) {
// return;
// }
state = world.getBlockState(pos);
// if (state != null && state.getBlock().hasTileEntity(state)) {
tile = world.getTileEntity(pos);
// }
}
public void set(IBlockState state, TileEntity tile) {
this.state = state;
this.tile = tile;
tracker.markTime(world);
}
private void tryRefresh() {
// if (Utils.CAULDRON_DETECTED || (tile != null && tile.isInvalid()) || (tile == null &&
// tracker.markTimeIfDelay(world))) {
refresh();
// }
}
public IBlockState getBlockState() {
tryRefresh();
return state;
}
public TileEntity getTile() {
return getTile(false);
}
// This is severely broken :( FIXME
public TileEntity getTile(boolean forceUpdate) {
// if (!Utils.CAULDRON_DETECTED && tile != null && !tile.isInvalid()) {
// return tile;
// }
// if (Utils.CAULDRON_DETECTED || (forceUpdate && tile != null && tile.isInvalid()) ||
// tracker.markTimeIfDelay(world)) {
refresh();
// if (tile != null && !tile.isInvalid()) {
return tile;
// }
// }
// return null;
}
public boolean exists() {
// if (tile != null && !Utils.CAULDRON_DETECTED && !tile.isInvalid()) {
// return true;
// }
return !world.isAirBlock(pos);
}
public static TileBuffer[] makeBuffer(World world, BlockPos pos, boolean loadUnloaded) {
TileBuffer[] buffer = new TileBuffer[6];
for (EnumFacing face : EnumFacing.VALUES) {
buffer[face.ordinal()] = new TileBuffer(world, pos.offset(face), loadUnloaded);
}
return buffer;
}
}