Added the Gem of burning

This commit is contained in:
Sollace 2019-02-20 17:24:26 +02:00
parent 7439352c7c
commit fba999e0ff
12 changed files with 145 additions and 43 deletions

View file

@ -6,11 +6,14 @@ import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Predicates; import com.minelittlepony.unicopia.Predicates;
import com.minelittlepony.unicopia.entity.EntitySpell; import com.minelittlepony.unicopia.entity.EntitySpell;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.unicopia.spell.IMagicEffect; import com.minelittlepony.unicopia.spell.IMagicEffect;
import com.minelittlepony.unicopia.spell.IUseAction; import com.minelittlepony.unicopia.spell.IUseAction;
import com.minelittlepony.unicopia.spell.SpellAffinity; import com.minelittlepony.unicopia.spell.SpellAffinity;
import com.minelittlepony.unicopia.spell.SpellCastResult; import com.minelittlepony.unicopia.spell.SpellCastResult;
import com.minelittlepony.unicopia.spell.IDispenceable; import com.minelittlepony.unicopia.spell.IDispenceable;
import com.minelittlepony.unicopia.spell.IHeldEffect;
import com.minelittlepony.unicopia.spell.SpellRegistry; import com.minelittlepony.unicopia.spell.SpellRegistry;
import com.minelittlepony.util.lang.ClientLocale; import com.minelittlepony.util.lang.ClientLocale;
import com.minelittlepony.util.vector.VecHelper; import com.minelittlepony.util.vector.VecHelper;
@ -80,6 +83,20 @@ public class ItemSpell extends Item implements ICastable {
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, dispenserBehavior); BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, dispenserBehavior);
} }
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isSelected) {
if (isSelected && entity instanceof EntityPlayer) {
IPlayer player = PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity);
if (player.getPlayerSpecies().canCast()) {
IHeldEffect effect = SpellRegistry.instance().getHeldFrom(stack);
if (effect != null) {
effect.updateInHand(player, getAffinity(stack));
}
}
}
}
public Item setTranslationKey(String key) { public Item setTranslationKey(String key) {
translationKey = key; translationKey = key;
return super.setTranslationKey(key); return super.setTranslationKey(key);
@ -120,7 +137,7 @@ public class ItemSpell extends Item implements ICastable {
return EnumActionResult.FAIL; return EnumActionResult.FAIL;
} }
IMagicEffect effect = SpellRegistry.instance().getSpellFromItemStack(stack); IMagicEffect effect = SpellRegistry.instance().getSpellFrom(stack);
if (effect == null) { if (effect == null) {
return EnumActionResult.FAIL; return EnumActionResult.FAIL;

View file

@ -14,6 +14,7 @@ import com.minelittlepony.unicopia.init.UEffects;
import com.minelittlepony.unicopia.init.UItems; import com.minelittlepony.unicopia.init.UItems;
import com.minelittlepony.unicopia.network.EffectSync; import com.minelittlepony.unicopia.network.EffectSync;
import com.minelittlepony.unicopia.network.MsgPlayerCapabilities; import com.minelittlepony.unicopia.network.MsgPlayerCapabilities;
import com.minelittlepony.unicopia.spell.IAttachedEffect;
import com.minelittlepony.unicopia.spell.IMagicEffect; import com.minelittlepony.unicopia.spell.IMagicEffect;
import com.minelittlepony.unicopia.spell.SpellAffinity; import com.minelittlepony.unicopia.spell.SpellAffinity;
import com.minelittlepony.unicopia.spell.SpellDisguise; import com.minelittlepony.unicopia.spell.SpellDisguise;
@ -210,12 +211,16 @@ class PlayerCapabilities implements IPlayer {
gravity.onUpdate(); gravity.onUpdate();
if (hasEffect()) { if (hasEffect()) {
if (entity.getEntityWorld().isRemote) { IAttachedEffect effect = getEffect(IAttachedEffect.class, true);
getEffect().renderOnPerson(this);
}
if (!getEffect().updateOnPerson(this)) { if (effect != null) {
setEffect(null); if (entity.getEntityWorld().isRemote) {
effect.renderOnPerson(this);
}
if (!effect.updateOnPerson(this)) {
setEffect(null);
}
} }
} }

View file

@ -0,0 +1,21 @@
package com.minelittlepony.unicopia.spell;
import com.minelittlepony.unicopia.player.IPlayer;
public interface IAttachedEffect extends IMagicEffect {
/**
* Called every tick when attached to a player.
*
* @param source The entity we are currently attached to.
* @return true to keep alive
*/
boolean updateOnPerson(IPlayer caster);
/**
* Called every tick when attached to a player. Used to apply particle effects.
* Is only called on the client side.
*
* @param source The entity we are currently attached to.
*/
default void renderOnPerson(IPlayer source) {}
}

View file

@ -0,0 +1,12 @@
package com.minelittlepony.unicopia.spell;
import com.minelittlepony.unicopia.player.IPlayer;
public interface IHeldEffect extends IMagicEffect {
/**
* Called every tick when held in a player's inventory.
*
* @param source The entity we are currently attached to.
*/
void updateInHand(IPlayer caster, SpellAffinity affinity);
}

View file

@ -62,16 +62,6 @@ public interface IMagicEffect extends InbtSerialisable, IAligned {
} }
/**
* Called every tick when attached to a player.
*
* @param source The entity we are currently attached to.
* @return true to keep alive
*/
default boolean updateOnPerson(ICaster<?> caster) {
return update(caster);
}
/** /**
* Called every tick when attached to an entity. * Called every tick when attached to an entity.
* Called on both sides. * Called on both sides.
@ -80,16 +70,6 @@ public interface IMagicEffect extends InbtSerialisable, IAligned {
*/ */
boolean update(ICaster<?> source); boolean update(ICaster<?> source);
/**
* Called every tick when attached to a player. Used to apply particle effects.
* Is only called on the client side.
*
* @param source The entity we are currently attached to.
*/
default void renderOnPerson(ICaster<?> source) {
render(source);
}
/** /**
* Called every tick when attached to an entity to produce particle effects. * Called every tick when attached to an entity to produce particle effects.
* Is only called on the client side. * Is only called on the client side.

View file

@ -0,0 +1,46 @@
package com.minelittlepony.unicopia.spell;
import com.minelittlepony.unicopia.player.IPlayer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.DamageSource;
public class SpellFlame extends AbstractSpell implements IHeldEffect {
@Override
public String getName() {
return "flame";
}
@Override
public SpellAffinity getAffinity() {
return SpellAffinity.NEUTRAL;
}
@Override
public int getTint() {
return 0xFF5D00;
}
@Override
public boolean update(ICaster<?> source) {
return false;
}
@Override
public void render(ICaster<?> source) {
}
@Override
public void updateInHand(IPlayer caster, SpellAffinity affinity) {
EntityPlayer player = caster.getOwner();
if (player.ticksExisted % 15 == 0) {
player.attackEntityFrom(DamageSource.ON_FIRE, 1);
player.playSound(SoundEvents.BLOCK_FIRE_AMBIENT, 0.5F, 1);
player.setFire(1);
}
}
}

View file

@ -136,11 +136,6 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseAc
} }
} }
@Override
public boolean updateOnPerson(ICaster<?> caster) {
return true;
}
@Override @Override
public boolean update(ICaster<?> source) { public boolean update(ICaster<?> source) {
if (!source.getWorld().isRemote) { if (!source.getWorld().isRemote) {
@ -153,11 +148,6 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseAc
return true; return true;
} }
@Override
public void renderOnPerson(ICaster<?> source) {
/*noop*/
}
@Override @Override
public void render(ICaster<?> source) { public void render(ICaster<?> source) {
source.spawnParticles(getPortalZone(), 10, pos -> { source.spawnParticles(getPortalZone(), 10, pos -> {

View file

@ -44,6 +44,7 @@ public class SpellRegistry {
registerSpell(SpellDrake::new); registerSpell(SpellDrake::new);
registerSpell(SpellReveal::new); registerSpell(SpellReveal::new);
registerSpell(SpellDarkness::new); registerSpell(SpellDarkness::new);
registerSpell(SpellFlame::new);
registerSpell(GenericSpell.factory("light", 0xF7FACB, SpellAffinity.GOOD)); registerSpell(GenericSpell.factory("light", 0xF7FACB, SpellAffinity.GOOD));
} }
@ -98,7 +99,12 @@ public class SpellRegistry {
} }
@Nullable @Nullable
public IMagicEffect getSpellFromItemStack(ItemStack stack) { public IHeldEffect getHeldFrom(ItemStack stack) {
return getEntryFromStack(stack).map(Entry::holdable).orElse(null);
}
@Nullable
public IMagicEffect getSpellFrom(ItemStack stack) {
return getSpellFromName(getKeyFromStack(stack)); return getSpellFromName(getKeyFromStack(stack));
} }
@ -168,6 +174,7 @@ public class SpellRegistry {
final boolean canDispense; final boolean canDispense;
final boolean canUse; final boolean canUse;
final boolean canHold;
final SpellAffinity affinity; final SpellAffinity affinity;
@ -178,6 +185,7 @@ public class SpellRegistry {
this.color = inst.getTint(); this.color = inst.getTint();
this.canDispense = inst instanceof IDispenceable; this.canDispense = inst instanceof IDispenceable;
this.canUse = inst instanceof IUseAction; this.canUse = inst instanceof IUseAction;
this.canHold = inst instanceof IHeldEffect;
this.affinity = inst.getAffinity(); this.affinity = inst.getAffinity();
if (inst.isCraftable()) { if (inst.isCraftable()) {
@ -197,6 +205,14 @@ public class SpellRegistry {
return (IUseAction)create(); return (IUseAction)create();
} }
IHeldEffect holdable() {
if (!canHold) {
return null;
}
return (IHeldEffect)create();
}
IDispenceable dispensable() { IDispenceable dispensable() {
if (!canDispense) { if (!canDispense) {
return null; return null;

View file

@ -16,7 +16,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents; import net.minecraft.init.SoundEvents;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
public class SpellShield extends AbstractSpell.RangedAreaSpell { public class SpellShield extends AbstractSpell.RangedAreaSpell implements IAttachedEffect {
private final ParticleConnection particlEffect = new ParticleConnection(); private final ParticleConnection particlEffect = new ParticleConnection();
@ -49,8 +49,8 @@ public class SpellShield extends AbstractSpell.RangedAreaSpell {
} }
@Override @Override
public boolean updateOnPerson(ICaster<?> source) { public boolean updateOnPerson(IPlayer source) {
if (super.updateOnPerson(source)) { if (update(source)) {
if (source.getEntity().getEntityWorld().getWorldTime() % 50 == 0) { if (source.getEntity().getEntityWorld().getWorldTime() % 50 == 0) {
double radius = 4 + (source.getCurrentLevel() * 2); double radius = 4 + (source.getCurrentLevel() * 2);
if (!IPower.takeFromPlayer((EntityPlayer)source.getOwner(), radius/4)) { if (!IPower.takeFromPlayer((EntityPlayer)source.getOwner(), radius/4)) {

View file

@ -1,7 +1,7 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "id": "unicopia:fire" }, { "item": "unicopia:gem", "spell": "flame" },
{ "id": "unicopia:fire" }, { "id": "unicopia:fire" },
{ "id": "unicopia:fire" } { "id": "unicopia:fire" }
], ],

View file

@ -0,0 +1,12 @@
{
"type": "unicopia:crafting_spell",
"ingredients": [
{ "id": "unicopia:fire" },
{ "id": "unicopia:fire" },
{ "id": "unicopia:fire" }
],
"result": {
"item": { "item": "unicopia:gem" },
"spell": "fire"
}
}

View file

@ -54,8 +54,11 @@ spell.light.tagline=Discovery I
spell.reveal.name=Revealing spell.reveal.name=Revealing
spell.reveal.tagline=Discovery II spell.reveal.tagline=Discovery II
spell.flame.name=Burning
spell.flame.tagline=Fire I
spell.fire.name=Flame spell.fire.name=Flame
spell.fire.tagline=Fire I spell.fire.tagline=Fire II
spell.vortex.name=Retention spell.vortex.name=Retention
spell.vortex.tagline=Containment I spell.vortex.tagline=Containment I
@ -88,7 +91,7 @@ curse.necromancy.name=Necromancy
curse.necromancy.tagline=Resurrection I curse.necromancy.tagline=Resurrection I
curse.inferno.name=Inferno curse.inferno.name=Inferno
curse.inferno.tagline=Fire II curse.inferno.tagline=Fire III
item.spellbook.name=Spellbook item.spellbook.name=Spellbook
item.bag_of_holding.name=Bag of Holding item.bag_of_holding.name=Bag of Holding