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-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;
|
2020-07-17 16:14:27 +00:00
|
|
|
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;
|
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-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;
|
2020-07-17 16:14:27 +00:00
|
|
|
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 {
|
2020-07-17 16:14:27 +00:00
|
|
|
@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
|
|
|
|
2020-07-17 03:55:31 +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-07-17 16:14:27 +00:00
|
|
|
|
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-07-17 16:14:27 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|