Changed formatting to have bracing on a new line
This commit is contained in:
parent
e5eddd6c45
commit
e48eedb874
189 changed files with 6092 additions and 4041 deletions
|
@ -14,36 +14,42 @@ import net.minecraftforge.client.model.ModelLoader;
|
|||
|
||||
/**
|
||||
* @author <a href="https://github.com/TehNut">TehNut</a>
|
||||
*
|
||||
*
|
||||
* The goal of this class is to make registering the inventory renders
|
||||
* for your Items/Blocks a much simpler and easier process.
|
||||
*
|
||||
* You must call this at the post initialization stage on
|
||||
* the clientside only.
|
||||
*
|
||||
* If you pass a Block through here that uses the default
|
||||
* ItemBlock, you should specify a custom name.
|
||||
*
|
||||
* You must call this at the post initialization stage on the clientside
|
||||
* only.
|
||||
*
|
||||
* If you pass a Block through here that uses the default ItemBlock, you
|
||||
* should specify a custom name.
|
||||
*/
|
||||
public class InventoryRenderHelper {
|
||||
public class InventoryRenderHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* This is the base string for your resources. It will usually be
|
||||
* your modid in all lowercase with a colon at the end.
|
||||
* This is the base string for your resources. It will usually be your modid
|
||||
* in all lowercase with a colon at the end.
|
||||
*/
|
||||
private final String domain;
|
||||
|
||||
public InventoryRenderHelper(String domain) {
|
||||
public InventoryRenderHelper(String domain)
|
||||
{
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Model for the given Item and meta.
|
||||
*
|
||||
* @param item - Item to register Model for
|
||||
* @param meta - Meta of Item
|
||||
* @param name - Name of the model JSON
|
||||
*
|
||||
* @param item
|
||||
* - Item to register Model for
|
||||
* @param meta
|
||||
* - Meta of Item
|
||||
* @param name
|
||||
* - Name of the model JSON
|
||||
*/
|
||||
public void itemRender(Item item, int meta, String name) {
|
||||
public void itemRender(Item item, int meta, String name)
|
||||
{
|
||||
String resName = domain + name;
|
||||
|
||||
ModelBakery.addVariantName(item, resName);
|
||||
|
@ -52,83 +58,103 @@ public class InventoryRenderHelper {
|
|||
|
||||
/**
|
||||
* Shorthand of {@code itemRender(Item, int, String)}
|
||||
*
|
||||
* @param item - Item to register Model for
|
||||
* @param meta - Meta of Item
|
||||
*
|
||||
* @param item
|
||||
* - Item to register Model for
|
||||
* @param meta
|
||||
* - Meta of Item
|
||||
*/
|
||||
public void itemRender(Item item, int meta) {
|
||||
public void itemRender(Item item, int meta)
|
||||
{
|
||||
itemRender(item, meta, getClassName(item) + meta);
|
||||
}
|
||||
|
||||
public void itemRender(Item item, String name) {
|
||||
public void itemRender(Item item, String name)
|
||||
{
|
||||
itemRender(item, 0, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand of {@code itemRender(Item, int)}
|
||||
*
|
||||
* @param item - Item to register Model for
|
||||
*
|
||||
* @param item
|
||||
* - Item to register Model for
|
||||
*/
|
||||
public void itemRender(Item item) {
|
||||
public void itemRender(Item item)
|
||||
{
|
||||
itemRender(item, 0, getClassName(item));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a model for the item across all Meta's that get used for the item
|
||||
*
|
||||
* @param item - Item to register Model for
|
||||
* Registers a model for the item across all Meta's that get used for the
|
||||
* item
|
||||
*
|
||||
* @param item
|
||||
* - Item to register Model for
|
||||
*/
|
||||
public void itemRenderAll(Item item) {
|
||||
public void itemRenderAll(Item item)
|
||||
{
|
||||
final Item toRender = item;
|
||||
|
||||
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
|
||||
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition()
|
||||
{
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack) {
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack)
|
||||
{
|
||||
return new ModelResourceLocation(domain + getClassName(toRender), "inventory");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void itemRenderToggle(Item item, String name) {
|
||||
public void itemRenderToggle(Item item, String name)
|
||||
{
|
||||
itemRender(item, 0, name + "_deactivated");
|
||||
itemRender(item, 1, name + "_activated");
|
||||
}
|
||||
|
||||
public void fluidRender(Block block) {
|
||||
public void fluidRender(Block block)
|
||||
{
|
||||
|
||||
final Block toRender = block;
|
||||
|
||||
ModelBakery.addVariantName(InventoryRenderHelper.getItemFromBlock(block));
|
||||
ModelLoader.setCustomMeshDefinition(InventoryRenderHelper.getItemFromBlock(block), new ItemMeshDefinition() {
|
||||
ModelLoader.setCustomMeshDefinition(InventoryRenderHelper.getItemFromBlock(block), new ItemMeshDefinition()
|
||||
{
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack) {
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack)
|
||||
{
|
||||
return new ModelResourceLocation(Constants.Mod.DOMAIN + toRender.getClass().getSimpleName(), "fluid");
|
||||
}
|
||||
});
|
||||
ModelLoader.setCustomStateMapper(block, new StateMapperBase() {
|
||||
ModelLoader.setCustomStateMapper(block, new StateMapperBase()
|
||||
{
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
||||
{
|
||||
return new ModelResourceLocation(domain + toRender.getClass().getSimpleName(), "fluid");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param block - Block to get Item of
|
||||
*
|
||||
* @param block
|
||||
* - Block to get Item of
|
||||
*
|
||||
* @return - The ItemBlock that corresponds to the Block.
|
||||
*/
|
||||
public static Item getItemFromBlock(Block block) {
|
||||
public static Item getItemFromBlock(Block block)
|
||||
{
|
||||
return Item.getItemFromBlock(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the class name of the given Item. If handed an ItemBlock, it will
|
||||
* use the class name of the contained Block.
|
||||
*
|
||||
*
|
||||
* @return The class name of the given Item
|
||||
*/
|
||||
private static String getClassName(Item item) {
|
||||
private static String getClassName(Item item)
|
||||
{
|
||||
return item instanceof ItemBlock ? Block.getBlockFromItem(item).getClass().getSimpleName() : item.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,21 +6,26 @@ import org.apache.commons.lang3.text.WordUtils;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TextHelper {
|
||||
public class TextHelper
|
||||
{
|
||||
|
||||
public static String getFormattedText(String string) {
|
||||
public static String getFormattedText(String string)
|
||||
{
|
||||
return string.replaceAll("&", "\u00A7");
|
||||
}
|
||||
|
||||
public static String localize(String input, Object... format) {
|
||||
public static String localize(String input, Object... format)
|
||||
{
|
||||
return StatCollector.translateToLocalFormatted(input, format);
|
||||
}
|
||||
|
||||
public static String localizeEffect(String input, Object... format) {
|
||||
public static String localizeEffect(String input, Object... format)
|
||||
{
|
||||
return getFormattedText(localize(input, format));
|
||||
}
|
||||
|
||||
public static String[] localizeAll(String[] input) {
|
||||
public static String[] localizeAll(String[] input)
|
||||
{
|
||||
String[] ret = new String[input.length];
|
||||
for (int i = 0; i < input.length; i++)
|
||||
ret[i] = localize(input[i]);
|
||||
|
@ -28,7 +33,8 @@ public class TextHelper {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static String[] localizeAllEffect(String[] input) {
|
||||
public static String[] localizeAllEffect(String[] input)
|
||||
{
|
||||
String[] ret = new String[input.length];
|
||||
for (int i = 0; i < input.length; i++)
|
||||
ret[i] = localizeEffect(input[i]);
|
||||
|
@ -36,7 +42,8 @@ public class TextHelper {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static ArrayList<String> localizeAll(List<String> input) {
|
||||
public static ArrayList<String> localizeAll(List<String> input)
|
||||
{
|
||||
ArrayList<String> ret = new ArrayList<String>(input.size());
|
||||
for (int i = 0; i < input.size(); i++)
|
||||
ret.add(i, localize(input.get(i)));
|
||||
|
@ -44,7 +51,8 @@ public class TextHelper {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static ArrayList<String> localizeAllEffect(List<String> input) {
|
||||
public static ArrayList<String> localizeAllEffect(List<String> input)
|
||||
{
|
||||
ArrayList<String> ret = new ArrayList<String>(input.size());
|
||||
for (int i = 0; i < input.size(); i++)
|
||||
ret.add(i, localizeEffect(input.get(i)));
|
||||
|
@ -52,11 +60,13 @@ public class TextHelper {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static String[] cutLongString(String string, int characters) {
|
||||
public static String[] cutLongString(String string, int characters)
|
||||
{
|
||||
return WordUtils.wrap(string, characters, "/cut", false).split("/cut");
|
||||
}
|
||||
|
||||
public static String[] cutLongString(String string) {
|
||||
public static String[] cutLongString(String string)
|
||||
{
|
||||
return cutLongString(string, 30);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue