Merge remote-tracking branch 'origin/main' into 1.18

This commit is contained in:
embeddedt 2023-04-16 14:39:23 -04:00
commit 3a15e5c6bc
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 27 additions and 5 deletions

View File

@ -32,12 +32,18 @@ import team.chisel.ctm.client.model.AbstractCTMBakedModel;
import team.chisel.ctm.client.util.CTMPackReloadListener;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
@Mixin(CTMPackReloadListener.class)
public abstract class CTMPackReloadListenerMixin {
/* caches the original render checks */
@Shadow @Final private static Map<IRegistryDelegate<Block>, Predicate<RenderType>> blockRenderChecks;
private static Map<IRegistryDelegate<Block>, Predicate<RenderType>> renderCheckOverrides = new ConcurrentHashMap<>();
private static Predicate<RenderType> DEFAULT_PREDICATE = type -> type == RenderType.solid();
@Shadow protected abstract Predicate<RenderType> getLayerCheck(BlockState state, BakedModel model);
@Shadow protected abstract Predicate<RenderType> getExistingRenderCheck(Block block);
@ -49,8 +55,23 @@ public abstract class CTMPackReloadListenerMixin {
@Overwrite(remap = false)
private void refreshLayerHacks() {
blockRenderChecks.forEach((b, p) -> ItemBlockRenderTypes.setRenderLayer((Block) b.get(), p));
blockRenderChecks.clear();
renderCheckOverrides.clear();
if(blockRenderChecks.isEmpty()) {
for(Block block : ForgeRegistries.BLOCKS.getValues()) {
Predicate<RenderType> original = this.getExistingRenderCheck(block);
if(original == null)
original = DEFAULT_PREDICATE;
blockRenderChecks.put(block.delegate, original);
ItemBlockRenderTypes.setRenderLayer(block, type -> this.useOverrideIfPresent(block.delegate, type));
}
}
}
private boolean useOverrideIfPresent(IRegistryDelegate<Block> delegate, RenderType type) {
Predicate<RenderType> override = renderCheckOverrides.get(delegate);
if(override == null)
override = blockRenderChecks.get(delegate);
return override.test(type);
}
private void onModelBake(DynamicModelBakeEvent event) {
@ -58,7 +79,7 @@ public abstract class CTMPackReloadListenerMixin {
return;
/* we construct a new ResourceLocation because an MRL is coming in */
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(event.getLocation().getNamespace(), event.getLocation().getPath()));
if(block == null || block == Blocks.AIR || blockRenderChecks.containsKey(block.delegate))
if(block == null || block == Blocks.AIR || renderCheckOverrides.containsKey(block.delegate))
return;
/* find all states that match this MRL */
ImmutableList<BlockState> allStates;
@ -71,8 +92,7 @@ public abstract class CTMPackReloadListenerMixin {
for(BlockState state : allStates) {
Predicate<RenderType> newPredicate = this.getLayerCheck(state, event.getModel());
if(newPredicate != null) {
blockRenderChecks.put(block.delegate, this.getExistingRenderCheck(block));
ItemBlockRenderTypes.setRenderLayer(block, newPredicate);
renderCheckOverrides.put(block.delegate, newPredicate);
return;
}
}

View File

@ -95,6 +95,8 @@ public abstract class PathResourcePackMixin {
if(path.getFileName() == null || path.getNameCount() == 0)
return false;
String str = path.toString();
if(str.length() == 0)
return false;
for(int i = 0; i < str.length(); i++) {
if(!ResourceLocation.validPathChar(str.charAt(i))) {
return false;