aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/core/util/Utils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/miscutil/core/util/Utils.java')
-rw-r--r--src/Java/miscutil/core/util/Utils.java167
1 files changed, 161 insertions, 6 deletions
diff --git a/src/Java/miscutil/core/util/Utils.java b/src/Java/miscutil/core/util/Utils.java
index 03bd0b7ded..5dd121f9b6 100644
--- a/src/Java/miscutil/core/util/Utils.java
+++ b/src/Java/miscutil/core/util/Utils.java
@@ -6,7 +6,9 @@ import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
@@ -16,15 +18,19 @@ import miscutil.MiscUtils;
import miscutil.core.lib.CORE;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLiving;
+import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
+import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import cpw.mods.fml.common.FMLLog;
+import cpw.mods.fml.common.registry.EntityRegistry;
public class Utils {
@@ -40,7 +46,7 @@ public class Utils {
/**
* Returns a psuedo-random number between min and max, inclusive.
* The difference between min and max can be at most
- * <code>Integer.MAX_VALUE - 1</code>.
+ * Integer.MAX_VALUE - 1.
*
* @param min Minimim value
* @param max Maximim value. Must be greater than min.
@@ -97,13 +103,18 @@ public class Utils {
public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict)
{
- if (input == null && target != null || input != null && target == null)
+ if (input == null || target == null)
{
return false;
}
return (target.getItem() == input.getItem() && ((target.getItemDamage() == WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage()));
}
+ //TODO
+ public static void registerEntityToBiomeSpawns(Class<EntityLiving> classy, EnumCreatureType EntityType, BiomeGenBase baseBiomeGen){
+ EntityRegistry.addSpawn(classy, 6, 1, 5, EntityType, baseBiomeGen); //change the values to vary the spawn rarity, biome, etc.
+ }
+
//Non-Dev Comments
public static void LOG_INFO(String s){
//if (CORE.DEBUG){
@@ -270,7 +281,7 @@ public class Utils {
}
return null;
}
-
+
@Deprecated
public static Block findBlockUnderEntityNonBoundingBox(Entity parEntity){
int blockX = MathHelper.floor_double(parEntity.posX);
@@ -285,27 +296,171 @@ public class Utils {
int blockZ = MathHelper.floor_double(parEntity.posZ);
return parEntity.worldObj.getBlock(blockX, blockY, blockZ);
}
-
+
public static int getFacingDirection(Entity entity){
int d = MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360) + 0.50) & 3;
return d;
}
-
+
public static boolean isPlayerOP(EntityPlayer player){
if (player.canCommandSenderUseCommand(2, "")){
return true;
}
return false;
}
-
+
+ public static void setEntityOnFire(Entity entity, int length){
+ entity.setFire(length);
+ }
+
public static void spawnCustomParticle(Entity entity){
MiscUtils.proxy.generateMysteriousParticles(entity);
+ }
+
+ public static void spawnFX(World world, int x, int y, int z, String particleName, Object particleName2){
+ if (!world.isRemote){
+ if (particleName2 == null || particleName2.equals("")){
+ particleName2 = particleName;
+ }
+ int l = randInt(0, 4);
+ double d0 = (double)((float)x + 0.5F);
+ double d1 = (double)((float)y + 0.7F);
+ double d2 = (double)((float)z + 0.5F);
+ double d3 = 0.2199999988079071D;
+ double d4 = 0.27000001072883606D;
+
+ if (l == 1)
+ {
+ world.spawnParticle(particleName, d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
+ }
+ else if (l == 2)
+ {
+ world.spawnParticle((String) particleName2, d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
+ }
+ else if (l == 3)
+ {
+ world.spawnParticle(particleName, d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
+ }
+ else if (l == 4)
+ {
+ world.spawnParticle((String) particleName2, d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
+ }
+ else
+ {
+ world.spawnParticle(particleName, d0, d1, d2, 0.0D, 0.0D, 0.0D);
+ if (particleName2 != null){
+ world.spawnParticle((String) particleName2, d0, d1, d2, 0.0D, 0.0D, 0.0D);
+ }
+ }
+ }
}
+ public static int getHexNumberFromInt(int myRandomNumber){
+ String result = Integer.toHexString(myRandomNumber);
+ int resultINT = Integer.getInteger(result);
+ return resultINT;
+ }
+ public static int generateRandomHexValue(int min, int max){
+ int result = getHexNumberFromInt(randInt(min, max));
+ return result;
+ }
+ /*
+ * http://javadevnotes.com/java-left-pad-string-with-zeros-examples
+ */
+ public static String leftPadWithZeroes(String originalString, int length) {
+ StringBuilder sb = new StringBuilder();
+ while (sb.length() + originalString.length() < length) {
+ sb.append('0');
+ }
+ sb.append(originalString);
+ String paddedString = sb.toString();
+ return paddedString;
+ }
+
+ /*
+ * Original Code by Chandana Napagoda - https://cnapagoda.blogspot.com.au/2011/03/java-hex-color-code-generator.html
+ */
+ public static Map<Integer, String> hexColourGenerator(int colorCount){
+ int maxColorValue = 16777215;
+ // this is decimal value of the "FFFFFF"
+ int devidedvalue = maxColorValue/colorCount;
+ int countValue = 0;
+ HashMap<Integer, String> hexColorMap = new HashMap<Integer, String>();
+ for(int a=0; a < colorCount && maxColorValue >= countValue ; a++){
+ if(a != 0){
+ countValue+=devidedvalue;
+ hexColorMap.put(a,Integer.toHexString( 0x10000 | countValue).substring(1).toUpperCase());
+ }
+ else {
+ hexColorMap.put(a,Integer.toHexString( 0x10000 | countValue).substring(1).toUpperCase());
+ }
+ }
+ return hexColorMap;
+ }
+
+ /*
+ * Original Code by Chandana Napagoda - https://cnapagoda.blogspot.com.au/2011/03/java-hex-color-code-generator.html
+ */
+ public static Map<Integer, String> hexColourGeneratorRandom(int colorCount){
+ HashMap<Integer, String> hexColorMap = new HashMap<Integer, String>();
+ for(int a=0;a < colorCount; a++){
+ String code = ""+(int)(Math.random()*256);
+ code = code+code+code;
+ int i = Integer.parseInt(code);
+ hexColorMap.put(a,Integer.toHexString( 0x1000000 | i).substring(1).toUpperCase());
+ Utils.LOG_INFO(""+Integer.toHexString( 0x1000000 | i).substring(1).toUpperCase());
+ }
+ return hexColorMap;
+ }
+
+ public static String appenedHexNotationToString(Object hexAsStringOrInt){
+ String hexChar = "0x";
+ String result;
+ if (hexAsStringOrInt.getClass() == String.class){
+ result = hexChar+hexAsStringOrInt;
+ if (result.length() != 6){
+ String temp = leftPadWithZeroes(result, 6);
+ result = temp;
+ }
+ return result;
+ }
+ else if (hexAsStringOrInt.getClass() == Integer.class){
+ result = hexChar+String.valueOf(hexAsStringOrInt);
+ return result;
+ }
+ else {
+ return null;
+ }
+ }
+ public static Integer appenedHexNotationToInteger(int hexAsStringOrInt){
+ String hexChar = "0x";
+ String result;
+ Utils.LOG_INFO(String.valueOf(hexAsStringOrInt));
+ result = hexChar+String.valueOf(hexAsStringOrInt);
+ return Integer.getInteger(result);
+ }
+
+ public static int generateSingularRandomHexValue(){
+ String temp;
+ int usefuleNumber = 0;
+ int tDecided = randInt(1, 5);
+ final Map<Integer, String> colours = Utils.hexColourGeneratorRandom(5);
+
+ if (colours.get(tDecided) != null && colours.size() > 0){
+ usefuleNumber = Integer.getInteger(colours.get(tDecided));
+ }
+ else {
+ usefuleNumber = 123456;
+ }
+ Utils.LOG_INFO("Operating with "+usefuleNumber);
+ temp = Utils.appenedHexNotationToString(String.valueOf(usefuleNumber));
+ Utils.LOG_INFO("Made "+temp+" - Hopefully it's not a mess.");
+ return Integer.decode(temp);
+ }
}