Browse Source

WIP pipe refactoring, bugfixes

1.11
Adrian Siekierka 2 years ago
parent
commit
065b0a5bc9

+ 2
- 1
src/main/java/pl/asie/charset/api/pipes/IPipeView.java View File

@@ -17,6 +17,7 @@
17 17
 package pl.asie.charset.api.pipes;
18 18
 
19 19
 import net.minecraft.item.ItemStack;
20
+import net.minecraft.util.EnumFacing;
20 21
 
21 22
 import java.util.Collection;
22 23
 
@@ -24,7 +25,7 @@ import java.util.Collection;
24 25
  * This interface is used for viewing items travelling through a pipe.
25 26
  * Note that the pipe can decide the contents at its own discretion and
26 27
  * that it is not necessarily exhaustive - the idea is to let other mods
27
- * react - and only react - to the act of items travelling inside a pipe.
28
+ * react - and only react - to the action of items travelling inside a pipe.
28 29
  */
29 30
 public interface IPipeView {
30 31
 	/**

+ 25
- 0
src/main/java/pl/asie/charset/lib/scheduler/ScheduledEvent.java View File

@@ -0,0 +1,25 @@
1
+package pl.asie.charset.lib.scheduler;
2
+
3
+public final class ScheduledEvent {
4
+	private final Runnable runnable;
5
+	private boolean executed;
6
+
7
+	ScheduledEvent(Runnable runnable) {
8
+		this.runnable = runnable;
9
+		this.executed = false;
10
+	}
11
+
12
+	public boolean hasExecuted() {
13
+		return executed;
14
+	}
15
+
16
+	boolean run() {
17
+		if (!executed) {
18
+			runnable.run();
19
+			executed = true;
20
+			return true;
21
+		} else {
22
+			throw new RuntimeException("ScheduledEvent tried to execute twice!");
23
+		}
24
+	}
25
+}

unmoved/WorldScheduler.java → src/main/java/pl/asie/charset/lib/scheduler/Scheduler.java View File

@@ -1,4 +1,4 @@
1
-package pl.asie.charset.lib;
1
+package pl.asie.charset.lib.scheduler;
2 2
 
3 3
 import gnu.trove.map.TLongObjectMap;
4 4
 import gnu.trove.map.hash.TLongObjectHashMap;
@@ -10,22 +10,24 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
10 10
 import java.util.*;
11 11
 
12 12
 // TODO: Implement saving? Ha, ha, I wish.
13
-public class WorldScheduler {
14
-    public static final WorldScheduler INSTANCE = new WorldScheduler();
15
-    private final Map<World, TLongObjectMap<Queue<Runnable>>> schedule = new WeakHashMap<>();
13
+public class Scheduler {
14
+    public static final Scheduler INSTANCE = new Scheduler();
15
+    private final Map<World, TLongObjectMap<Queue<ScheduledEvent>>> schedule = new WeakHashMap<>();
16 16
 
17
-    public void in(World world, int ticks, Runnable runnable) {
18
-        at(world, world.getTotalWorldTime() + ticks, runnable);
17
+    public ScheduledEvent in(World world, int ticks, Runnable runnable) {
18
+        return at(world, world.getTotalWorldTime() + ticks, runnable);
19 19
     }
20 20
 
21
-    public void at(World world, long targetTime, Runnable runnable) {
22
-        TLongObjectMap<Queue<Runnable>> requests = schedule.computeIfAbsent(world, k -> new TLongObjectHashMap<>());
23
-        Queue<Runnable> queue = requests.get(targetTime);
21
+    public ScheduledEvent at(World world, long targetTime, Runnable runnable) {
22
+        TLongObjectMap<Queue<ScheduledEvent>> requests = schedule.computeIfAbsent(world, k -> new TLongObjectHashMap<>());
23
+        Queue<ScheduledEvent> queue = requests.get(targetTime);
24 24
         if (queue == null) {
25 25
             queue = new ArrayDeque<>();
26 26
             requests.put(targetTime, queue);
27 27
         }
28
-        queue.add(runnable);
28
+        ScheduledEvent event = new ScheduledEvent(runnable);
29
+        queue.add(event);
30
+        return event;
29 31
     }
30 32
 
31 33
     @SubscribeEvent
@@ -36,14 +38,14 @@ public class WorldScheduler {
36 38
     @SubscribeEvent
37 39
     public void onWorldTick(TickEvent.WorldTickEvent event) {
38 40
         if (event.phase == TickEvent.Phase.END) {
39
-            TLongObjectMap<Queue<Runnable>> requests = schedule.get(event.world);
41
+            TLongObjectMap<Queue<ScheduledEvent>> requests = schedule.get(event.world);
40 42
             if (requests != null) {
41 43
                 // We tick at the *end* of a phase, so the world time has
42 44
                 // already had 1 added to it.
43 45
                 long time = event.world.getTotalWorldTime() - 1;
44
-                Queue<Runnable> queue = requests.remove(time);
46
+                Queue<ScheduledEvent> queue = requests.remove(time);
45 47
                 if (queue != null) {
46
-                    for (Runnable r : queue) {
48
+                    for (ScheduledEvent r : queue) {
47 49
                         event.world.profiler.startSection(r.getClass().getName());
48 50
                         r.run();
49 51
                         event.world.profiler.endSection();

+ 4
- 0
src/main/java/pl/asie/charset/misc/scaffold/TileScaffold.java View File

@@ -13,6 +13,10 @@ public class TileScaffold extends TileBase {
13 13
 	public static final UnlistedPropertyGeneric<ScaffoldCacheInfo> PROPERTY = new UnlistedPropertyGeneric<>("tile", ScaffoldCacheInfo.class);
14 14
 	private ItemMaterial plank;
15 15
 
16
+	public TileScaffold() {
17
+		plank = getPlankFromNBT(null);
18
+	}
19
+
16 20
 	public ItemMaterial getPlank() {
17 21
 		return plank;
18 22
 	}

+ 2
- 1
src/main/java/pl/asie/charset/pipes/pipe/PacketItemUpdate.java View File

@@ -65,7 +65,7 @@ public class PacketItemUpdate extends PacketTile {
65 65
 	public void writeItemData(ByteBuf buf) {
66 66
 		buf.writeShort(item.id);
67 67
 		buf.writeByte(SpaceUtils.ordinal(item.input) | (SpaceUtils.ordinal(item.output) << 3));
68
-		buf.writeByte((item.reachedCenter ? 0x01 : 0) | (item.isStuck(null) ? 0x02 : 0) | (syncStack ? 0x04 : 0));
68
+		buf.writeByte((item.reachedCenter ? 0x01 : 0) | (item.isStuck(null) ? 0x02 : 0) | (syncStack ? 0x04 : 0) | (SpaceUtils.ordinal(item.renderDirection) << 4));
69 69
 		buf.writeByte(item.progress);
70 70
 
71 71
 		if (syncStack) {
@@ -111,6 +111,7 @@ public class PacketItemUpdate extends PacketTile {
111 111
 
112 112
 		item.input = SpaceUtils.getFacing(dirs & 7);
113 113
 		item.output = SpaceUtils.getFacing((dirs >> 3) & 7);
114
+		item.renderDirection = SpaceUtils.getFacing((flags >> 4) & 7);
114 115
 		item.reachedCenter = (flags & 0x01) != 0;
115 116
 		item.blocksSinceSync = 0;
116 117
 		if (addWhenDone) {

+ 51
- 83
src/main/java/pl/asie/charset/pipes/pipe/PipeItem.java View File

@@ -16,6 +16,7 @@
16 16
 
17 17
 package pl.asie.charset.pipes.pipe;
18 18
 
19
+import com.google.common.collect.Lists;
19 20
 import net.minecraft.item.ItemStack;
20 21
 import net.minecraft.nbt.NBTTagCompound;
21 22
 import net.minecraft.tileentity.TileEntity;
@@ -46,6 +47,7 @@ public class PipeItem {
46 47
 	byte blocksSinceSync;
47 48
 
48 49
 	protected EnumFacing input, output;
50
+	protected EnumFacing renderDirection;
49 51
 	protected boolean reachedCenter;
50 52
 	protected ItemStack stack = ItemStack.EMPTY;
51 53
 	protected int progress;
@@ -57,6 +59,16 @@ public class PipeItem {
57 59
 	private TilePipe owner;
58 60
 	private boolean stuck;
59 61
 
62
+	protected void updateRenderDirection() {
63
+		if (renderDirection == null || (getDirection() != null && getDirection().getAxis() != EnumFacing.Axis.Y)) {
64
+			renderDirection = getDirection();
65
+		}
66
+	}
67
+
68
+	public EnumFacing getRenderDirection() {
69
+		return renderDirection;
70
+	}
71
+
60 72
 	public PipeItem(TilePipe owner, ItemStack stack, EnumFacing side) {
61 73
 		this.id = nextId++;
62 74
 		this.owner = owner;
@@ -137,7 +149,11 @@ public class PipeItem {
137 149
 
138 150
 	// This version takes priority into account (filtered shifters are
139 151
 	// prioritized over unfiltered shifters at the same distance).
140
-	private int getInternalShifterStrength(IShifter shifter, EnumFacing dir) {
152
+	private int getInternalShifterStrength(PipeLogic.Direction dir) {
153
+		return getInternalShifterStrength(dir.dir, dir.shifter);
154
+	}
155
+
156
+	private int getInternalShifterStrength(EnumFacing dir, IShifter shifter) {
141 157
 		if (shifter == null) {
142 158
 			return 0;
143 159
 		} else {
@@ -159,7 +175,7 @@ public class PipeItem {
159 175
 				// Find the closest shifter affecting the item.
160 176
 				for (EnumFacing dir : EnumFacing.VALUES) {
161 177
 					IShifter p = owner.getNearestShifter(dir);
162
-					int ps = getInternalShifterStrength(p, dir);
178
+					int ps = getInternalShifterStrength(dir, p);
163 179
 					if (ps > 0 && ps < minimumShifterDistance
164 180
 							&& isShifterPushing(p, output)) {
165 181
 						minimumShifterDistance = ps;
@@ -170,7 +186,7 @@ public class PipeItem {
170 186
 				if (
171 187
 						(!foundShifter && activeShifterDistance > 0)
172 188
 								|| (foundShifter && activeShifterDistance != minimumShifterDistance)
173
-								|| (foundShifter && activeShifterDistance != getInternalShifterStrength(owner.getNearestShifter(output), output))
189
+								|| (foundShifter && activeShifterDistance != getInternalShifterStrength(output, owner.getNearestShifter(output)))
174 190
 						) {
175 191
 					TileEntity shifterTile = owner.getWorld().getTileEntity(owner.getPos().offset(output.getOpposite(), activeShifterDistance));
176 192
 
@@ -351,98 +367,46 @@ public class PipeItem {
351 367
 			return;
352 368
 		}
353 369
 
354
-		List<EnumFacing> directionList = new ArrayList<EnumFacing>();
355
-		List<EnumFacing> pressureList = new ArrayList<EnumFacing>();
356
-
357
-		activeShifterDistance = 0;
358
-
359
-		// Step 1: Make a list of all valid directions, as well as all shifters.
360
-		for (EnumFacing direction : EnumFacing.VALUES) {
361
-			if (isValidDirection(direction)) {
362
-				directionList.add(direction);
363
-			}
364
-
365
-			IShifter p = owner.getNearestShifter(direction);
366
-
367
-			if (p != null && isShifterPushing(p, direction)) {
368
-				pressureList.add(direction);
369
-			}
370
-		}
371
-
372
-		// Step 2: Sort the shifter list.
373
-		Collections.sort(pressureList, new Comparator<EnumFacing>() {
374
-			@Override
375
-			public int compare(EnumFacing o1, EnumFacing o2) {
376
-				return getInternalShifterStrength(owner.getNearestShifter(o1), o1) - getInternalShifterStrength(owner.getNearestShifter(o2), o2);
377
-			}
378
-		});
379
-
370
+		PipeLogic.Direction dir = null;
380 371
 
381
-		EnumFacing firstOutput = null;
372
+		for (PipeLogic.Direction iDir : owner.getLogic().getPressuredDirections()) {
373
+			if (!iDir.test(stack))
374
+				continue;
382 375
 
383
-		// Step 3: Pick the next path.
384
-		for (EnumFacing dir : pressureList) {
385
-			if (canMoveDirection(dir, true)) {
376
+			dir = iDir;
377
+			if (canMoveDirection(dir.dir, true)) {
386 378
 				// Pressurizer prioritizing valid direction, move.
387
-				this.output = dir;
388
-				activeShifterDistance = getInternalShifterStrength(owner.getNearestShifter(dir), dir);
379
+				this.output = dir.dir;
380
+				activeShifterDistance = getInternalShifterStrength(dir);
389 381
 				return;
390
-			} else if (pressureList.contains(dir.getOpposite())
391
-					&& owner.getShifterStrength(dir) == owner.getShifterStrength(dir.getOpposite())) {
382
+			} else if (owner.getLogic().hasPressure(dir.dir.getOpposite())
383
+					&& owner.getShifterStrength(dir.dir) == owner.getShifterStrength(dir.dir.getOpposite())) {
392 384
 				// Pressurizers freezing an item in place.
393
-				this.output = dir;
394
-				activeShifterDistance = getInternalShifterStrength(owner.getNearestShifter(dir), dir);
385
+				this.output = dir.dir;
386
+				activeShifterDistance = getInternalShifterStrength(dir);
395 387
 				return;
396
-			} else if (directionList.contains(dir) && firstOutput == null) {
397
-				firstOutput = dir;
398 388
 			}
399 389
 		}
400 390
 
401
-		directionList.removeAll(pressureList);
402
-		directionList.remove(input);
403
-
404
-		if (directionList.size() > 0) {
405
-			EnumFacing dir;
406
-			int i = 0;
407
-
408
-			// Step 3b: Pick the first "unforced" direction to scan.
409
-			// A direction opposite to input (aka. "straight line")
410
-			// takes priority.
411
-			if (directionList.contains(input.getOpposite())) {
412
-				dir = input.getOpposite();
413
-				directionList.remove(input.getOpposite());
414
-			} else if (directionList.size() > 1) {
415
-				Collections.shuffle(directionList);
416
-				dir = directionList.get(0);
417
-				i = 1;
418
-			} else if (directionList.size() == 1) {
419
-				this.output = directionList.get(0);
420
-				return;
421
-			} else {
422
-				this.output = null;
423
-				return;
424
-			}
391
+		activeShifterDistance = 0;
425 392
 
426
-			if (firstOutput == null) {
427
-				firstOutput = dir;
428
-			}
393
+		List<PipeLogic.Direction> directionList = Lists.newArrayList(owner.getLogic().getNonPressuredDirections());
394
+		Collections.shuffle(directionList);
429 395
 
430
-			while (!canMoveDirection(dir, true) && i < directionList.size()) {
431
-				dir = directionList.get(i);
432
-				i++;
396
+		for (int i = directionList.size() - 1; i >= 0; i--) {
397
+			PipeLogic.Direction iDir = directionList.get(i);
398
+			if (iDir.dir == input || !iDir.test(stack)) {
399
+				continue;
433 400
 			}
434 401
 
435
-			// Step 3c: If a valid, free direction has been found, use that.
436
-			// Otherwise, set it to the first output direction selected to
437
-			// prioritize that, for some reason.
438
-			if (canMoveDirection(dir, true)) {
439
-				this.output = dir;
440
-			} else {
441
-				this.output = firstOutput;
402
+			dir = iDir;
403
+			if (canMoveDirection(iDir.dir, true)) {
404
+				this.output = iDir.dir;
405
+				return;
442 406
 			}
443
-		} else {
444
-			this.output = firstOutput;
445 407
 		}
408
+
409
+		this.output = dir != null ? dir.dir : null;
446 410
 	}
447 411
 
448 412
 	private void onReachedCenter() {
@@ -455,6 +419,7 @@ public class PipeItem {
455 419
 
456 420
 		owner.updateObservers(stack);
457 421
 		calculateOutputDirection();
422
+		updateRenderDirection();
458 423
 		updateStuckFlag();
459 424
 		sendPacket(false);
460 425
 	}
@@ -532,9 +497,7 @@ public class PipeItem {
532 497
 		this.stuck = false;
533 498
 		this.progress = 0;
534 499
 
535
-		if (owner.getWorld().isRemote) {
536
-
537
-		}
500
+		updateRenderDirection();
538 501
 	}
539 502
 
540 503
 	public void readFromNBT(NBTTagCompound nbt) {
@@ -549,6 +512,10 @@ public class PipeItem {
549 512
 		if (nbt.hasKey("activePD")) {
550 513
 			activeShifterDistance = nbt.getInteger("activePD");
551 514
 		}
515
+		if (nbt.hasKey("rendir")) {
516
+			renderDirection = SpaceUtils.getFacing(nbt.getByte("rendir"));
517
+		}
518
+		updateRenderDirection();
552 519
 	}
553 520
 
554 521
 	public void writeToNBT(NBTTagCompound nbt) {
@@ -556,6 +523,7 @@ public class PipeItem {
556 523
 		nbt.setShort("p", (short) progress);
557 524
 		nbt.setByte("in", (byte) SpaceUtils.ordinal(input));
558 525
 		nbt.setByte("out", (byte) SpaceUtils.ordinal(output));
526
+		nbt.setByte("rendir", (byte) SpaceUtils.ordinal(renderDirection));
559 527
 		nbt.setBoolean("reachedCenter", reachedCenter);
560 528
 		if (stuck) {
561 529
 			nbt.setBoolean("stuck", stuck);

+ 67
- 43
src/main/java/pl/asie/charset/pipes/pipe/PipeLogic.java View File

@@ -5,13 +5,11 @@ import net.minecraft.tileentity.TileEntity;
5 5
 import net.minecraft.util.EnumFacing;
6 6
 import net.minecraftforge.fluids.FluidStack;
7 7
 import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
8
-import net.minecraftforge.items.CapabilityItemHandler;
9
-import pl.asie.charset.ModCharset;
10 8
 import pl.asie.charset.api.pipes.IShifter;
11 9
 import pl.asie.charset.lib.capability.Capabilities;
12 10
 import pl.asie.charset.lib.capability.CapabilityHelper;
13
-import pl.asie.charset.pipes.PipeUtils;
14 11
 
12
+import javax.annotation.Nonnull;
15 13
 import javax.annotation.Nullable;
16 14
 import java.util.*;
17 15
 
@@ -30,32 +28,50 @@ public class PipeLogic {
30 28
     }
31 29
 
32 30
     public static class Direction {
31
+        public final DirectionType type;
33 32
         public final EnumFacing dir;
34 33
         public final IShifter shifter;
35 34
 
36
-        private Direction(EnumFacing dir, IShifter shifter) {
35
+        private Direction(@Nonnull DirectionType type, @Nonnull EnumFacing dir, @Nullable IShifter shifter) {
36
+            this.type = type;
37 37
             this.dir = dir;
38 38
             this.shifter = shifter;
39 39
         }
40 40
 
41
+        public boolean hasPressure() {
42
+            return shifter != null;
43
+        }
44
+
45
+        private boolean canShift() {
46
+            return shifter != null && shifter.isShifting() && shifter.getDirection() == dir;
47
+        }
48
+
41 49
         public boolean test(ItemStack stack) {
42
-            return (shifter == null || (shifter.isShifting() && shifter.matches(stack)));
50
+            return type.acceptsItems && (shifter == null || (canShift() && shifter.matches(stack)));
43 51
         }
44 52
 
45 53
         public boolean test(FluidStack stack) {
46
-            return (shifter != null && (shifter.isShifting() && shifter.matches(stack)));
54
+            return type.acceptsFluids && (shifter != null && (canShift() && shifter.matches(stack)));
47 55
         }
48 56
     }
49 57
 
50 58
     private final TilePipe owner;
51
-    private boolean isPressured;
52
-    private EnumMap<EnumFacing, DirectionType> directions = new EnumMap<EnumFacing, DirectionType>(EnumFacing.class);
53
-    private EnumMap<EnumFacing, IShifter> pressuredDirections = new EnumMap<EnumFacing, IShifter>(EnumFacing.class);
59
+    private byte pressuredDirMask;
60
+    private List<Direction> pressureDirections = new ArrayList<>(6);
61
+    private List<Direction> nonPressureDirections = new ArrayList<>(6);
54 62
 
55 63
     public PipeLogic(TilePipe owner) {
56 64
         this.owner = owner;
57 65
     }
58 66
 
67
+    public Collection<Direction> getPressuredDirections() {
68
+        return pressureDirections;
69
+    }
70
+
71
+    public Collection<Direction> getNonPressuredDirections() {
72
+        return nonPressureDirections;
73
+    }
74
+
59 75
     // This version takes priority into account (filtered shifters are
60 76
     // prioritized over unfiltered shifters at the same distance).
61 77
     private int getInternalShifterStrength(IShifter shifter, EnumFacing dir) {
@@ -66,59 +82,67 @@ public class PipeLogic {
66 82
         }
67 83
     }
68 84
 
69
-    public boolean hasPressure(EnumFacing direction) {
70
-        return isPressured ? directions.containsKey(direction) : pressuredDirections.containsKey(direction);
85
+    private DirectionType calcDirectionType(EnumFacing direction) {
86
+        TileEntity tile = owner.getNeighbourTile(direction);
87
+        boolean hasItem = CapabilityHelper.get(Capabilities.ITEM_INSERTION_HANDLER, tile, direction.getOpposite()) != null;
88
+        boolean hasFluid = CapabilityHelper.get(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, tile, direction.getOpposite()) != null;
89
+        DirectionType type = hasItem ? (hasFluid ? DirectionType.DUAL_TARGET : DirectionType.ITEM_TARGET) : (hasFluid ? DirectionType.FLUID_TARGET : null);
90
+        if (type == null) {
91
+            System.out.println("Type null! " + (tile != null ? tile.getClass().getName() : "null") + " " + owner.getPos().offset(direction) + " " + direction.getOpposite().getName());
92
+        }
93
+        return type;
71 94
     }
72 95
 
73 96
     public void updateDirections() {
74
-        List<EnumFacing> directionList = new ArrayList<EnumFacing>();
75
-        List<EnumFacing> pressureList = new ArrayList<EnumFacing>();
97
+        System.out.println("Update " + owner.getPos());
76 98
 
77
-        isPressured = false;
99
+        pressuredDirMask = 0;
100
+
101
+        Set<EnumFacing> directionSet = EnumSet.noneOf(EnumFacing.class);
102
+        List<IShifter> shifterList = new ArrayList<>(6);
78 103
 
79 104
         // Step 1: Make a list of all valid directions, as well as all shifters.
80 105
         for (EnumFacing direction : EnumFacing.VALUES) {
81
-            TilePipe pipe = PipeUtils.getPipe(owner.getWorld(), owner.getPos().offset(direction), direction.getOpposite());
82
-            if (pipe != null && pipe.getLogic().hasPressure(direction)) {
83
-                isPressured = true;
84
-                continue;
85
-            }
86
-
106
+            // TilePipe pipe = PipeUtils.getPipe(owner.getWorld(), owner.getPos().offset(direction), direction.getOpposite());
87 107
             if (owner.connects(direction)) {
88
-                directionList.add(direction);
108
+                directionSet.add(direction);
89 109
             }
90 110
 
91 111
             IShifter p = owner.getNearestShifter(direction);
92 112
 
93 113
             if (p != null && p.getDirection() == direction) {
94
-                pressureList.add(direction);
114
+                pressuredDirMask |= (1 << direction.ordinal());
115
+                shifterList.add(p);
95 116
             }
96 117
         }
97 118
 
98 119
         // Step 2: Sort the shifter list.
99
-        Collections.sort(pressureList, new Comparator<EnumFacing>() {
100
-            @Override
101
-            public int compare(EnumFacing o1, EnumFacing o2) {
102
-                return getInternalShifterStrength(owner.getNearestShifter(o1), o1) - getInternalShifterStrength(owner.getNearestShifter(o2), o2);
120
+        Collections.sort(shifterList, Comparator.comparingInt(o -> getInternalShifterStrength(o, o.getDirection())));
121
+
122
+        pressureDirections.clear();
123
+        for (IShifter shifter : shifterList) {
124
+            DirectionType type = calcDirectionType(shifter.getDirection());
125
+            if (type != null) {
126
+                //noinspection ConstantConditions
127
+                pressureDirections.add(new Direction(type, shifter.getDirection(), shifter));
103 128
             }
104
-        });
105
-
106
-        directions.clear();
107
-        pressuredDirections.clear();
108
-
109
-        for (EnumFacing direction : directionList) {
110
-            TileEntity tile = owner.getNeighbourTile(direction);
111
-            boolean hasItem = CapabilityHelper.get(Capabilities.ITEM_INSERTION_HANDLER, tile, direction.getOpposite()) != null;
112
-            boolean hasFluid = CapabilityHelper.get(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, tile, direction.getOpposite()) != null;
113
-            DirectionType type = hasItem ? (hasFluid ? DirectionType.DUAL_TARGET : DirectionType.FLUID_TARGET) : (hasFluid ? DirectionType.FLUID_TARGET : null);
114
-            if (type == null) {
115
-                ModCharset.logger.warn(owner.getPos().offset(direction) + " has connection but no DirectionType! Will be ignored.");
116
-            } else {
117
-                directions.put(direction, type);
118
-                if (pressureList.contains(direction)) {
119
-                    pressuredDirections.put(direction, owner.getNearestShifter(direction));
120
-                }
129
+            directionSet.remove(shifter.getDirection());
130
+        }
131
+
132
+        nonPressureDirections.clear();
133
+        for (EnumFacing direction : directionSet) {
134
+            DirectionType type = calcDirectionType(direction);
135
+            if (type != null) {
136
+                nonPressureDirections.add(new Direction(type, direction, null));
121 137
             }
122 138
         }
123 139
     }
140
+
141
+    public boolean hasPressure(EnumFacing direction) {
142
+        return (pressuredDirMask & (1 << direction.ordinal())) != 0;
143
+    }
144
+
145
+    public boolean hasPressure() {
146
+        return pressuredDirMask != 0;
147
+    }
124 148
 }

+ 2
- 2
src/main/java/pl/asie/charset/pipes/pipe/SpecialRendererPipe.java View File

@@ -314,7 +314,7 @@ public class SpecialRendererPipe extends DualTileEntitySpecialRenderer<TilePipe>
314 314
 
315 315
 		synchronized (part.getPipeItems()) {
316 316
 			for (PipeItem item : part.getPipeItems()) {
317
-				EnumFacing id = item.getDirection();
317
+				EnumFacing id = item.getRenderDirection();
318 318
 				ItemStack stack = item.getStack();
319 319
 				if (stack == null) {
320 320
 					continue;
@@ -384,7 +384,7 @@ public class SpecialRendererPipe extends DualTileEntitySpecialRenderer<TilePipe>
384 384
 
385 385
 		if (SLOW_ITEMS.size() > 0) {
386 386
 			for (PipeItem item : SLOW_ITEMS) {
387
-				EnumFacing id = item.getDirection();
387
+				EnumFacing id = item.getRenderDirection();
388 388
 				ItemStack stack = item.getStack();
389 389
 				float scale = getItemScale(item);
390 390
 				float[] offset = calculateItemOffset(item, partialTicks);

+ 35
- 7
src/main/java/pl/asie/charset/pipes/pipe/TilePipe.java View File

@@ -85,6 +85,7 @@ public class TilePipe extends TileBase implements IConnectable, IPipeView, ITick
85 85
     }
86 86
 
87 87
     public TilePipe() {
88
+        material = getMaterialFromNBT(null);
88 89
         for (EnumFacing facing : EnumFacing.VALUES)
89 90
             insertionHandlers[facing.ordinal()] = new InsertionHandler(facing);
90 91
     }
@@ -156,7 +157,7 @@ public class TilePipe extends TileBase implements IConnectable, IPipeView, ITick
156 157
             fluid.readFromNBT(tag);
157 158
         }
158 159
 
159
-        material = ItemMaterialRegistry.INSTANCE.getMaterial(nbt, "material", "stone", new ItemStack(Blocks.STONE));
160
+        material = getMaterialFromNBT(nbt);
160 161
         connectionCache = nbt.getByte("cc");
161 162
 
162 163
         if (!isClient) {
@@ -169,9 +170,13 @@ public class TilePipe extends TileBase implements IConnectable, IPipeView, ITick
169 170
         }
170 171
     }
171 172
 
173
+    protected ItemMaterial getMaterialFromNBT(NBTTagCompound compound) {
174
+        return ItemMaterialRegistry.INSTANCE.getMaterial(compound, "material", "stone", new ItemStack(Blocks.STONE));
175
+    }
176
+
172 177
     @Override
173 178
     public void onPlacedBy(EntityLivingBase placer, ItemStack stack) {
174
-        material = ItemMaterialRegistry.INSTANCE.getMaterial(stack.getTagCompound(), "material", "stone", new ItemStack(Blocks.STONE));
179
+        material = getMaterialFromNBT(stack.getTagCompound());
175 180
         color = stack.hasTagCompound() ? stack.getTagCompound().getByte("color") : 0;
176 181
         markBlockForUpdate();
177 182
     }
@@ -255,7 +260,7 @@ public class TilePipe extends TileBase implements IConnectable, IPipeView, ITick
255 260
     @Override
256 261
     public void validate() {
257 262
         super.validate();
258
-        neighborsUpdate = 0x3F;
263
+        scheduleFullNeighborUpdate();
259 264
         scheduleRenderUpdate();
260 265
     }
261 266
 
@@ -301,7 +306,12 @@ public class TilePipe extends TileBase implements IConnectable, IPipeView, ITick
301 306
             shifterDistance[i] = 0;
302 307
         }
303 308
 
304
-        return oldDistance != shifterDistance[i];
309
+        if (oldDistance != shifterDistance[i]) {
310
+            logic.updateDirections();
311
+            return true;
312
+        } else {
313
+            return false;
314
+        }
305 315
     }
306 316
 
307 317
     private void propagateShifterChange(EnumFacing dir, IShifter shifter, int shifterDist) {
@@ -344,10 +354,12 @@ public class TilePipe extends TileBase implements IConnectable, IPipeView, ITick
344 354
             }
345 355
         }
346 356
 
347
-        // TODO
348
-        // fluid.markFlowPath(null, false);
357
+        if (!getWorld().isRemote) {
358
+            logic.updateDirections();
359
+        }
349 360
 
350 361
         if (sendPacket && connectionCache != oc) {
362
+            world.notifyNeighborsRespectDebug(pos, getBlockType(), false);
351 363
             markBlockForUpdate();
352 364
         }
353 365
     }
@@ -603,13 +615,29 @@ public class TilePipe extends TileBase implements IConnectable, IPipeView, ITick
603 615
 
604 616
         stringList.add(info.toString());
605 617
 
618
+        int directions = 0;
619
+        int pDirections = 0;
620
+        for (PipeLogic.Direction direction : getLogic().getPressuredDirections()) {
621
+            pDirections |= 1 << direction.dir.ordinal();
622
+        }
623
+        for (PipeLogic.Direction direction : getLogic().getNonPressuredDirections()) {
624
+            directions |= 1 << direction.dir.ordinal();
625
+        }
626
+
606 627
         for (int i = 0; i <= 6; i++) {
607 628
             EnumFacing facing = SpaceUtils.getFacing(i);
608 629
             StringBuilder sideInfo = new StringBuilder();
609 630
 
610 631
             sideInfo.append(facing != null ? facing.name().charAt(0) : 'C');
611 632
             sideInfo.append(": ");
612
-            sideInfo.append(i < 6 && connects(facing) ? '+' : '-');
633
+            if (i < 6) {
634
+                sideInfo.append(connects(facing) ? '+' : '-');
635
+                sideInfo.append(
636
+                        (((pDirections) & (1 << facing.ordinal())) != 0) ? '>' :
637
+                                ((((directions) & (1 << facing.ordinal())) != 0) ? '+' : '-'));
638
+            } else {
639
+                sideInfo.append("--");
640
+            }
613 641
             sideInfo.append(" f" + fluid.tanks[i].type.name().charAt(0) + "(" + fluid.tanks[i].amount + ")");
614 642
             if (i < 6) {
615 643
                 sideInfo.append(" s" + shifterDistance[i]);

+ 0
- 1
src/main/java/pl/asie/charset/tools/wrench/ItemWrench.java View File

@@ -52,7 +52,6 @@ public class ItemWrench extends Item {
52 52
         return false;
53 53
     }
54 54
 
55
-    // TODO 1.11
56 55
     @net.minecraftforge.fml.common.Optional.Method(modid = "mcmultipart")
57 56
     public EnumActionResult tryRotateMultipart(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing targetFacing) {
58 57
         Optional<IMultipartContainer> uio = MultipartHelper.getContainer(worldIn, pos);

Loading…
Cancel
Save