rework effect powder to have its range based on the stack size

This commit is contained in:
Ellpeck 2019-01-28 14:58:08 +01:00
parent f0fc6085df
commit 47d565a70c
13 changed files with 38 additions and 27 deletions

View file

@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@ -95,11 +96,18 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
} }
@Override @Override
public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name, int radius) { public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name) {
List<EntityEffectInhibitor> inhibitors = world.getEntitiesWithinAABB( List<EntityEffectInhibitor> inhibitors = world.getEntitiesWithinAABB(
EntityEffectInhibitor.class, EntityEffectInhibitor.class,
new AxisAlignedBB(pos).grow(radius), new AxisAlignedBB(pos).grow(64),
entity -> entity.getDistanceSq(pos) <= radius * radius && name.equals(entity.getInhibitedEffect())); entity -> {
if (!name.equals(entity.getInhibitedEffect()))
return false;
AxisAlignedBB bounds = new AxisAlignedBB(
entity.posX, entity.posY, entity.posZ,
entity.posX, entity.posY, entity.posZ).grow(entity.amount);
return bounds.contains(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5));
});
return !inhibitors.isEmpty(); return !inhibitors.isEmpty();
} }

View file

@ -40,7 +40,7 @@ public final class NaturesAuraAPI {
public static final String MOD_ID = "naturesaura"; public static final String MOD_ID = "naturesaura";
public static final String API_ID = MOD_ID + "api"; public static final String API_ID = MOD_ID + "api";
public static final String VERSION = "6"; public static final String VERSION = "7";
/** /**
* The list of all {@link AltarRecipe} instances which are the recipes used * The list of all {@link AltarRecipe} instances which are the recipes used
@ -96,7 +96,7 @@ public final class NaturesAuraAPI {
* A map of all effect powder type. The integer the effect is registered to * A map of all effect powder type. The integer the effect is registered to
* is the color that the powder and its effect should have. To check if a * is the color that the powder and its effect should have. To check if a
* powder is active in any given area, use {@link IInternalHooks#isEffectPowderActive(World, * powder is active in any given area, use {@link IInternalHooks#isEffectPowderActive(World,
* BlockPos, ResourceLocation, int)} * BlockPos, ResourceLocation)}
*/ */
public static final Map<ResourceLocation, Integer> EFFECT_POWDERS = new HashMap<>(); public static final Map<ResourceLocation, Integer> EFFECT_POWDERS = new HashMap<>();
/** /**
@ -250,16 +250,15 @@ public final class NaturesAuraAPI {
/** /**
* Returns true if there is an effect powder entity active anywhere * Returns true if there is an effect powder entity active anywhere
* around the given position in the given radius. To register a powder * around the given position based on the radius it has. To register a
* with the supplied name, use {@link #EFFECT_POWDERS} * powder with the supplied name, use {@link #EFFECT_POWDERS}
* *
* @param world The world * @param world The world
* @param pos The center position * @param pos The center position
* @param name The registry name of the powder * @param name The registry name of the powder
* @param radius The radius around the center to check for
* @return If the effect is currently inhibited by any inhibitors * @return If the effect is currently inhibited by any inhibitors
*/ */
boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name, int radius); boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name);
/** /**
* @see IAuraChunk#getSpotsInArea(World, BlockPos, int, BiConsumer) * @see IAuraChunk#getSpotsInArea(World, BlockPos, int, BiConsumer)

View file

@ -37,7 +37,7 @@ public class StubHooks implements NaturesAuraAPI.IInternalHooks {
} }
@Override @Override
public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name, int radius) { public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name) {
return false; return false;
} }

View file

@ -50,7 +50,7 @@ public class AnimalEffect implements IDrainSpotEffect {
for (EntityItem item : items) { for (EntityItem item : items) {
if (item.isDead) if (item.isDead)
continue; continue;
if (NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME, 35)) if (NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME))
continue; continue;
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
@ -84,7 +84,7 @@ public class AnimalEffect implements IDrainSpotEffect {
EntityAnimal first = animals.get(world.rand.nextInt(animals.size())); EntityAnimal first = animals.get(world.rand.nextInt(animals.size()));
if (first.isChild() || first.isInLove()) if (first.isChild() || first.isInLove())
return; return;
if (NaturesAuraAPI.instance().isEffectPowderActive(world, first.getPosition(), NAME, 35)) if (NaturesAuraAPI.instance().isEffectPowderActive(world, first.getPosition(), NAME))
return; return;
Optional<EntityAnimal> secondOptional = animals.stream() Optional<EntityAnimal> secondOptional = animals.stream()

View file

@ -27,7 +27,7 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
int aura = IAuraChunk.getAuraInArea(world, pos, 20); int aura = IAuraChunk.getAuraInArea(world, pos, 20);
if (aura < 15000) if (aura < 15000)
return; return;
if (NaturesAuraAPI.instance().isEffectPowderActive(world, pos, NAME, 30)) if (NaturesAuraAPI.instance().isEffectPowderActive(world, pos, NAME))
return; return;
int dist = MathHelper.clamp(aura / 3500, 3, 15); int dist = MathHelper.clamp(aura / 3500, 3, 15);
int amount = aura / 2500 - 2; int amount = aura / 2500 - 2;

View file

@ -39,7 +39,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
int z = MathHelper.floor(pos.getZ() + world.rand.nextGaussian() * dist); int z = MathHelper.floor(pos.getZ() + world.rand.nextGaussian() * dist);
BlockPos plantPos = new BlockPos(x, world.getHeight(x, z), z); BlockPos plantPos = new BlockPos(x, world.getHeight(x, z), z);
if (plantPos.distanceSq(pos) <= dist * dist && world.isBlockLoaded(plantPos)) { if (plantPos.distanceSq(pos) <= dist * dist && world.isBlockLoaded(plantPos)) {
if (NaturesAuraAPI.instance().isEffectPowderActive(world, plantPos, NAME, 15)) if (NaturesAuraAPI.instance().isEffectPowderActive(world, plantPos, NAME))
continue; continue;
IBlockState state = world.getBlockState(plantPos); IBlockState state = world.getBlockState(plantPos);

View file

@ -18,6 +18,7 @@ public class EntityEffectInhibitor extends Entity {
private static final DataParameter<String> INHIBITED_EFFECT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.STRING); private static final DataParameter<String> INHIBITED_EFFECT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.STRING);
private static final DataParameter<Integer> COLOR = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT); private static final DataParameter<Integer> COLOR = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
public int amount;
public EntityEffectInhibitor(World worldIn) { public EntityEffectInhibitor(World worldIn) {
super(worldIn); super(worldIn);
@ -34,12 +35,14 @@ public class EntityEffectInhibitor extends Entity {
protected void readEntityFromNBT(NBTTagCompound compound) { protected void readEntityFromNBT(NBTTagCompound compound) {
this.setInhibitedEffect(new ResourceLocation(compound.getString("effect"))); this.setInhibitedEffect(new ResourceLocation(compound.getString("effect")));
this.setColor(compound.getInteger("color")); this.setColor(compound.getInteger("color"));
this.amount = compound.hasKey("amount") ? compound.getInteger("amount") : 24;
} }
@Override @Override
protected void writeEntityToNBT(NBTTagCompound compound) { protected void writeEntityToNBT(NBTTagCompound compound) {
compound.setString("effect", this.getInhibitedEffect().toString()); compound.setString("effect", this.getInhibitedEffect().toString());
compound.setInteger("color", this.getColor()); compound.setInteger("color", this.getColor());
compound.setInteger("amount", this.amount);
} }
@Override @Override
@ -67,7 +70,7 @@ public class EntityEffectInhibitor extends Entity {
public boolean attackEntityFrom(DamageSource source, float amount) { public boolean attackEntityFrom(DamageSource source, float amount) {
if (source instanceof EntityDamageSource && !this.world.isRemote) { if (source instanceof EntityDamageSource && !this.world.isRemote) {
this.setDead(); this.setDead();
this.entityDropItem(ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), this.getInhibitedEffect()), 0F); this.entityDropItem(ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, this.amount), this.getInhibitedEffect()), 0F);
return true; return true;
} else } else
return super.attackEntityFrom(source, amount); return super.attackEntityFrom(source, amount);

View file

@ -29,9 +29,10 @@ public class ItemEffectPowder extends ItemImpl implements IColorProvidingItem {
EntityEffectInhibitor entity = new EntityEffectInhibitor(worldIn); EntityEffectInhibitor entity = new EntityEffectInhibitor(worldIn);
entity.setInhibitedEffect(effect); entity.setInhibitedEffect(effect);
entity.setColor(NaturesAuraAPI.EFFECT_POWDERS.get(effect)); entity.setColor(NaturesAuraAPI.EFFECT_POWDERS.get(effect));
entity.amount = stack.getCount();
entity.setPosition(pos.getX() + hitX, pos.getY() + hitY + 1, pos.getZ() + hitZ); entity.setPosition(pos.getX() + hitX, pos.getY() + hitY + 1, pos.getZ() + hitZ);
worldIn.spawnEntity(entity); worldIn.spawnEntity(entity);
stack.shrink(1); stack.setCount(0);
} }
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }

View file

@ -84,21 +84,21 @@ public final class ModRecipes {
Helper.blockIng(Blocks.GLOWSTONE)).register(); Helper.blockIng(Blocks.GLOWSTONE)).register();
new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "plant_powder"), new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "plant_powder"),
Ingredient.fromStacks(new ItemStack(Blocks.SAPLING)), Ingredient.fromStacks(new ItemStack(Blocks.SAPLING)),
ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), PlantBoostEffect.NAME), 400, ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, 24), PlantBoostEffect.NAME), 400,
Helper.blockIng(ModBlocks.GOLD_POWDER), Helper.blockIng(ModBlocks.GOLD_POWDER),
Helper.blockIng(ModBlocks.GOLD_POWDER), Helper.blockIng(ModBlocks.GOLD_POWDER),
Ingredient.fromItem(ModItems.SKY_INGOT), Ingredient.fromItem(ModItems.SKY_INGOT),
Ingredient.fromItem(Items.WHEAT)).register(); Ingredient.fromItem(Items.WHEAT)).register();
new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "cache_powder"), new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "cache_powder"),
Ingredient.fromStacks(new ItemStack(Blocks.SAPLING)), Ingredient.fromStacks(new ItemStack(Blocks.SAPLING)),
ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), CacheRechargeEffect.NAME), 400, ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, 32), CacheRechargeEffect.NAME), 400,
Helper.blockIng(ModBlocks.GOLD_POWDER), Helper.blockIng(ModBlocks.GOLD_POWDER),
Helper.blockIng(ModBlocks.GOLD_POWDER), Helper.blockIng(ModBlocks.GOLD_POWDER),
Ingredient.fromItem(ModItems.SKY_INGOT), Ingredient.fromItem(ModItems.SKY_INGOT),
Ingredient.fromItem(ModItems.AURA_CACHE)).register(); Ingredient.fromItem(ModItems.AURA_CACHE)).register();
new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "animal_powder"), new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "animal_powder"),
Ingredient.fromStacks(new ItemStack(Blocks.SAPLING, 1, 3)), Ingredient.fromStacks(new ItemStack(Blocks.SAPLING, 1, 3)),
ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), AnimalEffect.NAME), 400, ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, 24), AnimalEffect.NAME), 400,
Helper.blockIng(ModBlocks.GOLD_POWDER), Helper.blockIng(ModBlocks.GOLD_POWDER),
Helper.blockIng(ModBlocks.GOLD_POWDER), Helper.blockIng(ModBlocks.GOLD_POWDER),
Ingredient.fromItem(ModItems.SKY_INGOT), Ingredient.fromItem(ModItems.SKY_INGOT),

View file

@ -15,7 +15,7 @@
{ {
"type": "naturesaura:tree_ritual", "type": "naturesaura:tree_ritual",
"recipe": "naturesaura:animal_powder", "recipe": "naturesaura:animal_powder",
"text": "This effect can be inhibited in a radius of about 15 blocks using $(l:effects/effect_powder)Powder of Chastity$()." "text": "This effect can be inhibited using $(l:effects/effect_powder)Powder of Chastity$()."
} }
] ]
} }

View file

@ -11,7 +11,7 @@
{ {
"type": "naturesaura:tree_ritual", "type": "naturesaura:tree_ritual",
"recipe": "naturesaura:cache_powder", "recipe": "naturesaura:cache_powder",
"text": "This effect can be inhibited in a radius of about 30 blocks around the saturated area using $(l:effects/effect_powder)Powder of no Storage$()." "text": "This effect can be inhibited using $(l:effects/effect_powder)Powder of no Storage$()."
} }
] ]
} }

View file

@ -7,11 +7,11 @@
"pages": [ "pages": [
{ {
"type": "text", "type": "text",
"text": "$(item)Effect Powder$() is a magical substance that has two purposes: For one, it can $(thing)inhibit$() existing passive effects from happening in a certain area around it. Additionally, some effects can only happen with it around in the first place, meaning that it also has $(thing)creational$() abilities.$(p)The powder, of course, only works on positive effects." "text": "$(item)Effect Powder$() is a magical substance that has two purposes: For one, it can $(thing)inhibit$() existing passive effects from happening. Additionally, some effects can only happen with it around in the first place, meaning that it also has $(thing)creational$() abilities.$(p)The powder, of course, only works on positive effects."
}, },
{ {
"type": "text", "type": "text",
"text": "To use it, simply placing it down on the ground will cause it to either stop its effect or create it, depending on the type of powder used. Hitting it while it is on the ground will cause it to go back into its item form.$(p)Each effect that has an $(item)Effect Powder$() attached to it will show the recipe and radius in its chapter." "text": "To use it, simply placing a stack of any size down on the ground will cause it to either stop its effect or create it, depending on the type of powder used. The $(thing)range$() the effect will have in blocks is equal to the size of the stack placed down. Hitting it while it is on the ground will cause it to go back into its item form.$(p)Each effect that has an $(item)Effect Powder$() attached to it will show the recipe in its chapter."
} }
] ]
} }

View file

@ -15,7 +15,7 @@
{ {
"type": "naturesaura:tree_ritual", "type": "naturesaura:tree_ritual",
"recipe": "naturesaura:plant_powder", "recipe": "naturesaura:plant_powder",
"text": "This effect can be inhibited in a radius of about 15 blocks using $(l:effects/effect_powder)Powder of Steady Growth$()." "text": "This effect can be inhibited using $(l:effects/effect_powder)Powder of Steady Growth$()."
} }
] ]
} }