Split up and reorganise WizardryUtilities

This commit is contained in:
Electroblob77
2020-06-13 23:29:01 +01:00
parent 57e96458d5
commit 238b9d04bb
189 changed files with 1724 additions and 1731 deletions
@@ -179,7 +179,7 @@ public class ItemArtefact extends Item {
}else{
// To find out if the given artefact is one of the first n on the player's hotbar (where n is the maximum
// number of that kind of artefact that can be active at once):
return WizardryUtilities.getPrioritisedHotbarAndOffhand(player).stream() // Retrieve the stacks in question
return InventoryUtils.getPrioritisedHotbarAndOffhand(player).stream() // Retrieve the stacks in question
// Filter out all except artefacts of the same type as the given one (preserving order)
.filter(s -> s.getItem() instanceof ItemArtefact && ((ItemArtefact)s.getItem()).type == ((ItemArtefact)artefact).type)
.limit(((ItemArtefact)artefact).type.maxAtOnce) // Ignore all but the first n
@@ -213,7 +213,7 @@ public class ItemArtefact extends Item {
List<ItemArtefact> artefacts = new ArrayList<>();
for(Type type : types){
artefacts.addAll(WizardryUtilities.getPrioritisedHotbarAndOffhand(player).stream()
artefacts.addAll(InventoryUtils.getPrioritisedHotbarAndOffhand(player).stream()
.filter(s -> s.getItem() instanceof ItemArtefact)
.map(s -> (ItemArtefact)s.getItem())
.filter(i -> type == i.type && i.enabled)
@@ -237,7 +237,7 @@ public class ItemArtefact extends Item {
*/
public static boolean findMatchingWandAndExecute(EntityPlayer player, Spell spell, Consumer<? super ItemStack> action){
List<ItemStack> hotbar = WizardryUtilities.getPrioritisedHotbarAndOffhand(player);
List<ItemStack> hotbar = InventoryUtils.getPrioritisedHotbarAndOffhand(player);
Optional<ItemStack> stack = hotbar.stream().filter(s -> s.getItem() instanceof ISpellCastingItem
&& Arrays.asList(((ISpellCastingItem)s.getItem()).getSpells(s)).contains(spell)).findFirst();
@@ -281,7 +281,7 @@ public class ItemArtefact extends Item {
if(artefact == WizardryItems.ring_condensing){
if(player.ticksExisted % 150 == 0){
for(ItemStack stack : WizardryUtilities.getHotbar(player)){
for(ItemStack stack : InventoryUtils.getHotbar(player)){
// Needs to be both of these interfaces because this ring only recharges wands
// (or more accurately, chargeable spellcasting items)
if(stack.getItem() instanceof ISpellCastingItem && stack.getItem() instanceof IManaStoringItem)
@@ -342,7 +342,7 @@ public class ItemArtefact extends Item {
findMatchingWandAndExecute(player, Spells.shield, wand -> {
List<Entity> projectiles = WizardryUtilities.getEntitiesWithinRadius(5, player.posX, player.posY, player.posZ, world, Entity.class);
List<Entity> projectiles = EntityUtils.getEntitiesWithinRadius(5, player.posX, player.posY, player.posZ, world, Entity.class);
projectiles.removeIf(e -> !(e instanceof IProjectile));
Vec3d look = player.getLookVec();
Vec3d playerPos = player.getPositionVector().add(0, player.height/2, 0);
@@ -480,7 +480,7 @@ public class ItemArtefact extends Item {
// Spell properties allow all three of the above spells to be dealt with the same way - neat!
float healthGained = event.getSpell().getProperty(Spell.HEALTH).floatValue() * event.getModifiers().get(SpellModifiers.POTENCY);
List<EntityLivingBase> nearby = WizardryUtilities.getEntitiesWithinRadius(4, player.posX, player.posY, player.posZ, event.getWorld());
List<EntityLivingBase> nearby = EntityUtils.getEntitiesWithinRadius(4, player.posX, player.posY, player.posZ, event.getWorld());
for(EntityLivingBase entity : nearby){
if(AllyDesignationSystem.isAllied(player, entity) && entity.getHealth() > 0 && entity.getHealth() < entity.getMaxHealth()){
@@ -505,13 +505,13 @@ public class ItemArtefact extends Item {
if(entityNBT.hasUniqueId(MindControl.NBT_KEY)){
Entity caster = WizardryUtilities.getEntityByUUID(entity.world, entityNBT.getUniqueId(MindControl.NBT_KEY));
Entity caster = EntityUtils.getEntityByUUID(entity.world, entityNBT.getUniqueId(MindControl.NBT_KEY));
if(caster instanceof EntityPlayer){
if(isArtefactActive((EntityPlayer)caster, WizardryItems.ring_mind_control)){
WizardryUtilities.getEntitiesWithinRadius(3, entity.posX, entity.posY, entity.posZ, entity.world, EntityLiving.class).stream()
EntityUtils.getEntitiesWithinRadius(3, entity.posX, entity.posY, entity.posZ, entity.world, EntityLiving.class).stream()
.filter(e -> e.world.rand.nextInt(10) == 0)
.filter(MindControl::canControl)
.filter(e -> AllyDesignationSystem.isValidTarget(caster, e))
@@ -573,7 +573,7 @@ public class ItemArtefact extends Item {
}else if(artefact == WizardryItems.amulet_potential){
if(player.world.rand.nextFloat() < 0.2f && WizardryUtilities.isMeleeDamage(event.getSource())
if(player.world.rand.nextFloat() < 0.2f && EntityUtils.isMeleeDamage(event.getSource())
&& event.getSource().getTrueSource() instanceof EntityLivingBase){
EntityLivingBase target = (EntityLivingBase)event.getSource().getTrueSource();
@@ -597,7 +597,7 @@ public class ItemArtefact extends Item {
if(!event.getSource().isUnblockable() && player.world.rand.nextFloat() < 0.15f){
List<EntityLiving> nearbyMobs = WizardryUtilities.getEntitiesWithinRadius(5, player.posX, player.posY, player.posZ, player.world, EntityLiving.class);
List<EntityLiving> nearbyMobs = EntityUtils.getEntitiesWithinRadius(5, player.posX, player.posY, player.posZ, player.world, EntityLiving.class);
nearbyMobs.removeIf(e -> !(e instanceof ISummonedCreature && ((ISummonedCreature)e).getCaster() == player));
if(!nearbyMobs.isEmpty()){
@@ -611,7 +611,7 @@ public class ItemArtefact extends Item {
}else if(artefact == WizardryItems.amulet_banishing){
if(player.world.rand.nextFloat() < 0.2f && WizardryUtilities.isMeleeDamage(event.getSource())
if(player.world.rand.nextFloat() < 0.2f && EntityUtils.isMeleeDamage(event.getSource())
&& event.getSource().getTrueSource() instanceof EntityLivingBase){
EntityLivingBase target = (EntityLivingBase)event.getSource().getTrueSource();
@@ -639,25 +639,25 @@ public class ItemArtefact extends Item {
if(artefact == WizardryItems.ring_fire_melee){
// Used ItemWand intentionally because we need the element
// Other mods can always make their own events if they want their own spellcasting items to do this
if(WizardryUtilities.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
if(EntityUtils.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
&& ((ItemWand)mainhandItem.getItem()).element == Element.FIRE){
event.getEntity().setFire(5);
}
}else if(artefact == WizardryItems.ring_ice_melee){
if(WizardryUtilities.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
if(EntityUtils.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
&& ((ItemWand)mainhandItem.getItem()).element == Element.ICE){
event.getEntityLiving().addPotionEffect(new PotionEffect(WizardryPotions.frost, 200, 0));
}
}else if(artefact == WizardryItems.ring_lightning_melee){
if(WizardryUtilities.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
if(EntityUtils.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
&& ((ItemWand)mainhandItem.getItem()).element == Element.LIGHTNING){
WizardryUtilities.getEntitiesWithinRadius(3, player.posX, player.posY, player.posZ, world).stream()
.filter(WizardryUtilities::isLiving)
EntityUtils.getEntitiesWithinRadius(3, player.posX, player.posY, player.posZ, world).stream()
.filter(EntityUtils::isLiving)
.filter(e -> e != player)
.min(Comparator.comparingDouble(player::getDistanceSq))
.ifPresent(target -> {
@@ -679,14 +679,14 @@ public class ItemArtefact extends Item {
}else if(artefact == WizardryItems.ring_necromancy_melee){
if(WizardryUtilities.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
if(EntityUtils.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
&& ((ItemWand)mainhandItem.getItem()).element == Element.NECROMANCY){
event.getEntityLiving().addPotionEffect(new PotionEffect(MobEffects.WITHER, 200, 0));
}
}else if(artefact == WizardryItems.ring_earth_melee){
if(WizardryUtilities.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
if(EntityUtils.isMeleeDamage(event.getSource()) && mainhandItem.getItem() instanceof ItemWand
&& ((ItemWand)mainhandItem.getItem()).element == Element.EARTH){
event.getEntityLiving().addPotionEffect(new PotionEffect(MobEffects.POISON, 200, 0));
}
@@ -696,7 +696,7 @@ public class ItemArtefact extends Item {
if(!player.world.isRemote && player.world.rand.nextFloat() < 0.15f
&& event.getEntityLiving().getHealth() < 12f // Otherwise it's a bit overpowered!
&& event.getEntityLiving().isPotionActive(WizardryPotions.frost)
&& WizardryUtilities.isMeleeDamage(event.getSource())){
&& EntityUtils.isMeleeDamage(event.getSource())){
event.setAmount(12f);
@@ -722,7 +722,7 @@ public class ItemArtefact extends Item {
if((event.getSource() instanceof IElementalDamage
&& (((IElementalDamage)event.getSource()).getType() == MagicDamage.DamageType.WITHER))
// or it's direct, non-melee damage and the player is holding a wand with a necromancy spell selected
|| (event.getSource().getImmediateSource() == player && !WizardryUtilities.isMeleeDamage(event.getSource())
|| (event.getSource().getImmediateSource() == player && !EntityUtils.isMeleeDamage(event.getSource())
&& Streams.stream(player.getHeldEquipment()).anyMatch(s -> s.getItem() instanceof ISpellCastingItem
&& ((ISpellCastingItem)s.getItem()).getCurrentSpell(s).getElement() == Element.NECROMANCY))){
@@ -735,7 +735,7 @@ public class ItemArtefact extends Item {
if(player.world.rand.nextFloat() < 0.3f && ((event.getSource() instanceof IElementalDamage
&& (((IElementalDamage)event.getSource()).getType() == MagicDamage.DamageType.WITHER))
// ...or it's direct, non-melee damage and the player is holding a wand with a necromancy spell selected
|| (event.getSource().getImmediateSource() == player && !WizardryUtilities.isMeleeDamage(event.getSource())
|| (event.getSource().getImmediateSource() == player && !EntityUtils.isMeleeDamage(event.getSource())
&& Streams.stream(player.getHeldEquipment()).anyMatch(s -> s.getItem() instanceof ISpellCastingItem
&& ((ISpellCastingItem)s.getItem()).getCurrentSpell(s).getElement() == Element.NECROMANCY
&& ((ISpellCastingItem)s.getItem()).getCurrentSpell(s) != Spells.life_drain)))){
@@ -753,7 +753,7 @@ public class ItemArtefact extends Item {
// ...or it was from a dart...
|| event.getSource().getImmediateSource() instanceof EntityDart
// ...or it's direct, non-melee damage and the player is holding a wand with an earth spell selected
|| (event.getSource().getImmediateSource() == player && !WizardryUtilities.isMeleeDamage(event.getSource())
|| (event.getSource().getImmediateSource() == player && !EntityUtils.isMeleeDamage(event.getSource())
&& Streams.stream(player.getHeldEquipment()).anyMatch(s -> s.getItem() instanceof ISpellCastingItem
&& ((ISpellCastingItem)s.getItem()).getCurrentSpell(s).getElement() == Element.EARTH))){
@@ -768,11 +768,11 @@ public class ItemArtefact extends Item {
// ...or it was from a force orb...
|| event.getSource().getImmediateSource() instanceof EntityForceOrb
// ...or it's direct, non-melee damage and the player is holding a wand with a sorcery spell selected
|| (event.getSource().getImmediateSource() == player && !WizardryUtilities.isMeleeDamage(event.getSource())
|| (event.getSource().getImmediateSource() == player && !EntityUtils.isMeleeDamage(event.getSource())
&& Streams.stream(player.getHeldEquipment()).anyMatch(s -> s.getItem() instanceof ISpellCastingItem
&& ((ISpellCastingItem)s.getItem()).getCurrentSpell(s).getElement() == Element.SORCERY))){
WizardryUtilities.getPrioritisedHotbarAndOffhand(player).stream()
InventoryUtils.getPrioritisedHotbarAndOffhand(player).stream()
.filter(s -> s.getItem() instanceof ISpellCastingItem && s.getItem() instanceof IManaStoringItem
&& !((IManaStoringItem)s.getItem()).isManaFull(s))
.findFirst()
@@ -845,7 +845,7 @@ public class ItemArtefact extends Item {
.findFirst().orElse(null);
if(item == null) return; // The player didn't have a wand with resurrection on it
if(!WizardryUtilities.getHotbar(event.getEntityPlayer()).contains(ItemStack.EMPTY)) return; // No space on hotbar
if(!InventoryUtils.getHotbar(event.getEntityPlayer()).contains(ItemStack.EMPTY)) return; // No space on hotbar
event.getDrops().remove(item);
// At this point the player probably has nothing in their hand, but if not just find a free space somewhere