ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/common/ClientRegistryHandler.java
Michael be421af8e2
Big Refactor of the package layout
Ignore this commit for diffs
2020-09-09 15:48:43 +01:00

64 lines
2.7 KiB
Java

package de.ellpeck.actuallyadditions.common;
import java.util.HashMap;
import java.util.Map;
import de.ellpeck.actuallyadditions.common.blocks.render.ActualCompostModel;
import de.ellpeck.actuallyadditions.common.blocks.render.CompostModel;
import de.ellpeck.actuallyadditions.common.blocks.render.IHasModel;
import de.ellpeck.actuallyadditions.common.fluids.InitFluids;
import de.ellpeck.actuallyadditions.common.util.FluidStateMapper;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class ClientRegistryHandler {
public static final Map<ItemStack, ModelResourceLocation> MODEL_LOCATIONS_FOR_REGISTERING = new HashMap<>();
/**
* (Excerpted from Tinkers' Construct with permission, thanks guys!)
*/
private static void registerCustomFluidBlockRenderer(Fluid fluid) {
Block block = fluid.getBlock();
Item item = Item.getItemFromBlock(block);
FluidStateMapper mapper = new FluidStateMapper(fluid);
ModelBakery.registerItemVariants(item);
ModelLoader.setCustomMeshDefinition(item, mapper);
ModelLoader.setCustomStateMapper(block, mapper);
}
@SubscribeEvent
public void onModelRegistry(ModelRegistryEvent event) {
for (Block block : RegistryHandler.BLOCKS_TO_REGISTER) {
if (block instanceof IHasModel) {
((IHasModel) block).registerRendering();
}
}
for (Map.Entry<ItemStack, ModelResourceLocation> entry : MODEL_LOCATIONS_FOR_REGISTERING.entrySet()) {
ModelLoader.setCustomModelResourceLocation(entry.getKey().getItem(), entry.getKey().getItemDamage(), entry.getValue());
}
registerCustomFluidBlockRenderer(InitFluids.fluidCanolaOil);
registerCustomFluidBlockRenderer(InitFluids.fluidRefinedCanolaOil);
registerCustomFluidBlockRenderer(InitFluids.fluidCrystalOil);
registerCustomFluidBlockRenderer(InitFluids.fluidEmpoweredOil);
}
@SubscribeEvent
public void onModelBake(ModelBakeEvent e) {
ModelResourceLocation mrl = new ModelResourceLocation(new ResourceLocation(ActuallyAdditions.MODID, "block_compost"), "normal");
CompostModel.compostBase = e.getModelRegistry().getObject(mrl);
e.getModelRegistry().putObject(mrl, new ActualCompostModel());
}
}