add the concept of aura types and make some stuff inaccessible in the nether and the end

This commit is contained in:
Ellpeck 2018-11-07 23:42:13 +01:00
parent 3ba7397005
commit b34c5b482b
17 changed files with 110 additions and 17 deletions

View file

@ -0,0 +1,27 @@
package de.ellpeck.naturesaura.aura;
import net.minecraft.world.World;
public enum AuraType {
OVERWORLD,
NETHER,
END,
OTHER;
public boolean isPresent(World world) {
return forWorld(world) == this;
}
public static AuraType forWorld(World world) {
switch (world.provider.getDimensionType()) {
case OVERWORLD:
return OVERWORLD;
case NETHER:
return NETHER;
case THE_END:
return END;
default:
return OTHER;
}
}
}

View file

@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.aura.chunk;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.Capabilities;
import de.ellpeck.naturesaura.aura.chunk.effect.GrassDieEffect; import de.ellpeck.naturesaura.aura.chunk.effect.GrassDieEffect;
import de.ellpeck.naturesaura.aura.chunk.effect.IDrainSpotEffect; import de.ellpeck.naturesaura.aura.chunk.effect.IDrainSpotEffect;
@ -36,15 +37,23 @@ public class AuraChunk implements ICapabilityProvider, INBTSerializable<NBTTagCo
public static final int DEFAULT_AURA = 10000; public static final int DEFAULT_AURA = 10000;
private final Chunk chunk; private final Chunk chunk;
private final AuraType type;
private final Map<BlockPos, MutableInt> drainSpots = new HashMap<>(); private final Map<BlockPos, MutableInt> drainSpots = new HashMap<>();
private final List<IDrainSpotEffect> effects = new ArrayList<>(); private final List<IDrainSpotEffect> effects = new ArrayList<>();
private boolean needsSync; private boolean needsSync;
public AuraChunk(Chunk chunk) { public AuraChunk(Chunk chunk, AuraType type) {
this.chunk = chunk; this.chunk = chunk;
this.effects.add(new ReplenishingEffect()); this.type = type;
this.effects.add(new GrassDieEffect());
this.effects.add(new PlantBoostEffect()); this.addEffect(new ReplenishingEffect());
this.addEffect(new GrassDieEffect());
this.addEffect(new PlantBoostEffect());
}
public void addEffect(IDrainSpotEffect effect) {
if (effect.appliesToType(this.type))
this.effects.add(effect);
} }
public static void getSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, MutableInt> consumer) { public static void getSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, MutableInt> consumer) {
@ -149,6 +158,10 @@ public class AuraChunk implements ICapabilityProvider, INBTSerializable<NBTTagCo
this.drainSpots.putAll(spots); this.drainSpots.putAll(spots);
} }
public AuraType getType() {
return this.type;
}
public void markDirty() { public void markDirty() {
this.needsSync = true; this.needsSync = true;
} }

View file

@ -1,6 +1,7 @@
package de.ellpeck.naturesaura.aura.chunk.effect; package de.ellpeck.naturesaura.aura.chunk.effect;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import de.ellpeck.naturesaura.blocks.ModBlocks; import de.ellpeck.naturesaura.blocks.ModBlocks;
import net.minecraft.block.*; import net.minecraft.block.*;
@ -49,4 +50,9 @@ public class GrassDieEffect implements IDrainSpotEffect {
} }
} }
} }
@Override
public boolean appliesToType(AuraType type) {
return type == AuraType.OVERWORLD;
}
} }

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.aura.chunk.effect; package de.ellpeck.naturesaura.aura.chunk.effect;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -10,4 +11,5 @@ public interface IDrainSpotEffect {
void update(World world, Chunk chunk, AuraChunk auraChunk, BlockPos pos, MutableInt spot); void update(World world, Chunk chunk, AuraChunk auraChunk, BlockPos pos, MutableInt spot);
boolean appliesToType(AuraType type);
} }

View file

