This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/client/EnergonRelicsClient.java

73 lines
3.7 KiB
Java

package com.thebrokenrail.energonrelics.client;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.PhaseShifterBlock;
import com.thebrokenrail.energonrelics.block.forcefield.util.AbstractFieldBlock;
import com.thebrokenrail.energonrelics.api.block.energy.EnergyBlock;
import com.thebrokenrail.energonrelics.client.config.UserConfig;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
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.client.rendering.v1.ColorProviderRegistry;
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<T extends ConfigData> extends GsonConfigSerializer<T> {
public ReloadSerializer(Config definition, Class<T> 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.Blocks.THERMAL_GLASS, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.Blocks.DEFENSIVE_LASER, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.Blocks.FORCEFIELD, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.Blocks.TRACTOR_BEAM, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.Blocks.REPULSOR_BEAM, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.Blocks.INDUSTRIAL_LASER, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.Blocks.ENERGY_PORTAL, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.Blocks.ENERGY_BEAM, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.Blocks.PHASE_SHIFTER, RenderLayer.getCutoutMipped());
ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) -> state.get(PhaseShifterBlock.COLOR).getFireworkColor(), EnergonRelics.Blocks.PHASE_SHIFTER);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? HardcodedConfig.PHASE_SHIFTER_DEFAULT_COLOR.getFireworkColor() : -1);
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.Blocks.ENERGY_PORTAL) {
return ActionResult.FAIL;
} else {
return ActionResult.PASS;
}
});
}
}