solved some pr comments
This commit is contained in:
@@ -48,10 +48,6 @@ class TurtleGame extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
this.generatePlatform();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generatePlatform() {
|
|
||||||
for(int x = -this.radius - 1; x <= this.radius + 1; x++) {
|
for(int x = -this.radius - 1; x <= this.radius + 1; x++) {
|
||||||
for(int z = -this.radius - 1; z <= this.radius + 1; z++) {
|
for(int z = -this.radius - 1; z <= this.radius + 1; z++) {
|
||||||
double distance = new Pos(x, 0, z).distance(new Pos(0, 0, 0));
|
double distance = new Pos(x, 0, z).distance(new Pos(0, 0, 0));
|
||||||
@@ -116,8 +112,7 @@ class TurtleGame extends StatelessGame {
|
|||||||
|
|
||||||
protected void eat(Player p, Entity snack) {
|
protected void eat(Player p, Entity snack) {
|
||||||
p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EAT, Sound.Source.MASTER, 1f, 1f), snack.getPosition());
|
p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EAT, Sound.Source.MASTER, 1f, 1f), snack.getPosition());
|
||||||
Material snackMaterial = this.snackBlock.registry().material();
|
Material snackMaterial = Objects.requireNonNull(this.snackBlock.registry().material());
|
||||||
if(snackMaterial == null) snackMaterial = Material.DIRT;
|
|
||||||
p.sendPacket(new ParticlePacket(Particle.ITEM.withItem(ItemStack.of(snackMaterial)), p.getPosition(), new Pos(0.5, 0.5, 0.5), 0, 8));
|
p.sendPacket(new ParticlePacket(Particle.ITEM.withItem(ItemStack.of(snackMaterial)), p.getPosition(), new Pos(0.5, 0.5, 0.5), 0, 8));
|
||||||
this.snacks.remove(snack);
|
this.snacks.remove(snack);
|
||||||
snack.remove();
|
snack.remove();
|
||||||
@@ -184,16 +179,15 @@ class TurtleGame extends StatelessGame {
|
|||||||
private void generateNewSnack() {
|
private void generateNewSnack() {
|
||||||
Entity snack = new Entity(EntityType.FALLING_BLOCK);
|
Entity snack = new Entity(EntityType.FALLING_BLOCK);
|
||||||
FallingBlockMeta meta = (FallingBlockMeta) snack.getEntityMeta();
|
FallingBlockMeta meta = (FallingBlockMeta) snack.getEntityMeta();
|
||||||
meta.setBlock(this.snackBlock.withProperty("half", "upper"));
|
meta.setBlock(this.snackBlock);
|
||||||
meta.setCustomName(Component.text("Snack").color(NamedTextColor.WHITE));
|
meta.setCustomName(Component.text("Snack"));
|
||||||
meta.setCustomNameVisible(true);
|
meta.setCustomNameVisible(true);
|
||||||
snack.setInstance(this);
|
|
||||||
Pos spawnPosition = this.newSpawnPosition(snack);
|
Pos spawnPosition = this.newSpawnPosition(snack);
|
||||||
if(spawnPosition == null) {
|
if(spawnPosition == null) {
|
||||||
snack.remove();
|
snack.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
snack.teleport(spawnPosition);
|
snack.setInstance(this, spawnPosition);
|
||||||
this.snacks.add(snack);
|
this.snacks.add(snack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,30 +203,25 @@ class TurtleGame extends StatelessGame {
|
|||||||
meta.setBlock(Block.TNT);
|
meta.setBlock(Block.TNT);
|
||||||
meta.setCustomName(Component.text("Bomb").color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
|
meta.setCustomName(Component.text("Bomb").color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
|
||||||
meta.setCustomNameVisible(true);
|
meta.setCustomNameVisible(true);
|
||||||
bomb.setInstance(this);
|
|
||||||
Pos spawnPosition = this.newSpawnPosition(bomb, false);
|
Pos spawnPosition = this.newSpawnPosition(bomb, false);
|
||||||
if(spawnPosition == null) {
|
if(spawnPosition == null) {
|
||||||
bomb.remove();
|
bomb.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bomb.teleport(spawnPosition);
|
bomb.setInstance(this, spawnPosition);
|
||||||
this.bombs.add(bomb);
|
this.bombs.add(bomb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private @Nullable Pos newSpawnPosition(Entity entity) {
|
||||||
private Pos newSpawnPosition(Entity entity) {
|
|
||||||
return this.newSpawnPosition(entity, true);
|
return this.newSpawnPosition(entity, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private @Nullable Pos newSpawnPosition(Entity entity, boolean nearPlayers) {
|
||||||
private Pos newSpawnPosition(Entity entity, boolean nearPlayers) {
|
|
||||||
Pos spawnPosition;
|
Pos spawnPosition;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
boolean isInRadius, collides;
|
boolean isInRadius, collides;
|
||||||
do {
|
do {
|
||||||
if(counter > 200) {
|
if(counter > 200) return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int x = this.rnd.nextInt(-this.radius+2, this.radius-2);
|
int x = this.rnd.nextInt(-this.radius+2, this.radius-2);
|
||||||
int z = this.rnd.nextInt(-this.radius+2, this.radius-2);
|
int z = this.rnd.nextInt(-this.radius+2, this.radius-2);
|
||||||
spawnPosition = new Pos(x, 1, z).add(0.5, 0, 0.5);
|
spawnPosition = new Pos(x, 1, z).add(0.5, 0, 0.5);
|
||||||
|
Reference in New Issue
Block a user