@ -1,6 +1,7 @@
package de.ellpeck.naturesaura.aura.chunk.effect; package de.ellpeck.naturesaura.aura.chunk.effect;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
@ -51,4 +52,9 @@ public class PlantBoostEffect implements IDrainSpotEffect {
} }
} }
} }
@Override
public boolean appliesToType(AuraType type) {
return type == AuraType.OVERWORLD;
}
} }

View file

@ -1,7 +1,7 @@
package de.ellpeck.naturesaura.aura.chunk.effect; package de.ellpeck.naturesaura.aura.chunk.effect;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.Capabilities;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import de.ellpeck.naturesaura.aura.chunk.ISpotDrainable; import de.ellpeck.naturesaura.aura.chunk.ISpotDrainable;
@ -19,6 +19,7 @@ public class ReplenishingEffect implements IDrainSpotEffect {
public void update(World world, Chunk chunk, AuraChunk auraChunk, BlockPos pos, MutableInt spot) { public void update(World world, Chunk chunk, AuraChunk auraChunk, BlockPos pos, MutableInt spot) {
int amount = spot.intValue(); int amount = spot.intValue();
if (amount < 0) { if (amount < 0) {
AuraType type = AuraType.forWorld(world);
List<ISpotDrainable> tiles = new ArrayList<>(); List<ISpotDrainable> tiles = new ArrayList<>();
Helper.getTileEntitiesInArea(world, pos, 25, tile -> { Helper.getTileEntitiesInArea(world, pos, 25, tile -> {
if (tile.hasCapability(Capabilities.auraContainer, null)) { if (tile.hasCapability(Capabilities.auraContainer, null)) {
@ -31,7 +32,11 @@ public class ReplenishingEffect implements IDrainSpotEffect {
if (!tiles.isEmpty()) { if (!tiles.isEmpty()) {
for (int i = world.rand.nextInt(6); i >= 0; i--) { for (int i = world.rand.nextInt(6); i >= 0; i--) {
ISpotDrainable tile = tiles.get(world.rand.nextInt(tiles.size())); ISpotDrainable tile = tiles.get(world.rand.nextInt(tiles.size()));
if (!tile.isAcceptableType(type))
continue;
int drained = tile.drainAuraPassively(-amount, false); int drained = tile.drainAuraPassively(-amount, false);
if (drained <= 0)
continue;
auraChunk.storeAura(pos, drained); auraChunk.storeAura(pos, drained);
amount += drained; amount += drained;
if (amount >= drained) { if (amount >= drained) {
@ -41,4 +46,9 @@ public class ReplenishingEffect implements IDrainSpotEffect {
} }
} }
} }
@Override
public boolean appliesToType(AuraType type) {
return true;
}
} }

View file

@ -1,13 +1,16 @@
package de.ellpeck.naturesaura.aura.container; package de.ellpeck.naturesaura.aura.container;
import de.ellpeck.naturesaura.aura.AuraType;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
public class BasicAuraContainer implements IAuraContainer { public class BasicAuraContainer implements IAuraContainer {
protected final AuraType type;
protected final int maxAura; protected final int maxAura;
protected int aura; protected int aura;
public BasicAuraContainer(int maxAura) { public BasicAuraContainer(AuraType type, int maxAura) {
this.type = type;
this.maxAura = maxAura; this.maxAura = maxAura;
} }
@ -44,6 +47,11 @@ public class BasicAuraContainer implements IAuraContainer {
return 0x1E891E; return 0x1E891E;
} }
@Override
public boolean isAcceptableType(AuraType type) {
return this.type == null || this.type == type;
}
public void writeNBT(NBTTagCompound compound) { public void writeNBT(NBTTagCompound compound) {
compound.setInteger("aura", this.aura); compound.setInteger("aura", this.aura);
} }

View file

@ -1,5 +1,7 @@
package de.ellpeck.naturesaura.aura.container; package de.ellpeck.naturesaura.aura.container;
import de.ellpeck.naturesaura.aura.AuraType;
public interface IAuraContainer { public interface IAuraContainer {
int storeAura(int amountToStore, boolean simulate); int storeAura(int amountToStore, boolean simulate);
@ -10,4 +12,6 @@ public interface IAuraContainer {
int getMaxAura(); int getMaxAura();
int getAuraColor(); int getAuraColor();
boolean isAcceptableType(AuraType type);
} }

View file

@ -1,15 +1,18 @@
package de.ellpeck.naturesaura.aura.container; package de.ellpeck.naturesaura.aura.container;
import de.ellpeck.naturesaura.aura.AuraType;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
public class ItemAuraContainer implements IAuraContainer { public class ItemAuraContainer implements IAuraContainer {
protected final ItemStack stack; protected final ItemStack stack;
protected final AuraType type;
protected final int maxAura; protected final int maxAura;
public ItemAuraContainer(ItemStack stack, int maxAura) { public ItemAuraContainer(ItemStack stack, AuraType type, int maxAura) {
this.stack = stack; this.stack = stack;
this.type = type;
this.maxAura = maxAura; this.maxAura = maxAura;
} }
@ -58,4 +61,9 @@ public class ItemAuraContainer implements IAuraContainer {
public int getAuraColor() { public int getAuraColor() {
return 0x42a6bc; return 0x42a6bc;
} }
@Override
public boolean isAcceptableType(AuraType type) {
return this.type == null || this.type == type;
}
} }

View file

@ -1,13 +1,14 @@
package de.ellpeck.naturesaura.aura.container; package de.ellpeck.naturesaura.aura.container;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.chunk.ISpotDrainable; import de.ellpeck.naturesaura.aura.chunk.ISpotDrainable;
public class NaturalAuraContainer extends BasicAuraContainer implements ISpotDrainable { public class NaturalAuraContainer extends BasicAuraContainer implements ISpotDrainable {
private final int drainAmount; private final int drainAmount;
public NaturalAuraContainer(int aura, int drainAmount) { public NaturalAuraContainer(AuraType type, int aura, int drainAmount) {
super(aura); super(type, aura);
this.aura = aura; this.aura = aura;
this.drainAmount = drainAmount; this.drainAmount = drainAmount;
} }

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.container.IAuraContainer; import de.ellpeck.naturesaura.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.aura.container.NaturalAuraContainer; import de.ellpeck.naturesaura.aura.container.NaturalAuraContainer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -7,7 +8,7 @@ import net.minecraft.util.EnumFacing;
public class TileEntityAncientLeaves extends TileEntityImpl { public class TileEntityAncientLeaves extends TileEntityImpl {
private final NaturalAuraContainer container = new NaturalAuraContainer(20, 5) { private final NaturalAuraContainer container = new NaturalAuraContainer(AuraType.OVERWORLD, 20, 5) {
@Override @Override
public int getAuraColor() { public int getAuraColor() {
return 0xc46df9; return 0xc46df9;

View file

@ -1,6 +1,7 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticleStream; import de.ellpeck.naturesaura.packet.PacketParticleStream;
@ -62,7 +63,7 @@ public class TileEntityFlowerGenerator extends TileEntityImpl implements ITickab
int toAdd = Math.max(0, addAmount - curr.getValue()); int toAdd = Math.max(0, addAmount - curr.getValue());
if (toAdd > 0) { if (toAdd > 0) {
BlockPos auraPos = AuraChunk.getLowestSpot(this.world, this.pos, 30, this.pos); BlockPos auraPos = AuraChunk.getLowestSpot(this.world, this.pos, 30, this.pos);
if (AuraChunk.getAuraInArea(this.world, auraPos, 30) < 20000) if (AuraType.OVERWORLD.isPresent(this.world) && AuraChunk.getAuraInArea(this.world, auraPos, 30) < 20000)
AuraChunk.getAuraChunk(this.world, auraPos).storeAura(auraPos, toAdd); AuraChunk.getAuraChunk(this.world, auraPos).storeAura(auraPos, toAdd);
else else
toAdd = 0; toAdd = 0;

View file

@ -1,6 +1,7 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.Capabilities;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import de.ellpeck.naturesaura.aura.container.BasicAuraContainer; import de.ellpeck.naturesaura.aura.container.BasicAuraContainer;
@ -47,7 +48,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable {
} }
}; };
private final BasicAuraContainer container = new BasicAuraContainer(5000); private final BasicAuraContainer container = new BasicAuraContainer(AuraType.OVERWORLD, 5000);
public boolean structureFine; public boolean structureFine;
private AltarRecipe currentRecipe; private AltarRecipe currentRecipe;
@ -70,7 +71,7 @@ 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 && this.container.isAcceptableType(AuraType.forWorld(this.world))) {
int toStore = Math.min(AuraChunk.getAuraInArea(this.world, this.pos, 20), space); int toStore = Math.min(AuraChunk.getAuraInArea(this.world, this.pos, 20), space);
if (toStore > 0) { if (toStore > 0) {
BlockPos spot = AuraChunk.getHighestSpot(this.world, this.pos, 20, this.pos); BlockPos spot = AuraChunk.getHighestSpot(this.world, this.pos, 20, this.pos);

View file

@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.events;
import baubles.api.BaublesApi; import baubles.api.BaublesApi;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.Capabilities;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import de.ellpeck.naturesaura.aura.container.IAuraContainer; import de.ellpeck.naturesaura.aura.container.IAuraContainer;
@ -60,6 +61,7 @@ public class ClientEvents {
left.add(prefix + drainSpot.intValue() + " @ " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ()); left.add(prefix + drainSpot.intValue() + " @ " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ());
})); }));
left.add(prefix + "Total: " + amount.intValue() + " in " + spots.intValue() + " spots"); left.add(prefix + "Total: " + amount.intValue() + " in " + spots.intValue() + " spots");
left.add(prefix + "Type: " + AuraType.forWorld(mc.world));
} }
} }
} }

View file

@ -1,6 +1,7 @@
package de.ellpeck.naturesaura.events; package de.ellpeck.naturesaura.events;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.aura.AuraType;
import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.Capabilities;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
@ -21,7 +22,9 @@ public class CommonEvents {
@SubscribeEvent @SubscribeEvent
public void onChunkCapsAttach(AttachCapabilitiesEvent<Chunk> event) { public void onChunkCapsAttach(AttachCapabilitiesEvent<Chunk> event) {
event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "aura"), new AuraChunk(event.getObject())); Chunk chunk = event.getObject();
AuraType type = AuraType.forWorld(chunk.getWorld());
event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "aura"), new AuraChunk(chunk, type));
} }
@SubscribeEvent @SubscribeEvent

View file

@ -76,7 +76,7 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
@Override @Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {
return new ICapabilityProvider() { return new ICapabilityProvider() {
private final ItemAuraContainer container = new ItemAuraContainer(stack, 4000); private final ItemAuraContainer container = new ItemAuraContainer(stack, null, 4000);
@Override @Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) { public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {

View file

@ -6,11 +6,11 @@
"pages": [ "pages": [
{ {
"type": "text", "type": "text",
"text": "Contrary to popular belief, $(aura) isn't stored in single, floating $(italic)nodes$(), but rather, it is present everywhere in the world.$(br)While touching it is impossible, making use of its powers certainly is not. When $(aura) is used right, it can assist in the production of materials, the creation of new ideas and the harnessing of the world and its components." "text": "Contrary to popular belief, $(aura) isn't stored in single, floating $(italic)nodes$(), but rather, it is present everywhere in the world.$(br)While touching it is impossible, making use of its powers certainly is not. When $(aura) is used right, it can assist in the $(thing)production$() of materials, the $(thing)creation$() of new ideas and the $(thing)harnessing$() of the world and its components."
}, },
{ {
"type": "text", "type": "text",
"text": "However, it isn't always as easy as that. Making use of it wrongly, specifically draining it completely from an area, will face the culprit with diminishing returns.$(br)So while $(aura) is plentiful and useful, abusing it would certainly be ill-advised." "text": "However, it isn't always as easy as that. Making use of it wrongly, specifically $(thing)draining$() it completely from an area, will face the culprit with diminishing returns.$(br)So while $(aura) is plentiful and useful, abusing it would certainly be ill-advised.$(p)An additional thing to note is that, based on the world you are in - specifically, the $(item)dimension$(), different types of $(aura) will be present, making some mechanics work unlike expected."
} }
] ]
} }