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