More optimizing.

This commit is contained in:
GJ 2012-02-23 22:26:20 -05:00
parent 10fa9e5465
commit 19ab8b89f5
6 changed files with 38 additions and 94 deletions

View File

@ -23,7 +23,6 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
@ -180,15 +179,21 @@ public class m
return true;
}
public static void mcDropItem(Location location, int id)
public static void mcDropItems(Location location, ItemStack is, int quantity)
{
if(location == null) return;
Material mat = Material.getMaterial(id);
ItemStack item = new ItemStack(mat, 1, (byte) 0, (byte) 0);
mcDropItem(location, item);
for(int i = 0; i < quantity; i++)
mcDropItem(location, is);
}
public static void mcRandomDropItem(Location location, ItemStack is, int chance)
{
if(Math.random() * 100 < chance)
mcDropItem(location, is);
}
public static void mcRandomDropItems(Location location, ItemStack is, int chance, int quantity)
{
for(int i = 0; i < quantity; i++)
mcRandomDropItem(location, is, chance);
}
public static void mcDropItem(Location location, ItemStack itemStack) {
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack);

View File

@ -49,56 +49,33 @@ public class BlastMining{
return;
}
switch (id)
{
switch (id){
//GLOWSTONE
case 89:
mat = Material.getMaterial(348);
item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
m.mcDropItems(loc, item, 2);
m.mcRandomDropItems(loc, item, 50, 2);
break;
//REDSTONE
case 73:
mat = Material.getMaterial(331);
item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
m.mcDropItems(loc, item, 4);
m.mcRandomDropItem(loc, item, 50);
break;
case 74:
mat = Material.getMaterial(331);
item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
m.mcDropItems(loc, item, 4);
m.mcRandomDropItem(loc, item, 50);
break;
//LAPIS
case 21:
mat = Material.getMaterial(351);
item = new ItemStack(mat, 1, (byte)0,(byte)0x4);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
m.mcDropItems(loc, item, 4);
m.mcRandomDropItems(loc, item, 50, 4);
break;
//DIAMOND
case 56:
@ -118,7 +95,7 @@ public class BlastMining{
item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item);
break;
}
}
}
/*

View File

@ -193,14 +193,8 @@ public class Herbalism
{
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
{
m.mcDropItem(loc, is);
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
m.mcDropItems(loc, is, 2);
m.mcRandomDropItems(loc, is, 50, 3);
}
}
}
@ -310,17 +304,8 @@ public class Herbalism
{
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
{
m.mcDropItem(loc, is);
m.mcDropItem(loc, is);
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, is);
m.mcDropItems(loc, is, 3);
m.mcRandomDropItems(loc, is, 50, 4);
}
}
PP.addXP(SkillType.HERBALISM, LoadProperties.mmelon, player);

View File

@ -100,50 +100,28 @@ public class Mining
case 89:
mat = Material.getMaterial(348);
item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
m.mcDropItems(loc, item, 2);
m.mcRandomDropItems(loc, item, 50, 2);
break;
//REDSTONE
case 73:
mat = Material.getMaterial(331);
item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
m.mcDropItems(loc, item, 4);
m.mcRandomDropItem(loc, item, 50);
break;
case 74:
mat = Material.getMaterial(331);
item = new ItemStack(mat, 1, (byte)0, damage);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
m.mcDropItems(loc, item, 4);
m.mcRandomDropItem(loc, item, 50);
break;
//LAPIS
case 21:
mat = Material.getMaterial(351);
item = new ItemStack(mat, 1, (byte)0,(byte)0x4);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
if(Math.random() * 10 > 5)
m.mcDropItem(loc, item);
m.mcDropItems(loc, item, 4);
m.mcRandomDropItems(loc, item, 50, 4);
break;
//DIAMOND
case 56:

View File

@ -441,7 +441,7 @@ public class Skills
Integer x = 0;
while(x < plugin.misc.arrowTracker.get(entity))
{
m.mcDropItem(entity.getLocation(), 262);
m.mcDropItem(entity.getLocation(), new ItemStack(262, 1));
x++;
}
}

View File

@ -109,9 +109,8 @@ public class WoodCutting
Material mat = Material.SAPLING;
ItemStack item = new ItemStack(mat, 1, (short)0, (byte)(x.getData()-8));
//1 in 10 chance to drop sapling
if(Math.random() * 10 > 9)
m.mcDropItem(x.getLocation(), item);
//90% chance to drop sapling
m.mcRandomDropItem(x.getLocation(), item, 90);
//Remove the block
x.setData((byte) 0);