Skip to content

Commit

Permalink
Footprint function was called too often and on client side as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ata4 committed May 29, 2016
1 parent 72067ba commit 4672cfd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,53 @@ public Item getBreedingItem() {
}

public void onUpdate(EntityTameableDragon dragon) {
// footprint loop, from EntitySnowman.onLivingUpdate with slight tweaks
placeFootprintBlocks(dragon);
}

protected void placeFootprintBlocks(EntityTameableDragon dragon) {
// only apply on server
if (!dragon.isServer()) {
return;
}

// only apply on adult dragons that don't fly
if (!dragon.isAdult() || dragon.isFlying()) {
return;
}

// only apply if footprints are enabled
float footprintChance = getFootprintChance();
if (footprintChance > 0 && dragon.isAdult() && !dragon.isFlying()) {
World world = dragon.worldObj;
for (int i = 0; i < 4; i++) {
if (world.rand.nextFloat() < footprintChance) {
continue;
}
// get footprint position
double bx = dragon.posX + (i % 2 * 2 - 1) * 0.25;
double by = dragon.posY + 0.5;
double bz = dragon.posZ + (i / 2 % 2 * 2 - 1) * 0.25;
BlockPos pos = new BlockPos(bx, by, bz);
// footprints can only be placed on empty space
if (world.isAirBlock(pos)) {
continue;
}
if (footprintChance == 0) {
return;
}

// footprint loop, from EntitySnowman.onLivingUpdate with slight tweaks
World world = dragon.worldObj;
for (int i = 0; i < 4; i++) {
// place only if randomly selected
if (world.rand.nextFloat() > footprintChance) {
continue;
}

// get footprint position
double bx = dragon.posX + (i % 2 * 2 - 1) * 0.25;
double by = dragon.posY + 0.5;
double bz = dragon.posZ + (i / 2 % 2 * 2 - 1) * 0.25;
BlockPos pos = new BlockPos(bx, by, bz);

placeFootprintBlock(dragon, pos);
// footprints can only be placed on empty space
if (world.isAirBlock(pos)) {
continue;
}

placeFootprintBlock(dragon, pos);
}
}

public void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) {
protected void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) {
}

public float getFootprintChance() {
protected float getFootprintChance() {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class DragonBreedForest extends DragonBreed {
}

@Override
public void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) {
protected void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) {
World world = dragon.worldObj;

// grow mushrooms and plants
Expand Down Expand Up @@ -109,7 +109,7 @@ public void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos)
}

@Override
public float getFootprintChance() {
protected float getFootprintChance() {
return 0.05f;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public class DragonBreedIce extends DragonBreed {
}

@Override
public float getFootprintChance() {
return 0.2f;
protected float getFootprintChance() {
return 0.1f;
}

@Override
public void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) {
protected void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) {
// place snow layer blocks, but only if the biome is cold enough
World world = dragon.worldObj;

Expand Down

0 comments on commit 4672cfd

Please sign in to comment.