2015-11-02 21:38:49 +01:00
|
|
|
/*
|
2016-05-16 22:52:27 +02: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-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-11-02 21:38:49 +01:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 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-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
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
|
|
|
|
2021-02-27 21:24:26 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class SpecialRenderInit {
|
2015-11-02 21:38:49 +01:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
public static final HashMap<String, RenderSpecial> SPECIAL_LIST = new HashMap<>();
|
2015-11-02 21:38:49 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public SpecialRenderInit() {
|
2015-11-02 21:38:49 +01:00
|
|
|
new ThreadSpecialFetcher();
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
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("@");
|
2019-05-02 09:10:29 +02:00
|
|
|
if (values.length > 0) {
|
2015-11-15 00:57:38 +01:00
|
|
|
String itemName = values[0];
|
2015-11-02 21:38:49 +01:00
|
|
|
|
2015-11-15 00:57:38 +01:00
|
|
|
int meta;
|
2019-05-02 09:10:29 +02:00
|
|
|
try {
|
2015-11-15 00:57:38 +01:00
|
|
|
meta = Integer.parseInt(values[1]);
|
2019-05-02 09:10:29 +02:00
|
|
|
} catch (Exception e) {
|
2015-11-15 00:57:38 +01:00
|
|
|
meta = 0;
|
2015-11-02 21:38:49 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 23:42:42 +01:00
|
|
|
ResourceLocation resLoc = new ResourceLocation(itemName);
|
2016-11-28 22:04:19 +01:00
|
|
|
ItemStack stack = findItem(resLoc, meta);
|
|
|
|
|
|
|
|
//TODO Remove this block once the transition to 1.11 is done and the special people stuff file has been converted to snake_case
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!StackUtil.isValid(stack)) {
|
2016-11-28 22:04:19 +01:00
|
|
|
String convertedItemName = "";
|
2019-05-02 09:10:29 +02:00
|
|
|
for (char c : itemName.toCharArray()) {
|
|
|
|
if (Character.isUpperCase(c)) {
|
2016-11-28 22:04:19 +01:00
|
|
|
convertedItemName += "_";
|
|
|
|
convertedItemName += Character.toLowerCase(c);
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-11-28 22:04:19 +01:00
|
|
|
convertedItemName += c;
|
|
|
|
}
|
2015-11-15 00:57:38 +01:00
|
|
|
}
|
2016-11-28 22:04:19 +01:00
|
|
|
stack = findItem(new ResourceLocation(convertedItemName), meta);
|
2015-11-15 00:57:38 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack)) {
|
2016-11-27 13:29:58 +01:00
|
|
|
SPECIAL_LIST.put(key.toLowerCase(Locale.ROOT), new RenderSpecial(stack));
|
2015-11-15 00:57:38 +01:00
|
|
|
}
|
2015-11-02 21:38:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private static ItemStack findItem(ResourceLocation resLoc, int meta) {
|
|
|
|
if (Item.REGISTRY.containsKey(resLoc)) {
|
2016-11-28 22:04:19 +01:00
|
|
|
Item item = Item.REGISTRY.getObject(resLoc);
|
2021-02-27 21:24:26 +01:00
|
|
|
if (item != null) {
|
|
|
|
return new ItemStack(item, 1, meta);
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else if (Block.REGISTRY.containsKey(resLoc)) {
|
2016-11-28 22:04:19 +01:00
|
|
|
Block block = Block.REGISTRY.getObject(resLoc);
|
2021-02-27 21:24:26 +01:00
|
|
|
if (block != null) {
|
|
|
|
return new ItemStack(block, 1, meta);
|
|
|
|
}
|
2016-11-28 22:04:19 +01:00
|
|
|
}
|
2017-11-02 22:49:53 +01:00
|
|
|
return StackUtil.getEmpty();
|
2016-11-28 22:04:19 +01:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
2019-05-02 09:10:29 +02:00
|
|
|
public void onPlayerRender(RenderPlayerEvent.Pre event) {
|
|
|
|
if (event.getEntityPlayer() != null) {
|
2016-11-27 13:29:58 +01:00
|
|
|
String name = event.getEntityPlayer().getName();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (name != null) {
|
2016-11-27 13:29:58 +01:00
|
|
|
String lower = name.toLowerCase(Locale.ROOT);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (SPECIAL_LIST.containsKey(lower)) {
|
2016-11-27 13:29:58 +01:00
|
|
|
RenderSpecial render = SPECIAL_LIST.get(lower);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (render != null) {
|
2016-11-27 13:29:58 +01:00
|
|
|
render.render(event.getEntityPlayer(), event.getPartialRenderTick());
|
2016-05-10 18:48:35 +02:00
|
|
|
}
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 21:38:49 +01:00
|
|
|
}
|