A whole lot of formatting cleanup

Also changes NBTHolder to a standard Constants class with subclasses for each category
This commit is contained in:
Nick 2015-11-28 18:25:46 -08:00
parent f9802900db
commit 34dee6447b
74 changed files with 861 additions and 662 deletions

View file

@ -17,50 +17,6 @@ import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class ChatUtil {
/**
* @author tterrag1098
*
* Ripped from EnderCore (and slightly altered)
*/
public static class PacketNoSpamChat implements IMessage {
private IChatComponent[] chatLines;
public PacketNoSpamChat() {
chatLines = new IChatComponent[0];
}
private PacketNoSpamChat(IChatComponent... lines) {
// this is guaranteed to be >1 length by accessing methods
this.chatLines = lines;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(chatLines.length);
for (IChatComponent c : chatLines) {
ByteBufUtils.writeUTF8String(buf, IChatComponent.Serializer.componentToJson(c));
}
}
@Override
public void fromBytes(ByteBuf buf) {
chatLines = new IChatComponent[buf.readInt()];
for (int i = 0; i < chatLines.length; i++) {
chatLines[i] = IChatComponent.Serializer.jsonToComponent(ByteBufUtils.readUTF8String(buf));
}
}
public static class Handler implements IMessageHandler<PacketNoSpamChat, IMessage> {
@Override
public IMessage onMessage(PacketNoSpamChat message, MessageContext ctx) {
sendNoSpamMessages(message.chatLines);
return null;
}
}
}
private static final int DELETION_ID = 2525277;
private static int lastAdded;
@ -78,8 +34,8 @@ public class ChatUtil {
/**
* Returns a standard {@link ChatComponentText} for the given {@link String}.
*
* @param s
* The string to wrap.
* @param s The string to wrap.
*
* @return An {@link IChatComponent} containing the string.
*/
public static IChatComponent wrap(String s) {
@ -100,10 +56,8 @@ public class ChatUtil {
/**
* 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
* @param s The string to format
* @param args The args to apply to the format
*/
public static IChatComponent wrapFormatted(String s, Object... args) {
return new ChatComponentTranslation(s, args);
@ -112,10 +66,8 @@ public class ChatUtil {
/**
* 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) {
sendChat(player, wrap(lines));
@ -133,10 +85,8 @@ public class ChatUtil {
/**
* 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) {
@ -157,8 +107,8 @@ public class ChatUtil {
* Same as {@link #sendNoSpamClient(IChatComponent...)}, but wraps the Strings
* automatically.
*
* @param lines
* The chat lines to send
* @param lines The chat lines to send
*
* @see #wrap(String)
*/
public static void sendNoSpamClient(String... lines) {
@ -223,16 +173,58 @@ public class ChatUtil {
/**
* Sends a chat message to the client, deleting past messages also sent via
* this method.
* <p>
* <p/>
* 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) {
if (lines.length > 0)
BloodMagicPacketHandler.INSTANCE.sendTo(new PacketNoSpamChat(lines), player);
}
/**
* @author tterrag1098
* <p/>
* Ripped from EnderCore (and slightly altered)
*/
public static class PacketNoSpamChat implements IMessage {
private IChatComponent[] chatLines;
public PacketNoSpamChat() {
chatLines = new IChatComponent[0];
}
private PacketNoSpamChat(IChatComponent... lines) {
// this is guaranteed to be >1 length by accessing methods
this.chatLines = lines;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(chatLines.length);
for (IChatComponent c : chatLines) {
ByteBufUtils.writeUTF8String(buf, IChatComponent.Serializer.componentToJson(c));
}
}
@Override
public void fromBytes(ByteBuf buf) {
chatLines = new IChatComponent[buf.readInt()];
for (int i = 0; i < chatLines.length; i++) {
chatLines[i] = IChatComponent.Serializer.jsonToComponent(ByteBufUtils.readUTF8String(buf));
}
}
public static class Handler implements IMessageHandler<PacketNoSpamChat, IMessage> {
@Override
public IMessage onMessage(PacketNoSpamChat message, MessageContext ctx) {
sendNoSpamMessages(message.chatLines);
return null;
}
}
}
}

View file

@ -10,9 +10,9 @@ public class Utils {
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
@ -21,7 +21,7 @@ public class Utils {
/**
* Used for inserting an ItemStack with a stacksize of 1 to a tile's inventory at slot 0.
*
* <p/>
* EG: Block Altar
*
* @param tile - The {@link TileInventory} to input the item to

View file

@ -8,7 +8,6 @@ import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import net.minecraftforge.fml.common.eventhandler.Event;

View file

@ -1,6 +1,6 @@
package WayofTime.bloodmagic.util.helper;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
@ -14,15 +14,15 @@ 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.
* <p/>
* The goal of this class is to make registering the inventory renders
* for your Items/Blocks a much simpler and easier process.
* <p/>
* You must call this at the post initialization stage on
* the clientside only.
* <p/>
* If you pass a Block through here that uses the default
* ItemBlock, you should specify a custom name.
*/
public class InventoryRenderHelper {
@ -31,7 +31,7 @@ public class InventoryRenderHelper {
* your modid in all lowercase with a colon at the end.
*/
private final String domain;
public InventoryRenderHelper(String domain) {
this.domain = domain;
}
@ -102,7 +102,7 @@ public class InventoryRenderHelper {
ModelLoader.setCustomMeshDefinition(InventoryRenderHelper.getItemFromBlock(block), new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(BloodMagic.DOMAIN + toRender.getClass().getSimpleName(), "fluid");
return new ModelResourceLocation(Constants.Mod.DOMAIN + toRender.getClass().getSimpleName(), "fluid");
}
});
ModelLoader.setCustomStateMapper(block, new StateMapperBase() {
@ -114,14 +114,20 @@ public class InventoryRenderHelper {
}
/**
*
* @param block - Block to get Item of
* @return - The ItemBlock that corresponds to the Block.
*
* @return - The ItemBlock that corresponds to the 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) {
return item instanceof ItemBlock ? Block.getBlockFromItem(item).getClass().getSimpleName() : item.getClass().getSimpleName();
}

View file

@ -1,8 +1,9 @@
package WayofTime.bloodmagic.util.helper;
import com.google.common.collect.Lists;
import net.minecraft.util.StatCollector;
import org.apache.commons.lang3.text.WordUtils;
import java.util.ArrayList;
import java.util.List;
public class TextHelper {
@ -11,30 +12,51 @@ public class TextHelper {
return string.replaceAll("&", "\u00A7");
}
public static String localize(String key, Object ... format) {
return getFormattedText(StatCollector.translateToLocalFormatted(key, format));
public static String localize(String input, Object... format) {
return StatCollector.translateToLocalFormatted(input, format);
}
/**
* Localizes all strings in a list, using the prefix.
*
* @param unloc
* The list of unlocalized strings.
* @return A list of localized versions of the passed strings.
*/
public static List<String> localizeAll(List<String> unloc) {
List<String> ret = Lists.newArrayList();
for (String s : unloc)
ret.add(localize(s));
public static String localizeEffect(String input, Object... format) {
return localize(input.replaceAll("&", "\u00A7"), format);
}
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]);
return ret;
}
public static String[] localizeAll(String... unloc) {
String[] ret = new String[unloc.length];
for (int i = 0; i < ret.length; i++)
ret[i] = localize(unloc[i]);
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]);
return ret;
}
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)));
return ret;
}
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)));
return ret;
}
public static String[] cutLongString(String string, int characters) {
return WordUtils.wrap(string, characters, "/cut", false).split("/cut");
}
public static String[] cutLongString(String string) {
return cutLongString(string, 30);
}
}