mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-05 04:49:10 +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) {
|
public static BlockPos getLowestSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) {
|
||||||
MutableDouble closestDist = new MutableDouble(Double.MAX_VALUE);
|
MutableInt lowestAmount = new MutableInt(Integer.MAX_VALUE);
|
||||||
MutableObject<BlockPos> closestSpot = new MutableObject<>();
|
MutableObject<BlockPos> lowestSpot = new MutableObject<>();
|
||||||
getSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> {
|
getSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> {
|
||||||
double dist = pos.distanceSq(blockPos);
|
int amount = drainSpot.intValue();
|
||||||
if (dist < closestDist.doubleValue()) {
|
if (amount < lowestAmount.intValue()) {
|
||||||
closestDist.setValue(dist);
|
lowestAmount.setValue(amount);
|
||||||
closestSpot.setValue(blockPos);
|
lowestSpot.setValue(blockPos);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
BlockPos closest = closestSpot.getValue();
|
BlockPos lowest = lowestSpot.getValue();
|
||||||
if (closest == null) {
|
if (lowest == null)
|
||||||
closest = defaultSpot;
|
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) {
|
public void getSpotsInArea(BlockPos pos, int radius, BiConsumer<BlockPos, MutableInt> consumer) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
|
||||||
if (aura <= 0)
|
if (aura <= 0)
|
||||||
return;
|
return;
|
||||||
int amount = Math.min(45, Math.abs(aura) / 1000);
|
int amount = Math.min(45, Math.abs(aura) / 1000);
|
||||||
if (amount <= 0)
|
if (amount <= 1)
|
||||||
return;
|
return;
|
||||||
int dist = MathHelper.clamp(Math.abs(aura) / 1500, 5, 35);
|
int dist = MathHelper.clamp(Math.abs(aura) / 1500, 5, 35);
|
||||||
if (dist <= 0)
|
if (dist <= 0)
|
||||||
|
@ -42,7 +42,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
|
||||||
if (growable.canGrow(world, plantPos, state, false)) {
|
if (growable.canGrow(world, plantPos, state, false)) {
|
||||||
growable.grow(world, world.rand, plantPos, state);
|
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);
|
AuraChunk.getAuraChunk(world, closestSpot).drainAura(closestSpot, 25);
|
||||||
|
|
||||||
PacketHandler.sendToAllAround(world, plantPos, 32,
|
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 ==
|
//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));
|
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);
|
AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot);
|
||||||
chunk.drainAura(spot, MathHelper.ceil((200 - time) / 4F));
|
chunk.drainAura(spot, MathHelper.ceil((200 - time) / 4F));
|
||||||
did = true;
|
did = true;
|
||||||
|
|
|
@ -68,9 +68,9 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable {
|
||||||
if (this.structureFine) {
|
if (this.structureFine) {
|
||||||
int space = this.container.storeAura(3, true);
|
int space = this.container.storeAura(3, true);
|
||||||
if (space > 0) {
|
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) {
|
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);
|
AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot);
|
||||||
|
|
||||||
chunk.drainAura(spot, toStore);
|
chunk.drainAura(spot, toStore);
|
||||||
|
|
|
@ -41,21 +41,30 @@ public class TileEntityPotionGenerator extends TileEntityImpl implements ITickab
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean dispersed = false;
|
int toAdd = ((effect.getAmplifier() * 5 + 1) * (effect.getDuration() / 40)) / 4;
|
||||||
int toAdd = (effect.getAmplifier() * 5 + 1) * (effect.getDuration() / 40);
|
int toAddTimes = 4;
|
||||||
|
while (toAddTimes > 0) {
|
||||||
|
boolean foundEmpty = false;
|
||||||
for (EnumFacing dir : EnumFacing.HORIZONTALS) {
|
for (EnumFacing dir : EnumFacing.HORIZONTALS) {
|
||||||
BlockPos offset = this.pos.offset(dir, 8);
|
BlockPos offset = this.pos.offset(dir, 12);
|
||||||
BlockPos spot = AuraChunk.getClosestSpot(this.world, offset, 10, offset);
|
BlockPos spot = AuraChunk.getLowestSpot(this.world, offset, 15, offset);
|
||||||
if (AuraChunk.getAuraInArea(this.world, spot, 10) < 15000) {
|
if (AuraChunk.getAuraInArea(this.world, spot, 15) < 20000) {
|
||||||
AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot);
|
AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot);
|
||||||
chunk.storeAura(spot, toAdd / 4);
|
chunk.storeAura(spot, toAdd);
|
||||||
dispersed = true;
|
|
||||||
|
foundEmpty = true;
|
||||||
|
toAddTimes--;
|
||||||
|
if (toAddTimes <= 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!foundEmpty)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(
|
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(
|
||||||
this.pos.getX(), this.pos.getY(), this.pos.getZ(), 5,
|
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;
|
addedOne = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -41,14 +41,14 @@ public class CommandAura extends CommandBase {
|
||||||
|
|
||||||
World world = sender.getEntityWorld();
|
World world = sender.getEntityWorld();
|
||||||
BlockPos pos = sender.getPosition();
|
BlockPos pos = sender.getPosition();
|
||||||
BlockPos spot = AuraChunk.getClosestSpot(world, pos, range, pos);
|
|
||||||
AuraChunk chunk = AuraChunk.getAuraChunk(world, spot);
|
|
||||||
|
|
||||||
if ("add".equals(action)) {
|
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"));
|
sender.sendMessage(new TextComponentString("Added " + amount + " aura"));
|
||||||
} else if ("remove".equals(action)) {
|
} 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"));
|
sender.sendMessage(new TextComponentString("Removed " + amount + " aura"));
|
||||||
} else {
|
} else {
|
||||||
throw new SyntaxErrorException("Invalid action " + action);
|
throw new SyntaxErrorException("Invalid action " + action);
|
||||||
|
|
Loading…
Reference in a new issue