Skip to content

Commit e7a3015

Browse files
committed
Change item tunnel back to item instead of item_in
1 parent d7674a5 commit e7a3015

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

src/main/java/dev/compactmods/machines/core/Tunnels.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static TunnelDefinition getDefinition(ResourceLocation id) {
6161
// ================================================================================================================
6262
// TUNNEL TYPE DEFINITIONS
6363
// ================================================================================================================
64-
public static final RegistryObject<TunnelDefinition> ITEM_IN_DEF = DEFINITIONS.register("item_in", ItemTunnel::new);
64+
public static final RegistryObject<TunnelDefinition> ITEM_TUNNEL_DEF = DEFINITIONS.register("item", ItemTunnel::new);
6565

6666
// ================================================================================================================
6767
// TUNNEL BLOCKS / TILES

src/main/java/dev/compactmods/machines/machine/CompactMachineBlockEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable D
7171
throw new MissingDimensionException();
7272

7373
if(compact.getBlockEntity(firstSupported.get()) instanceof TunnelWallEntity tunnel) {
74-
return tunnel.getCapability(cap, side);
74+
return tunnel.getTunnelCapability(cap, side);
7575
} else {
7676
return super.getCapability(cap, side);
7777
}

src/main/java/dev/compactmods/machines/tunnel/TunnelWallEntity.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,28 @@ public void onLoad() {
150150
}
151151
}
152152

153+
@Nonnull
154+
public <T> LazyOptional<T> getTunnelCapability(@Nonnull Capability<T> cap, @Nullable Direction outerSide) {
155+
if (level == null || level.isClientSide)
156+
return LazyOptional.empty();
157+
158+
if (outerSide != null && outerSide != getConnectedSide())
159+
return LazyOptional.empty();
160+
161+
if (tunnelType instanceof ITunnelCapabilityProvider c) {
162+
return c.getCapability(cap, tunnel);
163+
}
164+
165+
return LazyOptional.empty();
166+
}
167+
153168
@Nonnull
154169
@Override
155170
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
156171
if (level == null || level.isClientSide)
157172
return super.getCapability(cap, side);
158173

159-
if (side != null && side != getConnectedSide())
174+
if (side != null && side != getTunnelSide())
160175
return super.getCapability(cap, side);
161176

162177
if (cap == Capabilities.TUNNEL_CONNECTION)

src/main/java/dev/compactmods/machines/tunnel/definitions/ItemStorage.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.compactmods.machines.tunnel.definitions;
22

33
import dev.compactmods.machines.api.tunnels.ITunnel;
4-
import net.minecraft.core.Direction;
54
import net.minecraft.nbt.CompoundTag;
65
import net.minecraftforge.common.util.INBTSerializable;
76
import net.minecraftforge.common.util.LazyOptional;
@@ -12,13 +11,11 @@
1211

