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
Raw Normal View History

2020-07-13 20:37:21 +00:00
package com.thebrokenrail.energonrelics.client;
2020-07-16 18:50:18 +00:00
import com.thebrokenrail.energonrelics.EnergonRelics;
2020-08-16 03:01:24 +00:00
import com.thebrokenrail.energonrelics.block.PhaseShifterBlock;
2020-07-28 03:10:16 +00:00
import com.thebrokenrail.energonrelics.block.forcefield.util.AbstractFieldBlock;
2020-08-04 17:06:11 +00:00
import com.thebrokenrail.energonrelics.api.block.energy.EnergyBlock;
import com.thebrokenrail.energonrelics.client.config.UserConfig;
2020-08-16 03:01:24 +00:00
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;
2020-07-13 20:37:21 +00:00
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
2020-07-16 18:50:18 +00:00
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
2020-08-16 03:01:24 +00:00
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
2020-07-23 23:50:10 +00:00
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
2020-08-01 20:22:32 +00:00
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
2020-07-16 18:50:18 +00:00
import net.minecraft.client.render.RenderLayer;
2020-07-23 23:50:10 +00:00
import net.minecraft.util.ActionResult;
2020-07-13 20:37:21 +00:00
@Environment(EnvType.CLIENT)
2020-08-04 21:42:19 +00:00
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();
}
}
}
2020-07-13 20:37:21 +00:00
@Override
public void onInitializeClient() {
2020-07-26 23:05:59 +00:00
EnergyBlock.initRenderer();
2020-07-23 23:31:02 +00:00
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.THERMAL_GLASS_BLOCK, RenderLayer.getCutout());
2020-07-16 18:50:18 +00:00
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.DEFENSIVE_LASER_BLOCK, RenderLayer.getCutout());
2020-07-28 03:10:16 +00:00
2020-07-23 23:31:02 +00:00
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.FORCEFIELD_BLOCK, RenderLayer.getTranslucent());
2020-07-28 03:10:16 +00:00
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.TRACTOR_BEAM_BLOCK, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.REPULSOR_BEAM_BLOCK, RenderLayer.getTranslucent());
2020-07-28 20:38:21 +00:00
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.INDUSTRIAL_LASER_BLOCK, RenderLayer.getTranslucent());
2020-08-01 20:22:32 +00:00
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.ENERGY_PORTAL_BLOCK, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.ENERGY_BEAM_BLOCK, RenderLayer.getTranslucent());
2020-08-16 03:01:24 +00:00
BlockRenderLayerMap.INSTANCE.putBlock(EnergonRelics.PHASE_SHIFTER_BLOCK, RenderLayer.getCutoutMipped());
ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) -> state.get(PhaseShifterBlock.COLOR).getFireworkColor(), EnergonRelics.PHASE_SHIFTER_BLOCK);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? HardcodedConfig.PHASE_SHIFTER_DEFAULT_COLOR.getFireworkColor() : -1);
AutoConfig.register(UserConfig.class, ReloadSerializer::new);
2020-07-23 23:50:10 +00:00
AttackBlockCallback.EVENT.register((playerEntity, world, hand, blockPos, direction) -> {
2020-08-01 20:22:32 +00:00
BlockState state = world.getBlockState(blockPos);
if (state.getBlock() instanceof AbstractFieldBlock || state.getBlock() == EnergonRelics.ENERGY_PORTAL_BLOCK) {
2020-07-23 23:50:10 +00:00
return ActionResult.FAIL;
} else {
return ActionResult.PASS;
}
});
2020-07-13 20:37:21 +00:00
}
}