ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/misc/special/SpecialRenderInit.java

87 lines
3 KiB
Java
Raw Normal View History

/*
2016-05-16 22:52:27 +02:00
* This file ("SpecialRenderInit.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.misc.special;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderPlayerEvent;
2016-07-03 20:57:00 +02:00
import net.minecraftforge.common.MinecraftForge;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class SpecialRenderInit{
2016-06-17 23:50:38 +02:00
public static final HashMap<String, RenderSpecial> SPECIAL_LIST = new HashMap<String, RenderSpecial>();
2016-07-03 20:57:00 +02:00
public SpecialRenderInit(){
new ThreadSpecialFetcher();
2016-07-03 20:57:00 +02:00
MinecraftForge.EVENT_BUS.register(this);
}
public static void parse(Properties properties){
for(String key : properties.stringPropertyNames()){
String[] values = properties.getProperty(key).split("@");
2016-05-16 22:52:27 +02:00
if(values.length > 0){
String itemName = values[0];
int meta;
try{
meta = Integer.parseInt(values[1]);
}
catch(Exception e){
meta = 0;
}
ItemStack stack = null;
//Get the Item from the String
ResourceLocation resLoc = new ResourceLocation(itemName);
2016-04-20 21:39:03 +02:00
if(Item.REGISTRY.containsKey(resLoc)){
stack = new ItemStack(Item.REGISTRY.getObject(resLoc), 1, meta);
}
else{
2016-04-20 21:39:03 +02:00
if(Block.REGISTRY.containsKey(resLoc)){
stack = new ItemStack(Block.REGISTRY.getObject(resLoc), 1, meta);
}
}
//Add a new Special Renderer to the list
if(stack != null){
2016-06-17 23:50:38 +02:00
SPECIAL_LIST.put(key, new RenderSpecial(stack));
}
}
}
}
2015-12-01 19:48:09 +01:00
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerRender(RenderPlayerEvent.Pre event){
2016-06-17 23:50:38 +02:00
if(!SPECIAL_LIST.isEmpty()){
for(Map.Entry<String, RenderSpecial> entry : SPECIAL_LIST.entrySet()){
2015-12-01 19:48:09 +01:00
//Does the player have one of the names from the list?
2016-05-10 18:48:35 +02:00
String playerName = event.getEntityPlayer().getName();
if(entry.getKey() != null && playerName != null){
if(entry.getKey().equalsIgnoreCase(playerName)){
2016-05-10 18:48:35 +02:00
//Render the special Item/Block
entry.getValue().render(event.getEntityPlayer(), event.getPartialRenderTick());
break;
}
2015-12-01 19:48:09 +01:00
}
}
}
}
}