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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
From afec56d0a9ee4f0509c68ecc46de52311b33e519 Mon Sep 17 00:00:00 2001
From: "Evan A. Haskell" <eah2119@gmail.com>
Date: Sat, 19 Apr 2014 16:58:26 -0400
Subject: [PATCH] Alternative Hopper Ticking
diff --git a/src/main/java/net/minecraft/server/BlockHopper.java b/src/main/java/net/minecraft/server/BlockHopper.java
index b85b72f..b33ed64 100644
--- a/src/main/java/net/minecraft/server/BlockHopper.java
+++ b/src/main/java/net/minecraft/server/BlockHopper.java
@@ -87,6 +87,17 @@ public class BlockHopper extends BlockContainer {
if (flag != flag1) {
world.setData(i, j, k, i1 | (flag ? 0 : 8), 4);
+ // Spigot start - When this hopper becomes unpowered, make it active.
+ // Called when this block's power level changes. flag1 is the current
+ // isNotPowered from metadata. flag is the recalculated isNotPowered.
+ if (world.spigotConfig.altHopperTicking) {
+ // e returns the TileEntityHopper associated with this BlockHopper.
+ TileEntityHopper hopper = e((IBlockAccess) world, i, j, k);
+ if (flag && hopper != null) {
+ hopper.makeTick();
+ }
+ }
+ // Spigot end
}
}
@@ -163,4 +174,17 @@ public class BlockHopper extends BlockContainer {
public static TileEntityHopper e(IBlockAccess iblockaccess, int i, int j, int k) {
return (TileEntityHopper) iblockaccess.getTileEntity(i, j, k);
}
+
+ // Spigot start - Use random block updates to make hoppers active.
+ @Override
+ public void a(World world, int i, int j, int k, Random random) {
+ if (world.spigotConfig.altHopperTicking) {
+ // e returns the TileEntityHopper associated with this BlockHopper.
+ TileEntityHopper hopper = e((IBlockAccess) world, i, j, k);
+ if (hopper != null) {
+ hopper.makeTick();
+ }
+ }
+ }
+ // Spigot end
}
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 5641ad7..406aead 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -750,6 +750,11 @@ public class Chunk {
tileentity.t();
this.tileEntities.put(chunkposition, tileentity);
+ // Spigot start - The tile entity has a world, now hoppers can be born ticking.
+ if (this.world.spigotConfig.altHopperTicking) {
+ this.world.triggerHoppersList.add(tileentity);
+ }
+ // Spigot end
// CraftBukkit start
} else {
System.out.println("Attempted to place a tile entity (" + tileentity + ") at " + tileentity.x + "," + tileentity.y + "," + tileentity.z
diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java
index 98a4ac7..a61e91a 100644
--- a/src/main/java/net/minecraft/server/EntityItem.java
+++ b/src/main/java/net/minecraft/server/EntityItem.java
@@ -102,6 +102,27 @@ public class EntityItem extends Entity {
if (this.onGround) {
this.motY *= -0.5D;
}
+ // Spigot start - Make the hopper(s) below this item active.
+ // Called each tick on each item entity.
+ if (this.world.spigotConfig.altHopperTicking) {
+ int xi = MathHelper.floor(this.boundingBox.a);
+ int yi = MathHelper.floor(this.boundingBox.b) - 1;
+ int zi = MathHelper.floor(this.boundingBox.c);
+ int xf = MathHelper.floor(this.boundingBox.d);
+ int yf = MathHelper.floor(this.boundingBox.e) - 1;
+ int zf = MathHelper.floor(this.boundingBox.f);
+ for (int a = xi; a <= xf; a++) {
+ for (int c = zi; c <= zf; c++) {
+ for (int b = yi; b <= yf; b++) {
+ TileEntity tileEntity = this.world.getTileEntity(a, b, c);
+ if (tileEntity instanceof TileEntityHopper) {
+ ((TileEntityHopper) tileEntity).makeTick();
+ }
+ }
+ }
+ }
+ }
+ // Spigot end
// ++this.age; // CraftBukkit - Moved up
if (!this.world.isStatic && this.age >= world.spigotConfig.itemDespawnRate) { // Spigot
diff --git a/src/main/java/net/minecraft/server/EntityMinecartAbstract.java b/src/main/java/net/minecraft/server/EntityMinecartAbstract.java
index f1ccd3a..2a1e69d 100644
--- a/src/main/java/net/minecraft/server/EntityMinecartAbstract.java
+++ b/src/main/java/net/minecraft/server/EntityMinecartAbstract.java
@@ -342,6 +342,27 @@ public abstract class EntityMinecartAbstract extends Entity {
this.passenger = null;
}
+ // Spigot start - Make hoppers around this container minecart active.
+ // Called each tick on each minecart.
+ if (this.world.spigotConfig.altHopperTicking && this instanceof EntityMinecartContainer) {
+ int xi = MathHelper.floor(this.boundingBox.a) - 1;
+ int yi = MathHelper.floor(this.boundingBox.b) - 1;
+ int zi = MathHelper.floor(this.boundingBox.c) - 1;
+ int xf = MathHelper.floor(this.boundingBox.d) + 1;
+ int yf = MathHelper.floor(this.boundingBox.e) + 1;
+ int zf = MathHelper.floor(this.boundingBox.f) + 1;
+ for (int a = xi; a <= xf; a++) {
+ for (int b = yi; b <= yf; b++) {
+ for (int c = zi; c <= zf; c++) {
+ TileEntity tileEntity = this.world.getTileEntity(a, b, c);
+ if (tileEntity instanceof TileEntityHopper) {
+ ((TileEntityHopper) tileEntity).makeTick();
+ }
+ }
+ }
+ }
+ }
+ // Spigot end
}
}
diff --git a/src/main/java/net/minecraft/server/EntityOcelot.java b/src/main/java/net/minecraft/server/EntityOcelot.java
index aba3748..1f15e40 100644
--- a/src/main/java/net/minecraft/server/EntityOcelot.java
+++ b/src/main/java/net/minecraft/server/EntityOcelot.java
@@ -27,6 +27,31 @@ public class EntityOcelot extends EntityTameableAnimal {
this.datawatcher.a(18, Byte.valueOf((byte) 0));
}
+ // Spigot start - When this ocelot begins standing, chests below this ocelot must be
+ // updated as if its contents have changed. We update chests if this ocelot is sitting
+ // knowing that it may be dead, gone, or standing after this method returns.
+ // Called each tick on each ocelot.
+ @Override
+ public void h() {
+ if (this.world.spigotConfig.altHopperTicking && this.isSitting()) {
+ int xi = MathHelper.floor(this.boundingBox.a);
+ int yi = MathHelper.floor(this.boundingBox.b) - 1;
+ int zi = MathHelper.floor(this.boundingBox.c);
+ int xf = MathHelper.floor(this.boundingBox.d);
+ int yf = MathHelper.floor(this.boundingBox.e) - 1;
+ int zf = MathHelper.floor(this.boundingBox.f);
+ for (int a = xi; a <= xf; a++) {
+ for (int c = zi; c <= zf; c++) {
+ for (int b = yi; b <= yf; b++) {
+ this.world.updateChestAndHoppers(a, b, c);
+ }
+ }
+ }
+ }
+ super.h();
+ }
+ // Spigot end
+
public void bp() {
if (this.getControllerMove().a()) {
double d0 = this.getControllerMove().b();
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index ccea0b3..3c5ec6f 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -24,6 +24,40 @@ public class TileEntity {
public int g = -1;
public Block h;
+ // Spigot start
+ // Helper method for scheduleTicks. If the hopper at x0, y0, z0 is pointed
+ // at this tile entity, then make it active.
+ private void scheduleTick(int x0, int y0, int z0) {
+ TileEntity tileEntity = this.world.getTileEntity(x0, y0, z0);
+ if (tileEntity instanceof TileEntityHopper && tileEntity.world != null) {
+ // i is the metadeta assoiated with the direction the hopper faces.
+ int i = BlockHopper.b(tileEntity.p());
+ // Facing class provides arrays for direction offset.
+ if (tileEntity.x + Facing.b[i] == this.x && tileEntity.y + Facing.c[i] == this.y && tileEntity.z + Facing.d[i] == this.z) {
+ ((TileEntityHopper) tileEntity).makeTick();
+ }
+ }
+ }
+
+ // Called from update when the contents have changed, so hoppers need updates.
+ // Check all 6 faces.
+ public void scheduleTicks() {
+ if (this.world != null && this.world.spigotConfig.altHopperTicking) {
+ // Check the top
+ this.scheduleTick(this.x, this.y + 1, this.z);
+ // Check the sides
+ for (int i = 2; i < 6; i++) {
+ this.scheduleTick(this.x + Facing.b[i], this.y, this.z + Facing.d[i]);
+ }
+ // Check the bottom.
+ TileEntity tileEntity = this.world.getTileEntity(this.x, this.y - 1, this.z);
+ if (tileEntity instanceof TileEntityHopper && tileEntity.world != null) {
+ ((TileEntityHopper) tileEntity).makeTick();
+ }
+ }
+ }
+ // Spigot end
+
public TileEntity() {}
private static void a(Class oclass, String s) {
@@ -105,6 +139,10 @@ public class TileEntity {
if (this.q() != Blocks.AIR) {
this.world.updateAdjacentComparators(this.x, this.y, this.z, this.q());
}
+ // Spigot start - Called when the contents have changed, so hoppers around this
+ // tile need updating.
+ this.scheduleTicks();
+ // Spigot end
}
}
diff --git a/src/main/java/net/minecraft/server/TileEntityHopper.java b/src/main/java/net/minecraft/server/TileEntityHopper.java
index ace3617..65ee96c 100644
--- a/src/main/java/net/minecraft/server/TileEntityHopper.java
+++ b/src/main/java/net/minecraft/server/TileEntityHopper.java
@@ -17,6 +17,43 @@ public class TileEntityHopper extends TileEntity implements IHopper {
private String i;
private int j = -1;
+ // Spigot start
+ private long nextTick = -1; // Next tick this hopper will be ticked.
+ private long lastTick = -1; // Last tick this hopper was polled.
+
+ // If this hopper is not cooling down, assaign a visible tick for next time.
+ public void makeTick() {
+ if (!this.j()) {
+ this.c(0);
+ }
+ }
+
+ // Contents changed, so make this hopper active.
+ public void scheduleHopperTick() {
+ if (this.world != null && this.world.spigotConfig.altHopperTicking) {
+ this.makeTick();
+ }
+ }
+
+ // Called after this hopper is assaigned a world or when altHopperTicking is turned
+ // on from reload.
+ public void convertToScheduling() {
+ // j is the cooldown in ticks
+ this.c(this.j);
+ }
+
+ // Called when alt hopper ticking is turned off from the reload command
+ public void convertToPolling() {
+ long cooldownDiff;
+ if (this.lastTick == this.world.getTime()) {
+ cooldownDiff = this.nextTick - this.world.getTime();
+ } else {
+ cooldownDiff = this.nextTick - this.world.getTime() + 1;
+ }
+ this.c((int) Math.max(0, Math.min(cooldownDiff, Integer.MAX_VALUE)));
+ }
+ // Spigot end
+
// CraftBukkit start - add fields and methods
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
private int maxStack = MAX_STACK;
@@ -80,7 +117,20 @@ public class TileEntityHopper extends TileEntity implements IHopper {
}
nbttagcompound.set("Items", nbttaglist);
- nbttagcompound.setInt("TransferCooldown", this.j);
+ // Spigot start - Need to write the correct cooldown to disk. We convert from long to int on saving.
+ if (this.world != null && this.world.spigotConfig.altHopperTicking) {
+ long cooldownDiff;
+ if (this.lastTick == this.world.getTime()) {
+ cooldownDiff = this.nextTick - this.world.getTime();
+ } else {
+ cooldownDiff = this.nextTick - this.world.getTime() + 1;
+ }
+ nbttagcompound.setInt("TransferCooldown", (int) Math.max(0, Math.min(cooldownDiff, Integer.MAX_VALUE)));
+ } else {
+ // j is the cooldown in ticks.
+ nbttagcompound.setInt("TransferCooldown", this.j);
+ }
+ // Spigot end
if (this.k_()) {
nbttagcompound.setString("CustomName", this.i);
}
@@ -88,6 +138,9 @@ public class TileEntityHopper extends TileEntity implements IHopper {
public void update() {
super.update();
+ // Spigot start - The contents have changed, so make this hopper active.
+ this.scheduleHopperTick();
+ // Spigot end
}
public int getSize() {
@@ -167,11 +220,21 @@ public class TileEntityHopper extends TileEntity implements IHopper {
public void h() {
if (this.world != null && !this.world.isStatic) {
- --this.j;
- if (!this.j()) {
- this.c(0);
- this.i();
+ // Spigot start
+ if (this.world.spigotConfig.altHopperTicking) {
+ this.lastTick = this.world.getTime();
+ if (this.nextTick == this.world.getTime()) {
+ // Method that does the pushing and pulling.
+ this.i();
+ }
+ } else {
+ --this.j;
+ if (!this.j()) {
+ this.c(0);
+ this.i();
+ }
}
+ // Spigot end
}
}
@@ -196,7 +259,7 @@ public class TileEntityHopper extends TileEntity implements IHopper {
}
// Spigot start
- if ( !this.j() )
+ if ( !world.spigotConfig.altHopperTicking && !this.j() )
{
this.c( world.spigotConfig.hopperCheck );
}
@@ -584,10 +647,34 @@ public class TileEntityHopper extends TileEntity implements IHopper {
}
public void c(int i) {
- this.j = i;
+ // Spigot start - i is the delay for which this hopper will be ticked next.
+ // i of 1 or below implies a tick next tick.
+ if (this.world != null && this.world.spigotConfig.altHopperTicking) {
+ if (i <= 0) {
+ i = 1;
+ }
+ if (this.lastTick == this.world.getTime()) {
+ this.nextTick = this.world.getTime() + i;
+ } else {
+ this.nextTick = this.world.getTime() + i - 1;
+ }
+ } else {
+ this.j = i;
+ }
+ // Spigot end
}
public boolean j() {
- return this.j > 0;
+ // Spigot start - Return whether this hopper is cooling down.
+ if (this.world != null && this.world.spigotConfig.altHopperTicking) {
+ if (this.lastTick == this.world.getTime()) {
+ return this.nextTick > this.world.getTime();
+ } else {
+ return this.nextTick >= this.world.getTime();
+ }
+ } else {
+ return this.j > 0;
+ }
+ // Spigot end
}
}
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index e7cf335..3dba573 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -113,6 +113,7 @@ public abstract class World implements IBlockAccess {
private final byte chunkTickRadius;
public static boolean haveWeSilencedAPhysicsCrash;
public static String blockLocation;
+ public List<TileEntity> triggerHoppersList = new ArrayList<TileEntity>(); // Spigot, When altHopperTicking, tile entities being added go through here.
public static long chunkToKey(int x, int z)
{
@@ -130,6 +131,42 @@ public abstract class World implements IBlockAccess {
{
return (int) ( ( ( k >> 32 ) & 0xFFFF0000L ) | ( ( k >> 16 ) & 0x0000FFFF ) );
}
+
+ // Spigot Start - Hoppers need to be born ticking.
+ private void initializeHoppers() {
+ if (this.spigotConfig.altHopperTicking) {
+ for (TileEntity o : this.triggerHoppersList) {
+ o.scheduleTicks();
+ if (o instanceof TileEntityHopper) {
+ ((TileEntityHopper) o).convertToScheduling();
+ ((TileEntityHopper) o).scheduleHopperTick();
+ }
+ }
+ }
+ triggerHoppersList.clear();
+ }
+
+ // Helper method for altHopperTicking. Updates chests at the specified location,
+ // accounting for double chests. Updating the chest will update adjacent hoppers.
+ public void updateChestAndHoppers(int a, int b, int c) {
+ Block block = this.getType(a, b, c);
+ if (block instanceof BlockChest) {
+ TileEntity tile = this.getTileEntity(a, b, c);
+ if (tile instanceof TileEntityChest) {
+ tile.scheduleTicks();
+ }
+ for (int i = 2; i < 6; i++) {
+ // Facing class provides arrays for direction offset.
+ if (this.getType(a + Facing.b[i], b, c + Facing.d[i]) == block) {
+ tile = this.getTileEntity(a + Facing.b[i], b, c + Facing.d[i]);
+ if (tile instanceof TileEntityChest) {
+ tile.scheduleTicks();
+ }
+ break;
+ }
+ }
+ }
+ }
// Spigot end
public BiomeBase getBiome(int i, int j) {
@@ -407,6 +444,14 @@ public abstract class World implements IBlockAccess {
this.notifyAndUpdatePhysics(i, j, k, chunk, block1, block, i1);
// CraftBukkit end
}
+ // Spigot start - If this block is changing to that which a chest beneath it
+ // becomes able to be opened, then the chest must be updated.
+ // block1 is the old block. block is the new block. r returns true if the block type
+ // prevents access to a chest.
+ if (this.spigotConfig.altHopperTicking && block1 != null && block1.r() && !block.r()) {
+ this.updateChestAndHoppers(i, j - 1, k);
+ }
+ // Spigot end
return flag;
}
@@ -1433,8 +1478,9 @@ public abstract class World implements IBlockAccess {
this.tileEntityList.removeAll(this.b);
this.b.clear();
}
- // CraftBukkit end
+ // Spigot End
+ this.initializeHoppers(); // Spigot - Initializes hoppers which have been added recently.
Iterator iterator = this.tileEntityList.iterator();
while (iterator.hasNext()) {
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index 3e6b1e6..a81b7c9 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -166,11 +166,35 @@ public class SpigotWorldConfig
log( "Entity Tracking Range: Pl " + playerTrackingRange + " / An " + animalTrackingRange + " / Mo " + monsterTrackingRange + " / Mi " + miscTrackingRange + " / Other " + otherTrackingRange );
}
+ public boolean altHopperTicking;
public int hopperTransfer;
public int hopperCheck;
public int hopperAmount;
private void hoppers()
{
+ // Alternate ticking method. Uses inventory changes, redstone updates etc.
+ // to update hoppers. Hopper-check is disabled when this is true.
+ boolean prev = altHopperTicking;
+ altHopperTicking = getBoolean( "hopper-alt-ticking", false );
+ // Necessary for the reload command
+ if (prev != altHopperTicking) {
+ net.minecraft.server.World world = (net.minecraft.server.World) Bukkit.getWorld(this.worldName);
+ if (world != null) {
+ if (altHopperTicking) {
+ for (Object o : world.tileEntityList) {
+ if (o instanceof net.minecraft.server.TileEntityHopper) {
+ ((net.minecraft.server.TileEntityHopper) o).convertToScheduling();
+ }
+ }
+ } else {
+ for (Object o : world.tileEntityList) {
+ if (o instanceof net.minecraft.server.TileEntityHopper) {
+ ((net.minecraft.server.TileEntityHopper) o).convertToPolling();
+ }
+ }
+ }
+ }
+ }
// Set the tick delay between hopper item movements
hopperTransfer = getInt( "ticks-per.hopper-transfer", 8 );
// Set the tick delay between checking for items after the associated
@@ -178,6 +202,7 @@ public class SpigotWorldConfig
// hopper sorting machines from becoming out of sync.
hopperCheck = getInt( "ticks-per.hopper-check", hopperTransfer );
hopperAmount = getInt( "hopper-amount", 1 );
+ log( "Alternative Hopper Ticking: " + altHopperTicking );
log( "Hopper Transfer: " + hopperTransfer + " Hopper Check: " + hopperCheck + " Hopper Amount: " + hopperAmount );
}
--
1.9.1
|