Change arcane jammer so it only has a chance of preventing spells

This commit is contained in:
Electroblob77
2020-05-31 23:16:57 +01:00
parent 31eed1cb48
commit ef222e66f2
5 changed files with 61 additions and 11 deletions
@@ -224,9 +224,11 @@ public class GuiSpellDisplay {
discovered = WizardData.get(player).hasSpellBeenDiscovered(spell);
}
// Makes spells greyed out if they are in cooldown or if the player has the arcane jammer effect
String format = cooldown > 0 || player.isPotionActive(WizardryPotions.arcane_jammer) ? "\u00A78" : spell.getElement().getFormattingCode();
// Makes spells greyed out if they are in cooldown
String format = cooldown > 0 ? "\u00A78" : spell.getElement().getFormattingCode();
if(!discovered) format = "\u00A79";
// Obfuscates the spell name if the player has the arcane jammer effect
if(player.isPotionActive(WizardryPotions.arcane_jammer)) format = format + "\u00A7k";
String name = discovered ? spell.getDisplayName() : SpellGlyphData.getGlyphName(spell, player.world);
name = format + name;
@@ -479,7 +481,7 @@ public class GuiSpellDisplay {
int y1 = flipY && mirrorY ? y + spellIconInsetY : y - spellIconInsetY - SPELL_ICON_SIZE;
if(jammed){
random.setSeed(Minecraft.getMinecraft().world.getTotalWorldTime() * 3);
random.setSeed(Minecraft.getMinecraft().world.getTotalWorldTime() / 2);
DrawingUtils.drawGlitchRect(random, x1, y1, 0, 0, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE, false, false);
}else{
DrawingUtils.drawTexturedRect(x1, y1, 0, 0, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE, SPELL_ICON_SIZE);
@@ -143,6 +143,7 @@ public final class WizardrySounds {
public static final SoundEvent MISC_BOOK_OPEN = createSound("misc.book_open");
public static final SoundEvent MISC_PAGE_TURN = createSound("misc.page_turn");
public static final SoundEvent MISC_FREEZE = createSound("misc.freeze");
public static final SoundEvent MISC_SPELL_FAIL = createSound("misc.spell_fail");
// Trick borrowed from the Twilight Forest, makes things neater.
@@ -277,7 +278,8 @@ public final class WizardrySounds {
event.getRegistry().register(MISC_BOOK_OPEN);
event.getRegistry().register(MISC_PAGE_TURN);
event.getRegistry().register(MISC_FREEZE);
event.getRegistry().register(MISC_SPELL_FAIL);
for(Spell spell : Spell.getAllSpells()){
event.getRegistry().registerAll(spell.getSounds());
}
@@ -1,10 +1,13 @@
package electroblob.wizardry.spell;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.constants.Constants;
import electroblob.wizardry.event.SpellCastEvent;
import electroblob.wizardry.event.SpellCastEvent.Source;
import electroblob.wizardry.item.SpellActions;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.SpellModifiers;
@@ -14,6 +17,8 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntitySpellcasterIllager;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@@ -24,10 +29,16 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.lang.reflect.Field;
import java.util.Random;
@Mod.EventBusSubscriber
public class ArcaneJammer extends SpellRay {
/** Random number generator used to coordinate whether spellcasting works or not. */
private static final Random random = new Random();
/** The number of ticks between updates of whether spellcasting works or not. */
private static final int UPDATE_INTERVAL = 15;
private static final Field spellTicks;
static { // Yay more reflection
@@ -37,17 +48,18 @@ public class ArcaneJammer extends SpellRay {
public ArcaneJammer(){
super("arcane_jammer", false, SpellActions.POINT);
this.soundValues(0.7f, 1, 0.4f);
this.addProperties(EFFECT_DURATION);
this.addProperties(EFFECT_DURATION, EFFECT_STRENGTH);
}
@Override
protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){
if(WizardryUtilities.isLiving(target)){
if(!world.isRemote){
((EntityLivingBase)target).addPotionEffect(new PotionEffect(WizardryPotions.arcane_jammer,
(int)(getProperty(EFFECT_DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade)), 0));
(int)(getProperty(EFFECT_DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade)),
getProperty(EFFECT_STRENGTH).intValue() + (int)((modifiers.get(SpellModifiers.POTENCY) - 1)
/ Constants.POTENCY_INCREASE_PER_TIER + 0.5f)));
}
}
@@ -72,8 +84,40 @@ public class ArcaneJammer extends SpellRay {
@SubscribeEvent(priority = EventPriority.HIGHEST) // Prevents all spells so it comes before everything else
public static void onSpellCastPreEvent(SpellCastEvent.Pre event){
// Arcane jammer prevents spell casting.
if(event.getCaster() != null && event.getCaster().isPotionActive(WizardryPotions.arcane_jammer)) event.setCanceled(true);
// Arcane jammer has a chance to prevent spell casting
// We can't just use a straight-up random number because otherwise people can spam it to get it to cast
// Instead, we're using the world time to make blocks of time when spells will and won't work
random.setSeed(event.getWorld().getTotalWorldTime() / UPDATE_INTERVAL);
// For some unfathomable reason, the first call to this after setting the seed remains the same for long
// sequences of consecutive seeds, so let's clear it out first to get to a more changeable value
random.nextInt(2);
if(event.getCaster() != null && event.getCaster().isPotionActive(WizardryPotions.arcane_jammer)
// Arcane jammer I has a 1/2 chance, level II has a 2/3 chance, and so on
&& random.nextInt(event.getCaster().getActivePotionEffect(WizardryPotions.arcane_jammer).getAmplifier() + 2) > 0){
event.setCanceled(true);
if(event.getSource() == Source.WAND || event.getSource() == Source.SCROLL){
event.getCaster().setActiveHand(EnumHand.MAIN_HAND);
}
// Because we're using a seed that should be consistent, we can do client-side stuff!
event.getWorld().playSound(event.getCaster().posX, event.getCaster().posY, event.getCaster().posZ,
WizardrySounds.MISC_SPELL_FAIL, WizardrySounds.SPELLS, 1, 1, false);
if(event.getWorld().isRemote){
Vec3d centre = event.getCaster().getPositionEyes(0).add(event.getCaster().getLookVec());
for(int i = 0; i < 5; i++){
double x = centre.x + 0.5f * (event.getWorld().rand.nextFloat() - 0.5f);
double y = centre.y + 0.5f * (event.getWorld().rand.nextFloat() - 0.5f);
double z = centre.z + 0.5f * (event.getWorld().rand.nextFloat() - 0.5f);
event.getWorld().spawnParticle(EnumParticleTypes.SMOKE_LARGE, x, y, z, 0, 0, 0);
}
}
}
}
@SubscribeEvent
@@ -113,7 +113,8 @@
"misc.book_open": {"category": "player", "sounds": ["ebwizardry:book"]},
"misc.freeze": {"category": "spells", "sounds": ["ebwizardry:freeze"]},
"misc.spell_fail": {"category": "spells", "sounds": ["random/fizz"]},
"spell.agility": {"category": "spells", "sounds": ["ebwizardry:heal"]},
"spell.arc": {"category": "spells", "sounds": ["ebwizardry:arc1", "ebwizardry:arc2", "ebwizardry:arc3"]},
"spell.arcane_jammer": {"category": "spells", "sounds": ["ebwizardry:effect1", "ebwizardry:effect2"]},
@@ -18,6 +18,7 @@
"cooldown": 50,
"base_properties": {
"range": 10,
"effect_duration": 300
"effect_duration": 300,
"effect_strength": 0
}
}