From fba999e0ffd25c035344de1d52080d8c17990655 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 20 Feb 2019 17:24:26 +0200 Subject: [PATCH] Added the Gem of burning --- .../unicopia/item/ItemSpell.java | 19 +++++++- .../unicopia/player/PlayerCapabilities.java | 15 ++++-- .../unicopia/spell/IAttachedEffect.java | 21 +++++++++ .../unicopia/spell/IHeldEffect.java | 12 +++++ .../unicopia/spell/IMagicEffect.java | 20 -------- .../unicopia/spell/SpellFlame.java | 46 +++++++++++++++++++ .../unicopia/spell/SpellPortal.java | 10 ---- .../unicopia/spell/SpellRegistry.java | 18 +++++++- .../unicopia/spell/SpellShield.java | 6 +-- .../unicopia/enchanting/recipes/fire.json | 2 +- .../unicopia/enchanting/recipes/flame.json | 12 +++++ .../resources/assets/unicopia/lang/en_US.lang | 7 ++- 12 files changed, 145 insertions(+), 43 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/spell/IAttachedEffect.java create mode 100644 src/main/java/com/minelittlepony/unicopia/spell/IHeldEffect.java create mode 100644 src/main/java/com/minelittlepony/unicopia/spell/SpellFlame.java create mode 100644 src/main/resources/assets/unicopia/enchanting/recipes/flame.json diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemSpell.java b/src/main/java/com/minelittlepony/unicopia/item/ItemSpell.java index e4e7b005..77acfb09 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ItemSpell.java @@ -6,11 +6,14 @@ import javax.annotation.Nullable; import com.minelittlepony.unicopia.Predicates; 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.IUseAction; import com.minelittlepony.unicopia.spell.SpellAffinity; import com.minelittlepony.unicopia.spell.SpellCastResult; import com.minelittlepony.unicopia.spell.IDispenceable; +import com.minelittlepony.unicopia.spell.IHeldEffect; import com.minelittlepony.unicopia.spell.SpellRegistry; import com.minelittlepony.util.lang.ClientLocale; import com.minelittlepony.util.vector.VecHelper; @@ -80,6 +83,20 @@ public class ItemSpell extends Item implements ICastable { 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) { translationKey = key; return super.setTranslationKey(key); @@ -120,7 +137,7 @@ public class ItemSpell extends Item implements ICastable { return EnumActionResult.FAIL; } - IMagicEffect effect = SpellRegistry.instance().getSpellFromItemStack(stack); + IMagicEffect effect = SpellRegistry.instance().getSpellFrom(stack); if (effect == null) { return EnumActionResult.FAIL; diff --git a/src/main/java/com/minelittlepony/unicopia/player/PlayerCapabilities.java b/src/main/java/com/minelittlepony/unicopia/player/PlayerCapabilities.java index 30ec66d3..bc5492d5 100644 --- a/src/main/java/com/minelittlepony/unicopia/player/PlayerCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/player/PlayerCapabilities.java @@ -14,6 +14,7 @@ import com.minelittlepony.unicopia.init.UEffects; import com.minelittlepony.unicopia.init.UItems; import com.minelittlepony.unicopia.network.EffectSync; import com.minelittlepony.unicopia.network.MsgPlayerCapabilities; +import com.minelittlepony.unicopia.spell.IAttachedEffect; import com.minelittlepony.unicopia.spell.IMagicEffect; import com.minelittlepony.unicopia.spell.SpellAffinity; import com.minelittlepony.unicopia.spell.SpellDisguise; @@ -210,12 +211,16 @@ class PlayerCapabilities implements IPlayer { gravity.onUpdate(); if (hasEffect()) { - if (entity.getEntityWorld().isRemote) { - getEffect().renderOnPerson(this); - } + IAttachedEffect effect = getEffect(IAttachedEffect.class, true); - if (!getEffect().updateOnPerson(this)) { - setEffect(null); + if (effect != null) { + if (entity.getEntityWorld().isRemote) { + effect.renderOnPerson(this); + } + + if (!effect.updateOnPerson(this)) { + setEffect(null); + } } } diff --git a/src/main/java/com/minelittlepony/unicopia/spell/IAttachedEffect.java b/src/main/java/com/minelittlepony/unicopia/spell/IAttachedEffect.java new file mode 100644 index 00000000..a30b9741 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/spell/IAttachedEffect.java @@ -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) {} +} diff --git a/src/main/java/com/minelittlepony/unicopia/spell/IHeldEffect.java b/src/main/java/com/minelittlepony/unicopia/spell/IHeldEffect.java new file mode 100644 index 00000000..f9a0f75d --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/spell/IHeldEffect.java @@ -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); +} diff --git a/src/main/java/com/minelittlepony/unicopia/spell/IMagicEffect.java b/src/main/java/com/minelittlepony/unicopia/spell/IMagicEffect.java index cb5e72c4..2e31b47e 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/IMagicEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/IMagicEffect.java @@ -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 on both sides. @@ -80,16 +70,6 @@ public interface IMagicEffect extends InbtSerialisable, IAligned { */ 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. * Is only called on the client side. diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellFlame.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellFlame.java new file mode 100644 index 00000000..36f9ea2d --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellFlame.java @@ -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); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellPortal.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellPortal.java index ce1d4315..e5e6d3ce 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellPortal.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellPortal.java @@ -136,11 +136,6 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseAc } } - @Override - public boolean updateOnPerson(ICaster caster) { - return true; - } - @Override public boolean update(ICaster source) { if (!source.getWorld().isRemote) { @@ -153,11 +148,6 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseAc return true; } - @Override - public void renderOnPerson(ICaster source) { - /*noop*/ - } - @Override public void render(ICaster source) { source.spawnParticles(getPortalZone(), 10, pos -> { diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java index 5577075b..eb04c883 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java @@ -44,6 +44,7 @@ public class SpellRegistry { registerSpell(SpellDrake::new); registerSpell(SpellReveal::new); registerSpell(SpellDarkness::new); + registerSpell(SpellFlame::new); registerSpell(GenericSpell.factory("light", 0xF7FACB, SpellAffinity.GOOD)); } @@ -98,7 +99,12 @@ public class SpellRegistry { } @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)); } @@ -168,6 +174,7 @@ public class SpellRegistry { final boolean canDispense; final boolean canUse; + final boolean canHold; final SpellAffinity affinity; @@ -178,6 +185,7 @@ public class SpellRegistry { this.color = inst.getTint(); this.canDispense = inst instanceof IDispenceable; this.canUse = inst instanceof IUseAction; + this.canHold = inst instanceof IHeldEffect; this.affinity = inst.getAffinity(); if (inst.isCraftable()) { @@ -197,6 +205,14 @@ public class SpellRegistry { return (IUseAction)create(); } + IHeldEffect holdable() { + if (!canHold) { + return null; + } + + return (IHeldEffect)create(); + } + IDispenceable dispensable() { if (!canDispense) { return null; diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellShield.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellShield.java index 3130d109..a50de8aa 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellShield.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellShield.java @@ -16,7 +16,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.SoundEvents; 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(); @@ -49,8 +49,8 @@ public class SpellShield extends AbstractSpell.RangedAreaSpell { } @Override - public boolean updateOnPerson(ICaster source) { - if (super.updateOnPerson(source)) { + public boolean updateOnPerson(IPlayer source) { + if (update(source)) { if (source.getEntity().getEntityWorld().getWorldTime() % 50 == 0) { double radius = 4 + (source.getCurrentLevel() * 2); if (!IPower.takeFromPlayer((EntityPlayer)source.getOwner(), radius/4)) { diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/fire.json b/src/main/resources/assets/unicopia/enchanting/recipes/fire.json index 29013561..7dcff85b 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/fire.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/fire.json @@ -1,7 +1,7 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "id": "unicopia:fire" }, + { "item": "unicopia:gem", "spell": "flame" }, { "id": "unicopia:fire" }, { "id": "unicopia:fire" } ], diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/flame.json b/src/main/resources/assets/unicopia/enchanting/recipes/flame.json new file mode 100644 index 00000000..29013561 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/recipes/flame.json @@ -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" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/lang/en_US.lang b/src/main/resources/assets/unicopia/lang/en_US.lang index e7303c64..e7473a9d 100644 --- a/src/main/resources/assets/unicopia/lang/en_US.lang +++ b/src/main/resources/assets/unicopia/lang/en_US.lang @@ -54,8 +54,11 @@ spell.light.tagline=Discovery I spell.reveal.name=Revealing spell.reveal.tagline=Discovery II +spell.flame.name=Burning +spell.flame.tagline=Fire I + spell.fire.name=Flame -spell.fire.tagline=Fire I +spell.fire.tagline=Fire II spell.vortex.name=Retention spell.vortex.tagline=Containment I @@ -88,7 +91,7 @@ curse.necromancy.name=Necromancy curse.necromancy.tagline=Resurrection I curse.inferno.name=Inferno -curse.inferno.tagline=Fire II +curse.inferno.tagline=Fire III item.spellbook.name=Spellbook item.bag_of_holding.name=Bag of Holding