Skip to content

Commit

Permalink
WIP - Port to 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
PepperCode1 committed Jul 13, 2023
1 parent 3fe7a74 commit 23dbade
Show file tree
Hide file tree
Showing 75 changed files with 1,072 additions and 1,229 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ dependencies {
// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation('com.terraformersmc:modmenu:4.0.4') {
modImplementation('com.terraformersmc:modmenu:5.0.2') {
exclude group: 'net.fabricmc.fabric-api'
}

modCompileOnly 'maven.modrinth:sodium:mc1.19-0.4.2'
modCompileOnly 'maven.modrinth:indium:1.0.7+mc1.19'
modCompileOnly 'io.vram:frex-fabric-mc119:6.0.278'
modCompileOnly 'io.vram:canvas-fabric-mc119:1.0.2453'
modCompileOnly 'maven.modrinth:sodium:mc1.19.3-0.4.9'
modCompileOnly 'maven.modrinth:indium:1.0.12+mc1.19.3'
modCompileOnly 'io.vram:frex-fabric-mc119:6.1.305'
modCompileOnly 'io.vram:canvas-fabric-mc119:1.0.2503'
}

String getExtraBuildMetadata() {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs = -Xmx1G

# Fabric Properties
loom_version = 1.1-SNAPSHOT
minecraft_version = 1.19
yarn_mappings = 1.19+build.4
minecraft_version = 1.19.3
yarn_mappings = 1.19.3+build.5
loader_version = 0.14.13

# Mod Properties
mod_version = 2.0.2
mod_minecraft_version = 1.19
mod_version = 3.0.0-beta.2
mod_minecraft_version = 1.19.3
maven_group = me.pepperbell
archives_base_name = continuity

# Dependencies
fabric_version = 0.58.0+1.19
fabric_version = 0.71.0+1.19.3
14 changes: 1 addition & 13 deletions src/main/java/me/pepperbell/continuity/api/client/CTMLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,5 @@ public interface CTMLoader<T extends CTMProperties> {

QuadProcessorFactory<T> getProcessorFactory();

static <T extends CTMProperties> CTMLoader<T> of(CTMPropertiesFactory<T> propertiesFactory, QuadProcessorFactory<T> processorFactory) {
return new CTMLoader<T>() {
@Override
public CTMPropertiesFactory<T> getPropertiesFactory() {
return propertiesFactory;
}

@Override
public QuadProcessorFactory<T> getProcessorFactory() {
return processorFactory;
}
};
}
CachingPredicatesFactory<T> getPredicatesFactory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,8 @@

import java.util.Collection;

import net.minecraft.block.BlockState;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.util.Identifier;

public interface CTMProperties extends Comparable<CTMProperties> {
boolean affectsTextures();

boolean affectsTexture(Identifier id);

boolean affectsBlockStates();

boolean affectsBlockState(BlockState state);

Collection<SpriteIdentifier> getTextureDependencies();

default boolean isValidForMultipass() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import org.jetbrains.annotations.Nullable;

import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourcePack;
import net.minecraft.util.Identifier;

public interface CTMPropertiesFactory<T extends CTMProperties> {
@Nullable
T createProperties(Properties properties, Identifier id, String packName, int packPriority, String method);
T createProperties(Properties properties, Identifier id, ResourcePack pack, int packPriority, ResourceManager resourceManager, String method);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.pepperbell.continuity.api.client;

import net.minecraft.block.BlockState;
import net.minecraft.client.texture.Sprite;

public interface CachingPredicates {
boolean affectsSprites();

boolean affectsSprite(Sprite sprite);

boolean affectsBlockStates();

boolean affectsBlockState(BlockState state);

boolean isValidForMultipass();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.pepperbell.continuity.api.client;

import java.util.function.Function;

import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;

public interface CachingPredicatesFactory<T extends CTMProperties> {
CachingPredicates createPredicates(T properties, Function<SpriteIdentifier, Sprite> textureGetter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.world.BlockRenderView;

public interface QuadProcessor {
ProcessingResult processQuad(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, int processorIndex, ProcessingContext context);
ProcessingResult processQuad(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context);

interface ProcessingContext extends ProcessingDataProvider {
void addEmitterConsumer(Consumer<QuadEmitter> consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import me.pepperbell.continuity.api.client.CTMLoaderRegistry;
import me.pepperbell.continuity.api.client.CTMProperties;
import me.pepperbell.continuity.api.client.CTMPropertiesFactory;
import me.pepperbell.continuity.api.client.CachingPredicatesFactory;
import me.pepperbell.continuity.api.client.QuadProcessorFactory;
import me.pepperbell.continuity.client.processor.BaseCachingPredicates;
import me.pepperbell.continuity.client.processor.CompactCTMQuadProcessor;
import me.pepperbell.continuity.client.processor.HorizontalQuadProcessor;
import me.pepperbell.continuity.client.processor.HorizontalVerticalQuadProcessor;
Expand Down Expand Up @@ -35,7 +37,6 @@
import me.pepperbell.continuity.client.properties.overlay.StandardConnectingOverlayCTMProperties;
import me.pepperbell.continuity.client.properties.overlay.StandardOverlayCTMProperties;
import me.pepperbell.continuity.client.resource.CustomBlockLayers;
import me.pepperbell.continuity.client.resource.EmissiveIdProvider;
import me.pepperbell.continuity.client.util.RenderUtil;
import me.pepperbell.continuity.client.util.biome.BiomeHolderManager;
import me.pepperbell.continuity.client.util.biome.BiomeRetriever;
Expand All @@ -44,6 +45,7 @@
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class ContinuityClient implements ClientModInitializer {
Expand All @@ -56,14 +58,13 @@ public void onInitializeClient() {
ProcessingDataKeyRegistryImpl.INSTANCE.init();
BiomeHolderManager.init();
BiomeRetriever.init();
EmissiveIdProvider.init();
ProcessingDataKeys.init();
RenderUtil.ReloadListener.init();
CustomBlockLayers.ReloadListener.init();

FabricLoader.getInstance().getModContainer(ID).ifPresent(container -> {
ResourceManagerHelper.registerBuiltinResourcePack(asId("default"), container, ResourcePackActivationType.NORMAL);
ResourceManagerHelper.registerBuiltinResourcePack(asId("glass_pane_culling_fix"), container, ResourcePackActivationType.NORMAL);
ResourceManagerHelper.registerBuiltinResourcePack(asId("default"), container, Text.translatable("resourcePack.continuity.default.name"), ResourcePackActivationType.NORMAL);
ResourceManagerHelper.registerBuiltinResourcePack(asId("glass_pane_culling_fix"), container, Text.translatable("resourcePack.continuity.glass_pane_culling_fix.name"), ResourcePackActivationType.NORMAL);
});

// Regular methods
Expand Down Expand Up @@ -95,7 +96,8 @@ public void onInitializeClient() {
loader = createLoader(
CompactConnectingCTMProperties::new,
new TileAmountValidator.AtLeast<>(5),
new CompactCTMQuadProcessor.Factory()
new CompactCTMQuadProcessor.Factory(),
false
);
registry.registerLoader("ctm_compact", loader);

Expand Down Expand Up @@ -202,20 +204,47 @@ public void onInitializeClient() {
registry.registerLoader("overlay_fixed", loader);
}

private static <T extends CTMProperties> CTMLoader<T> createLoader(CTMPropertiesFactory<T> propertiesFactory, QuadProcessorFactory<T> processorFactory, CachingPredicatesFactory<T> predicatesFactory) {
return new CTMLoader<>() {
@Override
public CTMPropertiesFactory<T> getPropertiesFactory() {
return propertiesFactory;
}

@Override
public QuadProcessorFactory<T> getProcessorFactory() {
return processorFactory;
}

@Override
public CachingPredicatesFactory<T> getPredicatesFactory() {
return predicatesFactory;
}
};
}

private static <T extends BaseCTMProperties> CTMLoader<T> createLoader(CTMPropertiesFactory<T> propertiesFactory, TileAmountValidator<T> validator, QuadProcessorFactory<T> processorFactory, boolean isValidForMultipass) {
return createLoader(wrapWithOptifineOnlyCheck(TileAmountValidator.wrapFactory(BaseCTMProperties.wrapFactory(propertiesFactory), validator)), processorFactory, new BaseCachingPredicates.Factory<>(isValidForMultipass));
}

private static <T extends BaseCTMProperties> CTMLoader<T> createLoader(CTMPropertiesFactory<T> propertiesFactory, TileAmountValidator<T> validator, QuadProcessorFactory<T> processorFactory) {
return CTMLoader.of(wrapWithOptifineOnlyCheck(TileAmountValidator.wrapFactory(BaseCTMProperties.wrapFactory(propertiesFactory), validator)), processorFactory);
return createLoader(propertiesFactory, validator, processorFactory, true);
}

private static <T extends BaseCTMProperties> CTMLoader<T> createLoader(CTMPropertiesFactory<T> propertiesFactory, QuadProcessorFactory<T> processorFactory, boolean isValidForMultipass) {
return createLoader(wrapWithOptifineOnlyCheck(BaseCTMProperties.wrapFactory(propertiesFactory)), processorFactory, new BaseCachingPredicates.Factory<>(isValidForMultipass));
}

private static <T extends BaseCTMProperties> CTMLoader<T> createLoader(CTMPropertiesFactory<T> propertiesFactory, QuadProcessorFactory<T> processorFactory) {
return CTMLoader.of(wrapWithOptifineOnlyCheck(BaseCTMProperties.wrapFactory(propertiesFactory)), processorFactory);
return createLoader(propertiesFactory, processorFactory, true);
}

private static <T extends CTMProperties> CTMPropertiesFactory<T> wrapWithOptifineOnlyCheck(CTMPropertiesFactory<T> factory) {
return (properties, id, packName, packPriority, method) -> {
return (properties, id, pack, packPriority, resourceManager, method) -> {
if (PropertiesParsingHelper.parseOptifineOnly(properties, id)) {
return null;
}
return factory.createProperties(properties, id, packName, packPriority, method);
return factory.createProperties(properties, id, pack, packPriority, resourceManager, method);
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.pepperbell.continuity.client.config;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;

public class ContinuityConfigScreen extends Screen {
Expand All @@ -19,11 +19,19 @@ public ContinuityConfigScreen(Screen parent, ContinuityConfig config) {

@Override
protected void init() {
addDrawableChild(createBooleanOptionButton(width / 2 - 100 - 110, height / 2 - 10 - 12, 200, 20, config.connectedTextures));
addDrawableChild(createBooleanOptionButton(width / 2 - 100 + 110, height / 2 - 10 - 12, 200, 20, config.emissiveTextures));
addDrawableChild(createBooleanOptionButton(width / 2 - 100 - 110, height / 2 - 10 + 12, 200, 20, config.customBlockLayers));
addDrawableChild(startBooleanOptionButton(config.connectedTextures)
.dimensions(width / 2 - 100 - 110, height / 2 - 10 - 12, 200, 20)
.build());
addDrawableChild(startBooleanOptionButton(config.emissiveTextures)
.dimensions(width / 2 - 100 + 110, height / 2 - 10 - 12, 200, 20)
.build());
addDrawableChild(startBooleanOptionButton(config.customBlockLayers)
.dimensions(width / 2 - 100 - 110, height / 2 - 10 + 12, 200, 20)
.build());

addDrawableChild(new ButtonWidget(width / 2 - 100, height - 40, 200, 20, ScreenTexts.DONE, button -> close()));
addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, button -> close())
.dimensions(width / 2 - 100, height - 40, 200, 20)
.build());
}

@Override
Expand Down Expand Up @@ -52,23 +60,16 @@ private static String getTooltipKey(String translationKey) {
return translationKey + ".tooltip";
}

private ButtonWidget.TooltipSupplier createDefaultTooltipSupplier(StringVisitable text) {
return (button, matrices, mouseX, mouseY) -> {
renderOrderedTooltip(matrices, textRenderer.wrapLines(text, width / 100 * 100 / 2), mouseX, mouseY);
};
}

private ButtonWidget createBooleanOptionButton(int x, int y, int width, int height, Option<Boolean> option) {
private ButtonWidget.Builder startBooleanOptionButton(Option<Boolean> option) {
String translationKey = getTranslationKey(option.getKey());
Text text = Text.translatable(translationKey);
Text tooltipText = Text.translatable(getTooltipKey(translationKey));
return new ButtonWidget(x, y, width, height, ScreenTexts.composeToggleText(text, option.get()),
return ButtonWidget.builder(ScreenTexts.composeToggleText(text, option.get()),
button -> {
boolean newValue = !option.get();
button.setMessage(ScreenTexts.composeToggleText(text, newValue));
option.set(newValue);
},
createDefaultTooltipSupplier(tooltipText)
);
})
.tooltip(Tooltip.of(tooltipText));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package me.pepperbell.continuity.client.mixin;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import me.pepperbell.continuity.client.resource.AtlasLoaderInitContext;
import me.pepperbell.continuity.client.resource.AtlasLoaderLoadContext;
import me.pepperbell.continuity.client.resource.EmissiveSuffixLoader;
import net.minecraft.client.texture.SpriteContents;
import net.minecraft.client.texture.SpriteLoader;
import net.minecraft.client.texture.atlas.AtlasLoader;
import net.minecraft.client.texture.atlas.AtlasSource;
import net.minecraft.client.texture.atlas.SingleAtlasSource;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;

@Mixin(AtlasLoader.class)
public class AtlasLoaderMixin {
@ModifyVariable(method = "<init>(Ljava/util/List;)V", at = @At(value = "LOAD", ordinal = 0), argsOnly = true, ordinal = 0)
private List<AtlasSource> continuity$modifySources(List<AtlasSource> sources) {
AtlasLoaderInitContext context = AtlasLoaderInitContext.THREAD_LOCAL.get();
if (context != null) {
Set<Identifier> extraIds = context.getExtraIdsFuture().join();
if (extraIds != null && !extraIds.isEmpty()) {
List<AtlasSource> extraSources = new ObjectArrayList<>();
for (Identifier extraId : extraIds) {
extraSources.add(new SingleAtlasSource(extraId, Optional.empty()));
}

if (sources instanceof ArrayList) {
sources.addAll(0, extraSources);
} else {
List<AtlasSource> mutableSources = new ArrayList<>(extraSources);
mutableSources.addAll(sources);
return mutableSources;
}
}
}
return sources;
}

@Inject(method = "loadSources(Lnet/minecraft/resource/ResourceManager;)Ljava/util/List;", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableList;builder()Lcom/google/common/collect/ImmutableList$Builder;", remap = false), locals = LocalCapture.CAPTURE_FAILHARD)
private void continuity$afterLoadSources(ResourceManager resourceManager, CallbackInfoReturnable<List<Supplier<SpriteContents>>> cir, Map<Identifier, AtlasSource.SpriteRegion> suppliers) {
AtlasLoaderLoadContext context = AtlasLoaderLoadContext.THREAD_LOCAL.get();
if (context != null) {
String emissiveSuffix = EmissiveSuffixLoader.getEmissiveSuffix();
if (emissiveSuffix != null) {
Map<Identifier, AtlasSource.SpriteRegion> extraSuppliers = new Object2ObjectOpenHashMap<>();
Map<Identifier, Identifier> emissiveIdMap = new Object2ObjectOpenHashMap<>();
suppliers.forEach((id, supplier) -> {
if (!id.getPath().endsWith(emissiveSuffix)) {
Identifier emissiveId = new Identifier(id.getNamespace(), id.getPath() + emissiveSuffix);
if (!suppliers.containsKey(emissiveId)) {
Identifier emissiveLocation = emissiveId.withPath("textures/" + emissiveId.getPath() + ".png");
Optional<Resource> optionalResource = resourceManager.getResource(emissiveLocation);
if (optionalResource.isPresent()) {
Resource resource = optionalResource.get();
extraSuppliers.put(emissiveId, () -> SpriteLoader.load(emissiveId, resource));
emissiveIdMap.put(id, emissiveId);
}
} else {
emissiveIdMap.put(id, emissiveId);
}
}
});
suppliers.putAll(extraSuppliers);
if (!emissiveIdMap.isEmpty()) {
context.setEmissiveIdMap(emissiveIdMap);
}
}
}
}
}
Loading

0 comments on commit 23dbade

Please sign in to comment.