mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 11:53:29 +01:00
change aura system a bit to respect lowest and highest spots rather than closest - this makes it work more consistently
This commit is contained in:
parent
344bc1fd9c
commit
f305eb8e04
6 changed files with 55 additions and 31 deletions
|
@ -79,21 +79,36 @@ public class AuraChunk implements ICapabilityProvider, INBTSerializable<NBTTagCo
|
|||
}
|
||||
}
|
||||
|
||||
public static BlockPos getClosestSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) {
|
||||
MutableDouble closestDist = new MutableDouble(Double.MAX_VALUE);
|
||||
MutableObject<BlockPos> closestSpot = new MutableObject<>();
|
||||
public static BlockPos getLowestSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) {
|
||||
MutableInt lowestAmount = new MutableInt(Integer.MAX_VALUE);
|
||||
MutableObject<BlockPos> lowestSpot = new MutableObject<>();
|
||||
getSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> {
|
||||
double dist = pos.distanceSq(blockPos);
|
||||
if (dist < closestDist.doubleValue()) {
|
||||
closestDist.setValue(dist);
|
||||
closestSpot.setValue(blockPos);
|
||||
int amount = drainSpot.intValue();
|
||||
if (amount < lowestAmount.intValue()) {
|
||||
lowestAmount.setValue(amount);
|
||||
lowestSpot.setValue(blockPos);
|
||||
}
|
||||
});
|
||||
BlockPos closest = closestSpot.getValue();
|
||||
if (closest == null) {
|
||||
closest = defaultSpot;
|
||||
BlockPos lowest = lowestSpot.getValue();
|
||||
if (lowest == null)
|
||||
lowest = defaultSpot;
|
||||
return lowest;
|
||||
}
|
||||
return closest;
|
||||
|
||||
public static BlockPos getHighestSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) {
|
||||
MutableInt highestAmount = new MutableInt(Integer.MIN_VALUE);
|
||||
MutableObject<BlockPos> highestSpot = new MutableObject<>();
|
||||
getSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> {
|
||||
int amount = drainSpot.intValue();
|
||||
if (amount > highestAmount.intValue()) {
|
||||
highestAmount.setValue(amount);
|
||||
highestSpot.setValue(blockPos);
|
||||
}
|
||||
});
|
||||
BlockPos highest = highestSpot.getValue();
|
||||
if (highest == null)
|
||||
highest = defaultSpot;
|
||||
return highest;
|
||||
}
|
||||
|
||||
public void getSpotsInArea(BlockPos pos, int radius, BiConsumer<BlockPos, MutableInt> consumer) {
|
||||
|
|
|
@ -24,7 +24,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
|
|||
if (aura <= 0)
|
||||
return;
|
||||
int amount = Math.min(45, Math.abs(aura) / 1000);
|
||||
if (amount <= 0)
|
||||
if (amount <= 1)
|
||||
return;
|
||||
int dist = MathHelper.clamp(Math.abs(aura) / 1500, 5, 35);
|
||||
if (dist <= 0)
|
||||
|
@ -42,7 +42,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
|
|||
if (growable.canGrow(world, plantPos, state, false)) {
|
||||
growable.grow(world, world.rand, plantPos, state);
|
||||
|
||||
BlockPos closestSpot = AuraChunk.getClosestSpot(world, plantPos, 25, pos);
|
||||
BlockPos closestSpot = AuraChunk.getHighestSpot(world, plantPos, 25, pos);
|
||||
AuraChunk.getAuraChunk(world, closestSpot).drainAura(closestSpot, 25);
|
||||
|
||||
PacketHandler.sendToAllAround(world, plantPos, 32,
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickable
|
|||
//if set higher than 199, it'll never finish because the furnace does ++ and then ==
|
||||
furnace.setField(2, Math.min(199, furnace.getField(2) + 5));
|
||||
|
||||
BlockPos spot = AuraChunk.getClosestSpot(this.world, this.pos, 15, this.pos);
|
||||
BlockPos spot = AuraChunk.getHighestSpot(this.world, this.pos, 15, this.pos);
|
||||
AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot);
|
||||
chunk.drainAura(spot, MathHelper.ceil((200 - time) / 4F));
|
||||
did = true;
|
||||
|
|
|
@ -68,9 +68,9 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable {
|
|||
if (this.structureFine) {
|
||||
int space = this.container.storeAura(3, true);
|
||||
if (space > 0) {
|
||||
int toStore = Math.min(AuraChunk.getAuraInArea(this.world, this.pos, 10), space);
|
||||
int toStore = Math.min(AuraChunk.getAuraInArea(this.world, this.pos, 20), space);
|
||||
if (toStore > 0) {
|
||||
BlockPos spot = AuraChunk.getClosestSpot(this.world, this.pos, 10, this.pos);
|
||||
BlockPos spot = AuraChunk.getHighestSpot(this.world, this.pos, 20, this.pos);
|
||||
AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot);
|
||||
|
||||
chunk.drainAura(spot, toStore);
|
||||
|
|
|
@ -41,21 +41,30 @@ public class TileEntityPotionGenerator extends TileEntityImpl implements ITickab
|
|||
continue;
|
||||
}
|
||||
|
||||
boolean dispersed = false;
|
||||
int toAdd = (effect.getAmplifier() * 5 + 1) * (effect.getDuration() / 40);
|
||||
int toAdd = ((effect.getAmplifier() * 5 + 1) * (effect.getDuration() / 40)) / 4;
|
||||
int toAddTimes = 4;
|
||||
while (toAddTimes > 0) {
|
||||
boolean foundEmpty = false;
|
||||
for (EnumFacing dir : EnumFacing.HORIZONTALS) {
|
||||
BlockPos offset = this.pos.offset(dir, 8);
|
||||
BlockPos spot = AuraChunk.getClosestSpot(this.world, offset, 10, offset);
|
||||
if (AuraChunk.getAuraInArea(this.world, spot, 10) < 15000) {
|
||||
BlockPos offset = this.pos.offset(dir, 12);
|
||||
BlockPos spot = AuraChunk.getLowestSpot(this.world, offset, 15, offset);
|
||||
if (AuraChunk.getAuraInArea(this.world, spot, 15) < 20000) {
|
||||
AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot);
|
||||
chunk.storeAura(spot, toAdd / 4);
|
||||
dispersed = true;
|
||||
chunk.storeAura(spot, toAdd);
|
||||
|
||||
foundEmpty = true;
|
||||
toAddTimes--;
|
||||
if (toAddTimes <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundEmpty)
|
||||
break;
|
||||
}
|
||||
|
||||
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(
|
||||
this.pos.getX(), this.pos.getY(), this.pos.getZ(), 5,
|
||||
PotionUtils.getPotionColor(type), dispersed ? 1 : 0));
|
||||
PotionUtils.getPotionColor(type), toAddTimes < 4 ? 1 : 0));
|
||||
|
||||
addedOne = true;
|
||||
break;
|
||||
|
|
|
@ -41,14 +41,14 @@ public class CommandAura extends CommandBase {
|
|||
|
||||
World world = sender.getEntityWorld();
|
||||
BlockPos pos = sender.getPosition();
|
||||
BlockPos spot = AuraChunk.getClosestSpot(world, pos, range, pos);
|
||||
AuraChunk chunk = AuraChunk.getAuraChunk(world, spot);
|
||||
|
||||
if ("add".equals(action)) {
|
||||
chunk.storeAura(spot, amount);
|
||||
BlockPos spot = AuraChunk.getLowestSpot(world, pos, range, pos);
|
||||
AuraChunk.getAuraChunk(world, spot).storeAura(spot, amount);
|
||||
sender.sendMessage(new TextComponentString("Added " + amount + " aura"));
|
||||
} else if ("remove".equals(action)) {
|
||||
chunk.drainAura(spot, amount);
|
||||
BlockPos spot = AuraChunk.getHighestSpot(world, pos, range, pos);
|
||||
AuraChunk.getAuraChunk(world, spot).drainAura(spot, amount);
|
||||
sender.sendMessage(new TextComponentString("Removed " + amount + " aura"));
|
||||
} else {
|
||||
throw new SyntaxErrorException("Invalid action " + action);
|
||||
|
|
Loading…
Reference in a new issue