Skip to content

Commit

Permalink
Fix crash for crumbling/transmuting effect if effect range is 0 (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
mM4ri and Dream-Master authored Jan 2, 2025
1 parent 8fb3407 commit c4cb9a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ protected IEffectData doEffectThrottled(IBeeGenome genome, IEffectData storedDat
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);

// Get random coords within territory
int xRange = (int) (beeModifier.getTerritoryModifier(genome, 1f) * genome.getTerritory()[0]);
int yRange = (int) (beeModifier.getTerritoryModifier(genome, 1f) * genome.getTerritory()[1]);
int zRange = (int) (beeModifier.getTerritoryModifier(genome, 1f) * genome.getTerritory()[2]);
int[] randomCoords = new int[3];
for (int i = 0; i < 3; i++) {
int range = (int) (beeModifier.getTerritoryModifier(genome, 1f) * genome.getTerritory()[i]);
if (range > 0) {
randomCoords[i] = world.rand.nextInt(range) - range / 2;
}
}

int xCoord = coords.posX + world.rand.nextInt(xRange) - xRange / 2;
int yCoord = coords.posY + world.rand.nextInt(yRange) - yRange / 2;
int zCoord = coords.posZ + world.rand.nextInt(zRange) - zRange / 2;
int xCoord = coords.posX + randomCoords[0];
int yCoord = coords.posY + randomCoords[1];
int zCoord = coords.posZ + randomCoords[2];

Block block = world.getBlock(xCoord, yCoord, zCoord);
if (block != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ protected IEffectData doEffectThrottled(IBeeGenome genome, IEffectData storedDat
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);

// Get random coords within territory
int xRange = (int) (beeModifier.getTerritoryModifier(genome, 1f) * genome.getTerritory()[0]);
int yRange = (int) (beeModifier.getTerritoryModifier(genome, 1f) * genome.getTerritory()[1]);
int zRange = (int) (beeModifier.getTerritoryModifier(genome, 1f) * genome.getTerritory()[2]);
int[] randomCoords = new int[3];
for (int i = 0; i < 3; i++) {
int range = (int) (beeModifier.getTerritoryModifier(genome, 1f) * genome.getTerritory()[i]);
if (range > 0) {
randomCoords[i] = world.rand.nextInt(range) - range / 2;
}
}

int xCoord = coords.posX + world.rand.nextInt(xRange) - xRange / 2;
int yCoord = coords.posY + world.rand.nextInt(yRange) - yRange / 2;
int zCoord = coords.posZ + world.rand.nextInt(zRange) - zRange / 2;
int xCoord = coords.posX + randomCoords[0];
int yCoord = coords.posY + randomCoords[1];
int zCoord = coords.posZ + randomCoords[2];

BiomeGenBase biome = world.getBiomeGenForCoords(xCoord, zCoord);
transmutationController.attemptTransmutations(
Expand Down

0 comments on commit c4cb9a1

Please sign in to comment.