diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2018-05-24 15:50:07 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2018-05-24 15:50:07 -0400 |
| commit | 4f7ad220df0438b6f3382110577b53f29da46453 (patch) | |
| tree | 07d5e7c812721753cdbe3df7226dad5dc3802c29 /src/main/java/darkknight/jewelrycraft/item/ItemSpawnEgg.java | |
| parent | 01c8701b68986ccfa83e902515716838d6829311 (diff) | |
Update of all changes
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/item/ItemSpawnEgg.java')
| -rwxr-xr-x[-rw-r--r--] | src/main/java/darkknight/jewelrycraft/item/ItemSpawnEgg.java | 110 |
1 files changed, 77 insertions, 33 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/item/ItemSpawnEgg.java b/src/main/java/darkknight/jewelrycraft/item/ItemSpawnEgg.java index 474c778..cceab12 100644..100755 --- a/src/main/java/darkknight/jewelrycraft/item/ItemSpawnEgg.java +++ b/src/main/java/darkknight/jewelrycraft/item/ItemSpawnEgg.java @@ -3,6 +3,7 @@ package darkknight.jewelrycraft.item; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import darkknight.jewelrycraft.entities.EntityHeart;
@@ -27,10 +28,14 @@ import net.minecraft.world.World; * @author Betweenlands
*/
public class ItemSpawnEgg extends ItemMonsterPlacer {
- private static final Map<Short, EggData> eggTypes = new LinkedHashMap<Short, EggData>();
-
- public static void registerSpawnEgg(Class<? extends EntityLiving> entity, String entityName, int id, int eggBackgroundColor, int eggForegroundColor) {
- eggTypes.put((short) id, new EggData(id, entityName, entity, eggBackgroundColor, eggForegroundColor));
+ private static final Map<Short, EggData> eggTypes =
+ new LinkedHashMap<Short, EggData>();
+
+ public static void registerSpawnEgg(
+ Class<? extends EntityLiving> entity, String entityName,
+ int id, int eggBackgroundColor, int eggForegroundColor) {
+ eggTypes.put((short) id, new EggData(id, entityName, entity,
+ eggBackgroundColor, eggForegroundColor));
}
private static EggData getEggData(ItemStack is) {
@@ -44,18 +49,24 @@ public class ItemSpawnEgg extends ItemMonsterPlacer { @Override
public String getItemStackDisplayName(ItemStack is) {
- String s = StatCollector.translateToLocal(getUnlocalizedName() + ".name").trim();
+ String s = StatCollector
+ .translateToLocal(getUnlocalizedName() + ".name").trim();
String mob = "";
EggData egg = getEggData(is);
- if (egg != null) mob = StatCollector.translateToLocal("entity." + Variables.MODID + "." + egg.entityName + ".name");
+ if (egg != null)
+ mob = StatCollector.translateToLocal("entity."
+ + Variables.MODID + "." + egg.entityName + ".name");
return String.format(s, mob);
}
@Override
- public boolean onItemUse(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
- if (world.isRemote) return true;
+ public boolean onItemUse(ItemStack is, EntityPlayer player,
+ World world, int x, int y, int z, int side, float hitX,
+ float hitY, float hitZ) {
+ if (world.isRemote)
+ return true;
Block block = world.getBlock(x, y, z);
x += Facing.offsetsXForSide[side];
@@ -64,31 +75,41 @@ public class ItemSpawnEgg extends ItemMonsterPlacer { EggData egg = getEggData(is);
if (egg != null) {
- egg.spawnMob(world, x + 0.5D, y + (side == 1 && block != null && block.getRenderType() == 11 ? 0.5D : 0D), z + 0.5D, is);
+ egg.spawnMob(world, x + 0.5D,
+ y + (side == 1 && block != null
+ && block.getRenderType() == 11 ? 0.5D : 0D),
+ z + 0.5D, is);
- if (!player.capabilities.isCreativeMode) --is.stackSize;
+ if (!player.capabilities.isCreativeMode)
+ --is.stackSize;
}
return true;
}
@Override
- public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player) {
- if (world.isRemote) return is;
+ public ItemStack onItemRightClick(ItemStack is, World world,
+ EntityPlayer player) {
+ if (world.isRemote)
+ return is;
- MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world, player, true);
+ MovingObjectPosition mop =
+ getMovingObjectPositionFromPlayer(world, player, true);
if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
int x = mop.blockX, y = mop.blockY, z = mop.blockZ;
- if (!world.canMineBlock(player, x, y, z) || !player.canPlayerEdit(x, y, z, mop.sideHit, is)) return is;
+ if (!world.canMineBlock(player, x, y, z)
+ || !player.canPlayerEdit(x, y, z, mop.sideHit, is))
+ return is;
if (world.getBlock(x, y, z).getMaterial() == Material.water) {
EggData egg = getEggData(is);
if (egg != null) {
egg.spawnMob(world, x, y, z, is);
- if (!player.capabilities.isCreativeMode) --is.stackSize;
+ if (!player.capabilities.isCreativeMode)
+ --is.stackSize;
}
}
}
@@ -96,7 +117,8 @@ public class ItemSpawnEgg extends ItemMonsterPlacer { return is;
}
- public static EntityLiving getEntity(World world, double x, double y, double z, ItemStack is) {
+ public static EntityLiving getEntity(World world, double x, double y,
+ double z, ItemStack is) {
EggData egg = getEggData(is);
return egg.spawnMob(world, x, y, z, is);
}
@@ -105,10 +127,11 @@ public class ItemSpawnEgg extends ItemMonsterPlacer { @SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack is, int pass) {
EggData egg = getEggData(is);
- return egg != null ? pass == 0 ? egg.primaryColor : egg.secondaryColor : 16777215;
+ return egg != null
+ ? pass == 0 ? egg.primaryColor : egg.secondaryColor
+ : 16777215;
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item id, CreativeTabs tab, List list) {
@@ -123,11 +146,19 @@ public class ItemSpawnEgg extends ItemMonsterPlacer { int primaryColor;
int secondaryColor;
- EggData(int id, String entityName, Class<? extends EntityLiving> entityClass, int[] rgbPrimaryColor, int[] rgbSecondaryColor) {
- this(id, entityName, entityClass, rgbPrimaryColor[0] << 16 | rgbPrimaryColor[1] << 8 | rgbPrimaryColor[2], rgbSecondaryColor[0] << 16 | rgbSecondaryColor[1] << 8 | rgbSecondaryColor[2]);
+ EggData(int id, String entityName,
+ Class<? extends EntityLiving> entityClass,
+ int[] rgbPrimaryColor, int[] rgbSecondaryColor) {
+ this(id, entityName, entityClass,
+ rgbPrimaryColor[0] << 16 | rgbPrimaryColor[1] << 8
+ | rgbPrimaryColor[2],
+ rgbSecondaryColor[0] << 16 | rgbSecondaryColor[1] << 8
+ | rgbSecondaryColor[2]);
}
- EggData(int id, String entityName, Class<? extends EntityLiving> entityClass, int primaryColor, int secondaryColor) {
+ EggData(int id, String entityName,
+ Class<? extends EntityLiving> entityClass,
+ int primaryColor, int secondaryColor) {
this.id = (short) id;
this.entityName = entityName;
this.entityClass = entityClass;
@@ -135,35 +166,48 @@ public class ItemSpawnEgg extends ItemMonsterPlacer { this.secondaryColor = secondaryColor;
}
- public EntityLiving spawnMob(World world, double x, double y, double z, ItemStack is) {
+ public EntityLiving spawnMob(World world, double x, double y,
+ double z, ItemStack is) {
EntityLiving e = null;
try {
- e = entityClass.getConstructor(World.class).newInstance(world);
+ e = entityClass.getConstructor(World.class)
+ .newInstance(world);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
- if (e == null) return null;
+ if (e == null)
+ return null;
if (e instanceof EntityHeart) {
- if (id == 2) ((EntityHeart) e).setType("White");
- else if (id == 3) ((EntityHeart) e).setType("Blue");
- else if (id == 4) ((EntityHeart) e).setType("Black");
- else if (id == 6) ((EntityHeart) e).setType("White");
- else if (id == 7) ((EntityHeart) e).setType("Blue");
- else if (id == 8) ((EntityHeart) e).setType("Black");
- else ((EntityHeart) e).setType("Red");
+ if (id == 2)
+ ((EntityHeart) e).setType("White");
+ else if (id == 3)
+ ((EntityHeart) e).setType("Blue");
+ else if (id == 4)
+ ((EntityHeart) e).setType("Black");
+ else if (id == 6)
+ ((EntityHeart) e).setType("White");
+ else if (id == 7)
+ ((EntityHeart) e).setType("Blue");
+ else if (id == 8)
+ ((EntityHeart) e).setType("Black");
+ else
+ ((EntityHeart) e).setType("Red");
}
- e.setLocationAndAngles(x, y, z, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360F), 0F);
+ e.setLocationAndAngles(x, y, z, MathHelper
+ .wrapAngleTo180_float(world.rand.nextFloat() * 360F),
+ 0F);
e.rotationYawHead = e.rotationYaw;
e.renderYawOffset = e.rotationYaw;
e.onSpawnWithEgg((IEntityLivingData) null);
world.spawnEntityInWorld(e);
e.playLivingSound();
- if (is.hasDisplayName()) e.setCustomNameTag(is.getDisplayName());
+ if (is.hasDisplayName())
+ e.setCustomNameTag(is.getDisplayName());
return e;
}
|
