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
|
@ -15,121 +15,147 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
|||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class ChatUtil {
|
||||
public class ChatUtil
|
||||
{
|
||||
|
||||
private static final int DELETION_ID = 2525277;
|
||||
private static int lastAdded;
|
||||
|
||||
private static void sendNoSpamMessages(IChatComponent[] messages) {
|
||||
private static void sendNoSpamMessages(IChatComponent[] messages)
|
||||
{
|
||||
GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI();
|
||||
for (int i = DELETION_ID + messages.length - 1; i <= lastAdded; i++) {
|
||||
for (int i = DELETION_ID + messages.length - 1; i <= lastAdded; i++)
|
||||
{
|
||||
chat.deleteChatLine(i);
|
||||
}
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
for (int i = 0; i < messages.length; i++)
|
||||
{
|
||||
chat.printChatMessageWithOptionalDeletion(messages[i], DELETION_ID + i);
|
||||
}
|
||||
lastAdded = DELETION_ID + messages.length - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a standard {@link ChatComponentText} for the given {@link String}.
|
||||
*
|
||||
* @param s The string to wrap.
|
||||
*
|
||||
* Returns a standard {@link ChatComponentText} for the given {@link String}
|
||||
* .
|
||||
*
|
||||
* @param s
|
||||
* The string to wrap.
|
||||
*
|
||||
* @return An {@link IChatComponent} containing the string.
|
||||
*/
|
||||
public static IChatComponent wrap(String s) {
|
||||
public static IChatComponent wrap(String s)
|
||||
{
|
||||
return new ChatComponentText(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #wrap(String)
|
||||
*/
|
||||
public static IChatComponent[] wrap(String... s) {
|
||||
public static IChatComponent[] wrap(String... s)
|
||||
{
|
||||
IChatComponent[] ret = new IChatComponent[s.length];
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
for (int i = 0; i < ret.length; i++)
|
||||
{
|
||||
ret[i] = wrap(s[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a translatable chat component for the given string and format args.
|
||||
*
|
||||
* @param s The string to format
|
||||
* @param args The args to apply to the format
|
||||
* Returns a translatable chat component for the given string and format
|
||||
* args.
|
||||
*
|
||||
* @param s
|
||||
* The string to format
|
||||
* @param args
|
||||
* The args to apply to the format
|
||||
*/
|
||||
public static IChatComponent wrapFormatted(String s, Object... args) {
|
||||
public static IChatComponent wrapFormatted(String s, Object... args)
|
||||
{
|
||||
return new ChatComponentTranslation(s, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply sends the passed lines to the player in a chat message.
|
||||
*
|
||||
* @param player The player to send the chat to
|
||||
* @param lines The lines to send
|
||||
*
|
||||
* @param player
|
||||
* The player to send the chat to
|
||||
* @param lines
|
||||
* The lines to send
|
||||
*/
|
||||
public static void sendChat(EntityPlayer player, String... lines) {
|
||||
public static void sendChat(EntityPlayer player, String... lines)
|
||||
{
|
||||
sendChat(player, wrap(lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the lines before sending them.
|
||||
*
|
||||
*
|
||||
* @see #sendChat(EntityPlayer, String...)
|
||||
*/
|
||||
public static void sendChatUnloc(EntityPlayer player, String... unlocLines) {
|
||||
public static void sendChatUnloc(EntityPlayer player, String... unlocLines)
|
||||
{
|
||||
sendChat(player, TextHelper.localizeAll(unlocLines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends all passed chat components to the player.
|
||||
*
|
||||
* @param player The player to send the chat lines to.
|
||||
* @param lines The {@link IChatComponent chat components} to send.yes
|
||||
*
|
||||
* @param player
|
||||
* The player to send the chat lines to.
|
||||
* @param lines
|
||||
* The {@link IChatComponent chat components} to send.yes
|
||||
*/
|
||||
public static void sendChat(EntityPlayer player, IChatComponent... lines) {
|
||||
for (IChatComponent c : lines) {
|
||||
public static void sendChat(EntityPlayer player, IChatComponent... lines)
|
||||
{
|
||||
for (IChatComponent c : lines)
|
||||
{
|
||||
player.addChatComponentMessage(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the strings before sending them.
|
||||
*
|
||||
*
|
||||
* @see #sendNoSpamClient(String...)
|
||||
*/
|
||||
public static void sendNoSpamClientUnloc(String... unlocLines) {
|
||||
public static void sendNoSpamClientUnloc(String... unlocLines)
|
||||
{
|
||||
sendNoSpamClient(TextHelper.localizeAll(unlocLines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #sendNoSpamClient(IChatComponent...)}, but wraps the Strings
|
||||
* automatically.
|
||||
*
|
||||
* @param lines The chat lines to send
|
||||
*
|
||||
* Same as {@link #sendNoSpamClient(IChatComponent...)}, but wraps the
|
||||
* Strings automatically.
|
||||
*
|
||||
* @param lines
|
||||
* The chat lines to send
|
||||
*
|
||||
* @see #wrap(String)
|
||||
*/
|
||||
public static void sendNoSpamClient(String... lines) {
|
||||
public static void sendNoSpamClient(String... lines)
|
||||
{
|
||||
sendNoSpamClient(wrap(lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the packet sending, unsafe to call on servers.
|
||||
*
|
||||
*
|
||||
* @see #sendNoSpam(EntityPlayerMP, IChatComponent...)
|
||||
*/
|
||||
public static void sendNoSpamClient(IChatComponent... lines) {
|
||||
public static void sendNoSpamClient(IChatComponent... lines)
|
||||
{
|
||||
sendNoSpamMessages(lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the strings before sending them.
|
||||
*
|
||||
*
|
||||
* @see #sendNoSpam(EntityPlayer, String...)
|
||||
*/
|
||||
public static void sendNoSpamUnloc(EntityPlayer player, String... unlocLines) {
|
||||
public static void sendNoSpamUnloc(EntityPlayer player, String... unlocLines)
|
||||
{
|
||||
sendNoSpam(player, TextHelper.localizeAll(unlocLines));
|
||||
}
|
||||
|
||||
|
@ -137,28 +163,32 @@ public class ChatUtil {
|
|||
* @see #wrap(String)
|
||||
* @see #sendNoSpam(EntityPlayer, IChatComponent...)
|
||||
*/
|
||||
public static void sendNoSpam(EntityPlayer player, String... lines) {
|
||||
public static void sendNoSpam(EntityPlayer player, String... lines)
|
||||
{
|
||||
sendNoSpam(player, wrap(lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* First checks if the player is instanceof {@link EntityPlayerMP} before
|
||||
* casting.
|
||||
*
|
||||
*
|
||||
* @see #sendNoSpam(EntityPlayerMP, IChatComponent...)
|
||||
*/
|
||||
public static void sendNoSpam(EntityPlayer player, IChatComponent... lines) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
public static void sendNoSpam(EntityPlayer player, IChatComponent... lines)
|
||||
{
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
sendNoSpam((EntityPlayerMP) player, lines);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the strings before sending them.
|
||||
*
|
||||
*
|
||||
* @see #sendNoSpam(EntityPlayerMP, String...)
|
||||
*/
|
||||
public static void sendNoSpamUnloc(EntityPlayerMP player, String... unlocLines) {
|
||||
public static void sendNoSpamUnloc(EntityPlayerMP player, String... unlocLines)
|
||||
{
|
||||
sendNoSpam(player, TextHelper.localizeAll(unlocLines));
|
||||
}
|
||||
|
||||
|
@ -166,62 +196,75 @@ public class ChatUtil {
|
|||
* @see #wrap(String)
|
||||
* @see #sendNoSpam(EntityPlayerMP, IChatComponent...)
|
||||
*/
|
||||
public static void sendNoSpam(EntityPlayerMP player, String... lines) {
|
||||
public static void sendNoSpam(EntityPlayerMP player, String... lines)
|
||||
{
|
||||
sendNoSpam(player, wrap(lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a chat message to the client, deleting past messages also sent via
|
||||
* this method.
|
||||
*
|
||||
*
|
||||
* Credit to RWTema for the idea
|
||||
*
|
||||
* @param player The player to send the chat message to
|
||||
* @param lines The chat lines to send.
|
||||
*
|
||||
* @param player
|
||||
* The player to send the chat message to
|
||||
* @param lines
|
||||
* The chat lines to send.
|
||||
*/
|
||||
public static void sendNoSpam(EntityPlayerMP player, IChatComponent... lines) {
|
||||
public static void sendNoSpam(EntityPlayerMP player, IChatComponent... lines)
|
||||
{
|
||||
if (lines.length > 0)
|
||||
BloodMagicPacketHandler.INSTANCE.sendTo(new PacketNoSpamChat(lines), player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author tterrag1098
|
||||
*
|
||||
*
|
||||
* Ripped from EnderCore (and slightly altered)
|
||||
*/
|
||||
public static class PacketNoSpamChat implements IMessage {
|
||||
public static class PacketNoSpamChat implements IMessage
|
||||
{
|
||||
|
||||
private IChatComponent[] chatLines;
|
||||
|
||||
public PacketNoSpamChat() {
|
||||
public PacketNoSpamChat()
|
||||
{
|
||||
chatLines = new IChatComponent[0];
|
||||
}
|
||||
|
||||
private PacketNoSpamChat(IChatComponent... lines) {
|
||||
private PacketNoSpamChat(IChatComponent... lines)
|
||||
{
|
||||
// this is guaranteed to be >1 length by accessing methods
|
||||
this.chatLines = lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(chatLines.length);
|
||||
for (IChatComponent c : chatLines) {
|
||||
for (IChatComponent c : chatLines)
|
||||
{
|
||||
ByteBufUtils.writeUTF8String(buf, IChatComponent.Serializer.componentToJson(c));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
chatLines = new IChatComponent[buf.readInt()];
|
||||
for (int i = 0; i < chatLines.length; i++) {
|
||||
for (int i = 0; i < chatLines.length; i++)
|
||||
{
|
||||
chatLines[i] = IChatComponent.Serializer.jsonToComponent(ByteBufUtils.readUTF8String(buf));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<PacketNoSpamChat, IMessage> {
|
||||
public static class Handler implements IMessageHandler<PacketNoSpamChat, IMessage>
|
||||
{
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketNoSpamChat message, MessageContext ctx) {
|
||||
public IMessage onMessage(PacketNoSpamChat message, MessageContext ctx)
|
||||
{
|
||||
sendNoSpamMessages(message.chatLines);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -9,14 +9,19 @@ import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
|
|||
import WayofTime.bloodmagic.registry.ModBlocks;
|
||||
import WayofTime.bloodmagic.tile.TileInventory;
|
||||
|
||||
public class Utils {
|
||||
public class Utils
|
||||
{
|
||||
|
||||
public static boolean isInteger(String integer) {
|
||||
try {
|
||||
public static boolean isInteger(String integer)
|
||||
{
|
||||
try
|
||||
{
|
||||
Integer.parseInt(integer);
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (NumberFormatException e)
|
||||
{
|
||||
return false;
|
||||
} catch (NullPointerException e) {
|
||||
} catch (NullPointerException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// only got here if we didn't return false
|
||||
|
@ -24,27 +29,35 @@ public class Utils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Used for inserting an ItemStack with a stacksize of 1 to a tile's inventory at slot 0.
|
||||
* Returns {@code true} if the ItemStack is inserted, {@code false} otherwise
|
||||
*
|
||||
* Used for inserting an ItemStack with a stacksize of 1 to a tile's
|
||||
* inventory at slot 0. Returns {@code true} if the ItemStack is inserted,
|
||||
* {@code false} otherwise
|
||||
*
|
||||
* EG: Block Altar
|
||||
*
|
||||
* @param tile - The {@link TileInventory} to input the item to
|
||||
* @param player - The player to take the item from.
|
||||
*
|
||||
* @param tile
|
||||
* - The {@link TileInventory} to input the item to
|
||||
* @param player
|
||||
* - The player to take the item from.
|
||||
*/
|
||||
public static boolean insertItemToTile(TileInventory tile, EntityPlayer player) {
|
||||
public static boolean insertItemToTile(TileInventory tile, EntityPlayer player)
|
||||
{
|
||||
return insertItemToTile(tile, player, 0);
|
||||
}
|
||||
|
||||
public static boolean insertItemToTile(TileInventory tile, EntityPlayer player, int slot) {
|
||||
if (tile.getStackInSlot(slot) == null && player.getHeldItem() != null) {
|
||||
|
||||
public static boolean insertItemToTile(TileInventory tile, EntityPlayer player, int slot)
|
||||
{
|
||||
if (tile.getStackInSlot(slot) == null && player.getHeldItem() != null)
|
||||
{
|
||||
ItemStack input = player.getHeldItem().copy();
|
||||
input.stackSize = 1;
|
||||
player.getHeldItem().stackSize--;
|
||||
tile.setInventorySlotContents(slot, input);
|
||||
return true;
|
||||
} else if (tile.getStackInSlot(slot) != null && player.getHeldItem() == null) {
|
||||
if (!tile.getWorld().isRemote) {
|
||||
} else if (tile.getStackInSlot(slot) != null && player.getHeldItem() == null)
|
||||
{
|
||||
if (!tile.getWorld().isRemote)
|
||||
{
|
||||
EntityItem invItem = new EntityItem(tile.getWorld(), player.posX, player.posY + 0.25, player.posZ, tile.getStackInSlot(slot));
|
||||
tile.getWorld().spawnEntityInWorld(invItem);
|
||||
}
|
||||
|
@ -55,15 +68,24 @@ public class Utils {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static Block getBlockForComponent(EnumAltarComponent component) {
|
||||
switch (component) {
|
||||
case GLOWSTONE: return Blocks.glowstone;
|
||||
case BLOODSTONE: return ModBlocks.bloodStoneBrick;
|
||||
case BEACON: return Blocks.beacon;
|
||||
case BLOODRUNE: return ModBlocks.bloodRune;
|
||||
case CRYSTAL: return ModBlocks.crystal;
|
||||
case NOTAIR: return Blocks.stonebrick;
|
||||
default: return Blocks.air;
|
||||
public static Block getBlockForComponent(EnumAltarComponent component)
|
||||
{
|
||||
switch (component)
|
||||
{
|
||||
case GLOWSTONE:
|
||||
return Blocks.glowstone;
|
||||
case BLOODSTONE:
|
||||
return ModBlocks.bloodStoneBrick;
|
||||
case BEACON:
|
||||
return Blocks.beacon;
|
||||
case BLOODRUNE:
|
||||
return ModBlocks.bloodRune;
|
||||
case CRYSTAL:
|
||||
return ModBlocks.crystal;
|
||||
case NOTAIR:
|
||||
return Blocks.stonebrick;
|
||||
default:
|
||||
return Blocks.air;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,17 +21,21 @@ import net.minecraftforge.event.world.BlockEvent;
|
|||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class EventHandler {
|
||||
public class EventHandler
|
||||
{
|
||||
|
||||
@SubscribeEvent
|
||||
public void onEntityDeath(LivingHurtEvent event) {
|
||||
public void onEntityDeath(LivingHurtEvent event)
|
||||
{
|
||||
|
||||
int chestIndex = 2;
|
||||
|
||||
if (event.source.getEntity() instanceof EntityPlayer && !PlayerHelper.isFakePlayer((EntityPlayer) event.source.getEntity())) {
|
||||
if (event.source.getEntity() instanceof EntityPlayer && !PlayerHelper.isFakePlayer((EntityPlayer) event.source.getEntity()))
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) event.source.getEntity();
|
||||
|
||||
if (player.getCurrentArmor(chestIndex) != null && player.getCurrentArmor(chestIndex).getItem() instanceof ItemPackSacrifice) {
|
||||
if (player.getCurrentArmor(chestIndex) != null && player.getCurrentArmor(chestIndex).getItem() instanceof ItemPackSacrifice)
|
||||
{
|
||||
ItemPackSacrifice pack = (ItemPackSacrifice) player.getCurrentArmor(chestIndex).getItem();
|
||||
|
||||
boolean shouldSyphon = pack.getStoredLP(player.getCurrentArmor(chestIndex)) < pack.CAPACITY;
|
||||
|
@ -44,7 +48,8 @@ public class EventHandler {
|
|||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBucketFill(FillBucketEvent event) {
|
||||
public void onBucketFill(FillBucketEvent event)
|
||||
{
|
||||
if (event.current.getItem() != Items.bucket)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +57,8 @@ public class EventHandler {
|
|||
|
||||
Block block = event.world.getBlockState(event.target.getBlockPos()).getBlock();
|
||||
|
||||
if (block != null && (block.equals(ModBlocks.lifeEssence)) && block.getMetaFromState(event.world.getBlockState(event.target.getBlockPos())) == 0) {
|
||||
if (block != null && (block.equals(ModBlocks.lifeEssence)) && block.getMetaFromState(event.world.getBlockState(event.target.getBlockPos())) == 0)
|
||||
{
|
||||
event.world.setBlockToAir(event.target.getBlockPos());
|
||||
result = new ItemStack(ModItems.bucketEssence);
|
||||
}
|
||||
|
@ -65,17 +71,22 @@ public class EventHandler {
|
|||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void harvestEvent(PlayerEvent.HarvestCheck event) {
|
||||
if (event.block != null && event.block instanceof BlockAltar && event.entityPlayer != null && event.entityPlayer instanceof EntityPlayerMP && event.entityPlayer.getCurrentEquippedItem() != null && event.entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemAltarMaker) {
|
||||
public void harvestEvent(PlayerEvent.HarvestCheck event)
|
||||
{
|
||||
if (event.block != null && event.block instanceof BlockAltar && event.entityPlayer != null && event.entityPlayer instanceof EntityPlayerMP && event.entityPlayer.getCurrentEquippedItem() != null && event.entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemAltarMaker)
|
||||
{
|
||||
ItemAltarMaker altarMaker = (ItemAltarMaker) event.entityPlayer.getCurrentEquippedItem().getItem();
|
||||
ChatUtil.sendNoSpam(event.entityPlayer, TextHelper.localizeEffect("chat.BloodMagic.altarMaker.destroy", altarMaker.destroyAltar(event.entityPlayer)));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBlockBreak(BlockEvent.BreakEvent event) {
|
||||
if (!event.world.isRemote && event.getPlayer() != null) {
|
||||
if (event.getPlayer().capabilities.isCreativeMode && event.getPlayer().getCurrentEquippedItem() != null && event.getPlayer().getCurrentEquippedItem().getItem() instanceof ItemBoundSword) {
|
||||
public void onBlockBreak(BlockEvent.BreakEvent event)
|
||||
{
|
||||
if (!event.world.isRemote && event.getPlayer() != null)
|
||||
{
|
||||
if (event.getPlayer().capabilities.isCreativeMode && event.getPlayer().getCurrentEquippedItem() != null && event.getPlayer().getCurrentEquippedItem().getItem() instanceof ItemBoundSword)
|
||||
{
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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