Skip to content

Commit 14ab5bd

Browse files
committed
Fixes some cap issues, remove unneeded tag handler on tunnel walls
1 parent 71ffee4 commit 14ab5bd

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import net.minecraft.core.BlockPos;
1616
import net.minecraft.core.Direction;
1717
import net.minecraft.nbt.CompoundTag;
18-
import net.minecraft.network.Connection;
19-
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
2018
import net.minecraft.server.MinecraftServer;
2119
import net.minecraft.server.level.ServerLevel;
2220
import net.minecraft.world.level.ChunkPos;
@@ -33,12 +31,12 @@
3331

3432
public class CompactMachineBlockEntity extends BlockEntity implements ICapabilityProvider {
3533
public int machineId = -1;
36-
private final boolean initialized = false;
3734
public long nextSpawnTick = 0;
3835

3936
protected UUID owner;
4037
protected String schema;
4138
protected boolean locked = false;
39+
private ChunkPos roomChunk;
4240
private LazyOptional<IMachineRoom> room = LazyOptional.empty();
4341

4442
public CompactMachineBlockEntity(BlockPos pos, BlockState state) {
@@ -51,8 +49,7 @@ public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable D
5149
if (cap == Capabilities.ROOM) return room.cast();
5250

5351
if(level instanceof ServerLevel sl) {
54-
return room.map(r -> {
55-
var roomId = r.getChunk();
52+
return getInternalChunkPos().map(roomId -> {
5653
try {
5754
final var serv = sl.getServer();
5855

@@ -165,6 +162,9 @@ public CompoundTag getUpdateTag() {
165162

166163
public Optional<ChunkPos> getInternalChunkPos() {
167164
if (level instanceof ServerLevel) {
165+
if(roomChunk != null)
166+
return Optional.of(roomChunk);
167+
168168
MinecraftServer serv = level.getServer();
169169
if (serv == null)
170170
return Optional.empty();
@@ -173,7 +173,9 @@ public Optional<ChunkPos> getInternalChunkPos() {
173173
if (connections == null)
174174
return Optional.empty();
175175

176-
return connections.getConnectedRoom(this.machineId);
176+
var chunk = connections.getConnectedRoom(this.machineId);
177+
chunk.ifPresent(c -> this.roomChunk = c);
178+
return chunk;
177179
}
178180

179181
return Optional.empty();
@@ -194,16 +196,6 @@ public void handleUpdateTag(CompoundTag tag) {
194196
owner = tag.getUUID("owner");
195197
}
196198

197-
@Override
198-
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
199-
BlockState state = null;
200-
if (this.level != null) {
201-
state = this.level.getBlockState(worldPosition);
202-
}
203-
204-
super.onDataPacket(net, pkt);
205-
}
206-
207199
public Optional<UUID> getOwnerUUID() {
208200
return Optional.ofNullable(this.owner);
209201
}
@@ -215,6 +207,7 @@ public void setOwner(UUID owner) {
215207
public void setMachineId(int id) {
216208
this.machineId = id;
217209
this.room.invalidate();
210+
this.roomChunk = null;
218211
this.setChanged();
219212
}
220213

0 commit comments

Comments
 (0)