package com.thebrokenrail.energonrelics.client; import com.thebrokenrail.energonrelics.EnergonRelics; import com.thebrokenrail.energonrelics.block.forcefield.util.AbstractFieldBlock; import com.thebrokenrail.energonrelics.api.block.energy.EnergyBlock; import com.thebrokenrail.energonrelics.client.config.UserConfig; import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; import me.sargunvohra.mcmods.autoconfig1u.ConfigData; import me.sargunvohra.mcmods.autoconfig1u.annotation.Config; import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.event.player.AttackBlockCallback; import net.minecraft.block.BlockState; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.RenderLayer; import net.minecraft.util.ActionResult; @Environment(EnvType.CLIENT) public final class EnergonRelicsClient implements ClientModInitializer { @Environment(EnvType.CLIENT) private static class ReloadSerializer extends GsonConfigSerializer { public ReloadSerializer(Config definition, Class configClass) { super(definition, configClass); } @Override public void serialize(T config) throws SerializationException { super.serialize(config); MinecraftClient client = MinecraftClient.getInstance(); if (client.getResourceManager() != null) { client.reloadResources(); } } } @Override public void onInitializeClient() { EnergyBlock.initRenderer(); BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.THERMAL_GLASS_BLOCK, RenderLayer.getCutout()); BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.DEFENSIVE_LASER_BLOCK, RenderLayer.getCutout()); BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.FORCEFIELD_BLOCK, RenderLayer.getTranslucent()); BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.TRACTOR_BEAM_BLOCK, RenderLayer.getTranslucent()); BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.REPULSOR_BEAM_BLOCK, RenderLayer.getTranslucent()); BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.INDUSTRIAL_LASER_BLOCK, RenderLayer.getTranslucent()); BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.ENERGY_PORTAL_BLOCK, RenderLayer.getTranslucent()); BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.ENERGY_BEAM_BLOCK, RenderLayer.getTranslucent()); AutoConfig.register(UserConfig.class, ReloadSerializer::new); AttackBlockCallback.EVENT.register((playerEntity, world, hand, blockPos, direction) -> { BlockState state = world.getBlockState(blockPos); if (state.getBlock() instanceof AbstractFieldBlock || state.getBlock() == EnergonRelics.ENERGY_PORTAL_BLOCK) { return ActionResult.FAIL; } else { return ActionResult.PASS; } }); } }