Miscellaneous setup

This commit is contained in:
Electroblob
2018-01-30 16:02:13 +00:00
parent da6b007a3a
commit 2af7329478
59 changed files with 1833 additions and 13509 deletions
@@ -1,6 +1,12 @@
package electroblob.wizardry.util;
import electroblob.wizardry.registry.WizardryAchievements;
import electroblob.wizardry.util.MagicDamage.DamageType;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
/** This interface allows {@link MagicDamage} and {@link IndirectMagicDamage} to both be treated as instances of a
* single type so that the damage type field can be accessed, rather than having to deal with each of them separately,
@@ -8,10 +14,34 @@ import electroblob.wizardry.util.MagicDamage.DamageType;
* need to extend different subclasses of {@link net.minecraft.util.DamageSource DamageSource}).
* @since Wizardry 1.1
* @author Electroblob */
@Mod.EventBusSubscriber
public interface IElementalDamage {
DamageType getType();
boolean isRetaliatory();
@SubscribeEvent
public static void onLivingAttackEvent(LivingAttackEvent event){
if(event.getSource() instanceof IElementalDamage){
if(MagicDamage.isEntityImmune(((IElementalDamage)event.getSource()).getType(), event.getEntity())){
event.setCanceled(true);
// I would have liked to have done the 'resist' chat message here, but I overlooked the fact that I
// would need an instance of the spell to get its display name!
return;
}
// One convenient side effect of the new damage type system is that I can get rid of all the places where
// creepers are charged and just put them here under shock damage - this is precisely the sort of
// repetitive code I was trying to get rid of, since errors can (and did!) occur.
if(event.getEntityLiving() instanceof EntityCreeper && !((EntityCreeper)event.getEntityLiving()).getPowered()
&& ((IElementalDamage)event.getSource()).getType() == DamageType.SHOCK){
// Charges creepers when they are hit by shock damage
WizardryUtilities.chargeCreeper((EntityCreeper)event.getEntityLiving());
// Gives the player that caused the shock damage the 'It's Gonna Blow' achievement
if(event.getSource().getEntity() instanceof EntityPlayer){
((EntityPlayer)event.getSource().getEntity()).addStat(WizardryAchievements.charge_creeper);
}
}
}
}
}
@@ -5,22 +5,24 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import electroblob.wizardry.event.SpellCastEvent;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.network.ByteBufUtils;
/**
* Object that wraps any number of spell multipliers into one, allowing for expandability within the Spell#cast
* Object that wraps any number of spell modifiers into one, allowing for expandability within the Spell#cast
* methods. This class is essentially a glorified {@link Map} which can be written to and read from a {@link ByteBuf}.
* It is possible to calculate spell multipliers from wand NBT within the cast methods, but this is cumbersome and does
* not allow the multipliers to be sent to the client, which is sometimes necessary (for example, detonate needs to know
* about range multipliers on the client side or the particles wouldn't show outside of the base range).
* It is possible to calculate spell modifiers from wand NBT within the cast methods, but this is cumbersome and does
* not allow the modifiers to be sent to the client, which is sometimes necessary (for example, detonate needs to know
* about range modifiers on the client side or the particles wouldn't show outside of the base range).
* <p>
* Most external interaction with SpellModifiers objects will be in SpellCastEvent.Pre, where you can add additional
* multipliers to them if desired for use with your own spells, or modify the existing ones. If you have added a wand
* Most external interaction with SpellModifiers objects will be in {@link SpellCastEvent.Pre}, where you can add additional
* modifiers to them if desired for use with your own spells, or modify the existing ones. If you have added a wand
* upgrade, this is <b>not</b> done automatically for you; you will have to do it yourself (for the simple reason that
* not all wand upgrades affect spells).
* not all wand upgrades affect spells). SpellModifiers objects are <i>mutable</i>, so you can simply change the values
* they contain to modify the spell.
* <p>
* To use a SpellModifiers object within the <code>Spell.cast</code> methods, simply retrieve the desired multiplier
* using {@link SpellModifiers#get(Item)} for wand upgrades, or {@link SpellModifiers#get(String)} if the multiplier
@@ -29,13 +31,13 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
* @since Wizardry 1.2
* @see WandHelper
*/
// I have made the decision that the USERS of this class must decide whether the multipliers need syncing or not, on a
// I have made the decision that the USERS of this class must decide whether the modifiers need syncing or not, on a
// case-by-case basis. Why? Because assigning keys to either sync or not sync would be unnecessarily restrictive, and
// would mean they have to be registered, and part of the point of SpellModifiers is that they can be added to on the
// fly.
public final class SpellModifiers {
/** Constant string identifier for the damage multiplier. All the other multipliers in Wizardry have items. */
/** Constant string identifier for the damage modifier. All the other modifiers in Wizardry have items. */
public static final String DAMAGE = "damage";
private Map<String, Float> multiplierMap;
@@ -53,7 +55,7 @@ public final class SpellModifiers {
* upgrade item was registered with.
* @throws IllegalArgumentException if the given item is not a registered special wand upgrade.
* @param upgrade The upgrade item the multiplier corresponds to.
* @param multiplier The multiplier value, with 1 being default. Usage of multipliers is up to individual spells to
* @param multiplier The multiplier value, with 1 being default. Usage of modifiers is up to individual spells to
* implement.
* @param needsSyncing Whether this multiplier should be synchronised with the client via packets. <i>Only set this
* to true if particles will be spawned which need to know the value of the multiplier.</i>
@@ -69,7 +71,7 @@ public final class SpellModifiers {
* multiplier will correspond to a wand upgrade, in which case use {@link SpellModifiers#set(Item, float, boolean)}
* instead.
* @param key The key used to identify the multiplier.
* @param multiplier The multiplier value, with 1 being default. Usage of multipliers is up to individual spells to
* @param multiplier The multiplier value, with 1 being default. Usage of modifiers is up to individual spells to
* implement.
* @param needsSyncing Whether this multiplier should be synchronised with the client via packets. <i>Only set this
* to true if particles will be spawned which depend on the multiplier.</i>
@@ -23,7 +23,9 @@ import net.minecraft.nbt.NBTTagCompound;
* unlikely case that this is necessary.
* <p>
* Also note that none of the methods in this class actually check that the given ItemStack contains an ItemWand; you
* can, for example, pass in a stack of snowballs without causing problems, but that is of course pointless!
* can, for example, pass in a stack of snowballs without causing problems, but that is of course pointless! However,
* if you have your own spell casting item (which doesn't extend ItemWand), this setup means you can still use this class
* to manage its NBT structure.
* <p>
* All <b>get</b> methods in this class return some kind of default if the passed-in wand stack has no nbt data.
* See individual method descriptions for more details.<br>
@@ -6,6 +6,7 @@ import javax.annotation.Nullable;
import com.google.common.collect.Sets;
import electroblob.wizardry.spell.Clairvoyance;
import net.minecraft.entity.EntityLiving;
import net.minecraft.pathfinding.NodeProcessor;
import net.minecraft.pathfinding.Path;
@@ -14,7 +15,8 @@ import net.minecraft.pathfinding.PathPoint;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
/** Minecraft's pathfinder refused to play nicely, so I 'borrowed' its code and fiddled with it. */
/** Minecraft's pathfinder refused to play nicely, so I 'borrowed' its code and fiddled with it. Currently this is only
* used for the {@link Clairvoyance} spell. */
public class WizardryPathFinder {
/** The path being generated */
@@ -56,6 +56,14 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/** This class contains some useful static methods for use anywhere - items, entities, spells, events, blocks, etc.
* Broadly speaking, these fall into the following categories:
* <p>
* - In-world utilities (position calculating, retrieving entities, etc.)<br>
* - Raytracing<br>
* - Drawing utilities (client-only)<br>
* - NBT and data storage utilities<br>
* - Interaction with the ally designation system<br>
* - Loot and weighting utilities
* @see CommonProxy
* @see WandHelper
* @since Wizardry 1.0