2017-06-29 13:00:11 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod;
|
|
|
|
|
2018-06-24 02:44:47 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.render.ActualCompostModel;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.render.CompostModel;
|
2017-06-29 18:30:02 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.render.IHasModel;
|
2017-06-29 13:00:11 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.FluidStateMapper;
|
|
|
|
import net.minecraft.block.Block;
|
2019-02-27 19:53:05 +01:00
|
|
|
import net.minecraft.client.renderer.block.model.ModelBakery;
|
2017-06-29 13:00:11 +02:00
|
|
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2018-06-24 02:44:47 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraftforge.client.event.ModelBakeEvent;
|
2017-06-29 13:00:11 +02:00
|
|
|
import net.minecraftforge.client.event.ModelRegistryEvent;
|
|
|
|
import net.minecraftforge.client.model.ModelLoader;
|
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public class ClientRegistryHandler{
|
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
public static final Map<ItemStack, ModelResourceLocation> MODEL_LOCATIONS_FOR_REGISTERING = new HashMap<>();
|
2017-06-29 13:00:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* (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);
|
2019-02-27 19:53:05 +01:00
|
|
|
ModelBakery.registerItemVariants(item);
|
2017-06-29 13:00:11 +02:00
|
|
|
ModelLoader.setCustomMeshDefinition(item, mapper);
|
|
|
|
ModelLoader.setCustomStateMapper(block, mapper);
|
|
|
|
}
|
2017-06-29 18:36:33 +02:00
|
|
|
|
|
|
|
@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);
|
2017-07-12 20:19:48 +02:00
|
|
|
registerCustomFluidBlockRenderer(InitFluids.fluidRefinedCanolaOil);
|
2017-06-29 18:36:33 +02:00
|
|
|
registerCustomFluidBlockRenderer(InitFluids.fluidCrystalOil);
|
|
|
|
registerCustomFluidBlockRenderer(InitFluids.fluidEmpoweredOil);
|
|
|
|
}
|
2019-02-27 19:53:05 +01:00
|
|
|
|
2018-06-24 02:44:47 +02:00
|
|
|
@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());
|
|
|
|
}
|
2017-06-29 13:00:11 +02:00
|
|
|
}
|