Add several pieces of documentation

This commit is contained in:
Sollace 2019-03-12 22:10:48 +02:00
parent bae95b34aa
commit 1248b93995
9 changed files with 61 additions and 18 deletions

View file

@ -23,6 +23,11 @@ import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
/**
* A generalised version of Mojang's projectile entity class with added support for a custom appearance and water phobia.
*
* Can also carry a spell if needed.
*/
public class EntityProjectile extends EntitySnowball implements IMagicals, ICaster<EntityLivingBase> { public class EntityProjectile extends EntitySnowball implements IMagicals, ICaster<EntityLivingBase> {
private static final DataParameter<ItemStack> ITEM = EntityDataManager private static final DataParameter<ItemStack> ITEM = EntityDataManager

View file

@ -2,6 +2,10 @@ package com.minelittlepony.unicopia.entity;
import net.minecraft.entity.passive.IAnimals; import net.minecraft.entity.passive.IAnimals;
/**
* Any entities with magical abilities.
* Casters are automatically considered magic, for obvious reasons.
*/
public interface IMagicals extends IAnimals { public interface IMagicals extends IAnimals {
} }

View file

@ -1,9 +1,20 @@
package com.minelittlepony.unicopia.player; package com.minelittlepony.unicopia.player;
/**
* Interface for things that can be owned.
*
* @param <E> The type of object that owns us.
*/
public interface IOwned<E> { public interface IOwned<E> {
/**
* Updates the owner of this object.
*/
void setOwner(E owner); void setOwner(E owner);
/**
* Gets the owner that holds this object.
*/
E getOwner(); E getOwner();

View file

@ -2,6 +2,9 @@ package com.minelittlepony.unicopia.spell;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.IPlayer;
/**
* Represents a passive spell that does something when held in the player's hand.
*/
public interface IHeldEffect extends IMagicEffect { public interface IHeldEffect extends IMagicEffect {
/** /**
* Called every tick when held in a player's inventory. * Called every tick when held in a player's inventory.

View file

@ -1,5 +1,8 @@
package com.minelittlepony.unicopia.spell; package com.minelittlepony.unicopia.spell;
/**
* Object with levelling capabilities.
*/
public interface ILevelled { public interface ILevelled {
/** /**

View file

@ -1,16 +0,0 @@
package com.minelittlepony.unicopia.spell;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public interface IRangedEffect extends IMagicEffect {
void onImpact(World world, BlockPos pos, IBlockState state);
default SoundEvent getThrowSound(ItemStack stack) {
return SoundEvents.ENTITY_SNOWBALL_THROW;
}
}

View file

@ -1,10 +1,22 @@
package com.minelittlepony.unicopia.spell; package com.minelittlepony.unicopia.spell;
/**
* Magic effects that can be suppressed by other nearby effects.
*/
public interface ISuppressable extends IMagicEffect { public interface ISuppressable extends IMagicEffect {
/**
* Returns true if this spell is currently still suppressed.
*/
boolean getSuppressed(); boolean getSuppressed();
/**
* Returns true if this spell can be suppressed by the given other spell and caster.
*/
boolean isVulnerable(ICaster<?> otherSource, IMagicEffect other); boolean isVulnerable(ICaster<?> otherSource, IMagicEffect other);
/**
* Event triggered when this effect is suppressed.
*/
void onSuppressed(ICaster<?> otherSource); void onSuppressed(ICaster<?> otherSource);
} }

View file

@ -14,18 +14,29 @@ import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraft.world.World; import net.minecraft.world.World;
/**
* Magic effects that can be thrown.
*/
public interface ITossedEffect extends IMagicEffect, ITossable<ICaster<?>> { public interface ITossedEffect extends IMagicEffect, ITossable<ICaster<?>> {
default SoundEvent getThrowSound(ICaster<?> caster) { default SoundEvent getThrowSound(ICaster<?> caster) {
return SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT; return SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT;
} }
/**
* Gets the appearance to be used when projecting this spell.
*/
default ItemStack getCastAppearance(ICaster<?> caster) { default ItemStack getCastAppearance(ICaster<?> caster) {
Item item = this.getAffinity() == SpellAffinity.BAD ? UItems.curse : UItems.spell; Item item = getAffinity() == SpellAffinity.BAD ? UItems.curse : UItems.spell;
return SpellRegistry.instance().enchantStack(new ItemStack(item), getName()); return SpellRegistry.instance().enchantStack(new ItemStack(item), getName());
} }
/**
* Projects this spell.
*
* Returns the resulting projectile entity for customization (or null if on the client).
*/
@Nullable @Nullable
default EntityProjectile toss(ICaster<?> caster) { default EntityProjectile toss(ICaster<?> caster) {
World world = caster.getWorld(); World world = caster.getWorld();
@ -34,7 +45,7 @@ public interface ITossedEffect extends IMagicEffect, ITossable<ICaster<?>> {
world.playSound(null, entity.posX, entity.posY, entity.posZ, getThrowSound(caster), SoundCategory.NEUTRAL, 0.7F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F)); world.playSound(null, entity.posX, entity.posY, entity.posZ, getThrowSound(caster), SoundCategory.NEUTRAL, 0.7F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F));
if (!world.isRemote) { if (caster.isLocal()) {
EntityProjectile projectile = new EntityProjectile(world, caster.getOwner()); EntityProjectile projectile = new EntityProjectile(world, caster.getOwner());
projectile.setItem(getCastAppearance(caster)); projectile.setItem(getCastAppearance(caster));

View file

@ -8,12 +8,22 @@ import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
public interface ITossable<T> { public interface ITossable<T> {
/**
* Called once the projectile lands either hitting the ground or an entity.
*/
void onImpact(ICaster<?> caster, BlockPos pos, IBlockState state); void onImpact(ICaster<?> caster, BlockPos pos, IBlockState state);
/**
* The sound made when thrown.
*/
default SoundEvent getThrowSound(T stack) { default SoundEvent getThrowSound(T stack) {
return SoundEvents.ENTITY_SNOWBALL_THROW; return SoundEvents.ENTITY_SNOWBALL_THROW;
} }
/**
* The amount of damage to be dealt when the projectile collides with an entity.
*/
default int getThrowDamage(T stack) { default int getThrowDamage(T stack) {
return 0; return 0;
} }