From 5873bd99e81b74fecbfe7cfc29902abfbe656cc8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 16 Feb 2019 21:31:37 +0100 Subject: [PATCH] allow custom types to imitate existing types so that passive effects don't have to be copied --- src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java | 2 +- .../naturesaura/api/aura/container/BasicAuraContainer.java | 2 +- .../java/de/ellpeck/naturesaura/api/aura/type/IAuraType.java | 4 ++++ .../java/de/ellpeck/naturesaura/blocks/BlockOakGenerator.java | 3 ++- .../naturesaura/blocks/tiles/TileEntityFlowerGenerator.java | 3 ++- .../de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java | 2 +- .../de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java | 2 +- 7 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index 2272af57..af9d512f 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -42,7 +42,7 @@ public final class NaturesAuraAPI { public static final String MOD_ID = "naturesaura"; public static final String API_ID = MOD_ID + "api"; - public static final String VERSION = "8"; + public static final String VERSION = "9"; /** * The list of all {@link AltarRecipe} instances which are the recipes used diff --git a/src/main/java/de/ellpeck/naturesaura/api/aura/container/BasicAuraContainer.java b/src/main/java/de/ellpeck/naturesaura/api/aura/container/BasicAuraContainer.java index dc5bbd57..8abea1c0 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/aura/container/BasicAuraContainer.java +++ b/src/main/java/de/ellpeck/naturesaura/api/aura/container/BasicAuraContainer.java @@ -49,7 +49,7 @@ public class BasicAuraContainer implements IAuraContainer { @Override public boolean isAcceptableType(IAuraType type) { - return this.type == null || this.type == type; + return this.type == null || this.type.isSimilar(type); } public void writeNBT(NBTTagCompound compound) { diff --git a/src/main/java/de/ellpeck/naturesaura/api/aura/type/IAuraType.java b/src/main/java/de/ellpeck/naturesaura/api/aura/type/IAuraType.java index 9db8571b..88a9c468 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/aura/type/IAuraType.java +++ b/src/main/java/de/ellpeck/naturesaura/api/aura/type/IAuraType.java @@ -21,4 +21,8 @@ public interface IAuraType { int getColor(); int getPriority(); + + default boolean isSimilar(IAuraType type) { + return this == type; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockOakGenerator.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockOakGenerator.java index 6d1454a0..065d8324 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockOakGenerator.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockOakGenerator.java @@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.blocks; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.blocks.tiles.TileEntityOakGenerator; import net.minecraft.block.BlockSapling; @@ -32,7 +33,7 @@ public class BlockOakGenerator extends BlockContainerImpl implements IVisualizab public void onTreeGrow(SaplingGrowTreeEvent event) { World world = event.getWorld(); BlockPos pos = event.getPos(); - if (!world.isRemote && NaturesAuraAPI.TYPE_OVERWORLD.isPresentInWorld(world) + if (!world.isRemote && IAuraType.forWorld(world).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) && world.getBlockState(pos).getBlock() instanceof BlockSapling) { Helper.getTileEntitiesInArea(world, pos, 10, tile -> { if (!(tile instanceof TileEntityOakGenerator)) 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 f436ad13..ef56d8b5 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFlowerGenerator.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFlowerGenerator.java @@ -3,6 +3,7 @@ package de.ellpeck.naturesaura.blocks.tiles; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketParticleStream; import de.ellpeck.naturesaura.packet.PacketParticles; @@ -53,7 +54,7 @@ public class TileEntityFlowerGenerator extends TileEntityImpl implements ITickab int addAmount = 25000; int toAdd = Math.max(0, addAmount - curr.getValue() * 100); if (toAdd > 0) { - if (NaturesAuraAPI.TYPE_OVERWORLD.isPresentInWorld(this.world) && this.canGenerateRightNow(30, toAdd)) { + if (IAuraType.forWorld(this.world).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) && this.canGenerateRightNow(30, toAdd)) { int remain = toAdd; while (remain > 0) { BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 30, this.pos); diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java index ebbf1785..7d93da1f 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java @@ -83,7 +83,7 @@ public class GrassDieEffect implements IDrainSpotEffect { @Override public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) { - return ModConfig.enabledFeatures.grassDieEffect && type == NaturesAuraAPI.TYPE_OVERWORLD; + return ModConfig.enabledFeatures.grassDieEffect && type.isSimilar(NaturesAuraAPI.TYPE_OVERWORLD); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java index 4dc414cc..381986b2 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java @@ -90,7 +90,7 @@ public class PlantBoostEffect implements IDrainSpotEffect { @Override public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) { - return ModConfig.enabledFeatures.plantBoostEffect && type == NaturesAuraAPI.TYPE_OVERWORLD; + return ModConfig.enabledFeatures.plantBoostEffect && type.isSimilar(NaturesAuraAPI.TYPE_OVERWORLD); } @Override