Skip to content

Commit

Permalink
Add missing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Apr 28, 2024
1 parent cee0793 commit 3e7ddd9
Show file tree
Hide file tree
Showing 405 changed files with 9,957 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
loom {
mixin {
useLegacyMixinAp = false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt;

import com.google.auto.service.AutoService;
import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants;
import dev.lukebemish.excavatedvariants.impl.platform.services.CreativeTabLoader;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import org.jspecify.annotations.Nullable;

import java.util.Objects;

@SuppressWarnings("unused")
@AutoService(CreativeTabLoader.class)
public class CreativeTabLoaderImpl implements CreativeTabLoader {
private static final int MAX_INT_VAL = (int) Math.sqrt(Integer.MAX_VALUE);
public static @Nullable CreativeModeTab EXCAVATED_VARIANTS_TAB;

@Override
public void registerCreativeTab() {
EXCAVATED_VARIANTS_TAB = FabricItemGroup.builder()
.icon(() -> new ItemStack(Items.DEEPSLATE_COPPER_ORE))
.displayItems((displayParameters, output) -> {
for (var supplier : ExcavatedVariants.ITEMS) {
output.accept(supplier.get());
}
})
.title(Component.translatable("itemGroup.excavated_variants.excavated_variants"))
.build();
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, CREATIVE_TAB_ID, EXCAVATED_VARIANTS_TAB);
}

public CreativeModeTab getCreativeTab() {
return Objects.requireNonNull(EXCAVATED_VARIANTS_TAB);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt;

import dev.lukebemish.excavatedvariants.impl.network.SyncOresPayload;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking;
import net.minecraft.network.chat.Component;

public class ExcavatedVariantsClientFabriQuilt implements ClientModInitializer {
@Override
public void onInitializeClient() {
ClientConfigurationNetworking.registerGlobalReceiver(SyncOresPayload.TYPE, (msg, context) ->
msg.consumeMessage(string -> context.responseSender().disconnect(Component.literal(string)))
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt;

import dev.lukebemish.excavatedvariants.impl.BlockAddedCallback;
import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants;
import dev.lukebemish.excavatedvariants.impl.ExcavatedVariantsClient;
import dev.lukebemish.excavatedvariants.impl.RegistriesImpl;
import dev.lukebemish.excavatedvariants.impl.network.AckOresPayload;
import dev.lukebemish.excavatedvariants.impl.network.SyncOresPayload;
import dev.lukebemish.excavatedvariants.impl.worldgen.OreFinderUtil;
import dev.lukebemish.excavatedvariants.impl.worldgen.OreReplacer;
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.ModificationPhase;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;

import java.util.stream.Collectors;

public class ExcavatedVariantsFabriQuilt {
public static void onInitialize() {
ExcavatedVariants.init();
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
ExcavatedVariantsClient.init();
}

BuiltInRegistries.BLOCK.holders().forEach(reference ->
BlockAddedCallback.onRegister(reference.value(), reference.key()));
BlockAddedCallback.setReady();
BlockAddedCallback.register();

ServerLifecycleEvents.SERVER_STARTING.register(server ->
OreFinderUtil.setupBlocks());

ResourceKey<PlacedFeature> confKey = ResourceKey.create(Registries.PLACED_FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"));
BiomeModifications.create(confKey.location()).add(ModificationPhase.POST_PROCESSING, (x) -> true, context ->
context.getGenerationSettings().addFeature(GenerationStep.Decoration.TOP_LAYER_MODIFICATION, confKey));

/*if (QuiltLoader.isModLoaded("unearthed") && ExcavatedVariants.setupMap()) {
HyleCompat.init();
}*/

PayloadTypeRegistry.configurationS2C().register(SyncOresPayload.TYPE, SyncOresPayload.CODEC);
PayloadTypeRegistry.configurationC2S().register(AckOresPayload.TYPE, AckOresPayload.CODEC);

ServerConfigurationConnectionEvents.CONFIGURE.register((handler, server) -> {
var packet = new SyncOresPayload(ExcavatedVariants.COMPLETE_VARIANTS.stream().map(v -> v.fullId).collect(Collectors.toSet()));
ServerConfigurationNetworking.send(handler, packet);
});

Registry.register(BuiltInRegistries.FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"), new OreReplacer());
}

public static void cleanup() {
StateCapturer.checkState();
RegistriesImpl.registerRegistries();
ExcavatedVariants.initPostRegister();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt;

import dev.lukebemish.excavatedvariants.impl.fabriquilt.fabric.FabricPlatform;
import dev.lukebemish.excavatedvariants.impl.fabriquilt.quilt.MinimalQuiltPlatform;
import net.fabricmc.loader.api.FabricLoader;

import java.nio.file.Path;
import java.util.Set;

public interface FabriQuiltPlatform {

@SuppressWarnings("deprecation")
static FabriQuiltPlatform getInstance() {
if (FabricLoader.getInstance().isModLoaded("quilt_loader")) {
return MinimalQuiltPlatform.INSTANCE;
} else {
return FabricPlatform.INSTANCE;
}
}

Path getCacheFolder();
String getModVersion();
Set<String> getModIds();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt;

import com.google.auto.service.AutoService;
import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants;
import dev.lukebemish.excavatedvariants.impl.platform.services.Platform;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.Item;

import java.nio.file.Path;
import java.util.Set;

@AutoService(Platform.class)
public class PlatformImpl implements Platform {

@Override
public Set<String> getModIds() {
return FabriQuiltPlatform.getInstance().getModIds();
}

public Path getConfigFolder() {
return FabricLoader.getInstance().getConfigDir();
}

@Override
public Path getModDataFolder() {
return FabriQuiltPlatform.getInstance().getCacheFolder().resolve(ExcavatedVariants.MOD_ID);
}

@Override
public String getModVersion() {
return FabriQuiltPlatform.getInstance().getModVersion();
}

@Override
public boolean isClient() {
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
}

@Override
public void register(ExcavatedVariants.VariantFuture future) {
ExcavatedVariants.registerBlockAndItem(
(rlr, bl) -> Registry.register(BuiltInRegistries.BLOCK, rlr, bl),
(rlr, it) -> {
Item out = Registry.register(BuiltInRegistries.ITEM, rlr, it.get());
return () -> out;
}, future);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt;

import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants;
import dev.lukebemish.excavatedvariants.impl.ModLifecycle;
import net.fabricmc.api.ModInitializer;

public class StateCapturer implements ModInitializer {
private static boolean INITIALIZED = false;

@Override
public void onInitialize() {
INITIALIZED = true;
}

public static void checkState() {
if (ModLifecycle.getLifecyclePhase().above(ModLifecycle.REGISTRATION) || !INITIALIZED) {
var e = new RuntimeException("Something has gone very wrong with load ordering, and we have no clue what is going on. Please report this to Excavated Variants and be sure to provide a log!");
ExcavatedVariants.LOGGER.error("...what the heck? Where are we? Lifecycle state: {}, initialized: {}", ModLifecycle.getLifecyclePhase(), INITIALIZED, e);
throw e;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt.client;

import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.block.Block;

public class RenderTypeClientExecutor {
public static void setMipped(Block block) {
BlockRenderLayerMap.INSTANCE.putBlock(block, RenderType.cutoutMipped());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt.client;

import com.google.auto.service.AutoService;
import dev.lukebemish.excavatedvariants.impl.client.RenderTypeHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.world.level.block.Block;

@AutoService(RenderTypeHandler.class)
public class RenderTypeHandlerImpl implements RenderTypeHandler {
public void setRenderTypeMipped(Block block) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
RenderTypeClientExecutor.setMipped(block);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@NullMarked
@ApiStatus.Internal
package dev.lukebemish.excavatedvariants.impl.fabriquilt.client;

import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt.compat;

public class HyleCompat {
private static Map<Block, Pair<BaseOre, HashSet<BaseStone>>> excavatedVariantsOres;

public static void init() {
StoneTypeCallback.EVENT.register(stoneType -> {
if (excavatedVariantsOres == null) {
excavatedVariantsOres = new IdentityHashMap<>();
for (Pair<BaseOre, HashSet<BaseStone>> p : ExcavatedVariants.oreStoneList) {
for (ResourceLocation block_id : p.getFirst().block_id) {
Block baseOreBlock = Services.REGISTRY_UTIL.getBlockById(block_id);
excavatedVariantsOres.put(baseOreBlock, p);
}
}
}

Block baseBlock = stoneType.getBaseBlock().getBlock();
excavatedVariantsOres.forEach((baseOreBlock, pair) -> {
HashSet<BaseStone> stones = pair.getSecond();
stones.stream().variantFilter(stone -> Services.REGISTRY_UTIL.getBlockById(stone.block_id) == baseBlock).findAny().ifPresent(stone -> {
Block oreBlock = Services.REGISTRY_UTIL.getBlockById(new ResourceLocation(ExcavatedVariants.MOD_ID, stone.id + "_" + pair.getFirst().id));
if (!stoneType.getOreMap().containsKey(baseOreBlock) && oreBlock != null)
stoneType.getOreMap().put(baseOreBlock, oreBlock.defaultBlockState());
});
});
return true;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@NullMarked
@ApiStatus.Internal
package dev.lukebemish.excavatedvariants.impl.fabriquilt.compat;

import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt.fabric;

import dev.lukebemish.excavatedvariants.impl.fabriquilt.ExcavatedVariantsFabriQuilt;
import net.fabricmc.api.ModInitializer;

public class ExcavatedVariantsFabric implements ModInitializer {
@Override
public void onInitialize() {
ExcavatedVariantsFabriQuilt.onInitialize();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt.fabric;

import com.google.common.base.Suppliers;
import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants;
import dev.lukebemish.excavatedvariants.impl.fabriquilt.FabriQuiltPlatform;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.ModMetadata;

import java.nio.file.Path;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class FabricPlatform implements FabriQuiltPlatform {
public static final FabricPlatform INSTANCE = new FabricPlatform();
private static final Supplier<Set<String>> MOD_IDS = Suppliers.memoize(() -> FabricLoader.getInstance().getAllMods().stream().map(ModContainer::getMetadata).map(ModMetadata::getId).collect(Collectors.toSet()));

@Override
public Path getCacheFolder() {
return FabricLoader.getInstance().getGameDir().resolve(".cache");
}

@Override
public String getModVersion() {
return FabricLoader.getInstance().getModContainer(ExcavatedVariants.MOD_ID).orElseThrow().getMetadata().getVersion().getFriendlyString();
}

@Override
public Set<String> getModIds() {
return MOD_IDS.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@NullMarked
@ApiStatus.Internal
package dev.lukebemish.excavatedvariants.impl.fabriquilt.fabric;

import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.lukebemish.excavatedvariants.impl.fabriquilt.mixin;

import dev.lukebemish.excavatedvariants.impl.fabriquilt.ExcavatedVariantsFabriQuilt;
import net.minecraft.client.Minecraft;
import net.minecraft.client.main.GameConfig;
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.callback.CallbackInfo;

@Mixin(Minecraft.class)
public class ClientInitializerMixin {
// See where fabric's EntrypointPatch decides to shove fabric entrypoints...
@Inject(method = "<init>(Lnet/minecraft/client/main/GameConfig;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;<init>(Lnet/minecraft/client/Minecraft;Ljava/io/File;)V"))
private void postFabricInitialized(GameConfig gameConfig, CallbackInfo ci) {
ExcavatedVariantsFabriQuilt.cleanup();
}
}
Loading

0 comments on commit 3e7ddd9

Please sign in to comment.