Ignoring wool block when spawning floor
This commit is contained in:
parent
73604bfa1a
commit
a0d82cd1c0
@ -79,12 +79,12 @@ public class DiscoParty {
|
|||||||
private int duration, period, radius, sheep;
|
private int duration, period, radius, sheep;
|
||||||
private int state = 0; // basically our own tick system
|
private int state = 0; // basically our own tick system
|
||||||
private DiscoUpdater updater;
|
private DiscoUpdater updater;
|
||||||
|
|
||||||
public DiscoParty(DiscoSheep parent, Player player) {
|
public DiscoParty(DiscoSheep parent, Player player) {
|
||||||
this(parent);
|
this(parent);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty(DiscoSheep parent) {
|
public DiscoParty(DiscoSheep parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.duration = DiscoParty.defaultDuration;
|
this.duration = DiscoParty.defaultDuration;
|
||||||
@ -109,39 +109,39 @@ public class DiscoParty {
|
|||||||
newParty.guestNumbers = this.getGuestNumbers();
|
newParty.guestNumbers = this.getGuestNumbers();
|
||||||
return newParty;
|
return newParty;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Sheep> getSheepList() {
|
ArrayList<Sheep> getSheepList() {
|
||||||
return sheepList;
|
return sheepList;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Entity> getGuestList() {
|
ArrayList<Entity> getGuestList() {
|
||||||
return guestList;
|
return guestList;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<BlockState> getFloorCache() {
|
ArrayList<BlockState> getFloorCache() {
|
||||||
return this.floorBlockCache;
|
return this.floorBlockCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Block> getFloorBlocks() {
|
ArrayList<Block> getFloorBlocks() {
|
||||||
return this.floorBlocks;
|
return this.floorBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, Integer> getDefaultGuestNumbers() {
|
public static HashMap<String, Integer> getDefaultGuestNumbers() {
|
||||||
return defaultGuestNumbers;
|
return defaultGuestNumbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, Integer> getGuestNumbers() {
|
public HashMap<String, Integer> getGuestNumbers() {
|
||||||
return guestNumbers;
|
return guestNumbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, Integer> getMaxGuestNumbers() {
|
public static HashMap<String, Integer> getMaxGuestNumbers() {
|
||||||
return maxGuestNumbers;
|
return maxGuestNumbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSheep() {
|
public int getSheep() {
|
||||||
return this.sheep;
|
return this.sheep;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty setPlayer(Player player) {
|
public DiscoParty setPlayer(Player player) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -150,7 +150,7 @@ public class DiscoParty {
|
|||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty setDuration(int duration) throws IllegalArgumentException {
|
public DiscoParty setDuration(int duration) throws IllegalArgumentException {
|
||||||
if (duration <= DiscoParty.maxDuration && duration > 0) {
|
if (duration <= DiscoParty.maxDuration && duration > 0) {
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
@ -159,7 +159,7 @@ public class DiscoParty {
|
|||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty setPeriod(int period) throws IllegalArgumentException {
|
public DiscoParty setPeriod(int period) throws IllegalArgumentException {
|
||||||
if (period >= DiscoParty.minPeriod && period <= DiscoParty.maxPeriod) {
|
if (period >= DiscoParty.minPeriod && period <= DiscoParty.maxPeriod) {
|
||||||
this.period = period;
|
this.period = period;
|
||||||
@ -168,7 +168,7 @@ public class DiscoParty {
|
|||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty setRadius(int radius) throws IllegalArgumentException {
|
public DiscoParty setRadius(int radius) throws IllegalArgumentException {
|
||||||
if (radius <= DiscoParty.maxRadius && radius > 0) {
|
if (radius <= DiscoParty.maxRadius && radius > 0) {
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
@ -177,7 +177,7 @@ public class DiscoParty {
|
|||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty setDenseRadius(int sheepNo) throws IllegalArgumentException {
|
public DiscoParty setDenseRadius(int sheepNo) throws IllegalArgumentException {
|
||||||
Integer rand = (int) Math.floor(Math.sqrt(sheep / Math.PI));
|
Integer rand = (int) Math.floor(Math.sqrt(sheep / Math.PI));
|
||||||
if (rand > DiscoParty.maxRadius) {
|
if (rand > DiscoParty.maxRadius) {
|
||||||
@ -186,11 +186,11 @@ public class DiscoParty {
|
|||||||
if (rand < 1) {
|
if (rand < 1) {
|
||||||
rand = 1;
|
rand = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setRadius(rand);
|
this.setRadius(rand);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty setSheep(int sheep) throws IllegalArgumentException {
|
public DiscoParty setSheep(int sheep) throws IllegalArgumentException {
|
||||||
if (sheep <= DiscoParty.maxSheep && sheep > 0) {
|
if (sheep <= DiscoParty.maxSheep && sheep > 0) {
|
||||||
this.sheep = sheep;
|
this.sheep = sheep;
|
||||||
@ -199,22 +199,22 @@ public class DiscoParty {
|
|||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty setDoFireworks(boolean doFireworks) {
|
public DiscoParty setDoFireworks(boolean doFireworks) {
|
||||||
this.doFireworks = doFireworks;
|
this.doFireworks = doFireworks;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty setDoLightning(boolean doLightning) {
|
public DiscoParty setDoLightning(boolean doLightning) {
|
||||||
this.doLightning = doLightning;
|
this.doLightning = doLightning;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty setGuestNumber(String key, int n) throws IllegalArgumentException {
|
public DiscoParty setGuestNumber(String key, int n) throws IllegalArgumentException {
|
||||||
if (getMaxGuestNumbers().containsKey(key.toUpperCase())) {
|
if (getMaxGuestNumbers().containsKey(key.toUpperCase())) {
|
||||||
if (n <= getMaxGuestNumbers().get(key.toUpperCase()) && n >= 0) { // so that /ds defaults can take 0 as arg
|
if (n <= getMaxGuestNumbers().get(key.toUpperCase()) && n >= 0) { // so that /ds defaults can take 0 as arg
|
||||||
getGuestNumbers().put(key, n);
|
getGuestNumbers().put(key, n);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,10 +230,10 @@ public class DiscoParty {
|
|||||||
DiscoParty.defaultGuestNumbers = new HashMap<String, Integer>(this.getGuestNumbers());
|
DiscoParty.defaultGuestNumbers = new HashMap<String, Integer>(this.getGuestNumbers());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Location getRandomSpawnLocation(double x, double z, World world, int spawnRadius) {
|
Location getRandomSpawnLocation(double x, double z, World world, int spawnRadius) {
|
||||||
Location loc;
|
Location loc;
|
||||||
|
|
||||||
double y;
|
double y;
|
||||||
|
|
||||||
/* random point on circle with polar coordinates
|
/* random point on circle with polar coordinates
|
||||||
@ -244,11 +244,11 @@ public class DiscoParty {
|
|||||||
x += rand * Math.cos(azimuth);
|
x += rand * Math.cos(azimuth);
|
||||||
z += rand * Math.sin(azimuth);
|
z += rand * Math.sin(azimuth);
|
||||||
y = this.player.getLocation().getY();
|
y = this.player.getLocation().getY();
|
||||||
|
|
||||||
loc = new Location(world, x, y, z);
|
loc = new Location(world, x, y, z);
|
||||||
loc.setPitch(r.nextFloat() * 360 - 180);
|
loc.setPitch(r.nextFloat() * 360 - 180);
|
||||||
loc.setYaw(0);
|
loc.setYaw(0);
|
||||||
|
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,8 +256,8 @@ public class DiscoParty {
|
|||||||
void spawnAll(int sheep, int spawnRadius) {
|
void spawnAll(int sheep, int spawnRadius) {
|
||||||
Location loc;
|
Location loc;
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
|
|
||||||
|
|
||||||
double x = player.getLocation().getX();
|
double x = player.getLocation().getX();
|
||||||
double z = player.getLocation().getZ();
|
double z = player.getLocation().getZ();
|
||||||
for (int i = 0; i < sheep; i++) {
|
for (int i = 0; i < sheep; i++) {
|
||||||
@ -269,17 +269,17 @@ public class DiscoParty {
|
|||||||
for (Map.Entry entry : guestNumbers.entrySet()) {
|
for (Map.Entry entry : guestNumbers.entrySet()) {
|
||||||
EntityType ent = EntityType.valueOf((String) entry.getKey());
|
EntityType ent = EntityType.valueOf((String) entry.getKey());
|
||||||
int num = (Integer) entry.getValue();
|
int num = (Integer) entry.getValue();
|
||||||
|
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
loc = getRandomSpawnLocation(x, z, world, spawnRadius);
|
loc = getRandomSpawnLocation(x, z, world, spawnRadius);
|
||||||
spawnGuest(world, loc, ent);
|
spawnGuest(world, loc, ent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loc = player.getLocation();
|
loc = player.getLocation();
|
||||||
this.spawnFloor(world, new Location(world,loc.getBlockX(),loc.getBlockY()-1,loc.getBlockZ()));
|
this.spawnFloor(world, new Location(world, loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void spawnSheep(World world, Location loc) {
|
void spawnSheep(World world, Location loc) {
|
||||||
Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP);
|
Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP);
|
||||||
newSheep.setColor(discoColours[(r.nextInt(discoColours.length))]);
|
newSheep.setColor(discoColours[(r.nextInt(discoColours.length))]);
|
||||||
@ -290,7 +290,7 @@ public class DiscoParty {
|
|||||||
world.strikeLightningEffect(loc);
|
world.strikeLightningEffect(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spawnGuest(World world, Location loc, EntityType type) {
|
void spawnGuest(World world, Location loc, EntityType type) {
|
||||||
Entity newGuest = loc.getWorld().spawnEntity(loc, type);
|
Entity newGuest = loc.getWorld().spawnEntity(loc, type);
|
||||||
getGuestList().add(newGuest);
|
getGuestList().add(newGuest);
|
||||||
@ -298,15 +298,17 @@ public class DiscoParty {
|
|||||||
world.strikeLightningEffect(loc);
|
world.strikeLightningEffect(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spawnFloor(World world, Location loc) {
|
void spawnFloor(World world, Location loc) {
|
||||||
// First we'll save the floor state
|
// First we'll save the floor state
|
||||||
for (int x = loc.getBlockX() - this.radius; x < loc.getX() + this.radius; ++x) {
|
for (int x = loc.getBlockX() - this.radius; x < loc.getX() + this.radius; ++x) {
|
||||||
for (int z = loc.getBlockZ() - this.radius; z < loc.getZ() + this.radius; ++z) {
|
for (int z = loc.getBlockZ() - this.radius; z < loc.getZ() + this.radius; ++z) {
|
||||||
Block block = world.getBlockAt(x, loc.getBlockY(), z);
|
Block block = world.getBlockAt(x, loc.getBlockY(), z);
|
||||||
this.getFloorCache().add(block.getState());
|
if (block.getType() != Material.WOOL) {
|
||||||
block.setType(Material.WOOL);
|
this.getFloorCache().add(block.getState());
|
||||||
this.getFloorBlocks().add(block);
|
block.setType(Material.WOOL);
|
||||||
|
this.getFloorBlocks().add(block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -331,12 +333,12 @@ public class DiscoParty {
|
|||||||
void randomizeSheepColour(Sheep sheep) {
|
void randomizeSheepColour(Sheep sheep) {
|
||||||
sheep.setColor(discoColours[(r.nextInt(discoColours.length))]);
|
sheep.setColor(discoColours[(r.nextInt(discoColours.length))]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void randomizeFloorColour(Block block) {
|
void randomizeFloorColour(Block block) {
|
||||||
block.setType(Material.WOOL);
|
block.setType(Material.WOOL);
|
||||||
block.setData(discoColours[(r.nextInt(discoColours.length))].getData());
|
block.setData(discoColours[(r.nextInt(discoColours.length))].getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
void jump(Entity entity) {
|
void jump(Entity entity) {
|
||||||
Vector orgVel = entity.getVelocity();
|
Vector orgVel = entity.getVelocity();
|
||||||
Vector newVel = (new Vector()).copy(orgVel);
|
Vector newVel = (new Vector()).copy(orgVel);
|
||||||
@ -398,27 +400,27 @@ public class DiscoParty {
|
|||||||
if (i == 17) {
|
if (i == 17) {
|
||||||
c = Color.YELLOW;
|
c = Color.YELLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateAll() {
|
void updateAll() {
|
||||||
for (Sheep sheeple : getSheepList()) {
|
for (Sheep sheeple : getSheepList()) {
|
||||||
randomizeSheepColour(sheeple);
|
randomizeSheepColour(sheeple);
|
||||||
|
|
||||||
if (doFireworks && state % 8 == 0) {
|
if (doFireworks && state % 8 == 0) {
|
||||||
if (r.nextDouble() < 0.50) {
|
if (r.nextDouble() < 0.50) {
|
||||||
spawnRandomFireworkAtSheep(sheeple);
|
spawnRandomFireworkAtSheep(sheeple);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doJump) {
|
if (doJump) {
|
||||||
if (state % 2 == 0 && r.nextDouble() < 0.5) {
|
if (state % 2 == 0 && r.nextDouble() < 0.5) {
|
||||||
jump(sheeple);
|
jump(sheeple);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entity guest : getGuestList()) {
|
for (Entity guest : getGuestList()) {
|
||||||
if (doJump) {
|
if (doJump) {
|
||||||
if (state % 2 == 0 && r.nextDouble() < 0.5) {
|
if (state % 2 == 0 && r.nextDouble() < 0.5) {
|
||||||
@ -426,28 +428,28 @@ public class DiscoParty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Block block : this.floorBlocks) {
|
for (Block block : this.floorBlocks) {
|
||||||
this.randomizeFloorColour(block);
|
this.randomizeFloorColour(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getPentatonicNote() {
|
private float getPentatonicNote() {
|
||||||
return DiscoParty.pentatonicNotes[r.nextInt(pentatonicNotes.length)];
|
return DiscoParty.pentatonicNotes[r.nextInt(pentatonicNotes.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void playSounds() {
|
void playSounds() {
|
||||||
player.playSound(player.getLocation(), Sound.NOTE_BASS_DRUM, 0.75f, 1.0f);
|
player.playSound(player.getLocation(), Sound.NOTE_BASS_DRUM, 0.75f, 1.0f);
|
||||||
if (this.state % 2 == 0) {
|
if (this.state % 2 == 0) {
|
||||||
player.playSound(player.getLocation(), Sound.NOTE_SNARE_DRUM, 0.8f, 1.0f);
|
player.playSound(player.getLocation(), Sound.NOTE_SNARE_DRUM, 0.8f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((this.state + 1) % 8 == 0) {
|
if ((this.state + 1) % 8 == 0) {
|
||||||
player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1.0f, 1.0f);
|
player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void randomizeFirework(Firework firework) {
|
void randomizeFirework(Firework firework) {
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
Builder effect = FireworkEffect.builder();
|
Builder effect = FireworkEffect.builder();
|
||||||
@ -473,12 +475,12 @@ public class DiscoParty {
|
|||||||
// apply it to the given firework
|
// apply it to the given firework
|
||||||
firework.setFireworkMeta(meta);
|
firework.setFireworkMeta(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spawnRandomFireworkAtSheep(Sheep sheep) {
|
void spawnRandomFireworkAtSheep(Sheep sheep) {
|
||||||
Firework firework = (Firework) sheep.getWorld().spawnEntity(sheep.getEyeLocation(), EntityType.FIREWORK);
|
Firework firework = (Firework) sheep.getWorld().spawnEntity(sheep.getEyeLocation(), EntityType.FIREWORK);
|
||||||
randomizeFirework(firework);
|
randomizeFirework(firework);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update() {
|
void update() {
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
updateAll();
|
updateAll();
|
||||||
@ -490,12 +492,12 @@ public class DiscoParty {
|
|||||||
this.stopDisco();
|
this.stopDisco();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scheduleUpdate() {
|
void scheduleUpdate() {
|
||||||
updater = new DiscoUpdater();
|
updater = new DiscoUpdater();
|
||||||
updater.runTaskLater(parent, this.period);
|
updater.runTaskLater(parent, this.period);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startDisco() {
|
void startDisco() {
|
||||||
this.spawnAll(sheep, radius);
|
this.spawnAll(sheep, radius);
|
||||||
this.scheduleUpdate();
|
this.scheduleUpdate();
|
||||||
@ -504,7 +506,7 @@ public class DiscoParty {
|
|||||||
this.partyEvents = new PartyEvents(this.parent, this);
|
this.partyEvents = new PartyEvents(this.parent, this);
|
||||||
parent.getServer().getPluginManager().registerEvents(this.partyEvents, this.parent);
|
parent.getServer().getPluginManager().registerEvents(this.partyEvents, this.parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopDisco() {
|
void stopDisco() {
|
||||||
removeAll();
|
removeAll();
|
||||||
this.duration = 0;
|
this.duration = 0;
|
||||||
@ -516,9 +518,9 @@ public class DiscoParty {
|
|||||||
// stop listening
|
// stop listening
|
||||||
HandlerList.unregisterAll(this.partyEvents);
|
HandlerList.unregisterAll(this.partyEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DiscoUpdater extends BukkitRunnable {
|
class DiscoUpdater extends BukkitRunnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
update();
|
update();
|
||||||
|
Loading…
Reference in New Issue
Block a user