Optimised UtilBlockText

This commit is contained in:
Sam 2018-07-01 13:57:08 +01:00 committed by Alexander Meech
parent 89d95adfb2
commit d418bb276e
2 changed files with 20 additions and 89 deletions

View File

@ -1,11 +1,13 @@
package mineplex.core.common.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -19,77 +21,7 @@ public class UtilBlockText
CENTER
}
public static HashMap<Character, int[][]> alphabet = new HashMap<Character, int[][]>();
public static ArrayList<Location> GetTextLocations(String string, Location loc, BlockFace face)
{
if (alphabet.isEmpty())
PopulateAlphabet();
ArrayList<Location> locs = new ArrayList<Location>();
Block block = loc.getBlock();
//Get Width
int width = 0;
for (char c : string.toLowerCase().toCharArray())
{
int[][] letter = alphabet.get(c);
if (letter == null)
continue;
width += (letter[0].length+1) * 3;
}
//Shift Blocks
block = block.getRelative(face, (-1 * width/2) + 1);
//Clean
World world = block.getWorld();
int bX = block.getX();
int bY = block.getY();
int bZ = block.getZ();
//Make Blocks
for (char c : string.toLowerCase().toCharArray())
{
int[][] letter = alphabet.get(c);
if (letter == null)
continue;
for (int x=0 ; x<letter.length ; x++)
{
for (int y=0 ; y<letter[x].length ; y++)
{
if (letter[x][y] == 1)
locs.add(new Location(world, bX, bY, bZ));
//Forward
bX += face.getModX() * 3;
bY += face.getModY() * 3;
bZ += face.getModZ() * 3;
}
//Back
bX += face.getModX() * -3 * letter[x].length;
bY += face.getModY() * -3 * letter[x].length;
bZ += face.getModZ() * -3 * letter[x].length;
//Down
bY -= 3;
}
bY += 15;
bX += face.getModX() * (letter[0].length + 1) * 3;
bY += face.getModY() * (letter[0].length + 1) * 3;
bZ += face.getModZ() * (letter[0].length + 1) * 3;
}
return locs;
}
public static final Map<Character, int[][]> alphabet = new HashMap<>();
public static Collection<Block> MakeText(String string, Location loc, BlockFace face, int id, byte data, TextAlign align)
{
@ -98,7 +30,7 @@ public class UtilBlockText
public static Collection<Block> MakeText(String string, Location loc, BlockFace face, int id, byte data, TextAlign align, boolean setAir)
{
HashSet<Block> changes = new HashSet<Block>();
Set<Block> changes = new HashSet<>();
if (alphabet.isEmpty())
PopulateAlphabet();
@ -139,24 +71,21 @@ public class UtilBlockText
if (align == TextAlign.CENTER)
for (int i=-64 ; i<=64 ; i++)
{
if (world.getBlockAt(bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ()).getTypeId() == id)
MapUtil.ChunkBlockSet(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0, true);
MapUtil.QuickChangeBlockAt(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), Material.AIR);
}
if (align == TextAlign.LEFT)
for (int i=0 ; i<=128 ; i++)
{
if (world.getBlockAt(bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ()).getTypeId() == id)
MapUtil.ChunkBlockSet(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0, true);
MapUtil.QuickChangeBlockAt(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), Material.AIR);
}
if (align == TextAlign.RIGHT)
for (int i=-128 ; i<=0 ; i++)
{
if (world.getBlockAt(bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ()).getTypeId() == id)
MapUtil.ChunkBlockSet(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0, true);
MapUtil.QuickChangeBlockAt(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), Material.AIR);
}
@ -177,26 +106,28 @@ public class UtilBlockText
if (letter == null)
continue;
for (int x=0 ; x<letter.length ; x++)
for (int[] aLetter : letter)
{
for (int y=0 ; y<letter[x].length ; y++)
for (int anALetter : aLetter)
{
if (letter[x][y] == 1)
if (anALetter == 1)
{
changes.add(world.getBlockAt(bX, bY, bZ));
MapUtil.ChunkBlockSet(world, bX, bY, bZ, id, data, true);
Block changed = world.getBlockAt(bX, bY, bZ);
changes.add(changed);
MapUtil.QuickChangeBlockAt(changed.getLocation(), id, data);
}
//Forward
bX += face.getModX();
bY += face.getModY();
bZ += face.getModZ();
bZ += face.getModZ();
}
//Back
bX += face.getModX() * -1 * letter[x].length;
bY += face.getModY() * -1 * letter[x].length;
bZ += face.getModZ() * -1 * letter[x].length;
bX += face.getModX() * -1 * aLetter.length;
bY += face.getModY() * -1 * aLetter.length;
bZ += face.getModZ() * -1 * aLetter.length;
//Down
bY--;

View File

@ -70,7 +70,7 @@ public class PerkSlowSnowball extends Perk
return;
}
Manager.GetCondition().Factory().Slow(GetName(), damagee, damager, 3, 0, false, true, false, false);
Manager.GetCondition().Factory().Slow(GetName(), damagee, damager, 2.5, 1, false, true, false, false);
event.AddMod(damager.getName(), GetName(), 1, true);
event.AddKnockback(GetName(), 0.5);
}