use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.
the class MultiblockState method onBlockStateChanged.
public void onBlockStateChanged(BlockPos pos) {
if (pos.equals(controllerPos)) {
if (this.getMatchContext().containsKey("renderMask")) {
MultiblockedNetworking.sendToAll(new SPacketRemoveDisabledRendering(controllerPos));
}
if (lastController != null) {
lastController.onStructureInvalid();
}
MultiblockWorldSavedData mbds = MultiblockWorldSavedData.getOrCreate(world);
mbds.removeMapping(this);
mbds.removeLoading(controllerPos);
} else if (error != UNLOAD_ERROR) {
ControllerTileEntity controller = getController();
if (controller != null && !controller.checkPattern()) {
controller.onStructureInvalid();
MultiblockWorldSavedData.getOrCreate(world).removeMapping(this);
}
}
}
use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.
the class ControllerTileEntity method load.
@Override
public void load(@Nonnull BlockState blockState, @Nonnull CompoundNBT compound) {
try {
super.load(blockState, compound);
} catch (Exception e) {
if (definition == null) {
MultiblockWorldSavedData mwsd = MultiblockWorldSavedData.getOrCreate(level);
if (worldPosition != null && mwsd.mapping.containsKey(worldPosition)) {
mwsd.removeMapping(mwsd.mapping.get(worldPosition));
}
return;
}
}
if (compound.contains("ars")) {
asyncRecipeSearching = compound.getBoolean("ars");
}
if (compound.contains("recipeLogic")) {
recipeLogic = new RecipeLogic(this);
recipeLogic.readFromNBT(compound.getCompound("recipeLogic"));
status = recipeLogic.getStatus().name;
}
if (compound.contains("capabilities")) {
ListNBT tagList = compound.getList("capabilities", Constants.NBT.TAG_COMPOUND);
settings = new HashMap<>();
for (INBT base : tagList) {
CompoundNBT tag = (CompoundNBT) base;
settings.computeIfAbsent(tag.getLong("pos"), l -> new HashMap<>()).put(MbdCapabilities.get(tag.getString("cap")), new Tuple<>(IO.VALUES[tag.getInt("io")], Direction.values()[tag.getInt("facing")]));
}
}
}
use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.
the class ControllerTileTesterEntity method setLevelAndPosition.
@Override
public void setLevelAndPosition(@Nonnull World world, @Nonnull BlockPos pos) {
MultiblockWorldSavedData mwsd = MultiblockWorldSavedData.getOrCreate(world);
if (mwsd.mapping.containsKey(pos)) {
mwsd.removeMapping(mwsd.mapping.get(pos));
}
super.setLevelAndPosition(world, pos);
}
use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.
the class WorldMixin method afterUpdatingEntities.
@Inject(method = "tickBlockEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/IProfiler;pop()V", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD)
private void afterUpdatingEntities(CallbackInfo ci, IProfiler iprofiler) {
iprofiler.popPush("multiblocked_update");
if (!((World) (Object) this).isClientSide) {
List<ComponentTileEntity<?>> isRemoved = null;
MultiblockWorldSavedData mbds = MultiblockWorldSavedData.getOrCreate((World) (Object) this);
for (ComponentTileEntity<?> loading : mbds.getLoadings()) {
if (loading.isRemoved()) {
if (isRemoved == null) {
isRemoved = new ArrayList<>();
}
isRemoved.add(loading);
} else {
loading.update();
}
}
if (isRemoved != null) {
for (ComponentTileEntity<?> inValid : isRemoved) {
mbds.removeLoading(inValid.getBlockPos());
}
}
}
}
use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.
the class ControllerTileTesterEntity method setDefinition.
public void setDefinition(ControllerDefinition definition) {
if (level != null) {
MultiblockWorldSavedData mwsd = MultiblockWorldSavedData.getOrCreate(level);
state = null;
if (worldPosition != null && mwsd.mapping.containsKey(worldPosition)) {
mwsd.removeMapping(mwsd.mapping.get(worldPosition));
}
if (definition == null) {
this.definition = DEFAULT_DEFINITION;
} else if (definition != DEFAULT_DEFINITION) {
this.definition = definition;
if (isRemote()) {
scheduleChunkForRenderUpdate();
} else {
notifyBlockUpdate();
if (needAlwaysUpdate()) {
MultiblockWorldSavedData.getOrCreate(level).addLoading(this);
}
}
}
initTrait();
}
}
Aggregations