Merge remote-tracking branch 'origin/1.18' into 1.19.2
This commit is contained in:
commit
20b85f7567
|
|
@ -12,7 +12,9 @@ import net.minecraft.client.resources.model.BakedModel;
|
||||||
import net.minecraft.client.resources.model.SimpleBakedModel;
|
import net.minecraft.client.resources.model.SimpleBakedModel;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import org.embeddedt.modernfix.render.FastItemRenderType;
|
||||||
import org.embeddedt.modernfix.render.RenderState;
|
import org.embeddedt.modernfix.render.RenderState;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
@ -38,6 +40,17 @@ public abstract class ItemRendererMixin {
|
||||||
this.transformType = transformType;
|
this.transformType = transformType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Direction[] ITEM_DIRECTIONS = new Direction[] { Direction.SOUTH };
|
||||||
|
private static final Direction[] BLOCK_DIRECTIONS = new Direction[] { Direction.UP, Direction.EAST, Direction.NORTH };
|
||||||
|
|
||||||
|
private boolean isCorrectDirectionForType(FastItemRenderType type, Direction direction) {
|
||||||
|
if(type == FastItemRenderType.SIMPLE_ITEM)
|
||||||
|
return direction == Direction.SOUTH;
|
||||||
|
else {
|
||||||
|
return direction == Direction.UP || direction == Direction.EAST || direction == Direction.NORTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a model
|
* If a model
|
||||||
* - is a vanilla item model (SimpleBakedModel),
|
* - is a vanilla item model (SimpleBakedModel),
|
||||||
|
|
@ -48,25 +61,42 @@ public abstract class ItemRendererMixin {
|
||||||
*/
|
*/
|
||||||
@Inject(method = "renderModelLists", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "renderModelLists", at = @At("HEAD"), cancellable = true)
|
||||||
private void fasterItemRender(BakedModel model, ItemStack stack, int combinedLight, int combinedOverlay, PoseStack matrixStack, VertexConsumer buffer, CallbackInfo ci) {
|
private void fasterItemRender(BakedModel model, ItemStack stack, int combinedLight, int combinedOverlay, PoseStack matrixStack, VertexConsumer buffer, CallbackInfo ci) {
|
||||||
if(!RenderState.IS_RENDERING_LEVEL && !stack.isEmpty() && model.getClass() == SimpleBakedModel.class && transformType == ItemTransforms.TransformType.GUI && model.getTransforms().gui == ItemTransform.NO_TRANSFORM) {
|
if(!RenderState.IS_RENDERING_LEVEL && !stack.isEmpty() && model.getClass() == SimpleBakedModel.class && transformType == ItemTransforms.TransformType.GUI) {
|
||||||
|
FastItemRenderType type;
|
||||||
|
ItemTransform transform = model.getTransforms().gui;
|
||||||
|
if(transform == ItemTransform.NO_TRANSFORM)
|
||||||
|
type = FastItemRenderType.SIMPLE_ITEM;
|
||||||
|
else if(stack.getItem() instanceof BlockItem && isBlockTransforms(transform))
|
||||||
|
type = FastItemRenderType.SIMPLE_BLOCK;
|
||||||
|
else
|
||||||
|
return;
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
PoseStack.Pose pose = matrixStack.last();
|
PoseStack.Pose pose = matrixStack.last();
|
||||||
int[] combinedLights = new int[] {combinedLight, combinedLight, combinedLight, combinedLight};
|
int[] combinedLights = new int[] {combinedLight, combinedLight, combinedLight, combinedLight};
|
||||||
List<BakedQuad> culledFaces = model.getQuads(null, Direction.SOUTH, dummyRandom);
|
Direction[] directions = type == FastItemRenderType.SIMPLE_ITEM ? ITEM_DIRECTIONS : BLOCK_DIRECTIONS;
|
||||||
List<BakedQuad> unculledFaces = model.getQuads(null, null, dummyRandom);
|
for(Direction direction : directions) {
|
||||||
/* check size to avoid instantiating iterator when the list is empty */
|
List<BakedQuad> culledFaces = model.getQuads(null, direction, dummyRandom);
|
||||||
if(culledFaces.size() > 0) {
|
/* check size to avoid instantiating iterator when the list is empty */
|
||||||
for(BakedQuad quad : culledFaces) {
|
if(culledFaces.size() > 0) {
|
||||||
render2dItemFace(quad, stack, buffer, pose, combinedLights, combinedOverlay);
|
for(BakedQuad quad : culledFaces) {
|
||||||
|
render2dItemFace(quad, stack, buffer, pose, combinedLights, combinedOverlay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<BakedQuad> unculledFaces = model.getQuads(null, null, dummyRandom);
|
||||||
for(BakedQuad quad : unculledFaces) {
|
for(BakedQuad quad : unculledFaces) {
|
||||||
if(quad.getDirection() == Direction.SOUTH)
|
if(isCorrectDirectionForType(type, quad.getDirection()))
|
||||||
render2dItemFace(quad, stack, buffer, pose, combinedLights, combinedOverlay);
|
render2dItemFace(quad, stack, buffer, pose, combinedLights, combinedOverlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isBlockTransforms(ItemTransform transform) {
|
||||||
|
return transform.rotation.x() == 30f
|
||||||
|
&& transform.rotation.y() == 225f
|
||||||
|
&& transform.rotation.z() == 0f;
|
||||||
|
}
|
||||||
|
|
||||||
private void render2dItemFace(BakedQuad quad, ItemStack stack, VertexConsumer buffer, PoseStack.Pose pose, int[] combinedLights, int combinedOverlay) {
|
private void render2dItemFace(BakedQuad quad, ItemStack stack, VertexConsumer buffer, PoseStack.Pose pose, int[] combinedLights, int combinedOverlay) {
|
||||||
int i = -1;
|
int i = -1;
|
||||||
if (quad.isTinted()) {
|
if (quad.isTinted()) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package org.embeddedt.modernfix.render;
|
||||||
|
|
||||||
|
public enum FastItemRenderType {
|
||||||
|
SIMPLE_ITEM,
|
||||||
|
SIMPLE_BLOCK
|
||||||
|
}
|
||||||
|
|
@ -1,16 +1,19 @@
|
||||||
package org.embeddedt.modernfix.resources;
|
package org.embeddedt.modernfix.resources;
|
||||||
|
|
||||||
|
import com.google.common.base.Stopwatch;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.packs.PackType;
|
import net.minecraft.server.packs.PackType;
|
||||||
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
import org.embeddedt.modernfix.util.PackTypeHelper;
|
import org.embeddedt.modernfix.util.PackTypeHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
@ -26,6 +29,7 @@ public class PackResourcesCacheEngine {
|
||||||
private final Map<PackType, Set<String>> namespacesByType;
|
private final Map<PackType, Set<String>> namespacesByType;
|
||||||
private final Set<CachedResourcePath> containedPaths;
|
private final Set<CachedResourcePath> containedPaths;
|
||||||
private final EnumMap<PackType, Map<String, List<CachedResourcePath>>> resourceListings;
|
private final EnumMap<PackType, Map<String, List<CachedResourcePath>>> resourceListings;
|
||||||
|
private CompletableFuture<Void> cacheFuture;
|
||||||
|
|
||||||
public PackResourcesCacheEngine(Function<PackType, Set<String>> namespacesRetriever, BiFunction<PackType, String, Path> basePathRetriever) {
|
public PackResourcesCacheEngine(Function<PackType, Set<String>> namespacesRetriever, BiFunction<PackType, String, Path> basePathRetriever) {
|
||||||
this.namespacesByType = new EnumMap<>(PackType.class);
|
this.namespacesByType = new EnumMap<>(PackType.class);
|
||||||
|
|
@ -36,32 +40,50 @@ public class PackResourcesCacheEngine {
|
||||||
}
|
}
|
||||||
this.containedPaths = new ObjectOpenHashSet<>();
|
this.containedPaths = new ObjectOpenHashSet<>();
|
||||||
this.resourceListings = new EnumMap<>(PackType.class);
|
this.resourceListings = new EnumMap<>(PackType.class);
|
||||||
|
CompletableFuture<Void> future = CompletableFuture.completedFuture(null);
|
||||||
|
Stopwatch watch = Stopwatch.createStarted();
|
||||||
|
// used for log message
|
||||||
|
Path debugPath = basePathRetriever.apply(PackType.CLIENT_RESOURCES, "minecraft").toAbsolutePath();
|
||||||
for(PackType type : PackType.values()) {
|
for(PackType type : PackType.values()) {
|
||||||
Collection<String> namespaces = PackTypeHelper.isVanillaPackType(type) ? this.namespacesByType.get(type) : namespacesRetriever.apply(type);
|
Collection<String> namespaces = PackTypeHelper.isVanillaPackType(type) ? this.namespacesByType.get(type) : namespacesRetriever.apply(type);
|
||||||
ImmutableMap.Builder<String, List<CachedResourcePath>> packTypedMap = ImmutableMap.builder();
|
future = future.thenRunAsync(() -> {
|
||||||
for(String namespace : namespaces) {
|
ImmutableMap.Builder<String, List<CachedResourcePath>> packTypedMap = ImmutableMap.builder();
|
||||||
try {
|
for(String namespace : namespaces) {
|
||||||
ImmutableList.Builder<CachedResourcePath> namespacedList = ImmutableList.builder();
|
try {
|
||||||
Path root = basePathRetriever.apply(type, namespace).toAbsolutePath();
|
ImmutableList.Builder<CachedResourcePath> namespacedList = ImmutableList.builder();
|
||||||
String[] prefix = new String[] { type.getDirectory(), namespace };
|
Path root = basePathRetriever.apply(type, namespace).toAbsolutePath();
|
||||||
try (Stream<Path> stream = Files.walk(root)) {
|
String[] prefix = new String[] { type.getDirectory(), namespace };
|
||||||
stream
|
try (Stream<Path> stream = Files.walk(root)) {
|
||||||
.map(path -> root.relativize(path.toAbsolutePath()))
|
stream
|
||||||
.filter(PackResourcesCacheEngine::isValidCachedResourcePath)
|
.map(path -> root.relativize(path.toAbsolutePath()))
|
||||||
.forEach(path -> {
|
.filter(PackResourcesCacheEngine::isValidCachedResourcePath)
|
||||||
CachedResourcePath cachedPath = new CachedResourcePath(prefix, path);
|
.forEach(path -> {
|
||||||
this.containedPaths.add(cachedPath);
|
CachedResourcePath cachedPath = new CachedResourcePath(prefix, path);
|
||||||
if(!cachedPath.getFileName().endsWith(".mcmeta"))
|
synchronized (this.containedPaths) {
|
||||||
namespacedList.add(cachedPath);
|
this.containedPaths.add(cachedPath);
|
||||||
});
|
}
|
||||||
|
if(!cachedPath.getFileName().endsWith(".mcmeta"))
|
||||||
|
namespacedList.add(cachedPath);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
packTypedMap.put(namespace, namespacedList.build());
|
||||||
|
} catch(IOException ignored) {
|
||||||
}
|
}
|
||||||
packTypedMap.put(namespace, namespacedList.build());
|
|
||||||
} catch(IOException ignored) {
|
|
||||||
}
|
}
|
||||||
}
|
synchronized (this.resourceListings) {
|
||||||
this.resourceListings.put(type, packTypedMap.build());
|
this.resourceListings.put(type, packTypedMap.build());
|
||||||
|
}
|
||||||
|
}, ModernFix.resourceReloadExecutor());
|
||||||
}
|
}
|
||||||
((ObjectOpenHashSet<CachedResourcePath>)this.containedPaths).trim();
|
future = future.thenRunAsync(() -> {
|
||||||
|
((ObjectOpenHashSet<CachedResourcePath>)this.containedPaths).trim();
|
||||||
|
watch.stop();
|
||||||
|
}, ModernFix.resourceReloadExecutor());
|
||||||
|
this.cacheFuture = future;
|
||||||
|
// print debug message in separate task to prevent slowing down rest of load
|
||||||
|
future.thenRunAsync(() -> {
|
||||||
|
ModernFix.LOGGER.debug("Generated cache for {} in {}", debugPath, watch);
|
||||||
|
}, ModernFix.resourceReloadExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isValidCachedResourcePath(Path path) {
|
private static boolean isValidCachedResourcePath(Path path) {
|
||||||
|
|
@ -86,13 +108,22 @@ public class PackResourcesCacheEngine {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void awaitLoad() {
|
||||||
|
if(this.cacheFuture != null) {
|
||||||
|
this.cacheFuture.join();
|
||||||
|
this.cacheFuture = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasResource(String path) {
|
public boolean hasResource(String path) {
|
||||||
|
awaitLoad();
|
||||||
return this.containedPaths.contains(new CachedResourcePath(path));
|
return this.containedPaths.contains(new CachedResourcePath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ResourceLocation> getResources(PackType type, String resourceNamespace, String pathIn, int maxDepth, Predicate<ResourceLocation> filter) {
|
public Collection<ResourceLocation> getResources(PackType type, String resourceNamespace, String pathIn, int maxDepth, Predicate<ResourceLocation> filter) {
|
||||||
if(!PackTypeHelper.isVanillaPackType(type))
|
if(!PackTypeHelper.isVanillaPackType(type))
|
||||||
throw new IllegalArgumentException("Only vanilla PackTypes are supported");
|
throw new IllegalArgumentException("Only vanilla PackTypes are supported");
|
||||||
|
awaitLoad();
|
||||||
List<CachedResourcePath> paths = resourceListings.get(type).getOrDefault(resourceNamespace, Collections.emptyList());
|
List<CachedResourcePath> paths = resourceListings.get(type).getOrDefault(resourceNamespace, Collections.emptyList());
|
||||||
if(paths.isEmpty())
|
if(paths.isEmpty())
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user