use of com.lowdragmc.multiblocked.api.pattern.MultiblockState in project Multiblocked by Low-Drag-MC.
the class ControllerTileEntity method readState.
protected void readState(PacketBuffer buffer) {
if (buffer.readBoolean()) {
state = new MultiblockState(level, worldPosition);
state.setError(null);
int size = buffer.readVarInt();
if (size > 0) {
ImmutableList.Builder<BlockPos> listBuilder = new ImmutableList.Builder<>();
for (int i = size; i > 0; i--) {
listBuilder.add(BlockPos.of(buffer.readLong()));
}
MultiblockWorldSavedData.addDisableModel(state.controllerPos, listBuilder.build());
}
} else {
if (state != null) {
MultiblockWorldSavedData.removeDisableModel(state.controllerPos);
}
state = null;
}
}
use of com.lowdragmc.multiblocked.api.pattern.MultiblockState in project Multiblocked by Low-Drag-MC.
the class MultiblockWorldSavedData method addMapping.
public void addMapping(MultiblockState state) {
this.mapping.put(state.controllerPos, state);
for (BlockPos blockPos : state.getCache()) {
chunkPosMapping.computeIfAbsent(new ChunkPos(blockPos), c -> new HashSet<>()).add(state);
}
setDirty(true);
}
use of com.lowdragmc.multiblocked.api.pattern.MultiblockState in project Multiblocked by Low-Drag-MC.
the class PredicateAnyCapability method checkCapability.
private static boolean checkCapability(IO io, MultiblockCapability<?> capability, MultiblockState state) {
if (io != null) {
TileEntity tileEntity = state.getTileEntity();
if (tileEntity != null && capability.isBlockHasCapability(io, tileEntity)) {
Map<Long, EnumMap<IO, Set<MultiblockCapability<?>>>> capabilities = state.getMatchContext().getOrCreate("capabilities", Long2ObjectOpenHashMap::new);
capabilities.computeIfAbsent(state.getPos().asLong(), l -> new EnumMap<>(IO.class)).computeIfAbsent(io, x -> new HashSet<>()).add(capability);
return true;
}
}
state.setError(new PatternStringError(LocalizationUtils.format("multiblocked.pattern.error.capability", LocalizationUtils.format(capability.getUnlocalizedName()), io == null ? "NULL" : io.name())));
return false;
}
Aggregations