mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 11:53:29 +01:00
rework effect powder to have its range based on the stack size
This commit is contained in:
parent
f0fc6085df
commit
47d565a70c
13 changed files with 38 additions and 27 deletions
|
@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
@ -95,11 +96,18 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
|
|||
}
|
||||
|
||||
@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(
|
||||
EntityEffectInhibitor.class,
|
||||
new AxisAlignedBB(pos).grow(radius),
|
||||
entity -> entity.getDistanceSq(pos) <= radius * radius && name.equals(entity.getInhibitedEffect()));
|
||||
new AxisAlignedBB(pos).grow(64),
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,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 = "6";
|
||||
public static final String VERSION = "7";
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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,
|
||||
* BlockPos, ResourceLocation, int)}
|
||||
* BlockPos, ResourceLocation)}
|
||||
*/
|
||||
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
|
||||
* around the given position in the given radius. To register a powder
|
||||
* with the supplied name, use {@link #EFFECT_POWDERS}
|
||||
* around the given position based on the radius it has. To register a
|
||||
* powder with the supplied name, use {@link #EFFECT_POWDERS}
|
||||
*
|
||||
* @param world The world
|
||||
* @param pos The center position
|
||||
* @param name The registry name of the powder
|
||||
* @param radius The radius around the center to check for
|
||||
* @param world The world
|
||||
* @param pos The center position
|
||||
* @param name The registry name of the powder
|
||||
* @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)
|
||||
|
|
|
@ -37,7 +37,7 @@ public class StubHooks implements NaturesAuraAPI.IInternalHooks {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name, int radius) {
|
||||
public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class AnimalEffect implements IDrainSpotEffect {
|
|||
for (EntityItem item : items) {
|
||||
if (item.isDead)
|
||||
continue;
|
||||
if (NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME, 35))
|
||||
if (NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME))
|
||||
continue;
|
||||
|
||||
ItemStack stack = item.getItem();
|
||||
|
@ -84,7 +84,7 @@ public class AnimalEffect implements IDrainSpotEffect {
|
|||
EntityAnimal first = animals.get(world.rand.nextInt(animals.size()));
|
||||
if (first.isChild() || first.isInLove())
|
||||
return;
|
||||
if (NaturesAuraAPI.instance().isEffectPowderActive(world, first.getPosition(), NAME, 35))
|
||||
if (NaturesAuraAPI.instance().isEffectPowderActive(world, first.getPosition(), NAME))
|
||||
return;
|
||||
|
||||
Optional<EntityAnimal> secondOptional = animals.stream()
|
||||
|
|
|
@ -27,7 +27,7 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
|
|||
int aura = IAuraChunk.getAuraInArea(world, pos, 20);
|
||||
if (aura < 15000)
|
||||
return;
|
||||
if (NaturesAuraAPI.instance().isEffectPowderActive(world, pos, NAME, 30))
|
||||
if (NaturesAuraAPI.instance().isEffectPowderActive(world, pos, NAME))
|
||||
return;
|
||||
int dist = MathHelper.clamp(aura / 3500, 3, 15);
|
||||
int amount = aura / 2500 - 2;
|
||||
|
|
|
@ -39,7 +39,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
|
|||
int z = MathHelper.floor(pos.getZ() + world.rand.nextGaussian() * dist);
|
||||
BlockPos plantPos = new BlockPos(x, world.getHeight(x, z), z);
|
||||
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;
|
||||
|
||||
IBlockState state = world.getBlockState(plantPos);
|
||||
|
|
|
@ -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<Integer> COLOR = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
|
||||
public int amount;
|
||||
|
||||
public EntityEffectInhibitor(World worldIn) {
|
||||
super(worldIn);
|
||||
|
@ -34,12 +35,14 @@ public class EntityEffectInhibitor extends Entity {
|
|||
protected void readEntityFromNBT(NBTTagCompound compound) {
|
||||
this.setInhibitedEffect(new ResourceLocation(compound.getString("effect")));
|
||||
this.setColor(compound.getInteger("color"));
|
||||
this.amount = compound.hasKey("amount") ? compound.getInteger("amount") : 24;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound compound) {
|
||||
compound.setString("effect", this.getInhibitedEffect().toString());
|
||||
compound.setInteger("color", this.getColor());
|
||||
compound.setInteger("amount", this.amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,7 +70,7 @@ public class EntityEffectInhibitor extends Entity {
|
|||
public boolean attackEntityFrom(DamageSource source, float amount) {
|
||||
if (source instanceof EntityDamageSource && !this.world.isRemote) {
|
||||
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;
|
||||
} else
|
||||
return super.attackEntityFrom(source, amount);
|
||||
|
|
|
@ -29,9 +29,10 @@ public class ItemEffectPowder extends ItemImpl implements IColorProvidingItem {
|
|||
EntityEffectInhibitor entity = new EntityEffectInhibitor(worldIn);
|
||||
entity.setInhibitedEffect(effect);
|
||||
entity.setColor(NaturesAuraAPI.EFFECT_POWDERS.get(effect));
|
||||
entity.amount = stack.getCount();
|
||||
entity.setPosition(pos.getX() + hitX, pos.getY() + hitY + 1, pos.getZ() + hitZ);
|
||||
worldIn.spawnEntity(entity);
|
||||
stack.shrink(1);
|
||||
stack.setCount(0);
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
|
|
@ -84,21 +84,21 @@ public final class ModRecipes {
|
|||
Helper.blockIng(Blocks.GLOWSTONE)).register();
|
||||
new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "plant_powder"),
|
||||
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),
|
||||
Ingredient.fromItem(ModItems.SKY_INGOT),
|
||||
Ingredient.fromItem(Items.WHEAT)).register();
|
||||
new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "cache_powder"),
|
||||
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),
|
||||
Ingredient.fromItem(ModItems.SKY_INGOT),
|
||||
Ingredient.fromItem(ModItems.AURA_CACHE)).register();
|
||||
new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "animal_powder"),
|
||||
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),
|
||||
Ingredient.fromItem(ModItems.SKY_INGOT),
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
{
|
||||
"type": "naturesaura:tree_ritual",
|
||||
"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$()."
|
||||
}
|
||||
]
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
{
|
||||
"type": "naturesaura:tree_ritual",
|
||||
"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$()."
|
||||
}
|
||||
]
|
||||
}
|
|
@ -7,11 +7,11 @@
|
|||
"pages": [
|
||||
{
|
||||
"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",
|
||||
"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."
|
||||
}
|
||||
]
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
{
|
||||
"type": "naturesaura:tree_ritual",
|
||||
"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$()."
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue