develop-turtleGame #6
@@ -48,10 +48,6 @@ class TurtleGame extends StatelessGame {
|
||||
|
||||
@Override
|
||||
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 z = -this.radius - 1; z <= this.radius + 1; z++) {
|
||||
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) {
|
||||
p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EAT, Sound.Source.MASTER, 1f, 1f), snack.getPosition());
|
||||
Material snackMaterial = this.snackBlock.registry().material();
|
||||
if(snackMaterial == null) snackMaterial = Material.DIRT;
|
||||
Material snackMaterial = Objects.requireNonNull(this.snackBlock.registry().material());
|
||||
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);
|
||||
snack.remove();
|
||||
@@ -184,16 +179,15 @@ class TurtleGame extends StatelessGame {
|
||||
private void generateNewSnack() {
|
||||
Entity snack = new Entity(EntityType.FALLING_BLOCK);
|
||||
FallingBlockMeta meta = (FallingBlockMeta) snack.getEntityMeta();
|
||||
meta.setBlock(this.snackBlock.withProperty("half", "upper"));
|
||||
meta.setCustomName(Component.text("Snack").color(NamedTextColor.WHITE));
|
||||
meta.setBlock(this.snackBlock);
|
||||
meta.setCustomName(Component.text("Snack"));
|
||||
meta.setCustomNameVisible(true);
|
||||
snack.setInstance(this);
|
||||
Pos spawnPosition = this.newSpawnPosition(snack);
|
||||
if(spawnPosition == null) {
|
||||
snack.remove();
|
||||
return;
|
||||
}
|
||||
snack.teleport(spawnPosition);
|
||||
snack.setInstance(this, spawnPosition);
|
||||
this.snacks.add(snack);
|
||||
}
|
||||
|
||||
@@ -209,30 +203,25 @@ class TurtleGame extends StatelessGame {
|
||||
meta.setBlock(Block.TNT);
|
||||
meta.setCustomName(Component.text("Bomb").color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
|
||||
meta.setCustomNameVisible(true);
|
||||
bomb.setInstance(this);
|
||||
Pos spawnPosition = this.newSpawnPosition(bomb, false);
|
||||
if(spawnPosition == null) {
|
||||
bomb.remove();
|
||||
return;
|
||||
}
|
||||
bomb.teleport(spawnPosition);
|
||||
bomb.setInstance(this, spawnPosition);
|
||||
this.bombs.add(bomb);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Pos newSpawnPosition(Entity entity) {
|
||||
private @Nullable Pos newSpawnPosition(Entity entity) {
|
||||
return this.newSpawnPosition(entity, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Pos newSpawnPosition(Entity entity, boolean nearPlayers) {
|
||||
private @Nullable Pos newSpawnPosition(Entity entity, boolean nearPlayers) {
|
||||
Pos spawnPosition;
|
||||
int counter = 0;
|
||||
boolean isInRadius, collides;
|
||||
Pupsi marked this conversation as resolved
|
||||
do {
|
||||
if(counter > 200) {
|
||||
return null;
|
||||
}
|
||||
if(counter > 200) return null;
|
||||
int x = 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);
|
||||
|
Reference in New Issue
Block a user
@Nullable gehört vor die Rückgabe parameter
private @Nullable Pos newSpawnPosition(