Skip to content

Commit

Permalink
Avoid server-side deadlock when Starlight is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
hlysine committed Aug 3, 2024
1 parent f7d7e8a commit b581c45
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum Mods {
DIAGONAL_FENCES("diagonalfences"),
DIAGONAL_WALLS("diagonalwalls"),
ATHENA("athena"),
INDIUM("indium");
INDIUM("indium"),
STARLIGHT("starlight");

public final String id;
public final boolean isLoaded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.jozufozu.flywheel.config.BackendType;
import com.simibubi.create.content.kinetics.base.flwdata.RotatingData;
import com.simibubi.create.foundation.render.AllMaterialSpecs;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;

import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.copycatsplus.copycats.foundation.copycat.model.kinetic;

import com.copycatsplus.copycats.config.CCConfigs;
import com.copycatsplus.copycats.foundation.copycat.ICopycatBlockEntity;
import com.copycatsplus.copycats.foundation.copycat.multistate.IMultiStateCopycatBlockEntity;
import com.copycatsplus.copycats.utility.ChatUtils;
Expand All @@ -16,7 +15,8 @@
* @param state The state of the partial model. Should only contain states required by the partial model.
* @param material The material of the copycat.
*/
public record KineticCopycatRenderData(ICopycatPartialModel partialModel, PartialModelState state, BlockState material) {
public record KineticCopycatRenderData(ICopycatPartialModel partialModel, PartialModelState state,
BlockState material) {
/**
* Create a new render data object from the given partial model rendered by the given block entity.
*
Expand Down Expand Up @@ -44,14 +44,12 @@ public static KineticCopycatRenderData of(ICopycatPartialModel partialModel, IMu
}

private static KineticCopycatRenderData of(ICopycatPartialModel partialModel, ICopycatBlockEntity be, BlockState material) {
if (!CCConfigs.client().disableGraphicsWarnings.get()) {
if (Backend.getBackendType() != BackendType.INSTANCING &&
Minecraft.getInstance().getBlockColors().getColor(material, null, null, 0) != -1) {
ChatUtils.sendWarningOnce(
"flywheel_block_color",
"Block colors may be incorrect due to the current Flywheel rendering backend. Please switch to the instancing backend to fix this."
);
}
if (Backend.getBackendType() != BackendType.INSTANCING &&
Minecraft.getInstance().getBlockColors().getColor(material, null, null, 0) != -1) {
ChatUtils.sendWarningOnce(
"flywheel_block_color",
"Block colors may be incorrect due to the current Flywheel rendering backend. Please switch to the instancing backend to fix this."
);
}
return new KineticCopycatRenderData(partialModel, PartialModelState.fromBlockState(be.getBlockState(), partialModel.getProperties()), material);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.copycatsplus.copycats.utility;

import com.copycatsplus.copycats.compat.Mods;
import com.copycatsplus.copycats.mixin.foundation.copycat.ChunkAccessAccessor;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.apache.logging.log4j.core.jmx.Server;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
Expand Down Expand Up @@ -47,6 +46,10 @@ public static void requestModelDataUpdate(BlockEntity blockEntity) {
*/
@Nullable
public static BlockEntity getBlockEntityCrossThread(BlockGetter reader, BlockPos targetPos) {
if (Mods.STARLIGHT.getLoaded()) {
ChatUtils.sendWarningOnce("starlight_deadlock", "Starlight is incompatible with Copycats+ due to a deadlock during lighting computation. Please remove Starlight to restore light emission in copycats.");
return null;
}
try {
if (reader instanceof Level level) {
ChunkAccessAccessor chunkAccess = (ChunkAccessAccessor) level.getChunk(targetPos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package com.copycatsplus.copycats.utility;

import com.copycatsplus.copycats.Copycats;
import com.copycatsplus.copycats.config.CCConfigs;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;

import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;

public class ChatUtils {
public static Set<String> messages = new HashSet<>();

private static final Supplier<Boolean> disableWarnings = CCConfigs.safeGetter(() -> CCConfigs.client().disableGraphicsWarnings.get(), false);

/**
* Send a local warning message to the player once.
*
* @param id Unique identifier for the message. Messages with the same id will only be sent once.
* @param message The message to send.
*/
public static void sendWarningOnce(String id, String message) {
if (Minecraft.getInstance().player == null) return;
if (CCConfigs.client().disableGraphicsWarnings.get()) return;
if (disableWarnings.get()) return;
if (messages.contains(id)) return;
messages.add(id);
Minecraft.getInstance().player.sendSystemMessage(Component.literal("Warning: " + message));
if (!Platform.Environment.CLIENT.isCurrent() || !ClientUtils.sendSystemMessage("Warning: " + message)) {
Copycats.LOGGER.warn("Warning: {}", message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.copycatsplus.copycats.utility;

import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;

/**
* This class should only be accessed on the client side.
* It is not marked as client-only itself to avoid class loading issues.
*/
public class ClientUtils {
public static boolean sendSystemMessage(String message) {
if (Minecraft.getInstance().player == null) {
return false;
}
Minecraft.getInstance().player.sendSystemMessage(Component.literal(message));
return true;
}
}
1 change: 1 addition & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
modImplementation("curse.maven:additional-placements-674852:${additionalplacements_forge_curse_id}")
modImplementation("curse.maven:athena-841890:${athena_forge_curse_id}")
modLocalRuntime("curse.maven:create-industry-693815:${tfmg_forge_curse_id}")
modLocalRuntime("curse.maven:starlight-forge-526854:4631193")
// modLocalRuntime("curse.maven:create-extended-cogs-739973:${extended_cogwheels_forge_curse_id}")

modCompileOnly("curse.maven:double-slabs-350179:${double_slabs_curse_id}")
Expand Down

0 comments on commit b581c45

Please sign in to comment.