Compare commits

...
9 Commits
2 changed files with 53 additions and 22 deletions

No files matched your search

@@ -21,7 +21,7 @@ import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.apiculture.blocks.BlockAlveary;
import forestry.apiculture.multiblock.AlvearyController;
import forestry.core.utils.DamageSourceForestry;
import forestry.core.utils.vect.Vect;
@@ -36,8 +36,13 @@ public class AlleleEffectRadioactive extends AlleleEffectThrottled {
@Override
public IEffectData doEffectThrottled(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
harmEntities(genome, housing);
if (isMobGriefingEnabled(housing)) destroyEnvironment(genome, housing);
return destroyEnvironment(genome, storedData, housing);
return storedData;
}
private boolean isMobGriefingEnabled(IBeeHousing housing) {
return housing.getWorld().getGameRules().getGameRuleBooleanValue("mobGriefing");
}
private void harmEntities(IBeeGenome genome, IBeeHousing housing) {
@@ -56,7 +61,7 @@ public class AlleleEffectRadioactive extends AlleleEffectThrottled {
}
}
private static IEffectData destroyEnvironment(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
private static void destroyEnvironment(IBeeGenome genome, IBeeHousing housing) {
World world = housing.getWorld();
Random rand = world.rand;
@@ -65,43 +70,69 @@ public class AlleleEffectRadioactive extends AlleleEffectThrottled {
Vect offset = area.multiply(-1 / 2.0f);
Vect posHousing = new Vect(housing.getCoordinates());
boolean isAlveary = housing instanceof AlvearyController;
for (int i = 0; i < 20; i++) {
Vect randomPos = Vect.getRandomPositionInArea(rand, area);
Vect posBlock = randomPos.add(posHousing);
posBlock = posBlock.add(offset);
Vect posBlock = randomPos.add(posHousing).add(offset);
if (posBlock.y <= 1 || posBlock.y >= housing.getWorld().getActualHeight()) {
// Don't destroy blocks in the protected 3x3x4 area if housing is an Alveary.
// Stops the bee destroying itself. Silly behaviour.
if (isAlveary && isInAlvearyProtectedArea(posHousing, posBlock)) {
continue;
}
// Don't destroy ourselves or blocks below us.
if (posBlock.x == posHousing.x && posBlock.z == posHousing.z && posBlock.y <= posHousing.y) {
continue;
}
if (world.isAirBlock(posBlock.x, posBlock.y, posBlock.z)) {
continue;
// Don't destroy the block directly below the bee.
if (isAlveary) {
if (posBlock.y == posHousing.y - 3) {
continue;
}
} else {
if (posBlock.y == posHousing.y - 1) {
continue;
}
}
Block block = world.getBlock(posBlock.x, posBlock.y, posBlock.z);
if (block instanceof BlockAlveary) {
continue;
}
// Never delete a tile entity. Allows far too much griefing and abuse otherwise.
TileEntity tile = world.getTileEntity(posBlock.x, posBlock.y, posBlock.z);
if (tile instanceof IBeeHousing) {
if (tile != null) {
continue;
}
// Don't let us delete blocks that are not supposed to be breakable by players.
if (block.getBlockHardness(world, posBlock.x, posBlock.y, posBlock.z) < 0) {
continue;
}
// Some mods might use this logic? Idk, just a safety check. Might stop griefing.
if (!world.canMineBlock(
housing.getWorld().func_152378_a(housing.getOwner().getId()),
posHousing.x,
posHousing.y,
posHousing.z)) {
continue;
}
world.setBlockToAir(posBlock.x, posBlock.y, posBlock.z);
break;
}
}
return storedData;
private static boolean isInAlvearyProtectedArea(Vect posHousing, Vect posBlock) {
// Alveary protection area is a 3x3x4 area centered on the top middle, down one block.
int startX = posHousing.x - 1;
int endX = posHousing.x + 1;
int startZ = posHousing.z - 1;
int endZ = posHousing.z + 1;
int startY = posHousing.y - 2;
int endY = posHousing.y + 1;
return posBlock.x >= startX && posBlock.x <= endX
&& posBlock.z >= startZ
&& posBlock.z <= endZ
&& posBlock.y >= startY
&& posBlock.y <= endY;
}
}
@@ -73,9 +73,9 @@ public class Vect implements IVect {
}
public static Vect getRandomPositionInArea(Random random, IVect area) {
int x = random.nextInt(area.getX());
int y = random.nextInt(area.getY());
int z = random.nextInt(area.getZ());
int x = random.nextInt(area.getX() + 1);
int y = random.nextInt(area.getY() + 1);
int z = random.nextInt(area.getZ() + 1);
return new Vect(x, y, z);
}