Merge remote-tracking branch 'origin/main' into 1.18
This commit is contained in:
commit
fa9ac8c8ab
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,6 +3,7 @@ run
|
|||
libs
|
||||
media
|
||||
classes/
|
||||
.architectury-transformer/
|
||||
|
||||
# Changelog
|
||||
CHANGELOG.md
|
||||
|
|
|
|||
|
|
@ -2,18 +2,21 @@ package org.embeddedt.modernfix.dynamicresources;
|
|||
|
||||
import com.mojang.math.Transformation;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||
import net.minecraft.client.resources.model.BuiltInModel;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -22,7 +25,47 @@ public class DynamicBakedModelProvider implements Map<ResourceLocation, BakedMod
|
|||
private final Map<Triple<ResourceLocation, Transformation, Boolean>, BakedModel> bakedCache;
|
||||
private final Map<ResourceLocation, BakedModel> permanentOverrides;
|
||||
private BakedModel missingModel;
|
||||
private static final BakedModel SENTINEL = new BuiltInModel(null, null, null, false);
|
||||
private static final BakedModel SENTINEL = new BakedModel() {
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockLight() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomRenderer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemTransforms getTransforms() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrides getOverrides() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
public DynamicBakedModelProvider(ModelBakery bakery, Map<Triple<ResourceLocation, Transformation, Boolean>, BakedModel> cache) {
|
||||
this.bakery = bakery;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ import net.fabricmc.api.ClientModInitializer;
|
|||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class ModernFixClientFabric implements ClientModInitializer {
|
||||
public static ModernFixClient commonMod;
|
||||
|
|
@ -13,7 +16,16 @@ public class ModernFixClientFabric implements ClientModInitializer {
|
|||
commonMod = new ModernFixClient();
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register((mc) -> commonMod.onRenderTickEnd());
|
||||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> commonMod.onScreenOpening(screen));
|
||||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
||||
AtomicBoolean hasOpened = new AtomicBoolean(false);
|
||||
ScreenEvents.beforeTick(screen).register(screen1 -> {
|
||||
if(Minecraft.getInstance().getOverlay() != null)
|
||||
return;
|
||||
if(!hasOpened.getAndSet(true)) {
|
||||
commonMod.onScreenOpening(screen1);
|
||||
}
|
||||
});
|
||||
});
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||
commonMod.onServerStarted(server);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ import org.spongepowered.asm.mixin.Mutable;
|
|||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
|
|
@ -60,8 +60,6 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
|||
|
||||
@Shadow @Final public static ModelResourceLocation MISSING_MODEL_LOCATION;
|
||||
|
||||
@Shadow protected abstract BlockModel loadBlockModel(ResourceLocation location) throws IOException;
|
||||
|
||||
@Shadow @Final protected ResourceManager resourceManager;
|
||||
@Shadow private AtlasSet atlasSet;
|
||||
@Shadow @Final private Set<ResourceLocation> loadingStack;
|
||||
|
|
@ -132,12 +130,12 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
|||
private Set<ResourceLocation> blockStateFiles;
|
||||
private Set<ResourceLocation> modelFiles;
|
||||
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ModelBakery;loadBlockModel(Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/renderer/block/model/BlockModel;", ordinal = 0))
|
||||
private BlockModel captureMissingModel(ModelBakery bakery, ResourceLocation location) throws IOException {
|
||||
this.missingModel = this.loadBlockModel(location);
|
||||
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", ordinal = 0), index = 1)
|
||||
private Object captureMissingModel(Object model) {
|
||||
this.missingModel = (UnbakedModel)model;
|
||||
this.blockStateFiles = new HashSet<>();
|
||||
this.modelFiles = new HashSet<>();
|
||||
return (BlockModel)this.missingModel;
|
||||
return this.missingModel;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -147,6 +145,8 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
|||
*/
|
||||
@Inject(method = "loadTopLevel", at = @At("HEAD"), cancellable = true)
|
||||
private void addTopLevelFile(ModelResourceLocation location, CallbackInfo ci) {
|
||||
if(location == MISSING_MODEL_LOCATION)
|
||||
return; /* needed for FAPI compat */
|
||||
ci.cancel();
|
||||
if(Objects.equals(location.getVariant(), "inventory")) {
|
||||
modelFiles.add(new ResourceLocation(location.getNamespace(), "item/" + location.getPath()));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user