1312
public class ItemStorage implements ITunnel, INBTSerializable<CompoundTag> {
1413

15-
Direction side;
1614
private final LazyOptional<IItemHandler> laze;
1715
final ItemStackHandler handler;
1816

19-
public ItemStorage(int buffer, Direction side) {
17+
public ItemStorage(int buffer) {
2018
this.handler = new ItemStackHandler(buffer);
21-
this.side = side;
2219
this.laze = LazyOptional.of(this::getItems);
2320
}
2421

@@ -34,14 +31,12 @@ public <CapType> LazyOptional<CapType> lazy() {
3431
@Override
3532
public CompoundTag serializeNBT() {
3633
CompoundTag tag = new CompoundTag();
37-
tag.putString("side", side.getSerializedName());
3834
tag.put("items", handler.serializeNBT());
3935
return tag;
4036
}
4137

4238
@Override
4339
public void deserializeNBT(CompoundTag nbt) {
44-
this.side = Direction.byName(nbt.getString("side"));
4540
handler.deserializeNBT(nbt.getCompound("items"));
4641
}
4742
}

src/main/java/dev/compactmods/machines/tunnel/definitions/ItemTunnel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public int getTunnelIndicatorColor() {
3535
*/
3636
@Override
3737
public ITunnel newInstance(BlockPos pos, Direction side) {
38-
return new ItemStorage(10, side);
38+
return new ItemStorage(10);
3939
}
4040

4141
@Override

src/test/java/dev/compactmods/machines/test/tunnel/TunnelGraphTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public static void canRegisterTunnel(final GameTestHelper test) {
7272
public static void canFetchSupportingTunnelsOnSide(final GameTestHelper test) {
7373
var graph = new TunnelConnectionGraph();
7474

75-
graph.registerTunnel(BlockPos.ZERO, Tunnels.ITEM_IN_DEF.get(), 1, Direction.NORTH);
76-
graph.registerTunnel(BlockPos.ZERO.above(), Tunnels.ITEM_IN_DEF.get(), 1, Direction.SOUTH);
75+
graph.registerTunnel(BlockPos.ZERO, Tunnels.ITEM_TUNNEL_DEF.get(), 1, Direction.NORTH);
76+
graph.registerTunnel(BlockPos.ZERO.above(), Tunnels.ITEM_TUNNEL_DEF.get(), 1, Direction.SOUTH);
7777
graph.registerTunnel(BlockPos.ZERO.below(), Tunnels.UNKNOWN.get(), 1, Direction.NORTH);
7878

7979
final var positions = graph.getTunnelsSupporting(1, Direction.NORTH, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
@@ -93,8 +93,8 @@ public static void canFetchSidedTypes(final GameTestHelper test) {
9393
var graph = new TunnelConnectionGraph();
9494

9595
// Register three tunnels - two types on the north side (different positions), one on south
96-
graph.registerTunnel(BlockPos.ZERO, Tunnels.ITEM_IN_DEF.get(), 1, Direction.NORTH);
97-
graph.registerTunnel(BlockPos.ZERO.above(), Tunnels.ITEM_IN_DEF.get(), 1, Direction.SOUTH);
96+
graph.registerTunnel(BlockPos.ZERO, Tunnels.ITEM_TUNNEL_DEF.get(), 1, Direction.NORTH);
97+
graph.registerTunnel(BlockPos.ZERO.above(), Tunnels.ITEM_TUNNEL_DEF.get(), 1, Direction.SOUTH);
9898
graph.registerTunnel(BlockPos.ZERO.below(), Tunnels.UNKNOWN.get(), 1, Direction.NORTH);
9999

100100
final var positions = graph.getTypesForSide(1, Direction.NORTH)

src/test/java/dev/compactmods/machines/test/tunnel/TunnelTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private static void sidedTunnelTest(Direction dir, GameTestHelper t) {
132132
});
133133

134134
ItemStack tunnelStack = new ItemStack(Tunnels.ITEM_TUNNEL.get(), 1);
135-
TunnelItem.setTunnelType(tunnelStack, Tunnels.ITEM_IN_DEF.get());
135+
TunnelItem.setTunnelType(tunnelStack, Tunnels.ITEM_TUNNEL_DEF.get());
136136

137137
playerInRoom.setItemInHand(InteractionHand.MAIN_HAND, tunnelStack);
138138

@@ -160,7 +160,7 @@ private static void sidedTunnelTest(Direction dir, GameTestHelper t) {
160160
final var roomTunnels = RoomTunnelData.get(serv, TESTING_ROOM);
161161
final var graph = roomTunnels.getGraph();
162162

163-
var placed = graph.getMachineTunnels(machine, Tunnels.ITEM_IN_DEF.get())
163+
var placed = graph.getMachineTunnels(machine, Tunnels.ITEM_TUNNEL_DEF.get())
164164
.collect(Collectors.toSet());
165165

166166
if (placed.size() != 1)

0 commit comments

Comments
 (0)