From b34c5b482b091e58f34854e5220743f89f8d9427 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 7 Nov 2018 23:42:13 +0100 Subject: [PATCH] add the concept of aura types and make some stuff inaccessible in the nether and the end --- .../de/ellpeck/naturesaura/aura/AuraType.java | 27 +++++++++++++++++++ .../naturesaura/aura/chunk/AuraChunk.java | 21 ++++++++++++--- .../aura/chunk/effect/GrassDieEffect.java | 6 +++++ .../aura/chunk/effect/IDrainSpotEffect.java | 2 ++ .../aura/chunk/effect/PlantBoostEffect.java | 6 +++++ .../aura/chunk/effect/ReplenishingEffect.java | 12 ++++++++- .../aura/container/BasicAuraContainer.java | 10 ++++++- .../aura/container/IAuraContainer.java | 4 +++ .../aura/container/ItemAuraContainer.java | 10 ++++++- .../aura/container/NaturalAuraContainer.java | 5 ++-- .../blocks/tiles/TileEntityAncientLeaves.java | 3 ++- .../tiles/TileEntityFlowerGenerator.java | 3 ++- .../blocks/tiles/TileEntityNatureAltar.java | 5 ++-- .../naturesaura/events/ClientEvents.java | 2 ++ .../naturesaura/events/CommonEvents.java | 5 +++- .../naturesaura/items/ItemAuraCache.java | 2 +- .../book/en_us/entries/intro/aura.json | 4 +-- 17 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/aura/AuraType.java diff --git a/src/main/java/de/ellpeck/naturesaura/aura/AuraType.java b/src/main/java/de/ellpeck/naturesaura/aura/AuraType.java new file mode 100644 index 00000000..83b2f90b --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/aura/AuraType.java @@ -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; + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/aura/chunk/AuraChunk.java b/src/main/java/de/ellpeck/naturesaura/aura/chunk/AuraChunk.java index 46bf245a..6a5735ae 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/chunk/AuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/chunk/AuraChunk.java @@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.aura.chunk; 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.chunk.effect.GrassDieEffect; import de.ellpeck.naturesaura.aura.chunk.effect.IDrainSpotEffect; @@ -36,15 +37,23 @@ public class AuraChunk implements ICapabilityProvider, INBTSerializable drainSpots = new HashMap<>(); private final List effects = new ArrayList<>(); private boolean needsSync; - public AuraChunk(Chunk chunk) { + public AuraChunk(Chunk chunk, AuraType type) { this.chunk = chunk; - this.effects.add(new ReplenishingEffect()); - this.effects.add(new GrassDieEffect()); - this.effects.add(new PlantBoostEffect()); + this.type = type; + + 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 consumer) { @@ -149,6 +158,10 @@ public class AuraChunk implements ICapabilityProvider, INBTSerializable tiles = new ArrayList<>(); Helper.getTileEntitiesInArea(world, pos, 25, tile -> { if (tile.hasCapability(Capabilities.auraContainer, null)) { @@ -31,7 +32,11 @@ public class ReplenishingEffect implements IDrainSpotEffect { if (!tiles.isEmpty()) { for (int i = world.rand.nextInt(6); i >= 0; i--) { ISpotDrainable tile = tiles.get(world.rand.nextInt(tiles.size())); + if (!tile.isAcceptableType(type)) + continue; int drained = tile.drainAuraPassively(-amount, false); + if (drained <= 0) + continue; auraChunk.storeAura(pos, drained); amount += drained; if (amount >= drained) { @@ -41,4 +46,9 @@ public class ReplenishingEffect implements IDrainSpotEffect { } } } + + @Override + public boolean appliesToType(AuraType type) { + return true; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/aura/container/BasicAuraContainer.java b/src/main/java/de/ellpeck/naturesaura/aura/container/BasicAuraContainer.java index 0771e342..5c43d7e1 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/container/BasicAuraContainer.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/container/BasicAuraContainer.java @@ -1,13 +1,16 @@ package de.ellpeck.naturesaura.aura.container; +import de.ellpeck.naturesaura.aura.AuraType; import net.minecraft.nbt.NBTTagCompound; public class BasicAuraContainer implements IAuraContainer { + protected final AuraType type; protected final int maxAura; protected int aura; - public BasicAuraContainer(int maxAura) { + public BasicAuraContainer(AuraType type, int maxAura) { + this.type = type; this.maxAura = maxAura; } @@ -44,6 +47,11 @@ public class BasicAuraContainer implements IAuraContainer { return 0x1E891E; } + @Override + public boolean isAcceptableType(AuraType type) { + return this.type == null || this.type == type; + } + public void writeNBT(NBTTagCompound compound) { compound.setInteger("aura", this.aura); } diff --git a/src/main/java/de/ellpeck/naturesaura/aura/container/IAuraContainer.java b/src/main/java/de/ellpeck/naturesaura/aura/container/IAuraContainer.java index 2c842259..dbdbefd7 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/container/IAuraContainer.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/container/IAuraContainer.java @@ -1,5 +1,7 @@ package de.ellpeck.naturesaura.aura.container; +import de.ellpeck.naturesaura.aura.AuraType; + public interface IAuraContainer { int storeAura(int amountToStore, boolean simulate); @@ -10,4 +12,6 @@ public interface IAuraContainer { int getMaxAura(); int getAuraColor(); + + boolean isAcceptableType(AuraType type); } diff --git a/src/main/java/de/ellpeck/naturesaura/aura/container/ItemAuraContainer.java b/src/main/java/de/ellpeck/naturesaura/aura/container/ItemAuraContainer.java index 8b54b269..0b104151 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/container/ItemAuraContainer.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/container/ItemAuraContainer.java @@ -1,15 +1,18 @@ package de.ellpeck.naturesaura.aura.container; +import de.ellpeck.naturesaura.aura.AuraType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; public class ItemAuraContainer implements IAuraContainer { protected final ItemStack stack; + protected final AuraType type; protected final int maxAura; - public ItemAuraContainer(ItemStack stack, int maxAura) { + public ItemAuraContainer(ItemStack stack, AuraType type, int maxAura) { this.stack = stack; + this.type = type; this.maxAura = maxAura; } @@ -58,4 +61,9 @@ public class ItemAuraContainer implements IAuraContainer { public int getAuraColor() { return 0x42a6bc; } + + @Override + public boolean isAcceptableType(AuraType type) { + return this.type == null || this.type == type; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/aura/container/NaturalAuraContainer.java b/src/main/java/de/ellpeck/naturesaura/aura/container/NaturalAuraContainer.java index 1ea3667c..b1d2c9d3 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/container/NaturalAuraContainer.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/container/NaturalAuraContainer.java @@ -1,13 +1,14 @@ package de.ellpeck.naturesaura.aura.container; +import de.ellpeck.naturesaura.aura.AuraType; import de.ellpeck.naturesaura.aura.chunk.ISpotDrainable; public class NaturalAuraContainer extends BasicAuraContainer implements ISpotDrainable { private final int drainAmount; - public NaturalAuraContainer(int aura, int drainAmount) { - super(aura); + public NaturalAuraContainer(AuraType type, int aura, int drainAmount) { + super(type, aura); this.aura = aura; this.drainAmount = drainAmount; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java index ec9f2682..c154010b 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java @@ -1,5 +1,6 @@ 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.NaturalAuraContainer; import net.minecraft.nbt.NBTTagCompound; @@ -7,7 +8,7 @@ import net.minecraft.util.EnumFacing; public class TileEntityAncientLeaves extends TileEntityImpl { - private final NaturalAuraContainer container = new NaturalAuraContainer(20, 5) { + private final NaturalAuraContainer container = new NaturalAuraContainer(AuraType.OVERWORLD, 20, 5) { @Override public int getAuraColor() { return 0xc46df9; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFlowerGenerator.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFlowerGenerator.java index 7835a4ee..e5d334de 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFlowerGenerator.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFlowerGenerator.java @@ -1,6 +1,7 @@ package de.ellpeck.naturesaura.blocks.tiles; import de.ellpeck.naturesaura.Helper; +import de.ellpeck.naturesaura.aura.AuraType; import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.packet.PacketHandler; 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()); if (toAdd > 0) { 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); else toAdd = 0; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java index 8dc755d8..3a2dc738 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java @@ -1,6 +1,7 @@ package de.ellpeck.naturesaura.blocks.tiles; import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.aura.AuraType; import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.chunk.AuraChunk; 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; private AltarRecipe currentRecipe; @@ -70,7 +71,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable { if (this.structureFine) { 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); if (toStore > 0) { BlockPos spot = AuraChunk.getHighestSpot(this.world, this.pos, 20, this.pos); diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 8fbb0b1b..840ba1c7 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.events; import baubles.api.BaublesApi; import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.aura.AuraType; import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.chunk.AuraChunk; 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 + "Total: " + amount.intValue() + " in " + spots.intValue() + " spots"); + left.add(prefix + "Type: " + AuraType.forWorld(mc.world)); } } } diff --git a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java index 310150d7..ef569f74 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java @@ -1,6 +1,7 @@ package de.ellpeck.naturesaura.events; import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.aura.AuraType; import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.packet.PacketHandler; @@ -21,7 +22,9 @@ public class CommonEvents { @SubscribeEvent public void onChunkCapsAttach(AttachCapabilitiesEvent 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 diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java index 5c73fb94..a2aa8100 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java @@ -76,7 +76,7 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem { @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { return new ICapabilityProvider() { - private final ItemAuraContainer container = new ItemAuraContainer(stack, 4000); + private final ItemAuraContainer container = new ItemAuraContainer(stack, null, 4000); @Override public boolean hasCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { diff --git a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/intro/aura.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/intro/aura.json index 671b9e2d..6555d461 100644 --- a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/intro/aura.json +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/intro/aura.json @@ -6,11 +6,11 @@ "pages": [ { "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", - "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." } ] } \ No newline at end of file