From 238b9d04bb2593e022c032d8c765ece39ad12637 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Sat, 13 Jun 2020 23:29:01 +0100 Subject: [PATCH] Split up and reorganise WizardryUtilities --- .../wizardry/WizardryEventHandler.java | 4 +- .../wizardry/block/BlockReceptacle.java | 4 +- .../wizardry/block/BlockStatue.java | 14 +- .../block/BlockTransportationStone.java | 4 +- .../wizardry/client/DrawingUtils.java | 21 +- .../client/animation/ActionAnimation.java | 18 +- .../client/animation/PlayerAnimator.java | 7 +- .../wizardry/client/audio/SoundLoopSpell.java | 4 +- .../client/gui/GuiButtonResurrect.java | 6 +- .../wizardry/client/gui/GuiLectern.java | 6 +- .../client/gui/handbook/Contents.java | 4 +- .../wizardry/client/gui/handbook/Section.java | 4 +- .../particle/ParticleBlockHighlight.java | 4 +- .../client/particle/ParticleWizardry.java | 4 +- .../effect/RenderContainmentField.java | 4 +- .../renderer/effect/RenderShadowWard.java | 6 +- .../client/renderer/effect/RenderShield.java | 6 +- .../client/renderer/effect/RenderWings.java | 4 +- .../renderer/entity/RenderBlackHole.java | 4 +- .../client/renderer/entity/RenderBubble.java | 7 +- .../client/renderer/entity/RenderDecay.java | 4 +- .../renderer/entity/RenderFireRing.java | 4 +- .../client/renderer/entity/RenderSigil.java | 4 +- .../renderer/entity/RenderZombieSpawner.java | 9 +- .../overlay/RenderTargetPointers.java | 4 +- .../overlay/RenderTransportationUI.java | 4 +- .../renderer/tileentity/RenderArcaneLock.java | 4 +- .../renderer/tileentity/RenderMagicLight.java | 4 +- .../wizardry/command/CommandSetAlly.java | 4 +- .../wizardry/command/CommandViewAllies.java | 4 +- .../entity/EntityLevitatingBlock.java | 7 +- .../wizardry/entity/EntityMeteor.java | 4 +- .../entity/construct/EntityBlackHole.java | 13 +- .../entity/construct/EntityBlizzard.java | 8 +- .../entity/construct/EntityBubble.java | 26 +- .../construct/EntityCombustionRune.java | 6 +- .../entity/construct/EntityDecay.java | 4 +- .../entity/construct/EntityEarthquake.java | 7 +- .../entity/construct/EntityFireRing.java | 4 +- .../entity/construct/EntityFireSigil.java | 4 +- .../entity/construct/EntityForcefield.java | 22 +- .../entity/construct/EntityFrostSigil.java | 6 +- .../entity/construct/EntityHammer.java | 12 +- .../entity/construct/EntityHealAura.java | 4 +- .../entity/construct/EntityIceSpike.java | 6 +- .../construct/EntityLightningSigil.java | 6 +- .../construct/EntityMagicConstruct.java | 4 +- .../entity/construct/EntityStormcloud.java | 4 +- .../entity/construct/EntityTornado.java | 10 +- .../entity/construct/EntityZombieSpawner.java | 4 +- .../entity/living/EntityEvilWizard.java | 2 +- .../wizardry/entity/living/EntityPhoenix.java | 4 +- .../entity/living/EntitySkeletonMinion.java | 4 +- .../entity/living/EntitySpiderMinion.java | 4 +- .../entity/living/EntitySpiritHorse.java | 4 +- .../living/EntityWitherSkeletonMinion.java | 4 +- .../wizardry/entity/living/EntityWizard.java | 8 +- .../wizardry/entity/living/ISpellCaster.java | 4 +- .../entity/living/ISummonedCreature.java | 4 +- .../entity/projectile/EntityFirebomb.java | 4 +- .../entity/projectile/EntityForceArrow.java | 4 +- .../entity/projectile/EntityForceOrb.java | 4 +- .../entity/projectile/EntityIceCharge.java | 10 +- .../entity/projectile/EntityIceball.java | 8 +- .../projectile/EntityLargeMagicFireball.java | 4 +- .../entity/projectile/EntityMagicArrow.java | 7 +- .../projectile/EntityMagicFireball.java | 4 +- .../entity/projectile/EntityPoisonBomb.java | 4 +- .../entity/projectile/EntitySmokeBomb.java | 4 +- .../entity/projectile/EntitySparkBomb.java | 4 +- .../integration/DamageSafetyChecker.java | 10 +- .../inventory/ContainerArcaneWorkbench.java | 6 +- .../wizardry/item/ISpellCastingItem.java | 3 +- .../wizardry/item/ItemArtefact.java | 50 +- .../wizardry/item/ItemFlamingAxe.java | 4 +- .../wizardry/item/ItemFrostAxe.java | 4 +- .../item/ItemIdentificationScroll.java | 4 +- .../wizardry/item/ItemLightningHammer.java | 12 +- .../wizardry/item/ItemManaFlask.java | 9 +- .../wizardry/item/ItemSpectralSword.java | 4 +- .../electroblob/wizardry/item/ItemWand.java | 2 +- .../wizardry/item/ItemWizardArmour.java | 6 +- .../electroblob/wizardry/misc/Forfeit.java | 37 +- .../wizardry/misc/WildcardTradeList.java | 8 +- .../wizardry/packet/PacketControlInput.java | 6 +- .../wizardry/potion/PotionContainment.java | 7 +- .../wizardry/potion/PotionFrostStep.java | 6 +- .../wizardry/potion/PotionSlowTime.java | 10 +- .../registry/WizardryEnchantments.java | 8 +- .../java/electroblob/wizardry/spell/Arc.java | 7 +- .../wizardry/spell/ArcaneJammer.java | 4 +- .../wizardry/spell/ArcaneLock.java | 9 +- .../electroblob/wizardry/spell/Banish.java | 4 +- .../electroblob/wizardry/spell/Blink.java | 4 +- .../electroblob/wizardry/spell/Bubble.java | 7 +- .../wizardry/spell/ChainLightning.java | 10 +- .../electroblob/wizardry/spell/Charge.java | 7 +- .../electroblob/wizardry/spell/Cobwebs.java | 4 +- .../wizardry/spell/ConjureArmour.java | 6 +- .../wizardry/spell/ConjureBlock.java | 4 +- .../wizardry/spell/Containment.java | 4 +- .../wizardry/spell/CurseOfEnfeeblement.java | 7 +- .../wizardry/spell/CurseOfSoulbinding.java | 4 +- .../wizardry/spell/CurseOfUndeath.java | 4 +- .../electroblob/wizardry/spell/Decay.java | 4 +- .../electroblob/wizardry/spell/Decoy.java | 4 +- .../electroblob/wizardry/spell/Detonate.java | 4 +- .../wizardry/spell/Disintegration.java | 9 +- .../wizardry/spell/Divination.java | 7 +- .../wizardry/spell/Earthquake.java | 7 +- .../wizardry/spell/EmpoweringPresence.java | 7 +- .../wizardry/spell/Entrapment.java | 7 +- .../wizardry/spell/FireBreath.java | 9 +- .../electroblob/wizardry/spell/FlameRay.java | 7 +- .../wizardry/spell/FlamingWeapon.java | 4 +- .../wizardry/spell/FontOfMana.java | 7 +- .../wizardry/spell/ForestOfThorns.java | 4 +- .../wizardry/spell/ForestsCurse.java | 7 +- .../electroblob/wizardry/spell/Freeze.java | 14 +- .../wizardry/spell/FreezingWeapon.java | 4 +- .../electroblob/wizardry/spell/FrostRay.java | 9 +- .../electroblob/wizardry/spell/Grapple.java | 7 +- .../wizardry/spell/GreaterTelekinesis.java | 8 +- .../electroblob/wizardry/spell/GroupHeal.java | 7 +- .../wizardry/spell/GrowthAura.java | 4 +- .../electroblob/wizardry/spell/HealAlly.java | 4 +- .../electroblob/wizardry/spell/IceAge.java | 14 +- .../electroblob/wizardry/spell/IceSpikes.java | 11 +- .../electroblob/wizardry/spell/Ignite.java | 4 +- .../wizardry/spell/ImbueWeapon.java | 4 +- .../wizardry/spell/Intimidate.java | 6 +- .../wizardry/spell/InvigoratingPresence.java | 7 +- .../electroblob/wizardry/spell/LifeDrain.java | 9 +- .../wizardry/spell/LightningPulse.java | 4 +- .../wizardry/spell/LightningRay.java | 9 +- .../wizardry/spell/LightningWeb.java | 12 +- .../wizardry/spell/Metamorphosis.java | 7 +- .../electroblob/wizardry/spell/Meteor.java | 4 +- .../wizardry/spell/MindControl.java | 13 +- .../electroblob/wizardry/spell/MindTrick.java | 4 +- .../java/electroblob/wizardry/spell/Mine.java | 12 +- .../electroblob/wizardry/spell/Paralysis.java | 9 +- .../electroblob/wizardry/spell/PhaseStep.java | 4 +- .../wizardry/spell/PlagueOfDarkness.java | 4 +- .../wizardry/spell/PocketFurnace.java | 4 +- .../electroblob/wizardry/spell/Poison.java | 7 +- .../wizardry/spell/Possession.java | 11 +- .../wizardry/spell/RayOfPurification.java | 9 +- .../wizardry/spell/ShadowWard.java | 7 +- .../electroblob/wizardry/spell/Shockwave.java | 4 +- .../wizardry/spell/ShulkerBullet.java | 4 +- .../electroblob/wizardry/spell/Slime.java | 4 +- .../electroblob/wizardry/spell/Snare.java | 4 +- .../wizardry/spell/SpectralPathway.java | 8 +- .../electroblob/wizardry/spell/SpeedTime.java | 4 +- .../wizardry/spell/SpellAreaEffect.java | 4 +- .../wizardry/spell/SpellArrow.java | 4 +- .../wizardry/spell/SpellConjuration.java | 4 +- .../wizardry/spell/SpellConstruct.java | 4 +- .../wizardry/spell/SpellConstructRanged.java | 4 +- .../wizardry/spell/SpellMinion.java | 10 +- .../wizardry/spell/SpellProjectile.java | 4 +- .../electroblob/wizardry/spell/SpellRay.java | 6 +- .../wizardry/spell/SpellThrowable.java | 4 +- .../wizardry/spell/SummonIronGolem.java | 4 +- .../wizardry/spell/SummonSnowGolem.java | 4 +- .../wizardry/spell/SummonSpiritHorse.java | 12 +- .../wizardry/spell/SummonSpiritWolf.java | 12 +- .../wizardry/spell/Thunderstorm.java | 6 +- .../wizardry/spell/Transportation.java | 9 +- .../wizardry/spell/WallOfFrost.java | 12 +- .../electroblob/wizardry/spell/Wither.java | 7 +- .../wizardry/spell/ZombieApocalypse.java | 7 +- .../tileentity/TileEntityPlayerSave.java | 4 +- .../tileentity/TileEntityShrineCore.java | 10 +- .../wizardry/tileentity/TileEntityStatue.java | 4 +- .../wizardry/util/AllyDesignationSystem.java | 6 +- .../electroblob/wizardry/util/BlockUtils.java | 474 ++++++++ .../wizardry/util/EntityUtils.java | 353 ++++++ .../wizardry/util/GeometryUtils.java | 131 ++ .../wizardry/util/IElementalDamage.java | 2 +- .../wizardry/util/InventoryUtils.java | 145 +++ .../electroblob/wizardry/util/JavaUtils.java | 47 + .../electroblob/wizardry/util/NBTExtras.java | 2 +- .../electroblob/wizardry/util/RayTracer.java | 4 +- .../wizardry/util/WizardryUtilities.java | 1066 ----------------- .../worldgen/WoodTypeTemplateProcessor.java | 10 +- .../worldgen/WorldGenSurfaceStructure.java | 12 +- .../worldgen/WorldGenWizardTower.java | 4 +- 189 files changed, 1724 insertions(+), 1731 deletions(-) create mode 100644 src/main/java/electroblob/wizardry/util/BlockUtils.java create mode 100644 src/main/java/electroblob/wizardry/util/EntityUtils.java create mode 100644 src/main/java/electroblob/wizardry/util/GeometryUtils.java create mode 100644 src/main/java/electroblob/wizardry/util/InventoryUtils.java create mode 100644 src/main/java/electroblob/wizardry/util/JavaUtils.java delete mode 100644 src/main/java/electroblob/wizardry/util/WizardryUtilities.java diff --git a/src/main/java/electroblob/wizardry/WizardryEventHandler.java b/src/main/java/electroblob/wizardry/WizardryEventHandler.java index bdac3b8b..16d2b394 100644 --- a/src/main/java/electroblob/wizardry/WizardryEventHandler.java +++ b/src/main/java/electroblob/wizardry/WizardryEventHandler.java @@ -173,7 +173,7 @@ public final class WizardryEventHandler { && Wizardry.settings.discoveryMode){ // Sound and text only happen server-side, in survival, with discovery mode on, and only when // the spell wasn't cast using commands. - WizardryUtilities.playSoundAtPlayer(player, WizardrySounds.MISC_DISCOVER_SPELL, 1.25f, 1); + EntityUtils.playSoundAtPlayer(player, WizardrySounds.MISC_DISCOVER_SPELL, 1.25f, 1); player.sendMessage(new TextComponentTranslation("spell.discover", event.getSpell().getNameForTranslationFormatted())); } @@ -389,7 +389,7 @@ public final class WizardryEventHandler { } } - for(ItemStack stack : WizardryUtilities.getPrioritisedHotbarAndOffhand(player)){ + for(ItemStack stack : InventoryUtils.getPrioritisedHotbarAndOffhand(player)){ if(stack.getItem() instanceof IManaStoringItem && !((IManaStoringItem)stack.getItem()).isManaFull(stack) && WandHelper.getUpgradeLevel(stack, WizardryItems.siphon_upgrade) > 0){ diff --git a/src/main/java/electroblob/wizardry/block/BlockReceptacle.java b/src/main/java/electroblob/wizardry/block/BlockReceptacle.java index 7f4dc2f0..d57faa5d 100644 --- a/src/main/java/electroblob/wizardry/block/BlockReceptacle.java +++ b/src/main/java/electroblob/wizardry/block/BlockReceptacle.java @@ -7,8 +7,8 @@ import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.registry.WizardryTabs; import electroblob.wizardry.tileentity.TileEntityReceptacle; +import electroblob.wizardry.util.GeometryUtils; import electroblob.wizardry.util.ParticleBuilder; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.block.BlockTorch; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.SoundType; @@ -178,7 +178,7 @@ public class BlockReceptacle extends BlockTorch implements ITileEntityProvider { EnumFacing facing = state.getValue(FACING).getOpposite(); - Vec3d centre = WizardryUtilities.getCentre(pos); + Vec3d centre = GeometryUtils.getCentre(pos); if(facing.getAxis().isHorizontal()){ centre = centre.add(new Vec3d(facing.getDirectionVec()).scale(WALL_PARTICLE_OFFSET)).add(0, 0.125, 0); } diff --git a/src/main/java/electroblob/wizardry/block/BlockStatue.java b/src/main/java/electroblob/wizardry/block/BlockStatue.java index cf5b7dee..3733715a 100644 --- a/src/main/java/electroblob/wizardry/block/BlockStatue.java +++ b/src/main/java/electroblob/wizardry/block/BlockStatue.java @@ -1,7 +1,7 @@ package electroblob.wizardry.block; import electroblob.wizardry.tileentity.TileEntityStatue; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.BlockUtils; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.SoundType; @@ -197,7 +197,7 @@ public class BlockStatue extends Block implements ITileEntityProvider { entity.extinguish(); // Short mobs such as spiders and pigs - if((entity.height < 1.2 || entity.isChild()) && WizardryUtilities.canBlockBeReplaced(world, pos)){ + if((entity.height < 1.2 || entity.isChild()) && BlockUtils.canBlockBeReplaced(world, pos)){ world.setBlockState(pos, this.getDefaultState()); if(world.getTileEntity(pos) instanceof TileEntityStatue){ @@ -210,8 +210,8 @@ public class BlockStatue extends Block implements ITileEntityProvider { return true; } // Normal sized mobs like zombies and skeletons - else if(entity.height < 2.5 && WizardryUtilities.canBlockBeReplaced(world, pos) - && WizardryUtilities.canBlockBeReplaced(world, pos.up())){ + else if(entity.height < 2.5 && BlockUtils.canBlockBeReplaced(world, pos) + && BlockUtils.canBlockBeReplaced(world, pos.up())){ world.setBlockState(pos, this.getDefaultState()); if(world.getTileEntity(pos) instanceof TileEntityStatue){ @@ -229,9 +229,9 @@ public class BlockStatue extends Block implements ITileEntityProvider { return true; } // Tall mobs like endermen - else if(WizardryUtilities.canBlockBeReplaced(world, pos) - && WizardryUtilities.canBlockBeReplaced(world, pos.up()) - && WizardryUtilities.canBlockBeReplaced(world, pos.up(2))){ + else if(BlockUtils.canBlockBeReplaced(world, pos) + && BlockUtils.canBlockBeReplaced(world, pos.up()) + && BlockUtils.canBlockBeReplaced(world, pos.up(2))){ world.setBlockState(pos, this.getDefaultState()); if(world.getTileEntity(pos) instanceof TileEntityStatue){ diff --git a/src/main/java/electroblob/wizardry/block/BlockTransportationStone.java b/src/main/java/electroblob/wizardry/block/BlockTransportationStone.java index 163f043e..cb9d7c88 100644 --- a/src/main/java/electroblob/wizardry/block/BlockTransportationStone.java +++ b/src/main/java/electroblob/wizardry/block/BlockTransportationStone.java @@ -8,9 +8,9 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.spell.Transportation; +import electroblob.wizardry.util.GeometryUtils; import electroblob.wizardry.util.Location; import electroblob.wizardry.util.ParticleBuilder; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -162,7 +162,7 @@ public class BlockTransportationStone extends Block { for(int z = -1; z <= 1; z++){ if(x == 0 && z == 0) continue; ParticleBuilder.create(ParticleBuilder.Type.PATH) - .pos(WizardryUtilities.getCentre(centre).add(x, -0.3125, z)).clr(0x86ff65) + .pos(GeometryUtils.getCentre(centre).add(x, -0.3125, z)).clr(0x86ff65) .time(200).scale(2).spawn(world); } } diff --git a/src/main/java/electroblob/wizardry/client/DrawingUtils.java b/src/main/java/electroblob/wizardry/client/DrawingUtils.java index 9a63c4da..d4cb332f 100644 --- a/src/main/java/electroblob/wizardry/client/DrawingUtils.java +++ b/src/main/java/electroblob/wizardry/client/DrawingUtils.java @@ -12,8 +12,7 @@ import org.lwjgl.opengl.GL11; import java.util.Random; /** - * Utility class containing some useful static methods for drawing GUIs. Previously these were spread across the main - * {@code WizardryUtilities} class and various individual GUI classes. + * Utility class containing some useful static methods for drawing GUIs, as well as general rendering. * * @author Electroblob * @since Wizardry 4.2 @@ -269,4 +268,22 @@ public final class DrawingUtils { RenderHelper.enableStandardItemLighting(); } + /** + * Calculates a factor between 0 and 1 that results in a smooth, aesthetically-pleasing animation when used to scale + * things. Mainly for rendering, but can be used anywhere since it's just a mathematical formula. + * @param lifetime The lifetime of the thing being animated, in ticks (if this is negative, disappearing is ignored) + * @param ticksExisted The current age of the thing being animated, in ticks + * @param partialTicks The current partial tick time + * @param startLength The length of the appearing animation, in ticks + * @param endLength The length of the disappearing animation, in ticks + * @return A fraction between 0 and 1, with the value at the very start and end being 0 and the constant middle + * section having a value of 1. + */ + public static float smoothScaleFactor(int lifetime, int ticksExisted, float partialTicks, int startLength, int endLength){ + float age = ticksExisted + partialTicks; + float s = MathHelper.clamp(age < startLength || lifetime < 0 ? age/startLength : (lifetime - age) / endLength, 0, 1); + s = (float)Math.pow(s, 0.4); // Smooths the animation + return s; + } + } diff --git a/src/main/java/electroblob/wizardry/client/animation/ActionAnimation.java b/src/main/java/electroblob/wizardry/client/animation/ActionAnimation.java index e4ef4d70..6c5b94c6 100644 --- a/src/main/java/electroblob/wizardry/client/animation/ActionAnimation.java +++ b/src/main/java/electroblob/wizardry/client/animation/ActionAnimation.java @@ -3,7 +3,7 @@ package electroblob.wizardry.client.animation; import electroblob.wizardry.data.WizardData; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.spell.Grapple; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.InventoryUtils; import net.minecraft.client.model.ModelBiped; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -43,7 +43,7 @@ public abstract class ActionAnimation extends Animation { // Something (probably some sort of race condition) causes getActiveItemStack to sometimes be wrong if(player.getActiveItemStack() != player.getHeldItem(player.getActiveHand())) return; - EnumHandSide side = WizardryUtilities.getSideForHand(player, player.getActiveHand()); + EnumHandSide side = InventoryUtils.getSideForHand(player, player.getActiveHand()); float pitch = (float)Math.toRadians(player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks); float yaw = (float)Math.toRadians(player.prevRotationYawHead + (player.rotationYawHead - player.prevRotationYawHead) * partialTicks) @@ -61,7 +61,7 @@ public abstract class ActionAnimation extends Animation { @Override public void setRotationAngles(EntityPlayer player, ModelBiped model, float partialTicks, boolean firstPerson){ if(player.getActiveItemStack() != player.getHeldItem(player.getActiveHand())) return; - EnumHandSide side = WizardryUtilities.getSideForHand(player, player.getActiveHand()); + EnumHandSide side = InventoryUtils.getSideForHand(player, player.getActiveHand()); ModelRendererExtended arm = (ModelRendererExtended)getArmForSide(model, side); arm.addRotation(-2.2f, side == EnumHandSide.RIGHT ? 0.2f : -0.2f, 0); } @@ -72,7 +72,7 @@ public abstract class ActionAnimation extends Animation { public void setRotationAngles(EntityPlayer player, ModelBiped model, float partialTicks, boolean firstPerson){ float tick = player.getItemInUseMaxCount() + partialTicks; // It's not the "max" use count at all! float y = Math.min(0.4f + tick * 0.05f, 0.7f); - EnumHandSide side = WizardryUtilities.getSideForHand(player, player.getActiveHand()); + EnumHandSide side = InventoryUtils.getSideForHand(player, player.getActiveHand()); ModelRendererExtended arm = (ModelRendererExtended)getArmForSide(model, side); arm.addRotation(-0.2f, side == EnumHandSide.RIGHT ? y : -y, 0); } @@ -103,7 +103,7 @@ public abstract class ActionAnimation extends Animation { target = new Vec3d(hit.entityHit.posX, hit.entityHit.getEntityBoundingBox().minY + hit.entityHit.height/2, hit.entityHit.posZ); } - EnumHandSide side = WizardryUtilities.getSideForHand(player, player.getActiveHand()); + EnumHandSide side = InventoryUtils.getSideForHand(player, player.getActiveHand()); ModelRendererExtended arm = (ModelRendererExtended)getArmForSide(model, side); @@ -125,10 +125,10 @@ public abstract class ActionAnimation extends Animation { public void setRotationAngles(EntityPlayer player, ModelBiped model, float partialTicks, boolean firstPerson){ float tick = player.getItemInUseMaxCount() + partialTicks; // It's not the "max" use count at all! float z = Math.max(1.5f - tick * 0.1f, 0.8f); - EnumHandSide side = WizardryUtilities.getSideForHand(player, player.getActiveHand()); + EnumHandSide side = InventoryUtils.getSideForHand(player, player.getActiveHand()); ModelRendererExtended arm = (ModelRendererExtended)getArmForSide(model, side); arm.addRotation(-1.2f, side == EnumHandSide.RIGHT ? -0.2f : 0.2f, side == EnumHandSide.RIGHT ? z : -z); - if(!player.getHeldItem(WizardryUtilities.getHandForSide(player, side.opposite())).isEmpty()){ + if(!player.getHeldItem(InventoryUtils.getHandForSide(player, side.opposite())).isEmpty()){ ((ModelRendererExtended)getArmForSide(model, side.opposite())).addRotation(-0.8f, side == EnumHandSide.LEFT ? 0.3f : -0.3f, 0); } } @@ -138,11 +138,11 @@ public abstract class ActionAnimation extends Animation { @Override public void setRotationAngles(EntityPlayer player, ModelBiped model, float partialTicks, boolean firstPerson){ if(player.getActiveItemStack() != player.getHeldItem(player.getActiveHand())) return; - EnumHandSide side = WizardryUtilities.getSideForHand(player, player.getActiveHand()); + EnumHandSide side = InventoryUtils.getSideForHand(player, player.getActiveHand()); ModelRendererExtended arm = (ModelRendererExtended)getArmForSide(model, side); float y = side == EnumHandSide.RIGHT ? -0.6f : 0.6f; arm.addRotation(-1.2f, y, 0); - if(player.getHeldItem(WizardryUtilities.getHandForSide(player, side.opposite())).isEmpty()){ + if(player.getHeldItem(InventoryUtils.getHandForSide(player, side.opposite())).isEmpty()){ ModelRendererExtended otherArm = (ModelRendererExtended)getArmForSide(model, side.opposite()); otherArm.setRotation(arm.rotateAngleX - 1.2f, -arm.rotateAngleY - y, otherArm.rotateAngleZ); } diff --git a/src/main/java/electroblob/wizardry/client/animation/PlayerAnimator.java b/src/main/java/electroblob/wizardry/client/animation/PlayerAnimator.java index 449fa650..217d96eb 100644 --- a/src/main/java/electroblob/wizardry/client/animation/PlayerAnimator.java +++ b/src/main/java/electroblob/wizardry/client/animation/PlayerAnimator.java @@ -2,7 +2,8 @@ package electroblob.wizardry.client.animation; import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.SpellActions; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.InventoryUtils; +import electroblob.wizardry.util.JavaUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.model.ModelBiped; @@ -93,7 +94,7 @@ public class PlayerAnimator { for(LayerRenderer layer : layers){ - for(Field field : WizardryUtilities.getAllFields(layer.getClass())){ + for(Field field : JavaUtils.getAllFields(layer.getClass())){ field.setAccessible(true); @@ -123,7 +124,7 @@ public class PlayerAnimator { // This needs to be lazy-loaded because we need access to an actual item for(LayerRenderer layer : playerLayers.get(renderer)){ if(layer instanceof LayerBipedArmor){ - for(EntityEquipmentSlot slot : WizardryUtilities.ARMOUR_SLOTS){ + for(EntityEquipmentSlot slot : InventoryUtils.ARMOUR_SLOTS){ ItemStack armour = player.getItemStackFromSlot(slot); ModelBiped model = ForgeHooksClient.getArmorModel(player, armour, slot, ((LayerBipedArmor)layer).getModelFromSlot(slot)); diff --git a/src/main/java/electroblob/wizardry/client/audio/SoundLoopSpell.java b/src/main/java/electroblob/wizardry/client/audio/SoundLoopSpell.java index bb4d9b44..7937c86f 100644 --- a/src/main/java/electroblob/wizardry/client/audio/SoundLoopSpell.java +++ b/src/main/java/electroblob/wizardry/client/audio/SoundLoopSpell.java @@ -3,7 +3,7 @@ package electroblob.wizardry.client.audio; import electroblob.wizardry.data.DispenserCastingData; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.client.audio.PositionedSound; import net.minecraft.entity.EntityLivingBase; import net.minecraft.tileentity.TileEntity; @@ -49,7 +49,7 @@ public abstract class SoundLoopSpell extends SoundLoop { @Override protected boolean stillCasting(Spell spell){ - return WizardryUtilities.isCasting(source, spell); + return EntityUtils.isCasting(source, spell); } } diff --git a/src/main/java/electroblob/wizardry/client/gui/GuiButtonResurrect.java b/src/main/java/electroblob/wizardry/client/gui/GuiButtonResurrect.java index bf50192c..e9ad09d3 100644 --- a/src/main/java/electroblob/wizardry/client/gui/GuiButtonResurrect.java +++ b/src/main/java/electroblob/wizardry/client/gui/GuiButtonResurrect.java @@ -7,8 +7,8 @@ import electroblob.wizardry.packet.WizardryPacketHandler; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.spell.Resurrection; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiGameOver; @@ -52,7 +52,7 @@ public class GuiButtonResurrect extends GuiButton { public static void onGuiScreenInitEvent(GuiScreenEvent.InitGuiEvent event){ if(event.getGui() instanceof GuiGameOver && ItemArtefact.isArtefactActive(Minecraft.getMinecraft().player, WizardryItems.amulet_resurrection) - && WizardryUtilities.getHotbar(Minecraft.getMinecraft().player).stream().anyMatch(s -> Resurrection.canStackResurrect(s, Minecraft.getMinecraft().player))){ + && InventoryUtils.getHotbar(Minecraft.getMinecraft().player).stream().anyMatch(s -> Resurrection.canStackResurrect(s, Minecraft.getMinecraft().player))){ event.getButtonList().add(new GuiButtonResurrect(event.getButtonList().size(), event.getGui().width / 2 - 100, event.getGui().height / 4 + 120, "spell." + Spells.resurrection.getRegistryName() + ".button")); @@ -65,7 +65,7 @@ public class GuiButtonResurrect extends GuiButton { if(event.getGui() instanceof GuiGameOver){ - ItemStack stack = WizardryUtilities.getHotbar(Minecraft.getMinecraft().player).stream() + ItemStack stack = InventoryUtils.getHotbar(Minecraft.getMinecraft().player).stream() .filter(s -> Resurrection.canStackResurrect(s, Minecraft.getMinecraft().player)).findFirst().orElse(null); if(stack != null){ diff --git a/src/main/java/electroblob/wizardry/client/gui/GuiLectern.java b/src/main/java/electroblob/wizardry/client/gui/GuiLectern.java index 4a6571f4..3453f471 100644 --- a/src/main/java/electroblob/wizardry/client/gui/GuiLectern.java +++ b/src/main/java/electroblob/wizardry/client/gui/GuiLectern.java @@ -12,9 +12,9 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; import electroblob.wizardry.tileentity.TileEntityLectern; +import electroblob.wizardry.util.GeometryUtils; import electroblob.wizardry.util.ISpellSortable; import electroblob.wizardry.util.ParticleBuilder; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; @@ -278,9 +278,9 @@ public class GuiLectern extends GuiSpellInfo implements ISpellSortable { for(EnumFacing side : EnumFacing.VALUES){ ParticleBuilder.create(ParticleBuilder.Type.BLOCK_HIGHLIGHT).pos( - WizardryUtilities.getFaceCentre(pos, side) + GeometryUtils.getFaceCentre(pos, side) .add(new Vec3d(side.getDirectionVec()) - .scale(WizardryUtilities.ANTI_Z_FIGHTING_OFFSET))) + .scale(GeometryUtils.ANTI_Z_FIGHTING_OFFSET))) .face(side).clr(0.9f, 0.5f, 0.8f).fade(0.7f, 0, 1).spawn(mc.world); } diff --git a/src/main/java/electroblob/wizardry/client/gui/handbook/Contents.java b/src/main/java/electroblob/wizardry/client/gui/handbook/Contents.java index 1853e5a1..a6a762a5 100644 --- a/src/main/java/electroblob/wizardry/client/gui/handbook/Contents.java +++ b/src/main/java/electroblob/wizardry/client/gui/handbook/Contents.java @@ -3,7 +3,7 @@ package electroblob.wizardry.client.gui.handbook; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import electroblob.wizardry.client.DrawingUtils; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.JavaUtils; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.JsonUtils; @@ -50,7 +50,7 @@ class Contents { /** Returns an unmodifiable, flattened collection of all the buttons in this contents. */ Collection getButtons(){ - return WizardryUtilities.flatten(buttons); + return JavaUtils.flatten(buttons); } void addEntry(Section section){ diff --git a/src/main/java/electroblob/wizardry/client/gui/handbook/Section.java b/src/main/java/electroblob/wizardry/client/gui/handbook/Section.java index c057d5e5..5a1a8bd6 100644 --- a/src/main/java/electroblob/wizardry/client/gui/handbook/Section.java +++ b/src/main/java/electroblob/wizardry/client/gui/handbook/Section.java @@ -6,7 +6,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import electroblob.wizardry.Wizardry; import electroblob.wizardry.client.DrawingUtils; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.JavaUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; @@ -63,7 +63,7 @@ class Section { } Collection getButtons(){ - return WizardryUtilities.flatten(buttons); + return JavaUtils.flatten(buttons); } /** diff --git a/src/main/java/electroblob/wizardry/client/particle/ParticleBlockHighlight.java b/src/main/java/electroblob/wizardry/client/particle/ParticleBlockHighlight.java index e1674398..c083590b 100644 --- a/src/main/java/electroblob/wizardry/client/particle/ParticleBlockHighlight.java +++ b/src/main/java/electroblob/wizardry/client/particle/ParticleBlockHighlight.java @@ -1,7 +1,7 @@ package electroblob.wizardry.client.particle; import electroblob.wizardry.Wizardry; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.GeometryUtils; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; @@ -24,7 +24,7 @@ public class ParticleBlockHighlight extends ParticleWizardry { this.particleGravity = 0; this.setMaxAge(160); // 5 makes it the exact size of a block face, plus a little bit to account for the anti-z-fighting offset - this.particleScale = 5 * (1 + 2 * (float)WizardryUtilities.ANTI_Z_FIGHTING_OFFSET); + this.particleScale = 5 * (1 + 2 * (float)GeometryUtils.ANTI_Z_FIGHTING_OFFSET); this.shaded = false; } diff --git a/src/main/java/electroblob/wizardry/client/particle/ParticleWizardry.java b/src/main/java/electroblob/wizardry/client/particle/ParticleWizardry.java index 8c365b63..4d65ddcd 100644 --- a/src/main/java/electroblob/wizardry/client/particle/ParticleWizardry.java +++ b/src/main/java/electroblob/wizardry/client/particle/ParticleWizardry.java @@ -3,7 +3,7 @@ package electroblob.wizardry.client.particle; import electroblob.wizardry.Wizardry; import electroblob.wizardry.client.ClientProxy; import electroblob.wizardry.entity.ICustomHitbox; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.particle.Particle; import net.minecraft.client.renderer.BufferBuilder; @@ -467,7 +467,7 @@ public abstract class ParticleWizardry extends Particle { double searchRadius = 20; - List nearbyEntities = WizardryUtilities.getEntitiesWithinRadius(searchRadius, this.posX, + List nearbyEntities = EntityUtils.getEntitiesWithinRadius(searchRadius, this.posX, this.posY, this.posZ, world, Entity.class); nearbyEntities.removeIf(e -> !(e instanceof ICustomHitbox && ((ICustomHitbox)e).contains(new Vec3d(this.posX, this.posY, this.posZ)))); diff --git a/src/main/java/electroblob/wizardry/client/renderer/effect/RenderContainmentField.java b/src/main/java/electroblob/wizardry/client/renderer/effect/RenderContainmentField.java index a4fc5cf3..e0cdb632 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/effect/RenderContainmentField.java +++ b/src/main/java/electroblob/wizardry/client/renderer/effect/RenderContainmentField.java @@ -3,7 +3,7 @@ package electroblob.wizardry.client.renderer.effect; import electroblob.wizardry.Wizardry; import electroblob.wizardry.potion.PotionContainment; import electroblob.wizardry.registry.WizardryPotions; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.GeometryUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -42,7 +42,7 @@ public class RenderContainmentField { if(player.isPotionActive(WizardryPotions.containment)){ - Vec3d centre = WizardryUtilities.getCentre(NBTUtil.getPosFromTag(player.getEntityData().getCompoundTag(PotionContainment.ENTITY_TAG))); + Vec3d centre = GeometryUtils.getCentre(NBTUtil.getPosFromTag(player.getEntityData().getCompoundTag(PotionContainment.ENTITY_TAG))); float r = PotionContainment.getContainmentDistance(player.getActivePotionEffect(WizardryPotions.containment).getAmplifier()); GlStateManager.pushMatrix(); diff --git a/src/main/java/electroblob/wizardry/client/renderer/effect/RenderShadowWard.java b/src/main/java/electroblob/wizardry/client/renderer/effect/RenderShadowWard.java index 55f3f375..ce18d69c 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/effect/RenderShadowWard.java +++ b/src/main/java/electroblob/wizardry/client/renderer/effect/RenderShadowWard.java @@ -2,7 +2,7 @@ package electroblob.wizardry.client.renderer.effect; import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.Spells; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -32,7 +32,7 @@ public class RenderShadowWard { EntityPlayer player = Minecraft.getMinecraft().player; - if(WizardryUtilities.isCasting(player, Spells.shadow_ward)){ + if(EntityUtils.isCasting(player, Spells.shadow_ward)){ GlStateManager.pushMatrix(); @@ -94,7 +94,7 @@ public class RenderShadowWard { EntityPlayer player = event.getEntityPlayer(); - if(WizardryUtilities.isCasting(player, Spells.shadow_ward)){ + if(EntityUtils.isCasting(player, Spells.shadow_ward)){ GlStateManager.pushMatrix(); diff --git a/src/main/java/electroblob/wizardry/client/renderer/effect/RenderShield.java b/src/main/java/electroblob/wizardry/client/renderer/effect/RenderShield.java index b7024161..99e32caf 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/effect/RenderShield.java +++ b/src/main/java/electroblob/wizardry/client/renderer/effect/RenderShield.java @@ -4,7 +4,7 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.data.WizardData; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.spell.Shield; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -34,7 +34,7 @@ public class RenderShield { EntityPlayer player = Minecraft.getMinecraft().player; - if(WizardData.get(player).getVariable(Shield.SHIELD_KEY) != null && WizardryUtilities.isCasting(player, Spells.shield)){ + if(WizardData.get(player).getVariable(Shield.SHIELD_KEY) != null && EntityUtils.isCasting(player, Spells.shield)){ GlStateManager.pushMatrix(); @@ -76,7 +76,7 @@ public class RenderShield { EntityPlayer player = event.getEntityPlayer(); - if(WizardData.get(player).getVariable(Shield.SHIELD_KEY) != null && WizardryUtilities.isCasting(player, Spells.shield)){ + if(WizardData.get(player).getVariable(Shield.SHIELD_KEY) != null && EntityUtils.isCasting(player, Spells.shield)){ GlStateManager.pushMatrix(); diff --git a/src/main/java/electroblob/wizardry/client/renderer/effect/RenderWings.java b/src/main/java/electroblob/wizardry/client/renderer/effect/RenderWings.java index c8da9c3a..15493577 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/effect/RenderWings.java +++ b/src/main/java/electroblob/wizardry/client/renderer/effect/RenderWings.java @@ -2,7 +2,7 @@ package electroblob.wizardry.client.renderer.effect; import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.Spells; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -32,7 +32,7 @@ public class RenderWings { EntityPlayer player = event.getEntityPlayer(); - if(WizardryUtilities.isCasting(player, Spells.flight)){ + if(EntityUtils.isCasting(player, Spells.flight)){ GlStateManager.pushMatrix(); diff --git a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderBlackHole.java b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderBlackHole.java index d103886d..d1339090 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderBlackHole.java +++ b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderBlackHole.java @@ -1,9 +1,9 @@ package electroblob.wizardry.client.renderer.entity; import electroblob.wizardry.Wizardry; +import electroblob.wizardry.client.DrawingUtils; import electroblob.wizardry.client.renderer.RayHelper; import electroblob.wizardry.entity.construct.EntityBlackHole; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.entity.Render; @@ -50,7 +50,7 @@ public class RenderBlackHole extends Render { GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - float s = WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10); + float s = DrawingUtils.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10); GlStateManager.scale(s, s, s); this.bindTexture(RAY_TEXTURE); diff --git a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderBubble.java b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderBubble.java index fb8fa18c..5147a994 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderBubble.java +++ b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderBubble.java @@ -1,8 +1,9 @@ package electroblob.wizardry.client.renderer.entity; import electroblob.wizardry.Wizardry; +import electroblob.wizardry.client.DrawingUtils; import electroblob.wizardry.entity.construct.EntityBubble; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -33,7 +34,7 @@ public class RenderBubble extends Render { float yOffset = 0; - Entity rider = WizardryUtilities.getRider(entity); + Entity rider = EntityUtils.getRider(entity); if(rider != null){ yOffset = rider.height / 2; @@ -66,7 +67,7 @@ public class RenderBubble extends Render { GlStateManager.rotate(yaw, 1.0F, 0.0F, 0.0F); // Bubble 'bursts' so doesn't shrink when is disappears - float s = 3 * WizardryUtilities.smoothScaleFactor(entity.isDarkOrb ? entity.lifetime : -1, entity.ticksExisted, partialTicks, 10, 10); + float s = 3 * DrawingUtils.smoothScaleFactor(entity.isDarkOrb ? entity.lifetime : -1, entity.ticksExisted, partialTicks, 10, 10); GlStateManager.scale(s, s, s); double pixelwidth = (1.0d / 128); diff --git a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderDecay.java b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderDecay.java index 3e79094e..47a9ef21 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderDecay.java +++ b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderDecay.java @@ -1,8 +1,8 @@ package electroblob.wizardry.client.renderer.entity; import electroblob.wizardry.Wizardry; +import electroblob.wizardry.client.DrawingUtils; import electroblob.wizardry.entity.construct.EntityDecay; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; @@ -44,7 +44,7 @@ public class RenderDecay extends Render { GlStateManager.rotate(-90, 1, 0, 0); - float s = 2 * WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 50); + float s = 2 * DrawingUtils.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 50); GlStateManager.scale(s, s, s); Tessellator tessellator = Tessellator.getInstance(); diff --git a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderFireRing.java b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderFireRing.java index be7ef3b8..146722a3 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderFireRing.java +++ b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderFireRing.java @@ -1,7 +1,7 @@ package electroblob.wizardry.client.renderer.entity; +import electroblob.wizardry.client.DrawingUtils; import electroblob.wizardry.entity.construct.EntityFireRing; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -47,7 +47,7 @@ public class RenderFireRing extends Render { GlStateManager.rotate(-90, 1, 0, 0); - float s = WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10); + float s = DrawingUtils.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10); GlStateManager.scale(scale * s, scale * s, scale * s); Tessellator tessellator = Tessellator.getInstance(); diff --git a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderSigil.java b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderSigil.java index 86f5ca97..3e58323f 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderSigil.java +++ b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderSigil.java @@ -1,9 +1,9 @@ package electroblob.wizardry.client.renderer.entity; +import electroblob.wizardry.client.DrawingUtils; import electroblob.wizardry.entity.construct.EntityHealAura; import electroblob.wizardry.entity.construct.EntityMagicConstruct; import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -61,7 +61,7 @@ public class RenderSigil extends Render { // Healing aura rotates slowly if(entity instanceof EntityHealAura) GlStateManager.rotate(entity.ticksExisted / 3.0f, 0, 0, 1); - float s = WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10); + float s = DrawingUtils.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10); GlStateManager.scale(scale * s, scale * s, scale * s); Tessellator tessellator = Tessellator.getInstance(); diff --git a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderZombieSpawner.java b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderZombieSpawner.java index 48fd96d6..28d543ae 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/entity/RenderZombieSpawner.java +++ b/src/main/java/electroblob/wizardry/client/renderer/entity/RenderZombieSpawner.java @@ -1,8 +1,9 @@ package electroblob.wizardry.client.renderer.entity; import electroblob.wizardry.Wizardry; +import electroblob.wizardry.client.DrawingUtils; import electroblob.wizardry.entity.construct.EntityZombieSpawner; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.GeometryUtils; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; @@ -19,7 +20,7 @@ public class RenderZombieSpawner extends Render { private static final ResourceLocation TEXTURE = new ResourceLocation(Wizardry.MODID, "textures/entity/zombie_spawner.png"); - private static final Vec3d[] HIDDEN_BOX = WizardryUtilities.getVertices(new AxisAlignedBB(-1, 0, -1, 1, 2.5, 1)); + private static final Vec3d[] HIDDEN_BOX = GeometryUtils.getVertices(new AxisAlignedBB(-1, 0, -1, 1, 2.5, 1)); public RenderZombieSpawner(RenderManager renderManager){ super(renderManager); @@ -42,14 +43,14 @@ public class RenderZombieSpawner extends Render { // The visible bit GlStateManager.pushMatrix(); - float s = WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10); + float s = DrawingUtils.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10); GlStateManager.scale(s, s, s); GlStateManager.rotate((entity.ticksExisted + partialTicks) * 2, 0, 1, 0); this.bindTexture(TEXTURE); - Vec3d[] vertices = WizardryUtilities.getVertices(entity.getEntityBoundingBox().offset(entity.getPositionVector().scale(-1))); + Vec3d[] vertices = GeometryUtils.getVertices(entity.getEntityBoundingBox().offset(entity.getPositionVector().scale(-1))); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); drawFace(buffer, vertices[0], vertices[1], vertices[3], vertices[2], 0, 0, 1, 1); // Bottom diff --git a/src/main/java/electroblob/wizardry/client/renderer/overlay/RenderTargetPointers.java b/src/main/java/electroblob/wizardry/client/renderer/overlay/RenderTargetPointers.java index cb30fb22..191f236a 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/overlay/RenderTargetPointers.java +++ b/src/main/java/electroblob/wizardry/client/renderer/overlay/RenderTargetPointers.java @@ -3,8 +3,8 @@ package electroblob.wizardry.client.renderer.overlay; import electroblob.wizardry.Wizardry; import electroblob.wizardry.data.WizardData; import electroblob.wizardry.item.ISpellCastingItem; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.RayTracer; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -42,7 +42,7 @@ public class RenderTargetPointers { } // Target selection pointer - if(mc.player.isSneaking() && wand.getItem() instanceof ISpellCastingItem && WizardryUtilities.isLiving(event.getEntity()) + if(mc.player.isSneaking() && wand.getItem() instanceof ISpellCastingItem && EntityUtils.isLiving(event.getEntity()) && data != null && data.selectedMinion != null){ // -> Moved this in here so it isn't called every tick diff --git a/src/main/java/electroblob/wizardry/client/renderer/overlay/RenderTransportationUI.java b/src/main/java/electroblob/wizardry/client/renderer/overlay/RenderTransportationUI.java index 7fae6377..2be2861f 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/overlay/RenderTransportationUI.java +++ b/src/main/java/electroblob/wizardry/client/renderer/overlay/RenderTransportationUI.java @@ -7,8 +7,8 @@ import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.spell.Transportation; +import electroblob.wizardry.util.GeometryUtils; import electroblob.wizardry.util.Location; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.BufferBuilder; @@ -84,7 +84,7 @@ public class RenderTransportationUI { buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); - Vec3d position = WizardryUtilities.getCentre(location.pos).subtract(origin); + Vec3d position = GeometryUtils.getCentre(location.pos).subtract(origin); double distance = position.length(); // The icon lines up perfectly if you render it at actual distance, otherwise view bobbing messes things up // However, if that's outside the render distance it won't render at all! To fudge our way around this diff --git a/src/main/java/electroblob/wizardry/client/renderer/tileentity/RenderArcaneLock.java b/src/main/java/electroblob/wizardry/client/renderer/tileentity/RenderArcaneLock.java index ec03f7ec..e62577cf 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/tileentity/RenderArcaneLock.java +++ b/src/main/java/electroblob/wizardry/client/renderer/tileentity/RenderArcaneLock.java @@ -2,7 +2,7 @@ package electroblob.wizardry.client.renderer.tileentity; import electroblob.wizardry.Wizardry; import electroblob.wizardry.spell.ArcaneLock; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.GeometryUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -74,7 +74,7 @@ public class RenderArcaneLock { buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); } - Vec3d[] vertices = WizardryUtilities.getVertices(world.getBlockState(tileentity.getPos()).getBoundingBox(world, tileentity.getPos()).grow(0.05).offset(tileentity.getPos())); + Vec3d[] vertices = GeometryUtils.getVertices(world.getBlockState(tileentity.getPos()).getBoundingBox(world, tileentity.getPos()).grow(0.05).offset(tileentity.getPos())); drawFace(buffer, vertices[0], vertices[1], vertices[3], vertices[2], 0, 0, 1, 1); // Bottom drawFace(buffer, vertices[6], vertices[7], vertices[2], vertices[3], 0, 0, 1, 1); // South diff --git a/src/main/java/electroblob/wizardry/client/renderer/tileentity/RenderMagicLight.java b/src/main/java/electroblob/wizardry/client/renderer/tileentity/RenderMagicLight.java index 24af8489..55f82d74 100644 --- a/src/main/java/electroblob/wizardry/client/renderer/tileentity/RenderMagicLight.java +++ b/src/main/java/electroblob/wizardry/client/renderer/tileentity/RenderMagicLight.java @@ -2,11 +2,11 @@ package electroblob.wizardry.client.renderer.tileentity; import electroblob.wizardry.Wizardry; import electroblob.wizardry.block.BlockMagicLight; +import electroblob.wizardry.client.DrawingUtils; import electroblob.wizardry.item.ISpellCastingItem; import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.tileentity.TileEntityMagicLight; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; @@ -43,7 +43,7 @@ public class RenderMagicLight extends TileEntitySpecialRenderer((EntityLivingBase)entity); } diff --git a/src/main/java/electroblob/wizardry/entity/EntityMeteor.java b/src/main/java/electroblob/wizardry/entity/EntityMeteor.java index 938e5c16..aa85983f 100644 --- a/src/main/java/electroblob/wizardry/entity/EntityMeteor.java +++ b/src/main/java/electroblob/wizardry/entity/EntityMeteor.java @@ -5,7 +5,7 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Meteor; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.MoverType; import net.minecraft.entity.item.EntityFallingBlock; @@ -76,7 +76,7 @@ public class EntityMeteor extends EntityFallingBlock { this.setDead(); }else{ - WizardryUtilities.getEntitiesWithinRadius(15, posX, posY, posZ, world, EntityPlayer.class) + EntityUtils.getEntitiesWithinRadius(15, posX, posY, posZ, world, EntityPlayer.class) .forEach(p -> Wizardry.proxy.shakeScreen(p, 10)); } } diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityBlackHole.java b/src/main/java/electroblob/wizardry/entity/construct/EntityBlackHole.java index 16059b8a..2e1b3663 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityBlackHole.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityBlackHole.java @@ -5,9 +5,10 @@ import electroblob.wizardry.entity.EntityLevitatingBlock; import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardrySounds; +import electroblob.wizardry.util.BlockUtils; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; @@ -92,12 +93,12 @@ public class EntityBlackHole extends EntityMagicConstruct { double radius = 6; // TODO: Support for spell properties and modifiers - boolean suckInBlocks = getCaster() instanceof EntityPlayer && WizardryUtilities.canDamageBlocks(getCaster(), world) + boolean suckInBlocks = getCaster() instanceof EntityPlayer && EntityUtils.canDamageBlocks(getCaster(), world) && ItemArtefact.isArtefactActive((EntityPlayer)getCaster(), WizardryItems.charm_black_hole); if(suckInBlocks){ - List sphere = WizardryUtilities.getBlockSphere(new BlockPos(this), radius); + List sphere = BlockUtils.getBlockSphere(new BlockPos(this), radius); int blocksUnhooked = 0; @@ -105,7 +106,7 @@ public class EntityBlackHole extends EntityMagicConstruct { if(rand.nextInt(Math.max(1, (int)this.getDistanceSq(pos) * 3)) == 0){ - if(!WizardryUtilities.isBlockUnbreakable(world, pos) && !world.isAirBlock(pos) + if(!BlockUtils.isBlockUnbreakable(world, pos) && !world.isAirBlock(pos) && world.isBlockNormalCube(pos, false)){ // Checks that the block above is not solid, since this causes the falling block to vanish. // && !world.isBlockNormalCube(pos.up(), false)){ @@ -124,7 +125,7 @@ public class EntityBlackHole extends EntityMagicConstruct { } - List targets = WizardryUtilities.getEntitiesWithinRadius(radius, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(radius, this.posX, this.posY, this.posZ, this.world, Entity.class); targets.removeIf(t -> !(t instanceof EntityLivingBase || (suckInBlocks && t instanceof EntityFallingBlock))); @@ -137,7 +138,7 @@ public class EntityBlackHole extends EntityMagicConstruct { if(!(target instanceof EntityPlayer && ((getCaster() instanceof EntityPlayer && !Wizardry.settings.playersMoveEachOther) || ItemArtefact.isArtefactActive((EntityPlayer)target, WizardryItems.amulet_anchoring)))){ - WizardryUtilities.undoGravity(target); + EntityUtils.undoGravity(target); if(target instanceof EntityLevitatingBlock) ((EntityLevitatingBlock)target).suspend(); // Sucks the target in diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityBlizzard.java b/src/main/java/electroblob/wizardry/entity/construct/EntityBlizzard.java index 35ebe312..28c3b63b 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityBlizzard.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityBlizzard.java @@ -4,11 +4,11 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; @@ -38,7 +38,7 @@ public class EntityBlizzard extends EntityMagicConstruct { if(!this.world.isRemote){ - List targets = WizardryUtilities.getEntitiesWithinRadius(radius, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(radius, this.posX, this.posY, this.posZ, this.world); for(EntityLivingBase target : targets){ @@ -46,11 +46,11 @@ public class EntityBlizzard extends EntityMagicConstruct { if(this.isValidTarget(target)){ if(this.getCaster() != null){ - WizardryUtilities.attackEntityWithoutKnockback(target, + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeIndirectMagicDamage(this, getCaster(), DamageType.FROST), 1 * damageMultiplier); }else{ - WizardryUtilities.attackEntityWithoutKnockback(target, DamageSource.MAGIC, + EntityUtils.attackEntityWithoutKnockback(target, DamageSource.MAGIC, 1 * damageMultiplier); } } diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityBubble.java b/src/main/java/electroblob/wizardry/entity/construct/EntityBubble.java index 08a59b14..72884fd5 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityBubble.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityBubble.java @@ -3,9 +3,9 @@ package electroblob.wizardry.entity.construct; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Entrapment; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.WizardryUtilities; import io.netty.buffer.ByteBuf; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.MoverType; @@ -46,32 +46,32 @@ public class EntityBubble extends EntityMagicConstruct { // Synchronises the rider field if((this.rider == null || this.rider.get() == null) - && WizardryUtilities.getRider(this) instanceof EntityLivingBase - && !WizardryUtilities.getRider(this).isDead){ - this.rider = new WeakReference<>((EntityLivingBase)WizardryUtilities.getRider(this)); + && EntityUtils.getRider(this) instanceof EntityLivingBase + && !EntityUtils.getRider(this).isDead){ + this.rider = new WeakReference<>((EntityLivingBase)EntityUtils.getRider(this)); } // Prevents dismounting - if(WizardryUtilities.getRider(this) == null && this.rider != null && this.rider.get() != null + if(EntityUtils.getRider(this) == null && this.rider != null && this.rider.get() != null && !this.rider.get().isDead){ this.rider.get().startRiding(this); } // Stops the bubble bursting instantly. - if(this.ticksExisted < 1 && !isDarkOrb) ((EntityLivingBase)WizardryUtilities.getRider(this)).hurtTime = 0; + if(this.ticksExisted < 1 && !isDarkOrb) ((EntityLivingBase)EntityUtils.getRider(this)).hurtTime = 0; this.move(MoverType.SELF, 0, 0.03, 0); if(isDarkOrb){ - if(WizardryUtilities.getRider(this) != null - && WizardryUtilities.getRider(this).ticksExisted % Spells.entrapment.getProperty(Entrapment.DAMAGE_INTERVAL).intValue() == 0){ + if(EntityUtils.getRider(this) != null + && EntityUtils.getRider(this).ticksExisted % Spells.entrapment.getProperty(Entrapment.DAMAGE_INTERVAL).intValue() == 0){ if(this.getCaster() != null){ - WizardryUtilities.getRider(this).attackEntityFrom( + EntityUtils.getRider(this).attackEntityFrom( MagicDamage.causeIndirectMagicDamage(this, getCaster(), DamageType.MAGIC), 1 * damageMultiplier); }else{ - WizardryUtilities.getRider(this).attackEntityFrom(DamageSource.MAGIC, 1 * damageMultiplier); + EntityUtils.getRider(this).attackEntityFrom(DamageSource.MAGIC, 1 * damageMultiplier); } } @@ -92,7 +92,7 @@ public class EntityBubble extends EntityMagicConstruct { // Bubble bursts if the entity is hurt (see event handler) or killed, or if the bubble has existed for more than // 10 seconds. - if(WizardryUtilities.getRider(this) == null && this.ticksExisted > 1){ + if(EntityUtils.getRider(this) == null && this.ticksExisted > 1){ if(!this.isDarkOrb) this.playSound(WizardrySounds.ENTITY_BUBBLE_POP, 1.5f, 1.0f); this.setDead(); } @@ -100,8 +100,8 @@ public class EntityBubble extends EntityMagicConstruct { @Override public void despawn(){ - if(WizardryUtilities.getRider(this) != null){ - ((EntityLivingBase)WizardryUtilities.getRider(this)).dismountEntity(this); + if(EntityUtils.getRider(this) != null){ + ((EntityLivingBase)EntityUtils.getRider(this)).dismountEntity(this); } if(!this.isDarkOrb) this.playSound(WizardrySounds.ENTITY_BUBBLE_POP, 1.5f, 1.0f); super.despawn(); diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityCombustionRune.java b/src/main/java/electroblob/wizardry/entity/construct/EntityCombustionRune.java index 1077cdd3..60132203 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityCombustionRune.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityCombustionRune.java @@ -2,7 +2,7 @@ package electroblob.wizardry.entity.construct; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.spell.Spell; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.math.MathHelper; @@ -25,7 +25,7 @@ public class EntityCombustionRune extends EntityMagicConstruct { if(!this.world.isRemote){ - List targets = WizardryUtilities.getEntitiesWithinRadius(width/2, posX, posY, posZ, world); + List targets = EntityUtils.getEntitiesWithinRadius(width/2, posX, posY, posZ, world); for(EntityLivingBase target : targets){ @@ -34,7 +34,7 @@ public class EntityCombustionRune extends EntityMagicConstruct { float strength = Spells.combustion_rune.getProperty(Spell.BLAST_RADIUS).floatValue(); world.newExplosion(this.getCaster(), this.posX, this.posY, this.posZ, strength, true, - getCaster() != null && WizardryUtilities.canDamageBlocks(getCaster(), world)); + getCaster() != null && EntityUtils.canDamageBlocks(getCaster(), world)); // The trap is destroyed once triggered. this.setDead(); diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityDecay.java b/src/main/java/electroblob/wizardry/entity/construct/EntityDecay.java index e781a2d9..492a3fc7 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityDecay.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityDecay.java @@ -4,9 +4,9 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.PotionEffect; @@ -36,7 +36,7 @@ public class EntityDecay extends EntityMagicConstruct { 0.6F + rand.nextFloat() * 0.15F); if(!this.world.isRemote){ - List targets = WizardryUtilities.getEntitiesWithinRadius(1.0d, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(1.0d, this.posX, this.posY, this.posZ, this.world); for(EntityLivingBase target : targets){ if(target != this.getCaster()){ diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityEarthquake.java b/src/main/java/electroblob/wizardry/entity/construct/EntityEarthquake.java index 19dd083c..1c91640d 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityEarthquake.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityEarthquake.java @@ -2,9 +2,10 @@ package electroblob.wizardry.entity.construct; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.spell.Earthquake; +import electroblob.wizardry.util.BlockUtils; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityFallingBlock; import net.minecraft.entity.player.EntityPlayerMP; @@ -46,7 +47,7 @@ public class EntityEarthquake extends EntityMagicConstruct { BlockPos pos = new BlockPos(x, y, z); - if(!WizardryUtilities.isBlockUnbreakable(world, pos) && !world.isAirBlock(pos) + if(!BlockUtils.isBlockUnbreakable(world, pos) && !world.isAirBlock(pos) && world.isBlockNormalCube(pos, false) // Checks that the block above is not solid, since this causes the falling sand to vanish. && !world.isBlockNormalCube(pos.up(), false)){ @@ -61,7 +62,7 @@ public class EntityEarthquake extends EntityMagicConstruct { } - List targets = WizardryUtilities + List targets = EntityUtils .getEntitiesWithinRadius((this.ticksExisted * speed) + 1.5, this.posX, this.posY, this.posZ, world); // In this particular instance, the caster is completely unaffected because they will always be in the diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityFireRing.java b/src/main/java/electroblob/wizardry/entity/construct/EntityFireRing.java index e6e20e96..13068287 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityFireRing.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityFireRing.java @@ -3,9 +3,9 @@ package electroblob.wizardry.entity.construct; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.DamageSource; import net.minecraft.world.World; @@ -32,7 +32,7 @@ public class EntityFireRing extends EntityMagicConstruct { if(!this.world.isRemote){ - List targets = WizardryUtilities.getEntitiesWithinRadius(2.5d, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(2.5d, this.posX, this.posY, this.posZ, this.world); for(EntityLivingBase target : targets){ diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityFireSigil.java b/src/main/java/electroblob/wizardry/entity/construct/EntityFireSigil.java index 509511ff..ff3c9aa3 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityFireSigil.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityFireSigil.java @@ -3,9 +3,9 @@ package electroblob.wizardry.entity.construct; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumParticleTypes; @@ -29,7 +29,7 @@ public class EntityFireSigil extends EntityMagicConstruct { if(!this.world.isRemote){ - List targets = WizardryUtilities.getEntitiesWithinRadius(width/2, posX, posY, posZ, world); + List targets = EntityUtils.getEntitiesWithinRadius(width/2, posX, posY, posZ, world); for(EntityLivingBase target : targets){ diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityForcefield.java b/src/main/java/electroblob/wizardry/entity/construct/EntityForcefield.java index 0bd2d4c7..b06de2a2 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityForcefield.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityForcefield.java @@ -6,10 +6,8 @@ import electroblob.wizardry.entity.projectile.EntityMagicArrow; import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardrySounds; -import electroblob.wizardry.util.MagicDamage; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -100,7 +98,7 @@ public class EntityForcefield extends EntityMagicConstruct implements ICustomHit // If they will be inside the forcefield next tick, sets their position and velocity such that they appear to // bounce off the forcefield and creates impact particle effects and sounds where they hit it - List targets = WizardryUtilities.getEntitiesWithinRadius(radius + SEARCH_BORDER_SIZE, posX, posY, posZ, world, Entity.class); + List targets = EntityUtils.getEntitiesWithinRadius(radius + SEARCH_BORDER_SIZE, posX, posY, posZ, world, Entity.class); targets.remove(this); targets.removeIf(t -> t instanceof EntityXPOrb); // Gets annoying since they're attracted to the player @@ -117,7 +115,7 @@ public class EntityForcefield extends EntityMagicConstruct implements ICustomHit if(this.isValidTarget(target)){ - Vec3d currentPos = Arrays.stream(WizardryUtilities.getVertices(target.getEntityBoundingBox())) + Vec3d currentPos = Arrays.stream(GeometryUtils.getVertices(target.getEntityBoundingBox())) .min(Comparator.comparingDouble(v -> v.distanceTo(this.getPositionVector()))) .orElse(target.getPositionVector()); // This will never happen, it's just here to make the compiler happy @@ -130,7 +128,7 @@ public class EntityForcefield extends EntityMagicConstruct implements ICustomHit boolean flag; - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ // Non-allied living entities shouldn't be inside at all flag = nextTickDistance <= radius; }else{ @@ -143,7 +141,7 @@ public class EntityForcefield extends EntityMagicConstruct implements ICustomHit // Ring of interdiction if(getCaster() instanceof EntityPlayer && ItemArtefact.isArtefactActive((EntityPlayer)getCaster(), - WizardryItems.ring_interdiction) && WizardryUtilities.isLiving(target)){ + WizardryItems.ring_interdiction) && EntityUtils.isLiving(target)){ target.attackEntityFrom(MagicDamage.causeIndirectMagicDamage(this, getCaster(), MagicDamage.DamageType.MAGIC), 1); } @@ -151,7 +149,7 @@ public class EntityForcefield extends EntityMagicConstruct implements ICustomHit Vec3d targetRelativePos = currentPos.subtract(this.getPositionVector()); double nudgeVelocity = this.contains(target) ? -0.1 : 0.1; - if(WizardryUtilities.isLiving(target)) nudgeVelocity = 0.25; + if(EntityUtils.isLiving(target)) nudgeVelocity = 0.25; Vec3d extraVelocity = targetRelativePos.normalize().scale(nudgeVelocity); // ...make it bounce off! @@ -216,7 +214,7 @@ public class EntityForcefield extends EntityMagicConstruct implements ICustomHit /** Returns true if the given bounding box is completely inside this forcefield (the surface counts as outside). */ public boolean contains(AxisAlignedBB box){ - return Arrays.stream(WizardryUtilities.getVertices(box)).allMatch(this::contains); + return Arrays.stream(GeometryUtils.getVertices(box)).allMatch(this::contains); } /** Returns true if the given entity is completely inside this forcefield (the surface counts as outside). */ @@ -303,7 +301,7 @@ public class EntityForcefield extends EntityMagicConstruct implements ICustomHit double searchRadius = 20; - List forcefields = WizardryUtilities.getEntitiesWithinRadius(searchRadius, vec.x, + List forcefields = EntityUtils.getEntitiesWithinRadius(searchRadius, vec.x, vec.y, vec.z, world, EntityForcefield.class); forcefields.removeIf(f -> !f.contains(vec)); @@ -317,7 +315,7 @@ public class EntityForcefield extends EntityMagicConstruct implements ICustomHit double searchRadius = 20; - List forcefields = WizardryUtilities.getEntitiesWithinRadius(searchRadius, vec.x, + List forcefields = EntityUtils.getEntitiesWithinRadius(searchRadius, vec.x, vec.y, vec.z, world, EntityForcefield.class); forcefields.removeIf(f -> !f.contains(box)); @@ -348,7 +346,7 @@ public class EntityForcefield extends EntityMagicConstruct implements ICustomHit // If the player is trying to interact across a forcefield boundary, cancel the event // The most pragmatic solution here is to use the centres - it's not perfect, but it's simple! - if(getSurroundingForcefield(event.getWorld(), WizardryUtilities.getCentre(box)) + if(getSurroundingForcefield(event.getWorld(), GeometryUtils.getCentre(box)) != getSurroundingForcefield(event.getWorld(), event.getEntityPlayer().getPositionVector())){ event.setCanceled(true); } diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityFrostSigil.java b/src/main/java/electroblob/wizardry/entity/construct/EntityFrostSigil.java index 690e7ec8..8ae8ebfc 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityFrostSigil.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityFrostSigil.java @@ -4,11 +4,11 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; @@ -32,14 +32,14 @@ public class EntityFrostSigil extends EntityMagicConstruct { if(!this.world.isRemote){ - List targets = WizardryUtilities.getEntitiesWithinRadius(1.0d, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(1.0d, this.posX, this.posY, this.posZ, this.world); for(EntityLivingBase target : targets){ if(this.isValidTarget(target)){ - WizardryUtilities.attackEntityWithoutKnockback(target, this.getCaster() != null + EntityUtils.attackEntityWithoutKnockback(target, this.getCaster() != null ? MagicDamage.causeIndirectMagicDamage(this, this.getCaster(), DamageType.FROST) : DamageSource.MAGIC, Spells.frost_sigil.getProperty(Spell.DAMAGE).floatValue() * damageMultiplier); diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityHammer.java b/src/main/java/electroblob/wizardry/entity/construct/EntityHammer.java index 328a4077..28c0644c 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityHammer.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityHammer.java @@ -8,11 +8,11 @@ import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.LightningHammer; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -105,7 +105,7 @@ public class EntityHammer extends EntityMagicConstruct { double seekerRange = Spells.lightning_hammer.getProperty(Spell.EFFECT_RADIUS).doubleValue(); - List targets = WizardryUtilities.getEntitiesWithinRadius(seekerRange, this.posX, + List targets = EntityUtils.getEntitiesWithinRadius(seekerRange, this.posX, this.posY + 1, this.posZ, world); int maxTargets = Spells.lightning_hammer.getProperty(LightningHammer.SECONDARY_MAX_TARGETS).intValue(); @@ -113,7 +113,7 @@ public class EntityHammer extends EntityMagicConstruct { for(EntityLivingBase target : targets){ - if(WizardryUtilities.isLiving(target) && this.isValidTarget(target) + if(EntityUtils.isLiving(target) && this.isValidTarget(target) && target.ticksExisted % Spells.lightning_hammer.getProperty(LightningHammer.ATTACK_INTERVAL).floatValue() == 0){ if(world.isRemote){ @@ -129,9 +129,9 @@ public class EntityHammer extends EntityMagicConstruct { float damage = Spells.lightning_hammer.getProperty(Spell.SPLASH_DAMAGE).floatValue() * damageMultiplier; if(this.getCaster() != null){ - WizardryUtilities.attackEntityWithoutKnockback(target, MagicDamage.causeIndirectMagicDamage( + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeIndirectMagicDamage( this, getCaster(), DamageType.SHOCK), damage); - WizardryUtilities.applyStandardKnockback(this, target); + EntityUtils.applyStandardKnockback(this, target); }else{ target.attackEntityFrom(DamageSource.MAGIC, damage); } @@ -183,7 +183,7 @@ public class EntityHammer extends EntityMagicConstruct { } if(this.fallDistance > 10){ - WizardryUtilities.getEntitiesWithinRadius(10, posX, posY, posZ, world, EntityPlayer.class) + EntityUtils.getEntitiesWithinRadius(10, posX, posY, posZ, world, EntityPlayer.class) .forEach(p -> Wizardry.proxy.shakeScreen(p, 6)); } diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityHealAura.java b/src/main/java/electroblob/wizardry/entity/construct/EntityHealAura.java index dc32d17b..33afab60 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityHealAura.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityHealAura.java @@ -3,11 +3,11 @@ package electroblob.wizardry.entity.construct; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.DamageSource; import net.minecraft.util.math.MathHelper; @@ -36,7 +36,7 @@ public class EntityHealAura extends EntityMagicConstruct { if(!this.world.isRemote){ - List targets = WizardryUtilities.getEntitiesWithinRadius(2.5, posX, posY, posZ, world); + List targets = EntityUtils.getEntitiesWithinRadius(2.5, posX, posY, posZ, world); for(EntityLivingBase target : targets){ diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityIceSpike.java b/src/main/java/electroblob/wizardry/entity/construct/EntityIceSpike.java index 410f4b15..1a3d29d5 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityIceSpike.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityIceSpike.java @@ -4,9 +4,9 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.GeometryUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.MoverType; import net.minecraft.potion.PotionEffect; @@ -27,9 +27,9 @@ public class EntityIceSpike extends EntityMagicConstruct { public void setFacing(EnumFacing facing){ this.facing = facing; - this.setRotation(-facing.getHorizontalAngle(), WizardryUtilities.getPitch(facing)); + this.setRotation(-facing.getHorizontalAngle(), GeometryUtils.getPitch(facing)); float yaw = (-facing.getHorizontalAngle()) * (float)Math.PI/180; - float pitch = (WizardryUtilities.getPitch(facing) - 90) * (float)Math.PI/180; + float pitch = (GeometryUtils.getPitch(facing) - 90) * (float)Math.PI/180; Vec3d min = this.getPositionVector().add(new Vec3d(-width/2, 0, -width/2).rotatePitch(pitch).rotateYaw(yaw)); Vec3d max = this.getPositionVector().add(new Vec3d(width/2, height, width/2).rotatePitch(pitch).rotateYaw(yaw)); this.setEntityBoundingBox(new AxisAlignedBB(min.x, min.y, min.z, max.x, max.y, max.z)); diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityLightningSigil.java b/src/main/java/electroblob/wizardry/entity/construct/EntityLightningSigil.java index 412df121..f2350bc6 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityLightningSigil.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityLightningSigil.java @@ -3,11 +3,11 @@ package electroblob.wizardry.entity.construct; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.DamageSource; import net.minecraft.util.math.MathHelper; @@ -34,7 +34,7 @@ public class EntityLightningSigil extends EntityMagicConstruct { this.setDead(); } - List targets = WizardryUtilities.getEntitiesWithinRadius(1.0d, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(1.0d, this.posX, this.posY, this.posZ, this.world); for(EntityLivingBase target : targets){ @@ -60,7 +60,7 @@ public class EntityLightningSigil extends EntityMagicConstruct { // Secondary chaining effect double seekerRange = Spells.lightning_sigil.getProperty(Spell.EFFECT_RADIUS).doubleValue(); - List secondaryTargets = WizardryUtilities.getEntitiesWithinRadius(seekerRange, + List secondaryTargets = EntityUtils.getEntitiesWithinRadius(seekerRange, target.posX, target.posY + target.height / 2, target.posZ, world); for(int j = 0; j < Math.min(secondaryTargets.size(), diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityMagicConstruct.java b/src/main/java/electroblob/wizardry/entity/construct/EntityMagicConstruct.java index 6ef5f507..414fad02 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityMagicConstruct.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityMagicConstruct.java @@ -4,7 +4,7 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.ISpellCastingItem; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -147,7 +147,7 @@ public abstract class EntityMagicConstruct extends Entity implements IEntityOwna @Nullable public EntityLivingBase getCaster(){ // Kept despite the above method because it returns an EntityLivingBase - Entity entity = WizardryUtilities.getEntityByUUID(world, getOwnerId()); + Entity entity = EntityUtils.getEntityByUUID(world, getOwnerId()); if(entity != null && !(entity instanceof EntityLivingBase)){ // Should never happen Wizardry.logger.warn("{} has a non-living owner!", this); diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityStormcloud.java b/src/main/java/electroblob/wizardry/entity/construct/EntityStormcloud.java index 895b5511..ab2943c9 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityStormcloud.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityStormcloud.java @@ -4,10 +4,10 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -69,7 +69,7 @@ public class EntityStormcloud extends EntityMagicConstruct { if(target.ticksExisted % 150 == 0){ // Use target's lifetime so they don't all get hit at once, looks better if(!this.world.isRemote){ - WizardryUtilities.attackEntityWithoutKnockback(target, MagicDamage.causeIndirectMagicDamage( + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeIndirectMagicDamage( this, this.getCaster(), MagicDamage.DamageType.SHOCK), damage); }else{ ParticleBuilder.create(Type.LIGHTNING).pos(target.posX, posY + height/2, target.posZ) diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityTornado.java b/src/main/java/electroblob/wizardry/entity/construct/EntityTornado.java index 18c8d51d..29254c77 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityTornado.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityTornado.java @@ -7,11 +7,9 @@ import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; import electroblob.wizardry.spell.Tornado; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import io.netty.buffer.ByteBuf; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -60,7 +58,7 @@ public class EntityTornado extends EntityMagicConstruct { this.move(MoverType.SELF, velX, motionY, velZ); BlockPos pos = new BlockPos(this); - Integer y = WizardryUtilities.getNearestSurface(world, pos.up(3), EnumFacing.UP, 5, true, WizardryUtilities.SurfaceCriteria.NOT_AIR_TO_AIR); + Integer y = BlockUtils.getNearestSurface(world, pos.up(3), EnumFacing.UP, 5, true, BlockUtils.SurfaceCriteria.NOT_AIR_TO_AIR); if(y != null){ @@ -74,7 +72,7 @@ public class EntityTornado extends EntityMagicConstruct { if(!this.world.isRemote){ - List targets = WizardryUtilities.getEntitiesWithinRadius(radius, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(radius, this.posX, this.posY, this.posZ, this.world); for(EntityLivingBase target : targets){ @@ -125,7 +123,7 @@ public class EntityTornado extends EntityMagicConstruct { BlockPos pos1 = new BlockPos(blockX, this.posY + 3, blockZ); - Integer blockY = WizardryUtilities.getNearestSurface(world, pos1, EnumFacing.UP, 5, true, WizardryUtilities.SurfaceCriteria.NOT_AIR_TO_AIR); + Integer blockY = BlockUtils.getNearestSurface(world, pos1, EnumFacing.UP, 5, true, BlockUtils.SurfaceCriteria.NOT_AIR_TO_AIR); if(blockY != null){ diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityZombieSpawner.java b/src/main/java/electroblob/wizardry/entity/construct/EntityZombieSpawner.java index ae7eaba6..95b3cdff 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityZombieSpawner.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityZombieSpawner.java @@ -6,9 +6,9 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.SpellMinion; import electroblob.wizardry.spell.ZombieApocalypse; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities.Operations; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.IAttributeInstance; @@ -49,7 +49,7 @@ public class EntityZombieSpawner extends EntityMagicConstruct { zombie.setLifetime(Spells.zombie_apocalypse.getProperty(SpellMinion.MINION_LIFETIME).intValue()); IAttributeInstance attribute = zombie.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); attribute.applyModifier(new AttributeModifier(SpellMinion.POTENCY_ATTRIBUTE_MODIFIER, - damageMultiplier - 1, Operations.MULTIPLY_CUMULATIVE)); + damageMultiplier - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); zombie.setHealth(zombie.getMaxHealth()); // Need to set this because we may have just modified the value zombie.hurtResistantTime = 30; // Prevent fall damage zombie.hideParticles(); // Hide spawn particles or they pop out the top of the hidden box diff --git a/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java b/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java index ca20dd61..769f2baa 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java @@ -369,7 +369,7 @@ public class EntityEvilWizard extends EntityMob implements ISpellCaster, IEntity Element element = this.getElement(); // Adds armour. - for(EntityEquipmentSlot slot : WizardryUtilities.ARMOUR_SLOTS){ + for(EntityEquipmentSlot slot : InventoryUtils.ARMOUR_SLOTS){ this.setItemStackToSlot(slot, new ItemStack(WizardryItems.getArmour(element, slot))); } diff --git a/src/main/java/electroblob/wizardry/entity/living/EntityPhoenix.java b/src/main/java/electroblob/wizardry/entity/living/EntityPhoenix.java index e68b3e7b..dbfed9f9 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntityPhoenix.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntityPhoenix.java @@ -4,8 +4,8 @@ import electroblob.wizardry.client.DrawingUtils; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIHurtByTarget; @@ -161,7 +161,7 @@ public class EntityPhoenix extends EntitySummonedCreature implements ISpellCaste public void onLivingUpdate(){ // Makes the phoenix hover. - Integer floorLevel = WizardryUtilities.getNearestFloor(world, new BlockPos(this), 4); + Integer floorLevel = BlockUtils.getNearestFloor(world, new BlockPos(this), 4); if(floorLevel == null || this.posY - floorLevel > 3){ this.motionY = -0.1; diff --git a/src/main/java/electroblob/wizardry/entity/living/EntitySkeletonMinion.java b/src/main/java/electroblob/wizardry/entity/living/EntitySkeletonMinion.java index 67c681cb..0310c397 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntitySkeletonMinion.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntitySkeletonMinion.java @@ -1,7 +1,7 @@ package electroblob.wizardry.entity.living; import electroblob.wizardry.Wizardry; -import electroblob.wizardry.util.WizardryUtilities.Operations; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.entity.EntityFlying; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; @@ -73,7 +73,7 @@ public class EntitySkeletonMinion extends AbstractSkeleton implements ISummonedC public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata){ // Can't call super, so the code from the next level up (EntityLiving) had to be copied as well. this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE) - .applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, Operations.MULTIPLY_FLAT)); + .applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, EntityUtils.Operations.MULTIPLY_FLAT)); if(this.rand.nextFloat() < 0.05F){ this.setLeftHanded(true); diff --git a/src/main/java/electroblob/wizardry/entity/living/EntitySpiderMinion.java b/src/main/java/electroblob/wizardry/entity/living/EntitySpiderMinion.java index b4efebc2..d3510beb 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntitySpiderMinion.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntitySpiderMinion.java @@ -1,9 +1,9 @@ package electroblob.wizardry.entity.living; import electroblob.wizardry.Wizardry; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities.Operations; import net.minecraft.entity.EntityFlying; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; @@ -67,7 +67,7 @@ public class EntitySpiderMinion extends EntityCaveSpider implements ISummonedCre // Can't call super, so the code from the next level up (EntityLiving) had to be copied as well. this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE) - .applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, Operations.MULTIPLY_FLAT)); + .applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, EntityUtils.Operations.MULTIPLY_FLAT)); if(this.rand.nextFloat() < 0.05F){ this.setLeftHanded(true); diff --git a/src/main/java/electroblob/wizardry/entity/living/EntitySpiritHorse.java b/src/main/java/electroblob/wizardry/entity/living/EntitySpiritHorse.java index 98deb764..d3aeb8ec 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntitySpiritHorse.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntitySpiritHorse.java @@ -3,9 +3,9 @@ package electroblob.wizardry.entity.living; import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.ISpellCastingItem; import electroblob.wizardry.registry.WizardrySounds; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; @@ -124,7 +124,7 @@ public class EntitySpiritHorse extends EntityHorse { private EntityLivingBase getOwner(){ // I think the DataManager stores any objects, so it now stores the UUID instead of its string representation. - Entity owner = WizardryUtilities.getEntityByUUID(world, this.getOwnerUniqueId()); + Entity owner = EntityUtils.getEntityByUUID(world, this.getOwnerUniqueId()); if(owner instanceof EntityLivingBase){ return (EntityLivingBase)owner; diff --git a/src/main/java/electroblob/wizardry/entity/living/EntityWitherSkeletonMinion.java b/src/main/java/electroblob/wizardry/entity/living/EntityWitherSkeletonMinion.java index a8994683..a34f63f6 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntityWitherSkeletonMinion.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntityWitherSkeletonMinion.java @@ -1,7 +1,7 @@ package electroblob.wizardry.entity.living; import electroblob.wizardry.Wizardry; -import electroblob.wizardry.util.WizardryUtilities.Operations; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.entity.EntityFlying; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; @@ -75,7 +75,7 @@ public class EntityWitherSkeletonMinion extends EntityWitherSkeleton implements public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata){ // Can't call super, so the code from the next level up (EntityLiving) had to be copied as well. this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE) - .applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, Operations.MULTIPLY_FLAT)); + .applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, EntityUtils.Operations.MULTIPLY_FLAT)); if(this.rand.nextFloat() < 0.05F){ this.setLeftHanded(true); diff --git a/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java b/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java index 99d9e93c..0b197347 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java @@ -469,7 +469,7 @@ public class EntityWizard extends EntityCreature implements INpc, IMerchant, ISp if(!world.isRemote && !this.getCustomer().isCreative() && Wizardry.settings.discoveryMode){ // Sound and text only happen server-side, in survival, with discovery mode on - WizardryUtilities.playSoundAtPlayer(this.getCustomer(), WizardrySounds.MISC_DISCOVER_SPELL, 1.25f, 1); + EntityUtils.playSoundAtPlayer(this.getCustomer(), WizardrySounds.MISC_DISCOVER_SPELL, 1.25f, 1); this.getCustomer().sendMessage(new TextComponentTranslation("spell.discover", spell.getNameForTranslationFormatted())); } @@ -673,7 +673,7 @@ public class EntityWizard extends EntityCreature implements INpc, IMerchant, ISp }else if(randomiser < 8){ return new ItemStack(WizardryItems.arcane_tome, 1, 1); }else if(randomiser < 10){ - EntityEquipmentSlot slot = WizardryUtilities.ARMOUR_SLOTS[rand.nextInt(WizardryUtilities.ARMOUR_SLOTS.length)]; + EntityEquipmentSlot slot = InventoryUtils.ARMOUR_SLOTS[rand.nextInt(InventoryUtils.ARMOUR_SLOTS.length)]; if(this.getElement() != Element.MAGIC && rand.nextInt(4) > 0){ // This means it is more likely for armour sold to be of the same element as the wizard if the // wizard has an element. @@ -755,7 +755,7 @@ public class EntityWizard extends EntityCreature implements INpc, IMerchant, ISp Element element = this.getElement(); // Adds armour. - for(EntityEquipmentSlot slot : WizardryUtilities.ARMOUR_SLOTS){ + for(EntityEquipmentSlot slot : InventoryUtils.ARMOUR_SLOTS){ this.setItemStackToSlot(slot, new ItemStack(WizardryItems.getArmour(element, slot))); } @@ -888,7 +888,7 @@ public class EntityWizard extends EntityCreature implements INpc, IMerchant, ISp // Makes wizards angry if a player breaks a block in their tower if(!(event.getPlayer() instanceof FakePlayer)){ - List wizards = WizardryUtilities.getEntitiesWithinRadius(64, event.getPos().getX(), + List wizards = EntityUtils.getEntitiesWithinRadius(64, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), event.getWorld(), EntityWizard.class); if(!wizards.isEmpty()){ diff --git a/src/main/java/electroblob/wizardry/entity/living/ISpellCaster.java b/src/main/java/electroblob/wizardry/entity/living/ISpellCaster.java index af70b1d1..37144516 100644 --- a/src/main/java/electroblob/wizardry/entity/living/ISpellCaster.java +++ b/src/main/java/electroblob/wizardry/entity/living/ISpellCaster.java @@ -2,8 +2,8 @@ package electroblob.wizardry.entity.living; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.world.EnumDifficulty; import javax.annotation.Nonnull; @@ -91,6 +91,6 @@ public interface ISpellCaster { * skeletons, which are: Easy - 10, Normal - 6, Hard - 2, Peaceful - 10 (rarely used). */ default int getAimingError(EnumDifficulty difficulty) { - return WizardryUtilities.getDefaultAimingError(difficulty); + return EntityUtils.getDefaultAimingError(difficulty); } } diff --git a/src/main/java/electroblob/wizardry/entity/living/ISummonedCreature.java b/src/main/java/electroblob/wizardry/entity/living/ISummonedCreature.java index 772551f7..f3fb3521 100644 --- a/src/main/java/electroblob/wizardry/entity/living/ISummonedCreature.java +++ b/src/main/java/electroblob/wizardry/entity/living/ISummonedCreature.java @@ -118,7 +118,7 @@ public interface ISummonedCreature extends IEntityAdditionalSpawnData, IEntityOw if(this instanceof Entity){ // Bit of a cheat but it saves having yet another method just to get the world - Entity entity = WizardryUtilities.getEntityByUUID(((Entity)this).world, getOwnerId()); + Entity entity = EntityUtils.getEntityByUUID(((Entity)this).world, getOwnerId()); if(entity != null && !(entity instanceof EntityLivingBase)){ // Should never happen Wizardry.logger.warn("{} has a non-living owner!", this); @@ -395,7 +395,7 @@ public interface ISummonedCreature extends IEntityAdditionalSpawnData, IEntityOw // no summoner. if(DamageSafetyChecker.attackEntitySafely(event.getEntity(), newSource, event.getAmount(), event.getSource(), false)){ // Uses event.getSource().getTrueSource() as this means the target is knocked back from the minion - WizardryUtilities.applyStandardKnockback(event.getSource().getTrueSource(), event.getEntityLiving()); + EntityUtils.applyStandardKnockback(event.getSource().getTrueSource(), event.getEntityLiving()); ((ISummonedCreature)event.getSource().getTrueSource()).onSuccessfulAttack(event.getEntityLiving()); // If the target revenge-targeted the summoner, make it revenge-target the minion instead // (if it didn't revenge-target, do nothing) diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntityFirebomb.java b/src/main/java/electroblob/wizardry/entity/projectile/EntityFirebomb.java index 0c4693ce..d42a04f3 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntityFirebomb.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntityFirebomb.java @@ -3,11 +3,11 @@ package electroblob.wizardry.entity.projectile; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumParticleTypes; @@ -69,7 +69,7 @@ public class EntityFirebomb extends EntityBomb { double range = Spells.firebomb.getProperty(Spell.BLAST_RADIUS).floatValue() * blastMultiplier; - List targets = WizardryUtilities.getEntitiesWithinRadius(range, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(range, this.posX, this.posY, this.posZ, this.world); for(EntityLivingBase target : targets){ diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntityForceArrow.java b/src/main/java/electroblob/wizardry/entity/projectile/EntityForceArrow.java index 0b5bb9cb..27bb0da8 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntityForceArrow.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntityForceArrow.java @@ -7,10 +7,10 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -65,7 +65,7 @@ public class EntityForceArrow extends EntityMagicArrow { if(!player.capabilities.isCreativeMode && ItemArtefact.isArtefactActive(player, WizardryItems.ring_mana_return)){ - for(ItemStack stack : WizardryUtilities.getPrioritisedHotbarAndOffhand(player)){ + for(ItemStack stack : InventoryUtils.getPrioritisedHotbarAndOffhand(player)){ if(stack.getItem() instanceof ISpellCastingItem && stack.getItem() instanceof IManaStoringItem && Arrays.asList(((ISpellCastingItem)stack.getItem()).getSpells(stack)).contains(Spells.force_arrow)){ ((IManaStoringItem)stack.getItem()).rechargeMana(stack, mana); diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntityForceOrb.java b/src/main/java/electroblob/wizardry/entity/projectile/EntityForceOrb.java index 3967b0ba..424b2fba 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntityForceOrb.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntityForceOrb.java @@ -3,11 +3,11 @@ package electroblob.wizardry.entity.projectile; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.math.RayTraceResult; @@ -53,7 +53,7 @@ public class EntityForceOrb extends EntityBomb { double blastRadius = Spells.force_orb.getProperty(Spell.BLAST_RADIUS).floatValue() * blastMultiplier; - List targets = WizardryUtilities.getEntitiesWithinRadius(blastRadius, this.posX, + List targets = EntityUtils.getEntitiesWithinRadius(blastRadius, this.posX, this.posY, this.posZ, this.world); for(EntityLivingBase target : targets){ diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntityIceCharge.java b/src/main/java/electroblob/wizardry/entity/projectile/EntityIceCharge.java index 048d47c9..6c6bcb01 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntityIceCharge.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntityIceCharge.java @@ -4,11 +4,9 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; @@ -74,7 +72,7 @@ public class EntityIceCharge extends EntityBomb { double radius = Spells.ice_charge.getProperty(Spell.EFFECT_RADIUS).floatValue() * blastMultiplier; - List targets = WizardryUtilities.getEntitiesWithinRadius(radius, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(radius, this.posX, this.posY, this.posZ, this.world); // Slows targets @@ -93,8 +91,8 @@ public class EntityIceCharge extends EntityBomb { BlockPos pos = new BlockPos(this.posX + i, this.posY, this.posZ + j); - Integer y = WizardryUtilities.getNearestSurface(world, pos, EnumFacing.UP, 7, true, - WizardryUtilities.SurfaceCriteria.SOLID_LIQUID_TO_AIR); + Integer y = BlockUtils.getNearestSurface(world, pos, EnumFacing.UP, 7, true, + BlockUtils.SurfaceCriteria.SOLID_LIQUID_TO_AIR); if(y != null){ diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntityIceball.java b/src/main/java/electroblob/wizardry/entity/projectile/EntityIceball.java index f3989ffa..254ca6b0 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntityIceball.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntityIceball.java @@ -4,10 +4,8 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; @@ -47,12 +45,12 @@ public class EntityIceball extends EntityMagicProjectile { }else{ - if(this.getThrower() == null || WizardryUtilities.canDamageBlocks(this.getThrower(), world)){ + if(this.getThrower() == null || EntityUtils.canDamageBlocks(this.getThrower(), world)){ BlockPos pos = rayTrace.getBlockPos(); if(rayTrace.sideHit == EnumFacing.UP && !world.isRemote && world.isSideSolid(pos, EnumFacing.UP) - && WizardryUtilities.canBlockBeReplaced(world, pos.up())){ + && BlockUtils.canBlockBeReplaced(world, pos.up())){ world.setBlockState(pos.up(), Blocks.SNOW_LAYER.getDefaultState()); } } diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntityLargeMagicFireball.java b/src/main/java/electroblob/wizardry/entity/projectile/EntityLargeMagicFireball.java index 4a4d9b43..26e27918 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntityLargeMagicFireball.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntityLargeMagicFireball.java @@ -3,7 +3,7 @@ package electroblob.wizardry.entity.projectile; import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.spell.Spell; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import io.netty.buffer.ByteBuf; import net.minecraft.entity.projectile.EntityLargeFireball; import net.minecraft.nbt.NBTTagCompound; @@ -51,7 +51,7 @@ public class EntityLargeMagicFireball extends EntityMagicFireball { protected void onImpact(RayTraceResult rayTrace){ if(!world.isRemote){ - boolean flag = this.getThrower() == null || WizardryUtilities.canDamageBlocks(this.getThrower(), world); + boolean flag = this.getThrower() == null || EntityUtils.canDamageBlocks(this.getThrower(), world); this.world.newExplosion(null, this.posX, this.posY, this.posZ, getExplosionPower() * blastMultiplier, flag, flag); } diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntityMagicArrow.java b/src/main/java/electroblob/wizardry/entity/projectile/EntityMagicArrow.java index 2dd166e6..5c7221a8 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntityMagicArrow.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntityMagicArrow.java @@ -3,11 +3,8 @@ package electroblob.wizardry.entity.projectile; import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardrySounds; -import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.RayTracer; -import electroblob.wizardry.util.WizardryUtilities; import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -237,7 +234,7 @@ public abstract class EntityMagicArrow extends Entity implements IProjectile, IE } if(this.getCaster() == null && this.casterUUID != null){ - Entity entity = WizardryUtilities.getEntityByUUID(world, casterUUID); + Entity entity = EntityUtils.getEntityByUUID(world, casterUUID); if(entity instanceof EntityLivingBase){ this.caster = new WeakReference<>((EntityLivingBase)entity); } diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntityMagicFireball.java b/src/main/java/electroblob/wizardry/entity/projectile/EntityMagicFireball.java index 96d98607..31e2da8c 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntityMagicFireball.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntityMagicFireball.java @@ -3,10 +3,10 @@ package electroblob.wizardry.entity.projectile; import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; -import electroblob.wizardry.util.WizardryUtilities; import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -84,7 +84,7 @@ public class EntityMagicFireball extends EntityMagicProjectile { }else{ - if(this.getThrower() == null || WizardryUtilities.canDamageBlocks(this.getThrower(), world)){ + if(this.getThrower() == null || EntityUtils.canDamageBlocks(this.getThrower(), world)){ BlockPos blockpos = rayTrace.getBlockPos().offset(rayTrace.sideHit); diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntityPoisonBomb.java b/src/main/java/electroblob/wizardry/entity/projectile/EntityPoisonBomb.java index 286e7259..e2bbb739 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntityPoisonBomb.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntityPoisonBomb.java @@ -3,11 +3,11 @@ package electroblob.wizardry.entity.projectile; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.MobEffects; @@ -74,7 +74,7 @@ public class EntityPoisonBomb extends EntityBomb { double range = Spells.poison_bomb.getProperty(Spell.EFFECT_RADIUS).floatValue() * blastMultiplier; - List targets = WizardryUtilities.getEntitiesWithinRadius(range, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(range, this.posX, this.posY, this.posZ, this.world); for(EntityLivingBase target : targets){ diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntitySmokeBomb.java b/src/main/java/electroblob/wizardry/entity/projectile/EntitySmokeBomb.java index 75b5a590..9033963e 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntitySmokeBomb.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntitySmokeBomb.java @@ -4,9 +4,9 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.MobEffects; @@ -57,7 +57,7 @@ public class EntitySmokeBomb extends EntityBomb { double range = Spells.smoke_bomb.getProperty(Spell.BLAST_RADIUS).floatValue() * blastMultiplier; - List targets = WizardryUtilities.getEntitiesWithinRadius(range, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(range, this.posX, this.posY, this.posZ, this.world); int duration = Spells.smoke_bomb.getProperty(Spell.EFFECT_DURATION).intValue(); diff --git a/src/main/java/electroblob/wizardry/entity/projectile/EntitySparkBomb.java b/src/main/java/electroblob/wizardry/entity/projectile/EntitySparkBomb.java index 721a06a2..93c9d14a 100644 --- a/src/main/java/electroblob/wizardry/entity/projectile/EntitySparkBomb.java +++ b/src/main/java/electroblob/wizardry/entity/projectile/EntitySparkBomb.java @@ -3,11 +3,11 @@ package electroblob.wizardry.entity.projectile; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -55,7 +55,7 @@ public class EntitySparkBomb extends EntityBomb { double seekerRange = Spells.spark_bomb.getProperty(Spell.EFFECT_RADIUS).doubleValue() * blastMultiplier; - List targets = WizardryUtilities.getEntitiesWithinRadius(seekerRange, this.posX, this.posY, + List targets = EntityUtils.getEntitiesWithinRadius(seekerRange, this.posX, this.posY, this.posZ, this.world); for(int i = 0; i < Math.min(targets.size(), Spells.spark_bomb.getProperty(SECONDARY_MAX_TARGETS).intValue()); i++){ diff --git a/src/main/java/electroblob/wizardry/integration/DamageSafetyChecker.java b/src/main/java/electroblob/wizardry/integration/DamageSafetyChecker.java index 4444507c..af2e7afc 100644 --- a/src/main/java/electroblob/wizardry/integration/DamageSafetyChecker.java +++ b/src/main/java/electroblob/wizardry/integration/DamageSafetyChecker.java @@ -2,7 +2,7 @@ package electroblob.wizardry.integration; import com.google.common.collect.ImmutableSet; import electroblob.wizardry.Wizardry; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.entity.Entity; import net.minecraft.util.DamageSource; import net.minecraftforge.fml.common.Mod; @@ -58,7 +58,7 @@ public final class DamageSafetyChecker { * @param fallback The fallback damage source for when excessive looping is detected. This must not be the * same as the re-applied source, or this method is pointless! Usually it will be more general. * @param knockback True to apply knockback as normal, false to use the knockback-free methods in WizardryUtilities - * (see {@link WizardryUtilities#attackEntityWithoutKnockback(Entity, DamageSource, float)}). + * (see {@link EntityUtils#attackEntityWithoutKnockback(Entity, DamageSource, float)}). */ public static boolean attackEntitySafely(Entity target, DamageSource source, float damage, String originalSourceName, DamageSource fallback, boolean knockback){ @@ -70,7 +70,7 @@ public final class DamageSafetyChecker { // No harm in still incrementing the counter attacksThisTick++; return knockback ? target.attackEntityFrom(fallback, damage) - : WizardryUtilities.attackEntityWithoutKnockback(target, fallback, damage); + : EntityUtils.attackEntityWithoutKnockback(target, fallback, damage); } } @@ -88,13 +88,13 @@ public final class DamageSafetyChecker { // Fallback behaviour attacksThisTick++; return knockback ? target.attackEntityFrom(fallback, damage) - : WizardryUtilities.attackEntityWithoutKnockback(target, fallback, damage); + : EntityUtils.attackEntityWithoutKnockback(target, fallback, damage); }else{ // Normal behaviour attacksThisTick++; return knockback ? target.attackEntityFrom(source, damage) - : WizardryUtilities.attackEntityWithoutKnockback(target, source, damage); + : EntityUtils.attackEntityWithoutKnockback(target, source, damage); } } diff --git a/src/main/java/electroblob/wizardry/inventory/ContainerArcaneWorkbench.java b/src/main/java/electroblob/wizardry/inventory/ContainerArcaneWorkbench.java index 118ce291..cc770a03 100644 --- a/src/main/java/electroblob/wizardry/inventory/ContainerArcaneWorkbench.java +++ b/src/main/java/electroblob/wizardry/inventory/ContainerArcaneWorkbench.java @@ -10,8 +10,8 @@ import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.spell.Spell; import electroblob.wizardry.tileentity.TileEntityArcaneWorkbench; import electroblob.wizardry.util.ISpellSortable; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.WandHelper; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.ClickType; @@ -371,10 +371,10 @@ public class ContainerArcaneWorkbench extends Container implements ISpellSortabl Set slots = new LinkedHashSet<>(bookshelfSlots.size()); // Add all slots that currently contain a matching stack - collect to list to retain order - slots.addAll(bookshelfSlots.stream().filter(s -> WizardryUtilities.canMerge(stack, s.getStack())).collect(Collectors.toList())); + slots.addAll(bookshelfSlots.stream().filter(s -> InventoryUtils.canMerge(stack, s.getStack())).collect(Collectors.toList())); // Then add all empty slots that previously contained a matching stack, if they weren't already added // No need to actually check if they're empty since inserting a new stack overwrites prevStack anyway - slots.addAll(bookshelfSlots.stream().filter(s -> WizardryUtilities.canMerge(stack, s.getPrevStack())).collect(Collectors.toList())); + slots.addAll(bookshelfSlots.stream().filter(s -> InventoryUtils.canMerge(stack, s.getPrevStack())).collect(Collectors.toList())); // Then add all slots that did not previously contain anything slots.addAll(bookshelfSlots.stream().filter(s -> s.getPrevStack().isEmpty()).collect(Collectors.toList())); // Finally add all other empty slots (these will be the ones that used to contain something else) diff --git a/src/main/java/electroblob/wizardry/item/ISpellCastingItem.java b/src/main/java/electroblob/wizardry/item/ISpellCastingItem.java index cc1e9884..ebac96e5 100644 --- a/src/main/java/electroblob/wizardry/item/ISpellCastingItem.java +++ b/src/main/java/electroblob/wizardry/item/ISpellCastingItem.java @@ -2,6 +2,7 @@ package electroblob.wizardry.item; import electroblob.wizardry.data.WizardData; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -18,7 +19,7 @@ import javax.annotation.Nonnull; * this interface if appropriate. *

* This interface is used for the following:
- * - General-purpose detection of continuous spell casting (see {@link electroblob.wizardry.util.WizardryUtilities#isCasting(EntityLivingBase, Spell)})
+ * - General-purpose detection of continuous spell casting (see {@link EntityUtils#isCasting(EntityLivingBase, Spell)})
* - Display of the arcane workbench tooltip (in conjunction with {@link IManaStoringItem})
* - Spell HUD visibility
* - Spell switching controls (they won't do anything unless the player is holding an {@code ISpellCastingItem})
diff --git a/src/main/java/electroblob/wizardry/item/ItemArtefact.java b/src/main/java/electroblob/wizardry/item/ItemArtefact.java index 92eb8ff7..1579c8c3 100644 --- a/src/main/java/electroblob/wizardry/item/ItemArtefact.java +++ b/src/main/java/electroblob/wizardry/item/ItemArtefact.java @@ -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 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 action){ - List hotbar = WizardryUtilities.getPrioritisedHotbarAndOffhand(player); + List hotbar = InventoryUtils.getPrioritisedHotbarAndOffhand(player); Optional 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 projectiles = WizardryUtilities.getEntitiesWithinRadius(5, player.posX, player.posY, player.posZ, world, Entity.class); + List 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 nearby = WizardryUtilities.getEntitiesWithinRadius(4, player.posX, player.posY, player.posZ, event.getWorld()); + List 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 nearbyMobs = WizardryUtilities.getEntitiesWithinRadius(5, player.posX, player.posY, player.posZ, player.world, EntityLiving.class); + List 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 diff --git a/src/main/java/electroblob/wizardry/item/ItemFlamingAxe.java b/src/main/java/electroblob/wizardry/item/ItemFlamingAxe.java index dcfe3110..c3632dbc 100644 --- a/src/main/java/electroblob/wizardry/item/ItemFlamingAxe.java +++ b/src/main/java/electroblob/wizardry/item/ItemFlamingAxe.java @@ -3,9 +3,9 @@ package electroblob.wizardry.item; import com.google.common.collect.Multimap; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; @@ -39,7 +39,7 @@ public class ItemFlamingAxe extends ItemAxe implements IConjuredItem { if(slot == EntityEquipmentSlot.MAINHAND){ multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(POTENCY_MODIFIER, - "Potency modifier", IConjuredItem.getDamageMultiplier(stack) - 1, WizardryUtilities.Operations.MULTIPLY_CUMULATIVE)); + "Potency modifier", IConjuredItem.getDamageMultiplier(stack) - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); } return multimap; diff --git a/src/main/java/electroblob/wizardry/item/ItemFrostAxe.java b/src/main/java/electroblob/wizardry/item/ItemFrostAxe.java index a7f3fffc..adcb8c32 100644 --- a/src/main/java/electroblob/wizardry/item/ItemFrostAxe.java +++ b/src/main/java/electroblob/wizardry/item/ItemFrostAxe.java @@ -4,9 +4,9 @@ import com.google.common.collect.Multimap; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; @@ -41,7 +41,7 @@ public class ItemFrostAxe extends ItemAxe implements IConjuredItem { if(slot == EntityEquipmentSlot.MAINHAND){ multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(POTENCY_MODIFIER, - "Potency modifier", IConjuredItem.getDamageMultiplier(stack) - 1, WizardryUtilities.Operations.MULTIPLY_CUMULATIVE)); + "Potency modifier", IConjuredItem.getDamageMultiplier(stack) - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); } return multimap; diff --git a/src/main/java/electroblob/wizardry/item/ItemIdentificationScroll.java b/src/main/java/electroblob/wizardry/item/ItemIdentificationScroll.java index 61375b1e..9801d6e8 100644 --- a/src/main/java/electroblob/wizardry/item/ItemIdentificationScroll.java +++ b/src/main/java/electroblob/wizardry/item/ItemIdentificationScroll.java @@ -6,7 +6,7 @@ import electroblob.wizardry.event.DiscoverSpellEvent; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.registry.WizardryTabs; import electroblob.wizardry.spell.Spell; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.InventoryUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; @@ -56,7 +56,7 @@ public class ItemIdentificationScroll extends Item { WizardData data = WizardData.get(player); - for(ItemStack stack1 : WizardryUtilities.getPrioritisedHotbarAndOffhand(player)){ + for(ItemStack stack1 : InventoryUtils.getPrioritisedHotbarAndOffhand(player)){ if(!stack1.isEmpty()){ Spell spell = Spell.byMetadata(stack1.getItemDamage()); diff --git a/src/main/java/electroblob/wizardry/item/ItemLightningHammer.java b/src/main/java/electroblob/wizardry/item/ItemLightningHammer.java index 33ecab67..9209799c 100644 --- a/src/main/java/electroblob/wizardry/item/ItemLightningHammer.java +++ b/src/main/java/electroblob/wizardry/item/ItemLightningHammer.java @@ -6,11 +6,11 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.LightningHammer; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; @@ -83,9 +83,9 @@ public class ItemLightningHammer extends Item implements IConjuredItem { if(slot == EntityEquipmentSlot.MAINHAND){ float attackDamage = Spells.lightning_hammer.arePropertiesInitialised() ? Spells.lightning_hammer.getProperty(Spell.DIRECT_DAMAGE).floatValue() : 10; // Fallback for search tree init, value doesn't really matter - multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", attackDamage, WizardryUtilities.Operations.ADD)); - multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", ATTACK_SPEED, WizardryUtilities.Operations.ADD)); - multimap.put(SharedMonsterAttributes.MOVEMENT_SPEED.getName(), new AttributeModifier(MOVEMENT_SPEED_MODIFIER, "Weapon modifier", MOVEMENT_SPEED_REDUCTION, WizardryUtilities.Operations.MULTIPLY_FLAT)); + multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", attackDamage, EntityUtils.Operations.ADD)); + multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", ATTACK_SPEED, EntityUtils.Operations.ADD)); + multimap.put(SharedMonsterAttributes.MOVEMENT_SPEED.getName(), new AttributeModifier(MOVEMENT_SPEED_MODIFIER, "Weapon modifier", MOVEMENT_SPEED_REDUCTION, EntityUtils.Operations.MULTIPLY_FLAT)); } return multimap; @@ -135,7 +135,7 @@ public class ItemLightningHammer extends Item implements IConjuredItem { world.spawnEntity(hammer); } - WizardryUtilities.playSoundAtPlayer(player, WizardrySounds.ENTITY_HAMMER_THROW, 1.0F, 0.8f); + EntityUtils.playSoundAtPlayer(player, WizardrySounds.ENTITY_HAMMER_THROW, 1.0F, 0.8f); //player.swingArm(hand); @@ -195,7 +195,7 @@ public class ItemLightningHammer extends Item implements IConjuredItem { if(attackStrength == 1){ // Only chains when the attack meter is full - List nearby = WizardryUtilities.getEntitiesWithinRadius(CHAINING_RANGE, hit.posX, hit.posY, hit.posZ, hit.world); + List nearby = EntityUtils.getEntitiesWithinRadius(CHAINING_RANGE, hit.posX, hit.posY, hit.posZ, hit.world); nearby.remove(hit); nearby.remove(wielder); diff --git a/src/main/java/electroblob/wizardry/item/ItemManaFlask.java b/src/main/java/electroblob/wizardry/item/ItemManaFlask.java index 8ecad4a1..2b7f9508 100644 --- a/src/main/java/electroblob/wizardry/item/ItemManaFlask.java +++ b/src/main/java/electroblob/wizardry/item/ItemManaFlask.java @@ -3,7 +3,8 @@ package electroblob.wizardry.item; import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.registry.WizardryTabs; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; +import electroblob.wizardry.util.InventoryUtils; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; @@ -61,7 +62,7 @@ public class ItemManaFlask extends Item { ItemStack flask = player.getHeldItem(hand); - List stacks = WizardryUtilities.getPrioritisedHotbarAndOffhand(player); + List stacks = InventoryUtils.getPrioritisedHotbarAndOffhand(player); stacks.addAll(player.inventory.armorInventory); // player#getArmorInventoryList() only returns an Iterable // Find the chargeable item with the least mana @@ -73,8 +74,8 @@ public class ItemManaFlask extends Item { ((IManaStoringItem)toCharge.getItem()).rechargeMana(toCharge, size.capacity); - WizardryUtilities.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_USE, 1, 1); - WizardryUtilities.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_RECHARGE, 0.7f, 1.1f); + EntityUtils.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_USE, 1, 1); + EntityUtils.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_RECHARGE, 0.7f, 1.1f); if(!player.isCreative()) flask.shrink(1); player.getCooldownTracker().setCooldown(this, 20); diff --git a/src/main/java/electroblob/wizardry/item/ItemSpectralSword.java b/src/main/java/electroblob/wizardry/item/ItemSpectralSword.java index 8a14bbab..a10764c7 100644 --- a/src/main/java/electroblob/wizardry/item/ItemSpectralSword.java +++ b/src/main/java/electroblob/wizardry/item/ItemSpectralSword.java @@ -2,7 +2,7 @@ package electroblob.wizardry.item; import com.google.common.collect.Multimap; import electroblob.wizardry.registry.Spells; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; @@ -35,7 +35,7 @@ public class ItemSpectralSword extends ItemSword implements IConjuredItem { if(slot == EntityEquipmentSlot.MAINHAND){ multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(POTENCY_MODIFIER, - "Potency modifier", IConjuredItem.getDamageMultiplier(stack) - 1, WizardryUtilities.Operations.MULTIPLY_CUMULATIVE)); + "Potency modifier", IConjuredItem.getDamageMultiplier(stack) - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); } return multimap; diff --git a/src/main/java/electroblob/wizardry/item/ItemWand.java b/src/main/java/electroblob/wizardry/item/ItemWand.java index a09a8300..f6ea7a7a 100644 --- a/src/main/java/electroblob/wizardry/item/ItemWand.java +++ b/src/main/java/electroblob/wizardry/item/ItemWand.java @@ -632,7 +632,7 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem, RayTraceResult rayTrace = RayTracer.standardEntityRayTrace(world, player, 16, false); - if(rayTrace != null && WizardryUtilities.isLiving(rayTrace.entityHit)){ + if(rayTrace != null && EntityUtils.isLiving(rayTrace.entityHit)){ EntityLivingBase entity = (EntityLivingBase)rayTrace.entityHit; diff --git a/src/main/java/electroblob/wizardry/item/ItemWizardArmour.java b/src/main/java/electroblob/wizardry/item/ItemWizardArmour.java index 5e9c6c91..ad2f0ff2 100644 --- a/src/main/java/electroblob/wizardry/item/ItemWizardArmour.java +++ b/src/main/java/electroblob/wizardry/item/ItemWizardArmour.java @@ -12,8 +12,8 @@ import electroblob.wizardry.registry.WizardryAdvancementTriggers; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryRecipes; import electroblob.wizardry.registry.WizardryTabs; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentMending; import net.minecraft.entity.Entity; @@ -271,13 +271,13 @@ public class ItemWizardArmour extends ItemArmor implements IWorkbenchItem, IMana if(event.getCaster() == null) return; int armourPieces = getMatchingArmourCount(event.getCaster(), event.getSpell().getElement()); float multiplier = 1f - armourPieces * Constants.COST_REDUCTION_PER_ARMOUR; - if(armourPieces == WizardryUtilities.ARMOUR_SLOTS.length) multiplier -= Constants.FULL_ARMOUR_SET_BONUS; + if(armourPieces == InventoryUtils.ARMOUR_SLOTS.length) multiplier -= Constants.FULL_ARMOUR_SET_BONUS; event.getModifiers().set(SpellModifiers.COST, event.getModifiers().get(SpellModifiers.COST) * multiplier, false); } /** Counts the number of armour pieces the given entity is wearing that match the given element. */ public static int getMatchingArmourCount(EntityLivingBase entity, Element element){ - return (int)Arrays.stream(WizardryUtilities.ARMOUR_SLOTS) + return (int)Arrays.stream(InventoryUtils.ARMOUR_SLOTS) .map(s -> entity.getItemStackFromSlot(s).getItem()) .filter(i -> i instanceof ItemWizardArmour && ((ItemWizardArmour)i).element == element) .count(); diff --git a/src/main/java/electroblob/wizardry/misc/Forfeit.java b/src/main/java/electroblob/wizardry/misc/Forfeit.java index 31d2c185..54a98178 100644 --- a/src/main/java/electroblob/wizardry/misc/Forfeit.java +++ b/src/main/java/electroblob/wizardry/misc/Forfeit.java @@ -15,7 +15,8 @@ import electroblob.wizardry.event.SpellCastEvent; import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.registry.*; import electroblob.wizardry.spell.Banish; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.BlockUtils; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.item.EntityFallingBlock; import net.minecraft.entity.passive.EntitySquid; @@ -173,7 +174,7 @@ public abstract class Forfeit { WizardryAdvancementTriggers.spell_failure.triggerFor(player); - WizardryUtilities.playSoundAtPlayer(player, forfeit.getSound(), WizardrySounds.SPELLS, 1, 1); + EntityUtils.playSoundAtPlayer(player, forfeit.getSound(), WizardrySounds.SPELLS, 1, 1); if(!event.getWorld().isRemote) player.sendMessage( event.getSource() == SpellCastEvent.Source.WAND ? forfeit.getMessageForWand() : forfeit.getMessageForScroll()); @@ -209,7 +210,7 @@ public abstract class Forfeit { add(Tier.ADVANCED, Element.FIRE, create("blazes", (w, p) -> { if(!w.isRemote){ for(int i = 0; i < 3; i++){ - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(p, 4, 2); + BlockPos pos = BlockUtils.findNearbyFloorSpace(p, 4, 2); if(pos == null) break; EntityBlazeMinion blaze = new EntityBlazeMinion(w); blaze.setPosition(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5); @@ -220,7 +221,7 @@ public abstract class Forfeit { add(Tier.MASTER, Element.FIRE, create("burn_surroundings", (w, p) -> { if(!w.isRemote){ - List sphere = WizardryUtilities.getBlockSphere(p.getPosition(), 6); + List sphere = BlockUtils.getBlockSphere(p.getPosition(), 6); for(BlockPos pos : sphere){ if(w.rand.nextBoolean() && w.isAirBlock(pos)) w.setBlockState(pos, Blocks.FIRE.getDefaultState()); } @@ -230,7 +231,7 @@ public abstract class Forfeit { add(Tier.MASTER, Element.FIRE, create("meteors", (w, p) -> { if(!w.isRemote) for(int i=0; i<5; i++) w.spawnEntity(new EntityMeteor(w, p.posX + w.rand.nextDouble() * 16 - 8, p.posY + 40 + w.rand.nextDouble() * 30, p.posZ + w.rand.nextDouble() * 16 - 8, - 1, WizardryUtilities.canDamageBlocks(p, w))); + 1, EntityUtils.canDamageBlocks(p, w))); })); add(Tier.NOVICE, Element.ICE, create("freeze_self", (w, p) -> p.addPotionEffect(new PotionEffect(WizardryPotions.frost, 200)))); @@ -243,8 +244,8 @@ public abstract class Forfeit { EntityIceSpike iceSpike = new EntityIceSpike(w); double x = p.posX + 2 - w.rand.nextFloat() * 4; double z = p.posZ + 2 - w.rand.nextFloat() * 4; - Integer y = WizardryUtilities.getNearestSurface(w, new BlockPos(x, p.posY, z), EnumFacing.UP, 2, true, - WizardryUtilities.SurfaceCriteria.basedOn(World::isBlockFullCube)); + Integer y = BlockUtils.getNearestSurface(w, new BlockPos(x, p.posY, z), EnumFacing.UP, 2, true, + BlockUtils.SurfaceCriteria.basedOn(World::isBlockFullCube)); if(y == null) break; iceSpike.setFacing(EnumFacing.UP); iceSpike.setPosition(x, y, z); @@ -264,7 +265,7 @@ public abstract class Forfeit { add(Tier.ADVANCED, Element.ICE, create("ice_wraiths", (w, p) -> { if(!w.isRemote){ for(int i = 0; i < 3; i++){ - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(p, 4, 2); + BlockPos pos = BlockUtils.findNearbyFloorSpace(p, 4, 2); if(pos == null) break; EntityIceWraith iceWraith = new EntityIceWraith(w); iceWraith.setPosition(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5); @@ -306,7 +307,7 @@ public abstract class Forfeit { if(!w.isRemote){ for(EnumFacing direction : EnumFacing.HORIZONTALS){ BlockPos pos = p.getPosition().offset(direction, 2); - Integer y = WizardryUtilities.getNearestFloor(w, pos, 2); + Integer y = BlockUtils.getNearestFloor(w, pos, 2); if(y == null) continue; EntityLightningSigil sigil = new EntityLightningSigil(w); sigil.setPosition(pos.getX() + 0.5, y, pos.getZ() + 0.5); @@ -322,7 +323,7 @@ public abstract class Forfeit { add(Tier.ADVANCED, Element.LIGHTNING, create("lightning_wraiths", (w, p) -> { if(!w.isRemote){ for(int i = 0; i < 3; i++){ - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(p, 4, 2); + BlockPos pos = BlockUtils.findNearbyFloorSpace(p, 4, 2); if(pos == null) break; EntityLightningWraith lightningWraith = new EntityLightningWraith(w); lightningWraith.setPosition(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5); @@ -347,7 +348,7 @@ public abstract class Forfeit { add(Tier.APPRENTICE, Element.NECROMANCY, create("zombie_horde", (w, p) -> { if(!w.isRemote){ for(int i = 0; i < 3; i++){ - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(p, 4, 2); + BlockPos pos = BlockUtils.findNearbyFloorSpace(p, 4, 2); if(pos == null) break; EntityZombieMinion zombie = new EntityZombieMinion(w); zombie.setPosition(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5); @@ -375,7 +376,7 @@ public abstract class Forfeit { if(!w.isRemote){ for(EnumFacing direction : EnumFacing.HORIZONTALS){ BlockPos pos = p.getPosition().offset(direction); - if(WizardryUtilities.canBlockBeReplaced(w, pos)) w.setBlockState(pos, WizardryBlocks.snare.getDefaultState()); + if(BlockUtils.canBlockBeReplaced(w, pos)) w.setBlockState(pos, WizardryBlocks.snare.getDefaultState()); } } })); @@ -390,7 +391,7 @@ public abstract class Forfeit { add(Tier.APPRENTICE, Element.EARTH, create("uproot_plants", (w, p) -> { if(!w.isRemote){ - List sphere = WizardryUtilities.getBlockSphere(p.getPosition(), 5); + List sphere = BlockUtils.getBlockSphere(p.getPosition(), 5); sphere.removeIf(pos -> !(w.getBlockState(pos).getBlock() instanceof IPlantable)); sphere.forEach(pos -> w.destroyBlock(pos, true)); } @@ -400,17 +401,17 @@ public abstract class Forfeit { add(Tier.ADVANCED, Element.EARTH, create("flood", (w, p) -> { if(!w.isRemote){ - List sphere = WizardryUtilities.getBlockSphere(p.getPosition().up(), 2); - sphere.removeIf(pos -> !WizardryUtilities.canBlockBeReplaced(w, pos, true)); + List sphere = BlockUtils.getBlockSphere(p.getPosition().up(), 2); + sphere.removeIf(pos -> !BlockUtils.canBlockBeReplaced(w, pos, true)); sphere.forEach(pos -> w.setBlockState(pos, Blocks.WATER.getDefaultState())); } })); add(Tier.MASTER, Element.EARTH, create("bury_self", (w, p) -> { if(!w.isRemote){ - List sphere = WizardryUtilities.getBlockSphere(p.getPosition(), 4); + List sphere = BlockUtils.getBlockSphere(p.getPosition(), 4); sphere.removeIf(pos -> !w.getBlockState(pos).isFullCube()); - sphere.removeIf(pos -> WizardryUtilities.isBlockUnbreakable(w, pos)); + sphere.removeIf(pos -> BlockUtils.isBlockUnbreakable(w, pos)); sphere.forEach(pos -> { EntityFallingBlock block = new EntityFallingBlock(w, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, w.getBlockState(pos)); @@ -437,7 +438,7 @@ public abstract class Forfeit { add(Tier.ADVANCED, Element.SORCERY, create("vex_horde", (w, p) -> { if(!w.isRemote){ for(int i = 0; i < 4; i++){ - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(p, 4, 2); + BlockPos pos = BlockUtils.findNearbyFloorSpace(p, 4, 2); if(pos == null) break; EntityVexMinion vex = new EntityVexMinion(w); vex.setPosition(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5); diff --git a/src/main/java/electroblob/wizardry/misc/WildcardTradeList.java b/src/main/java/electroblob/wizardry/misc/WildcardTradeList.java index 46d24d07..d03a376d 100644 --- a/src/main/java/electroblob/wizardry/misc/WildcardTradeList.java +++ b/src/main/java/electroblob/wizardry/misc/WildcardTradeList.java @@ -1,6 +1,6 @@ package electroblob.wizardry.misc; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.InventoryUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTUtil; @@ -74,18 +74,18 @@ public class WildcardTradeList extends MerchantRecipeList { for(MerchantRecipe merchantrecipe : this){ ItemStack itemToBuy = merchantrecipe.getItemToBuy(); - if(itemToBuy.getMetadata() == OreDictionary.WILDCARD_VALUE) itemToBuy = WizardryUtilities.copyWithMeta(itemToBuy, 0); + if(itemToBuy.getMetadata() == OreDictionary.WILDCARD_VALUE) itemToBuy = InventoryUtils.copyWithMeta(itemToBuy, 0); buffer.writeItemStack(itemToBuy); ItemStack itemToSell = merchantrecipe.getItemToSell(); - if(itemToSell.getMetadata() == OreDictionary.WILDCARD_VALUE) itemToSell = WizardryUtilities.copyWithMeta(itemToSell, 0); + if(itemToSell.getMetadata() == OreDictionary.WILDCARD_VALUE) itemToSell = InventoryUtils.copyWithMeta(itemToSell, 0); buffer.writeItemStack(itemToSell); ItemStack secondItemToBuy = merchantrecipe.getSecondItemToBuy(); buffer.writeBoolean(!secondItemToBuy.isEmpty()); if(!secondItemToBuy.isEmpty()){ - if(secondItemToBuy.getMetadata() == OreDictionary.WILDCARD_VALUE) secondItemToBuy = WizardryUtilities.copyWithMeta(secondItemToBuy, 0); + if(secondItemToBuy.getMetadata() == OreDictionary.WILDCARD_VALUE) secondItemToBuy = InventoryUtils.copyWithMeta(secondItemToBuy, 0); buffer.writeItemStack(secondItemToBuy); } diff --git a/src/main/java/electroblob/wizardry/packet/PacketControlInput.java b/src/main/java/electroblob/wizardry/packet/PacketControlInput.java index f06ae27c..152e89b4 100644 --- a/src/main/java/electroblob/wizardry/packet/PacketControlInput.java +++ b/src/main/java/electroblob/wizardry/packet/PacketControlInput.java @@ -7,8 +7,8 @@ import electroblob.wizardry.packet.PacketControlInput.Message; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.spell.Possession; import electroblob.wizardry.spell.Resurrection; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -75,7 +75,7 @@ public class PacketControlInput implements IMessageHandler { if(player.isDead && Resurrection.getRemainingWaitTime(player.deathTime) == 0){ - ItemStack stack = WizardryUtilities.getHotbar(player).stream() + ItemStack stack = InventoryUtils.getHotbar(player).stream() .filter(s -> Resurrection.canStackResurrect(s, player)).findFirst().orElse(null); if(stack != null){ @@ -96,7 +96,7 @@ public class PacketControlInput implements IMessageHandler { if(player.isDead){ - ItemStack stack = WizardryUtilities.getHotbar(player).stream() + ItemStack stack = InventoryUtils.getHotbar(player).stream() .filter(s -> Resurrection.canStackResurrect(s, player)).findFirst().orElse(null); if(stack != null){ diff --git a/src/main/java/electroblob/wizardry/potion/PotionContainment.java b/src/main/java/electroblob/wizardry/potion/PotionContainment.java index 46188438..a29e9831 100644 --- a/src/main/java/electroblob/wizardry/potion/PotionContainment.java +++ b/src/main/java/electroblob/wizardry/potion/PotionContainment.java @@ -2,8 +2,9 @@ package electroblob.wizardry.potion; import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.WizardryPotions; +import electroblob.wizardry.util.EntityUtils; +import electroblob.wizardry.util.GeometryUtils; import electroblob.wizardry.util.NBTExtras; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTUtil; @@ -44,7 +45,7 @@ public class PotionContainment extends PotionMagicEffect { NBTExtras.storeTagSafely(target.getEntityData(), ENTITY_TAG, NBTUtil.createPosTag(new BlockPos(target.getPositionVector().subtract(0.5, 0.5, 0.5)))); } - Vec3d origin = WizardryUtilities.getCentre(NBTUtil.getPosFromTag(target.getEntityData().getCompoundTag(ENTITY_TAG))); + Vec3d origin = GeometryUtils.getCentre(NBTUtil.getPosFromTag(target.getEntityData().getCompoundTag(ENTITY_TAG))); double x = target.posX, y = target.posY, z = target.posZ; @@ -93,7 +94,7 @@ public class PotionContainment extends PotionMagicEffect { // } // } - WizardryUtilities.undoGravity(target); + EntityUtils.undoGravity(target); target.addVelocity(0.35 * Math.signum(x - target.posX), 0.35 * Math.signum(y - target.posY), 0.35 * Math.signum(z - target.posZ)); target.setPositionAndUpdate(x, y, z); // Player motion is handled on that player's client so needs packets diff --git a/src/main/java/electroblob/wizardry/potion/PotionFrostStep.java b/src/main/java/electroblob/wizardry/potion/PotionFrostStep.java index 57057cd9..3bdeee3f 100644 --- a/src/main/java/electroblob/wizardry/potion/PotionFrostStep.java +++ b/src/main/java/electroblob/wizardry/potion/PotionFrostStep.java @@ -5,16 +5,14 @@ import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; -import net.minecraft.block.BlockLiquid; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.enchantment.EnchantmentFrostWalker; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; @@ -104,7 +102,7 @@ public class PotionFrostStep extends PotionMagicEffect implements ICustomPotionP IBlockState state2 = world.getBlockState(pos2); - if(WizardryUtilities.isLavaSource(state2) && world.mayPlace(WizardryBlocks.obsidian_crust, pos2, false, EnumFacing.DOWN, null)){ + if(BlockUtils.isLavaSource(state2) && world.mayPlace(WizardryBlocks.obsidian_crust, pos2, false, EnumFacing.DOWN, null)){ world.setBlockState(pos2, WizardryBlocks.obsidian_crust.getDefaultState()); world.scheduleUpdate(pos2.toImmutable(), WizardryBlocks.obsidian_crust, MathHelper.getInt(living.getRNG(), 60, 120)); } diff --git a/src/main/java/electroblob/wizardry/potion/PotionSlowTime.java b/src/main/java/electroblob/wizardry/potion/PotionSlowTime.java index e767be5c..330f1a37 100644 --- a/src/main/java/electroblob/wizardry/potion/PotionSlowTime.java +++ b/src/main/java/electroblob/wizardry/potion/PotionSlowTime.java @@ -7,8 +7,8 @@ import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.spell.SlowTime; import electroblob.wizardry.spell.Spell; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IProjectile; @@ -43,7 +43,7 @@ public class PotionSlowTime extends PotionMagicEffect implements ISyncedPotion { } public static void unblockNearbyEntities(EntityLivingBase host){ - List targetsBeyondRange = WizardryUtilities.getEntitiesWithinRadius(getEffectRadius() + 3, host.posX, host.posY, host.posZ, host.world, Entity.class); + List targetsBeyondRange = EntityUtils.getEntitiesWithinRadius(getEffectRadius() + 3, host.posX, host.posY, host.posZ, host.world, Entity.class); targetsBeyondRange.forEach(e -> e.updateBlocked = false); } @@ -56,7 +56,7 @@ public class PotionSlowTime extends PotionMagicEffect implements ISyncedPotion { int interval = strength * 4 + 6; // Mark all entities within range - List targetsInRange = WizardryUtilities.getEntitiesWithinRadius(getEffectRadius(), host.posX, host.posY, host.posZ, host.world, Entity.class); + List targetsInRange = EntityUtils.getEntitiesWithinRadius(getEffectRadius(), host.posX, host.posY, host.posZ, host.world, Entity.class); targetsInRange.remove(host); // Other entities with the slow time effect are unaffected targetsInRange.removeIf(t -> t instanceof EntityLivingBase && ((EntityLivingBase)t).isPotionActive(WizardryPotions.slow_time)); @@ -130,7 +130,7 @@ public class PotionSlowTime extends PotionMagicEffect implements ISyncedPotion { } // Un-mark all entities that have just left range - List targetsBeyondRange = WizardryUtilities.getEntitiesWithinRadius(getEffectRadius() + 3, host.posX, host.posY, host.posZ, host.world, Entity.class); + List targetsBeyondRange = EntityUtils.getEntitiesWithinRadius(getEffectRadius() + 3, host.posX, host.posY, host.posZ, host.world, Entity.class); targetsBeyondRange.removeAll(targetsInRange); targetsBeyondRange.forEach(e -> e.updateBlocked = false); @@ -150,7 +150,7 @@ public class PotionSlowTime extends PotionMagicEffect implements ISyncedPotion { for(Entity entity : loadedEntityList){ if(entity.getEntityData().getBoolean(NBT_KEY)){ // Currently only players can cast slow time, but you could apply the effect to NPCs with commands - List nearby = WizardryUtilities.getEntitiesWithinRadius(getEffectRadius(), entity.posX, entity.posY, entity.posZ, entity.world, EntityLivingBase.class); + List nearby = EntityUtils.getEntitiesWithinRadius(getEffectRadius(), entity.posX, entity.posY, entity.posZ, entity.world, EntityLivingBase.class); if(nearby.stream().noneMatch(e -> e.isPotionActive(WizardryPotions.slow_time))){ entity.getEntityData().removeTag(NBT_KEY); entity.updateBlocked = false; diff --git a/src/main/java/electroblob/wizardry/registry/WizardryEnchantments.java b/src/main/java/electroblob/wizardry/registry/WizardryEnchantments.java index 7c3014b0..9f33c8f3 100644 --- a/src/main/java/electroblob/wizardry/registry/WizardryEnchantments.java +++ b/src/main/java/electroblob/wizardry/registry/WizardryEnchantments.java @@ -4,7 +4,7 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.enchantment.EnchantmentMagicProtection; import electroblob.wizardry.enchantment.EnchantmentMagicSword; import electroblob.wizardry.enchantment.EnchantmentTimed; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.InventoryUtils; import net.minecraft.enchantment.Enchantment; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod; @@ -56,9 +56,9 @@ public final class WizardryEnchantments { event.getRegistry().register(new EnchantmentTimed().setRegistryName(Wizardry.MODID, "flaming_weapon")); event.getRegistry().register(new EnchantmentTimed().setRegistryName(Wizardry.MODID, "freezing_weapon")); - event.getRegistry().register(new EnchantmentMagicProtection(Enchantment.Rarity.UNCOMMON, EnchantmentMagicProtection.Type.MAGIC, WizardryUtilities.ARMOUR_SLOTS).setRegistryName(Wizardry.MODID, "magic_protection")); - event.getRegistry().register(new EnchantmentMagicProtection(Enchantment.Rarity.RARE, EnchantmentMagicProtection.Type.FROST, WizardryUtilities.ARMOUR_SLOTS).setRegistryName(Wizardry.MODID, "frost_protection")); - event.getRegistry().register(new EnchantmentMagicProtection(Enchantment.Rarity.RARE, EnchantmentMagicProtection.Type.SHOCK, WizardryUtilities.ARMOUR_SLOTS).setRegistryName(Wizardry.MODID, "shock_protection")); + event.getRegistry().register(new EnchantmentMagicProtection(Enchantment.Rarity.UNCOMMON, EnchantmentMagicProtection.Type.MAGIC, InventoryUtils.ARMOUR_SLOTS).setRegistryName(Wizardry.MODID, "magic_protection")); + event.getRegistry().register(new EnchantmentMagicProtection(Enchantment.Rarity.RARE, EnchantmentMagicProtection.Type.FROST, InventoryUtils.ARMOUR_SLOTS).setRegistryName(Wizardry.MODID, "frost_protection")); + event.getRegistry().register(new EnchantmentMagicProtection(Enchantment.Rarity.RARE, EnchantmentMagicProtection.Type.SHOCK, InventoryUtils.ARMOUR_SLOTS).setRegistryName(Wizardry.MODID, "shock_protection")); } } diff --git a/src/main/java/electroblob/wizardry/spell/Arc.java b/src/main/java/electroblob/wizardry/spell/Arc.java index ab961d1c..a0871c5f 100644 --- a/src/main/java/electroblob/wizardry/spell/Arc.java +++ b/src/main/java/electroblob/wizardry/spell/Arc.java @@ -1,12 +1,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -28,7 +25,7 @@ public class Arc extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(world.isRemote){ // Rather neatly, the entity can be set here and if it's null nothing will happen. diff --git a/src/main/java/electroblob/wizardry/spell/ArcaneJammer.java b/src/main/java/electroblob/wizardry/spell/ArcaneJammer.java index c3478ddf..1be4d779 100644 --- a/src/main/java/electroblob/wizardry/spell/ArcaneJammer.java +++ b/src/main/java/electroblob/wizardry/spell/ArcaneJammer.java @@ -8,10 +8,10 @@ import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntitySpellcasterIllager; @@ -54,7 +54,7 @@ public class ArcaneJammer extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(!world.isRemote){ ((EntityLivingBase)target).addPotionEffect(new PotionEffect(WizardryPotions.arcane_jammer, (int)(getProperty(EFFECT_DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade)), diff --git a/src/main/java/electroblob/wizardry/spell/ArcaneLock.java b/src/main/java/electroblob/wizardry/spell/ArcaneLock.java index 6d22d37a..79cf8ee1 100644 --- a/src/main/java/electroblob/wizardry/spell/ArcaneLock.java +++ b/src/main/java/electroblob/wizardry/spell/ArcaneLock.java @@ -2,10 +2,7 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.SpellActions; -import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.NBTExtras; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.*; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -49,7 +46,7 @@ public class ArcaneLock extends SpellRay { if(caster instanceof EntityPlayer){ if(toggleLock(world, pos, (EntityPlayer)caster)){ - BlockPos otherHalf = WizardryUtilities.getConnectedChest(world, pos); + BlockPos otherHalf = BlockUtils.getConnectedChest(world, pos); if(otherHalf != null) toggleLock(world, otherHalf, (EntityPlayer)caster); return true; } @@ -133,7 +130,7 @@ public class ArcaneLock extends SpellRay { if(!player.isCreative()) return false; if(Wizardry.settings.creativeBypassesArcaneLock) return true; MinecraftServer server = player.world.getMinecraftServer(); - return server != null && WizardryUtilities.isPlayerOp(player, server); + return server != null && EntityUtils.isPlayerOp(player, server); } @SubscribeEvent diff --git a/src/main/java/electroblob/wizardry/spell/Banish.java b/src/main/java/electroblob/wizardry/spell/Banish.java index 50cd6701..204d7a41 100644 --- a/src/main/java/electroblob/wizardry/spell/Banish.java +++ b/src/main/java/electroblob/wizardry/spell/Banish.java @@ -3,10 +3,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -67,7 +67,7 @@ public class Banish extends SpellRay { int x = MathHelper.floor(entity.posX + MathHelper.sin(angle) * radius); int z = MathHelper.floor(entity.posZ - MathHelper.cos(angle) * radius); - Integer y = WizardryUtilities.getNearestFloor(world, + Integer y = BlockUtils.getNearestFloor(world, new BlockPos(x, (int)entity.getEntityBoundingBox().minY, z), (int)radius); if(world.isRemote){ diff --git a/src/main/java/electroblob/wizardry/spell/Blink.java b/src/main/java/electroblob/wizardry/spell/Blink.java index 841b025b..01c63c46 100644 --- a/src/main/java/electroblob/wizardry/spell/Blink.java +++ b/src/main/java/electroblob/wizardry/spell/Blink.java @@ -3,9 +3,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.RayTracer; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -90,7 +90,7 @@ public class Blink extends Spell { int x = MathHelper.floor(target.posX + MathHelper.sin(angle) * radius); int z = MathHelper.floor(target.posZ - MathHelper.cos(angle) * radius); - Integer y = WizardryUtilities.getNearestFloor(world, new BlockPos(caster), (int)radius); + Integer y = BlockUtils.getNearestFloor(world, new BlockPos(caster), (int)radius); // It's worth noting that on the client side, the cast() method only gets called if the server side // cast method succeeded, so you need not check any conditions for spawning particles. diff --git a/src/main/java/electroblob/wizardry/spell/Bubble.java b/src/main/java/electroblob/wizardry/spell/Bubble.java index 499b4ca0..dd689a33 100644 --- a/src/main/java/electroblob/wizardry/spell/Bubble.java +++ b/src/main/java/electroblob/wizardry/spell/Bubble.java @@ -3,12 +3,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.entity.construct.EntityBubble; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; @@ -34,7 +31,7 @@ public class Bubble extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(!world.isRemote){ // Deals a small amount damage so the target counts as being hit by the caster diff --git a/src/main/java/electroblob/wizardry/spell/ChainLightning.java b/src/main/java/electroblob/wizardry/spell/ChainLightning.java index 1a31f86f..fe0fcfb0 100644 --- a/src/main/java/electroblob/wizardry/spell/ChainLightning.java +++ b/src/main/java/electroblob/wizardry/spell/ChainLightning.java @@ -40,17 +40,17 @@ public class ChainLightning extends SpellRay { // Anything can be attacked with the initial arc, because the player has control over where it goes. If they // hit a minion or an ally, it's their problem! - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ electrocute(world, caster, origin, target, getProperty(PRIMARY_DAMAGE).floatValue() * modifiers.get(SpellModifiers.POTENCY)); // Secondary chaining effect - List secondaryTargets = WizardryUtilities.getEntitiesWithinRadius( + List secondaryTargets = EntityUtils.getEntitiesWithinRadius( getProperty(SECONDARY_RANGE).doubleValue(), target.posX, target.posY + target.height / 2, target.posZ, world); secondaryTargets.remove(target); - secondaryTargets.removeIf(e -> !WizardryUtilities.isLiving(e)); + secondaryTargets.removeIf(e -> !EntityUtils.isLiving(e)); secondaryTargets.removeIf(e -> !AllyDesignationSystem.isValidTarget(caster, e)); if(secondaryTargets.size() > getProperty(SECONDARY_MAX_TARGETS).intValue()) secondaryTargets = secondaryTargets.subList(0, getProperty(SECONDARY_MAX_TARGETS).intValue()); @@ -62,13 +62,13 @@ public class ChainLightning extends SpellRay { // Tertiary chaining effect - List tertiaryTargets = WizardryUtilities.getEntitiesWithinRadius( + List tertiaryTargets = EntityUtils.getEntitiesWithinRadius( getProperty(TERTIARY_RANGE).doubleValue(), secondaryTarget.posX, secondaryTarget.posY + secondaryTarget.height / 2, secondaryTarget.posZ, world); tertiaryTargets.remove(target); tertiaryTargets.removeAll(secondaryTargets); - tertiaryTargets.removeIf(e -> !WizardryUtilities.isLiving(e)); + tertiaryTargets.removeIf(e -> !EntityUtils.isLiving(e)); tertiaryTargets.removeIf(e -> !AllyDesignationSystem.isValidTarget(caster, e)); if(tertiaryTargets.size() > getProperty(TERTIARY_MAX_TARGETS).intValue()) tertiaryTargets = tertiaryTargets.subList(0, getProperty(TERTIARY_MAX_TARGETS).intValue()); diff --git a/src/main/java/electroblob/wizardry/spell/Charge.java b/src/main/java/electroblob/wizardry/spell/Charge.java index 20725625..bed1ce9f 100644 --- a/src/main/java/electroblob/wizardry/spell/Charge.java +++ b/src/main/java/electroblob/wizardry/spell/Charge.java @@ -6,11 +6,8 @@ import electroblob.wizardry.data.WizardData; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.SoundEvents; @@ -94,7 +91,7 @@ public class Charge extends Spell { if(collided.isEmpty()) chargeTime--; else{ - WizardryUtilities.playSoundAtPlayer(player, SoundEvents.ENTITY_GENERIC_HURT, 1, 1); + EntityUtils.playSoundAtPlayer(player, SoundEvents.ENTITY_GENERIC_HURT, 1, 1); chargeTime = 0; } } diff --git a/src/main/java/electroblob/wizardry/spell/Cobwebs.java b/src/main/java/electroblob/wizardry/spell/Cobwebs.java index 857f7317..d1af5d61 100644 --- a/src/main/java/electroblob/wizardry/spell/Cobwebs.java +++ b/src/main/java/electroblob/wizardry/spell/Cobwebs.java @@ -5,8 +5,8 @@ import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.tileentity.TileEntityTimer; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; @@ -42,7 +42,7 @@ public class Cobwebs extends SpellRay { float radius = getProperty(EFFECT_RADIUS).floatValue() + 0.73f * blastUpgradeCount; - List sphere = WizardryUtilities.getBlockSphere(pos, radius * modifiers.get(WizardryItems.blast_upgrade)); + List sphere = BlockUtils.getBlockSphere(pos, radius * modifiers.get(WizardryItems.blast_upgrade)); for(BlockPos pos1 : sphere){ diff --git a/src/main/java/electroblob/wizardry/spell/ConjureArmour.java b/src/main/java/electroblob/wizardry/spell/ConjureArmour.java index bc62c719..b180ad29 100644 --- a/src/main/java/electroblob/wizardry/spell/ConjureArmour.java +++ b/src/main/java/electroblob/wizardry/spell/ConjureArmour.java @@ -3,9 +3,9 @@ package electroblob.wizardry.spell; import com.google.common.collect.ImmutableMap; import electroblob.wizardry.item.IConjuredItem; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.NBTExtras; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.Item; @@ -33,10 +33,10 @@ public class ConjureArmour extends SpellConjuration { boolean flag = false; // Used this rather than getArmorInventoryList because I need to access the slot itself - for(EntityEquipmentSlot slot : WizardryUtilities.ARMOUR_SLOTS){ + for(EntityEquipmentSlot slot : InventoryUtils.ARMOUR_SLOTS){ if(caster.getItemStackFromSlot(slot).isEmpty() && - !WizardryUtilities.doesPlayerHaveItem(caster, SPECTRAL_ARMOUR_MAP.get(slot))){ + !InventoryUtils.doesPlayerHaveItem(caster, SPECTRAL_ARMOUR_MAP.get(slot))){ armour = new ItemStack(SPECTRAL_ARMOUR_MAP.get(slot)); IConjuredItem.setDurationMultiplier(armour, modifiers.get(WizardryItems.duration_upgrade)); diff --git a/src/main/java/electroblob/wizardry/spell/ConjureBlock.java b/src/main/java/electroblob/wizardry/spell/ConjureBlock.java index c4a3bc56..31fc12b2 100644 --- a/src/main/java/electroblob/wizardry/spell/ConjureBlock.java +++ b/src/main/java/electroblob/wizardry/spell/ConjureBlock.java @@ -4,10 +4,10 @@ import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.tileentity.TileEntityTimer; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; @@ -53,7 +53,7 @@ public class ConjureBlock extends SpellRay { .clr(0.75f, 1, 0.85f).spawn(world); } - if(WizardryUtilities.canBlockBeReplaced(world, pos)){ + if(BlockUtils.canBlockBeReplaced(world, pos)){ if(!world.isRemote){ diff --git a/src/main/java/electroblob/wizardry/spell/Containment.java b/src/main/java/electroblob/wizardry/spell/Containment.java index ddedbe53..0353bf2d 100644 --- a/src/main/java/electroblob/wizardry/spell/Containment.java +++ b/src/main/java/electroblob/wizardry/spell/Containment.java @@ -3,10 +3,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.potion.PotionEffect; @@ -26,7 +26,7 @@ public class Containment extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ ((EntityLivingBase)target).addPotionEffect(new PotionEffect(WizardryPotions.containment, (int)(getProperty(EFFECT_DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade)), getProperty(EFFECT_STRENGTH).intValue() + SpellBuff.getStandardBonusAmplifier(modifiers.get(SpellModifiers.POTENCY)))); diff --git a/src/main/java/electroblob/wizardry/spell/CurseOfEnfeeblement.java b/src/main/java/electroblob/wizardry/spell/CurseOfEnfeeblement.java index 29fcc938..dfa5ab0b 100644 --- a/src/main/java/electroblob/wizardry/spell/CurseOfEnfeeblement.java +++ b/src/main/java/electroblob/wizardry/spell/CurseOfEnfeeblement.java @@ -2,11 +2,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryPotions; -import electroblob.wizardry.util.MagicDamage; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.potion.PotionEffect; @@ -26,7 +23,7 @@ public class CurseOfEnfeeblement extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ // This will actually run out in the end, but only if you leave Minecraft running for 3.4 years ((EntityLivingBase)target).addPotionEffect(new PotionEffect(WizardryPotions.curse_of_enfeeblement, Integer.MAX_VALUE, getProperty(EFFECT_STRENGTH).intValue() + SpellBuff.getStandardBonusAmplifier(modifiers.get(SpellModifiers.POTENCY)))); diff --git a/src/main/java/electroblob/wizardry/spell/CurseOfSoulbinding.java b/src/main/java/electroblob/wizardry/spell/CurseOfSoulbinding.java index e36bbc36..a86bf721 100644 --- a/src/main/java/electroblob/wizardry/spell/CurseOfSoulbinding.java +++ b/src/main/java/electroblob/wizardry/spell/CurseOfSoulbinding.java @@ -54,7 +54,7 @@ public class CurseOfSoulbinding extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target) && caster instanceof EntityPlayer){ + if(EntityUtils.isLiving(target) && caster instanceof EntityPlayer){ WizardData data = WizardData.get((EntityPlayer)caster); if(data != null){ // Return false if soulbinding failed (e.g. if the target is already soulbound) @@ -101,7 +101,7 @@ public class CurseOfSoulbinding extends SpellRay { for(Iterator iterator = getSoulboundCreatures(data).iterator(); iterator.hasNext();){ - Entity entity = WizardryUtilities.getEntityByUUID(player.world, iterator.next()); + Entity entity = EntityUtils.getEntityByUUID(player.world, iterator.next()); if(entity == null) iterator.remove(); diff --git a/src/main/java/electroblob/wizardry/spell/CurseOfUndeath.java b/src/main/java/electroblob/wizardry/spell/CurseOfUndeath.java index eec32c73..61147792 100644 --- a/src/main/java/electroblob/wizardry/spell/CurseOfUndeath.java +++ b/src/main/java/electroblob/wizardry/spell/CurseOfUndeath.java @@ -2,10 +2,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryPotions; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.potion.PotionEffect; @@ -25,7 +25,7 @@ public class CurseOfUndeath extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ // This will actually run out in the end, but only if you leave Minecraft running for 3.4 years ((EntityLivingBase)target).addPotionEffect(new PotionEffect(WizardryPotions.curse_of_undeath, Integer.MAX_VALUE, diff --git a/src/main/java/electroblob/wizardry/spell/Decay.java b/src/main/java/electroblob/wizardry/spell/Decay.java index 119b7b79..be660d3b 100644 --- a/src/main/java/electroblob/wizardry/spell/Decay.java +++ b/src/main/java/electroblob/wizardry/spell/Decay.java @@ -2,8 +2,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.entity.construct.EntityDecay; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -37,7 +37,7 @@ public class Decay extends SpellConstructRanged { int verticalRange = (int)(6 * modifiers.get(WizardryItems.blast_upgrade)); for(int i=0; i targets = WizardryUtilities.getEntitiesWithinRadius(getProperty(BLAST_RADIUS).doubleValue() + List targets = EntityUtils.getEntitiesWithinRadius(getProperty(BLAST_RADIUS).doubleValue() * modifiers.get(WizardryItems.blast_upgrade), pos.getX(), pos.getY(), pos.getZ(), world); for(EntityLivingBase target : targets){ diff --git a/src/main/java/electroblob/wizardry/spell/Disintegration.java b/src/main/java/electroblob/wizardry/spell/Disintegration.java index be3a59ff..4cfa3eae 100644 --- a/src/main/java/electroblob/wizardry/spell/Disintegration.java +++ b/src/main/java/electroblob/wizardry/spell/Disintegration.java @@ -3,12 +3,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.entity.projectile.EntityEmber; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -41,7 +38,7 @@ public class Disintegration extends SpellRay { }else{ target.setFire((int)(getProperty(BURN_DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade))); - WizardryUtilities.attackEntityWithoutKnockback(target, caster == null ? DamageSource.MAGIC : + EntityUtils.attackEntityWithoutKnockback(target, caster == null ? DamageSource.MAGIC : MagicDamage.causeDirectMagicDamage(caster, DamageType.FIRE), getProperty(DAMAGE).floatValue() * modifiers.get(SpellModifiers.POTENCY)); @@ -90,7 +87,7 @@ public class Disintegration extends SpellRay { } if(world.getBlockState(pos).getMaterial().isSolid()){ - Vec3d vec = hit.add(new Vec3d(side.getDirectionVec()).scale(WizardryUtilities.ANTI_Z_FIGHTING_OFFSET)); + Vec3d vec = hit.add(new Vec3d(side.getDirectionVec()).scale(GeometryUtils.ANTI_Z_FIGHTING_OFFSET)); ParticleBuilder.create(Type.SCORCH).pos(vec).face(side).clr(1, 0.2f, 0).spawn(world); } } diff --git a/src/main/java/electroblob/wizardry/spell/Divination.java b/src/main/java/electroblob/wizardry/spell/Divination.java index be21e09f..78d6421f 100644 --- a/src/main/java/electroblob/wizardry/spell/Divination.java +++ b/src/main/java/electroblob/wizardry/spell/Divination.java @@ -5,10 +5,7 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.block.BlockCrystalOre; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.ParticleBuilder; -import electroblob.wizardry.util.RelativeFacing; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.*; import net.minecraft.block.Block; import net.minecraft.block.BlockOre; import net.minecraft.block.BlockRedstoneOre; @@ -64,7 +61,7 @@ public class Divination extends Spell { double range = getProperty(RANGE).floatValue() * modifiers.get(WizardryItems.range_upgrade); - List sphere = WizardryUtilities.getBlockSphere(caster.getPosition(), range); + List sphere = BlockUtils.getBlockSphere(caster.getPosition(), range); sphere.removeIf(b -> { Block block = world.getBlockState(b).getBlock(); diff --git a/src/main/java/electroblob/wizardry/spell/Earthquake.java b/src/main/java/electroblob/wizardry/spell/Earthquake.java index 50c7f901..c4164392 100644 --- a/src/main/java/electroblob/wizardry/spell/Earthquake.java +++ b/src/main/java/electroblob/wizardry/spell/Earthquake.java @@ -4,8 +4,9 @@ import electroblob.wizardry.entity.construct.EntityEarthquake; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; + import electroblob.wizardry.util.BlockUtils; + import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; - import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; @@ -51,12 +52,12 @@ particleX = x - 1.0d + 2 * world.rand.nextDouble(); particleZ = z - 1.0d + 2 * world.rand.nextDouble(); - IBlockState block = WizardryUtilities.getBlockEntityIsStandingOn(caster); + IBlockState block = BlockUtils.getBlockEntityIsStandingOn(caster); world.spawnParticle(EnumParticleTypes.BLOCK_DUST, particleX, y, particleZ, particleX - x, 0, particleZ - z, Block.getStateId(block)); } - WizardryUtilities.getEntitiesWithinRadius(15, x, y, z, world, EntityPlayer.class) + EntityUtils.getEntitiesWithinRadius(15, x, y, z, world, EntityPlayer.class) .forEach(p -> Wizardry.proxy.shakeScreen(p, 12)); } diff --git a/src/main/java/electroblob/wizardry/spell/EmpoweringPresence.java b/src/main/java/electroblob/wizardry/spell/EmpoweringPresence.java index 833d2cb5..01928e33 100644 --- a/src/main/java/electroblob/wizardry/spell/EmpoweringPresence.java +++ b/src/main/java/electroblob/wizardry/spell/EmpoweringPresence.java @@ -6,11 +6,8 @@ import electroblob.wizardry.event.SpellCastEvent; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; -import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.PotionEffect; import net.minecraft.util.EnumHand; @@ -33,7 +30,7 @@ public class EmpoweringPresence extends Spell { @Override public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){ - List targets = WizardryUtilities.getEntitiesWithinRadius(getProperty(EFFECT_RADIUS).doubleValue() + List targets = EntityUtils.getEntitiesWithinRadius(getProperty(EFFECT_RADIUS).doubleValue() * modifiers.get(WizardryItems.blast_upgrade), caster.posX, caster.posY, caster.posZ, world, EntityPlayer.class); for(EntityPlayer target : targets){ diff --git a/src/main/java/electroblob/wizardry/spell/Entrapment.java b/src/main/java/electroblob/wizardry/spell/Entrapment.java index 107eba36..484052c4 100644 --- a/src/main/java/electroblob/wizardry/spell/Entrapment.java +++ b/src/main/java/electroblob/wizardry/spell/Entrapment.java @@ -3,12 +3,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.entity.construct.EntityBubble; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; @@ -30,7 +27,7 @@ public class Entrapment extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(!world.isRemote){ // Deals a small amount damage so the target counts as being hit by the caster diff --git a/src/main/java/electroblob/wizardry/spell/FireBreath.java b/src/main/java/electroblob/wizardry/spell/FireBreath.java index 3f514e68..e8ae6410 100644 --- a/src/main/java/electroblob/wizardry/spell/FireBreath.java +++ b/src/main/java/electroblob/wizardry/spell/FireBreath.java @@ -2,12 +2,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -58,7 +55,7 @@ public class FireBreath extends SpellRay { // with this mechanic for their own purposes, so this line makes sure that doesn't affect wizardry. }else if(ticksInUse % ((EntityLivingBase)target).maxHurtResistantTime == 1){ target.setFire((int)(getProperty(BURN_DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade))); - WizardryUtilities.attackEntityWithoutKnockback(target, + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeDirectMagicDamage(caster, DamageType.FIRE), getProperty(DAMAGE).floatValue() * modifiers.get(SpellModifiers.POTENCY)); } @@ -70,7 +67,7 @@ public class FireBreath extends SpellRay { @Override protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(!WizardryUtilities.canDamageBlocks(caster, world)) return false; + if(!EntityUtils.canDamageBlocks(caster, world)) return false; pos = pos.offset(side); diff --git a/src/main/java/electroblob/wizardry/spell/FlameRay.java b/src/main/java/electroblob/wizardry/spell/FlameRay.java index c96aaa57..74e7ba24 100644 --- a/src/main/java/electroblob/wizardry/spell/FlameRay.java +++ b/src/main/java/electroblob/wizardry/spell/FlameRay.java @@ -2,12 +2,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -58,7 +55,7 @@ public class FlameRay extends SpellRay { // with this mechanic for their own purposes, so this line makes sure that doesn't affect wizardry. }else if(ticksInUse % ((EntityLivingBase)target).maxHurtResistantTime == 1){ target.setFire((int)(getProperty(BURN_DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade))); - WizardryUtilities.attackEntityWithoutKnockback(target, + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeDirectMagicDamage(caster, DamageType.FIRE), getProperty(DAMAGE).floatValue() * modifiers.get(SpellModifiers.POTENCY)); } diff --git a/src/main/java/electroblob/wizardry/spell/FlamingWeapon.java b/src/main/java/electroblob/wizardry/spell/FlamingWeapon.java index 6fbfcd61..1a02fa3b 100644 --- a/src/main/java/electroblob/wizardry/spell/FlamingWeapon.java +++ b/src/main/java/electroblob/wizardry/spell/FlamingWeapon.java @@ -5,10 +5,10 @@ import electroblob.wizardry.data.WizardData; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryEnchantments; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -29,7 +29,7 @@ public class FlamingWeapon extends Spell { if(WizardData.get(caster) != null && WizardData.get(caster).getImbuementDuration(WizardryEnchantments.flaming_weapon) <= 0){ - for(ItemStack stack : WizardryUtilities.getPrioritisedHotbarAndOffhand(caster)){ + for(ItemStack stack : InventoryUtils.getPrioritisedHotbarAndOffhand(caster)){ if((ImbueWeapon.isSword(stack) || ImbueWeapon.isBow(stack)) && !EnchantmentHelper.getEnchantments(stack).containsKey(WizardryEnchantments.flaming_weapon)){ diff --git a/src/main/java/electroblob/wizardry/spell/FontOfMana.java b/src/main/java/electroblob/wizardry/spell/FontOfMana.java index abf10b97..fdb2a977 100644 --- a/src/main/java/electroblob/wizardry/spell/FontOfMana.java +++ b/src/main/java/electroblob/wizardry/spell/FontOfMana.java @@ -4,11 +4,8 @@ import electroblob.wizardry.event.SpellCastEvent; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; -import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.PotionEffect; import net.minecraft.util.EnumHand; @@ -32,7 +29,7 @@ public class FontOfMana extends Spell { double maxRadius = getProperty(EFFECT_RADIUS).doubleValue(); - List targets = WizardryUtilities.getEntitiesWithinRadius( + List targets = EntityUtils.getEntitiesWithinRadius( maxRadius * modifiers.get(WizardryItems.blast_upgrade), caster.posX, caster.posY, caster.posZ, world, EntityPlayer.class); diff --git a/src/main/java/electroblob/wizardry/spell/ForestOfThorns.java b/src/main/java/electroblob/wizardry/spell/ForestOfThorns.java index 805977f3..1afe4123 100644 --- a/src/main/java/electroblob/wizardry/spell/ForestOfThorns.java +++ b/src/main/java/electroblob/wizardry/spell/ForestOfThorns.java @@ -5,8 +5,8 @@ import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.tileentity.TileEntityPlayerSaveTimed; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -70,7 +70,7 @@ public class ForestOfThorns extends Spell { if(distance > radius || distance < radius - 1.5) continue; - Integer y = WizardryUtilities.getNearestSurface(world, origin.add(x, 0, z), EnumFacing.UP, (int)radius, true, WizardryUtilities.SurfaceCriteria.BUILDABLE); + Integer y = BlockUtils.getNearestSurface(world, origin.add(x, 0, z), EnumFacing.UP, (int)radius, true, BlockUtils.SurfaceCriteria.BUILDABLE); if(y != null) ring.add(new BlockPos(origin.getX() + x, y, origin.getZ() + z)); } } diff --git a/src/main/java/electroblob/wizardry/spell/ForestsCurse.java b/src/main/java/electroblob/wizardry/spell/ForestsCurse.java index a618609b..ec6c6dbc 100644 --- a/src/main/java/electroblob/wizardry/spell/ForestsCurse.java +++ b/src/main/java/electroblob/wizardry/spell/ForestsCurse.java @@ -2,12 +2,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.MobEffects; import net.minecraft.potion.PotionEffect; @@ -24,7 +21,7 @@ public class ForestsCurse extends SpellAreaEffect { @Override protected void affectEntity(World world, EntityLivingBase caster, EntityLivingBase target, SpellModifiers modifiers){ - if(!MagicDamage.isEntityImmune(DamageType.POISON, target) && WizardryUtilities.isLiving(target)){ + if(!MagicDamage.isEntityImmune(DamageType.POISON, target) && EntityUtils.isLiving(target)){ target.attackEntityFrom(MagicDamage.causeDirectMagicDamage(caster, DamageType.POISON), getProperty(DAMAGE).floatValue() * modifiers.get(SpellModifiers.POTENCY)); diff --git a/src/main/java/electroblob/wizardry/spell/Freeze.java b/src/main/java/electroblob/wizardry/spell/Freeze.java index 6f026dc8..b8b612a7 100644 --- a/src/main/java/electroblob/wizardry/spell/Freeze.java +++ b/src/main/java/electroblob/wizardry/spell/Freeze.java @@ -3,20 +3,14 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntityBlaze; import net.minecraft.entity.monster.EntityMagmaCube; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.potion.PotionEffect; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -37,7 +31,7 @@ public class Freeze extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(target instanceof EntityBlaze || target instanceof EntityMagmaCube){ target.attackEntityFrom(MagicDamage.causeDirectMagicDamage(caster, DamageType.FROST), @@ -64,8 +58,8 @@ public class Freeze extends SpellRay { @Override protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(!world.isRemote && WizardryUtilities.canDamageBlocks(caster, world)){ - WizardryUtilities.freeze(world, pos, true); + if(!world.isRemote && EntityUtils.canDamageBlocks(caster, world)){ + BlockUtils.freeze(world, pos, true); } return true; // Always succeeds if it hits a block diff --git a/src/main/java/electroblob/wizardry/spell/FreezingWeapon.java b/src/main/java/electroblob/wizardry/spell/FreezingWeapon.java index a4862ffe..753c7add 100644 --- a/src/main/java/electroblob/wizardry/spell/FreezingWeapon.java +++ b/src/main/java/electroblob/wizardry/spell/FreezingWeapon.java @@ -5,10 +5,10 @@ import electroblob.wizardry.data.WizardData; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryEnchantments; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -35,7 +35,7 @@ public class FreezingWeapon extends Spell { if(WizardData.get(caster) != null && WizardData.get(caster).getImbuementDuration(WizardryEnchantments.freezing_weapon) <= 0){ - for(ItemStack stack : WizardryUtilities.getPrioritisedHotbarAndOffhand(caster)){ + for(ItemStack stack : InventoryUtils.getPrioritisedHotbarAndOffhand(caster)){ if((ImbueWeapon.isSword(stack) || ImbueWeapon.isBow(stack)) && !EnchantmentHelper.getEnchantments(stack).containsKey(WizardryEnchantments.freezing_weapon)){ diff --git a/src/main/java/electroblob/wizardry/spell/FrostRay.java b/src/main/java/electroblob/wizardry/spell/FrostRay.java index 556d2b8d..3099c739 100644 --- a/src/main/java/electroblob/wizardry/spell/FrostRay.java +++ b/src/main/java/electroblob/wizardry/spell/FrostRay.java @@ -3,12 +3,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntityBlaze; @@ -49,7 +46,7 @@ public class FrostRay extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(target.isBurning()) target.extinguish(); @@ -68,7 +65,7 @@ public class FrostRay extends SpellRay { float damage = getProperty(DAMAGE).floatValue() * modifiers.get(SpellModifiers.POTENCY); if(target instanceof EntityBlaze || target instanceof EntityMagmaCube) damage *= 2; - WizardryUtilities.attackEntityWithoutKnockback(target, MagicDamage.causeDirectMagicDamage(caster, + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeDirectMagicDamage(caster, DamageType.FROST), damage); } diff --git a/src/main/java/electroblob/wizardry/spell/Grapple.java b/src/main/java/electroblob/wizardry/spell/Grapple.java index a61e46e0..012ecdd1 100644 --- a/src/main/java/electroblob/wizardry/spell/Grapple.java +++ b/src/main/java/electroblob/wizardry/spell/Grapple.java @@ -8,11 +8,8 @@ import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.RayTracer; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -416,7 +413,7 @@ public class Grapple extends Spell { private static RayTraceResult update(EntityPlayer player, RayTraceResult grapplingTarget){ - if(grapplingTarget != null && (!WizardryUtilities.isCasting(player, Spells.grapple) + if(grapplingTarget != null && (!EntityUtils.isCasting(player, Spells.grapple) || (grapplingTarget.entityHit != null && !grapplingTarget.entityHit.isEntityAlive()))){ return null; } diff --git a/src/main/java/electroblob/wizardry/spell/GreaterTelekinesis.java b/src/main/java/electroblob/wizardry/spell/GreaterTelekinesis.java index b7a7c17c..90048c39 100644 --- a/src/main/java/electroblob/wizardry/spell/GreaterTelekinesis.java +++ b/src/main/java/electroblob/wizardry/spell/GreaterTelekinesis.java @@ -5,10 +5,8 @@ import electroblob.wizardry.entity.EntityLevitatingBlock; import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -92,7 +90,7 @@ public class GreaterTelekinesis extends SpellRay { }else{ - WizardryUtilities.undoGravity(target); + EntityUtils.undoGravity(target); // The following code extrapolates the entity's current velocity to determine whether it will pass the // target position in the next tick, and adds or subtracts velocity accordingly. @@ -132,7 +130,7 @@ public class GreaterTelekinesis extends SpellRay { @Override protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.canDamageBlocks(caster, world) && !WizardryUtilities.isBlockUnbreakable(world, pos) + if(EntityUtils.canDamageBlocks(caster, world) && !BlockUtils.isBlockUnbreakable(world, pos) && world.getBlockState(pos).getMaterial().isSolid() && (world.getTileEntity(pos) == null || !world.getTileEntity(pos).getTileData().hasUniqueId(ArcaneLock.NBT_KEY))){ diff --git a/src/main/java/electroblob/wizardry/spell/GroupHeal.java b/src/main/java/electroblob/wizardry/spell/GroupHeal.java index d0849810..ae8abef8 100644 --- a/src/main/java/electroblob/wizardry/spell/GroupHeal.java +++ b/src/main/java/electroblob/wizardry/spell/GroupHeal.java @@ -2,10 +2,7 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.ParticleBuilder; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.*; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumHand; @@ -26,7 +23,7 @@ public class GroupHeal extends Spell { boolean flag = false; - List targets = WizardryUtilities.getEntitiesWithinRadius(getProperty(EFFECT_RADIUS).floatValue() + List targets = EntityUtils.getEntitiesWithinRadius(getProperty(EFFECT_RADIUS).floatValue() * modifiers.get(WizardryItems.blast_upgrade), caster.posX, caster.posY, caster.posZ, world); for(EntityLivingBase target : targets){ diff --git a/src/main/java/electroblob/wizardry/spell/GrowthAura.java b/src/main/java/electroblob/wizardry/spell/GrowthAura.java index 09dfa81c..678ccd44 100644 --- a/src/main/java/electroblob/wizardry/spell/GrowthAura.java +++ b/src/main/java/electroblob/wizardry/spell/GrowthAura.java @@ -3,8 +3,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.block.IGrowable; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; @@ -33,7 +33,7 @@ public class GrowthAura extends Spell { boolean flag = false; - List sphere = WizardryUtilities.getBlockSphere(caster.getPosition(), + List sphere = BlockUtils.getBlockSphere(caster.getPosition(), getProperty(EFFECT_RADIUS).floatValue() * modifiers.get(WizardryItems.blast_upgrade)); for(BlockPos pos : sphere){ diff --git a/src/main/java/electroblob/wizardry/spell/HealAlly.java b/src/main/java/electroblob/wizardry/spell/HealAlly.java index 0b375381..1beb0083 100644 --- a/src/main/java/electroblob/wizardry/spell/HealAlly.java +++ b/src/main/java/electroblob/wizardry/spell/HealAlly.java @@ -1,9 +1,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -28,7 +28,7 @@ public class HealAlly extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ EntityLivingBase entity = (EntityLivingBase)target; diff --git a/src/main/java/electroblob/wizardry/spell/IceAge.java b/src/main/java/electroblob/wizardry/spell/IceAge.java index 5e09ed8c..c9498bf0 100644 --- a/src/main/java/electroblob/wizardry/spell/IceAge.java +++ b/src/main/java/electroblob/wizardry/spell/IceAge.java @@ -6,12 +6,8 @@ import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; -import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; -import electroblob.wizardry.util.WizardryUtilities.SurfaceCriteria; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -43,7 +39,7 @@ public class IceAge extends Spell { float radius = getProperty(EFFECT_RADIUS).floatValue() * modifiers.get(WizardryItems.blast_upgrade); - List targets = WizardryUtilities.getEntitiesWithinRadius(radius, caster.posX, caster.posY, caster.posZ, world); + List targets = EntityUtils.getEntitiesWithinRadius(radius, caster.posX, caster.posY, caster.posZ, world); for(EntityLivingBase target : targets){ if(AllyDesignationSystem.isValidTarget(caster, target)){ @@ -63,13 +59,13 @@ public class IceAge extends Spell { } } - if(!world.isRemote && WizardryUtilities.canDamageBlocks(caster, world)){ + if(!world.isRemote && EntityUtils.canDamageBlocks(caster, world)){ for(int i = -(int)radius; i <= (int)radius; i++){ for(int j = -(int)radius; j <= (int)radius; j++){ BlockPos pos = new BlockPos(caster).add(i, 0, j); - Integer y = WizardryUtilities.getNearestSurface(world, new BlockPos(pos), EnumFacing.UP, (int)radius, true, SurfaceCriteria.SOLID_LIQUID_TO_AIR); + Integer y = BlockUtils.getNearestSurface(world, new BlockPos(pos), EnumFacing.UP, (int)radius, true, BlockUtils.SurfaceCriteria.SOLID_LIQUID_TO_AIR); if(y != null){ @@ -79,7 +75,7 @@ public class IceAge extends Spell { // Randomised with weighting so that the nearer the block the more likely it is to be snowed. if(y != -1 && world.rand.nextInt((int)(dist * 2) + 1) < radius && dist < radius){ - WizardryUtilities.freeze(world, pos.down(), true); + BlockUtils.freeze(world, pos.down(), true); } } } diff --git a/src/main/java/electroblob/wizardry/spell/IceSpikes.java b/src/main/java/electroblob/wizardry/spell/IceSpikes.java index 6fe93b3e..acbdfe1d 100644 --- a/src/main/java/electroblob/wizardry/spell/IceSpikes.java +++ b/src/main/java/electroblob/wizardry/spell/IceSpikes.java @@ -2,8 +2,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.entity.construct.EntityIceSpike; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; +import electroblob.wizardry.util.GeometryUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -48,15 +49,15 @@ public class IceSpikes extends SpellConstructRanged { // First, generate a random vector of length radius with a z component of zero // Then rotate it so that what was south is now the side that was hit Vec3d offset = Vec3d.fromPitchYaw(world.rand.nextFloat() * 180 - 90, world.rand.nextBoolean() ? 0 : 180) - .scale(radius).rotateYaw(side.getHorizontalAngle() * (float)Math.PI/180).rotatePitch(WizardryUtilities.getPitch(side) * (float)Math.PI/180); + .scale(radius).rotateYaw(side.getHorizontalAngle() * (float)Math.PI/180).rotatePitch(GeometryUtils.getPitch(side) * (float)Math.PI/180); if(side.getAxis().isHorizontal()) offset = offset.rotateYaw((float)Math.PI/2); - Integer surface = WizardryUtilities.getNearestSurface(world, new BlockPos(origin.add(offset)), side, - (int)maxRadius, true, WizardryUtilities.SurfaceCriteria.basedOn(World::isBlockFullCube)); + Integer surface = BlockUtils.getNearestSurface(world, new BlockPos(origin.add(offset)), side, + (int)maxRadius, true, BlockUtils.SurfaceCriteria.basedOn(World::isBlockFullCube)); if(surface != null){ - Vec3d vec = WizardryUtilities.replaceComponent(origin.add(offset), side.getAxis(), surface) + Vec3d vec = GeometryUtils.replaceComponent(origin.add(offset), side.getAxis(), surface) .subtract(new Vec3d(side.getDirectionVec())); super.spawnConstruct(world, vec.x, vec.y, vec.z, side, caster, modifiers); } diff --git a/src/main/java/electroblob/wizardry/spell/Ignite.java b/src/main/java/electroblob/wizardry/spell/Ignite.java index 63561d53..e35f18cb 100644 --- a/src/main/java/electroblob/wizardry/spell/Ignite.java +++ b/src/main/java/electroblob/wizardry/spell/Ignite.java @@ -2,10 +2,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.MagicDamage; import electroblob.wizardry.util.MagicDamage.DamageType; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -46,7 +46,7 @@ public class Ignite extends SpellRay { @Override protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(!WizardryUtilities.canDamageBlocks(caster, world)) return false; + if(!EntityUtils.canDamageBlocks(caster, world)) return false; pos = pos.offset(side); diff --git a/src/main/java/electroblob/wizardry/spell/ImbueWeapon.java b/src/main/java/electroblob/wizardry/spell/ImbueWeapon.java index b3c881b4..55e71787 100644 --- a/src/main/java/electroblob/wizardry/spell/ImbueWeapon.java +++ b/src/main/java/electroblob/wizardry/spell/ImbueWeapon.java @@ -7,10 +7,10 @@ import electroblob.wizardry.data.WizardData; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryEnchantments; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBow; @@ -32,7 +32,7 @@ public class ImbueWeapon extends Spell { // Won't work if the weapon already has the enchantment if(WizardData.get(caster) != null){ - for(ItemStack stack : WizardryUtilities.getPrioritisedHotbarAndOffhand(caster)){ + for(ItemStack stack : InventoryUtils.getPrioritisedHotbarAndOffhand(caster)){ if(isSword(stack) && !EnchantmentHelper.getEnchantments(stack).containsKey(WizardryEnchantments.magic_sword) diff --git a/src/main/java/electroblob/wizardry/spell/Intimidate.java b/src/main/java/electroblob/wizardry/spell/Intimidate.java index 408d0304..39c722db 100644 --- a/src/main/java/electroblob/wizardry/spell/Intimidate.java +++ b/src/main/java/electroblob/wizardry/spell/Intimidate.java @@ -3,10 +3,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLivingBase; @@ -45,7 +45,7 @@ public class Intimidate extends Spell { if(!world.isRemote){ - List entities = WizardryUtilities.getEntitiesWithinRadius( + List entities = EntityUtils.getEntitiesWithinRadius( getProperty(EFFECT_RADIUS).floatValue() * modifiers.get(WizardryItems.range_upgrade), caster.posX, caster.posY, caster.posZ, world, EntityCreature.class); @@ -126,7 +126,7 @@ public class Intimidate extends Spell { if(entityNBT != null && entityNBT.hasUniqueId(NBT_KEY)){ - Entity caster = WizardryUtilities.getEntityByUUID(creature.world, entityNBT.getUniqueId(NBT_KEY)); + Entity caster = EntityUtils.getEntityByUUID(creature.world, entityNBT.getUniqueId(NBT_KEY)); if(caster instanceof EntityLivingBase){ double distance = BASE_AVOID_DISTANCE + AVOID_DISTANCE_PER_LEVEL diff --git a/src/main/java/electroblob/wizardry/spell/InvigoratingPresence.java b/src/main/java/electroblob/wizardry/spell/InvigoratingPresence.java index 503d80f9..4d530615 100644 --- a/src/main/java/electroblob/wizardry/spell/InvigoratingPresence.java +++ b/src/main/java/electroblob/wizardry/spell/InvigoratingPresence.java @@ -3,11 +3,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.MobEffects; import net.minecraft.potion.PotionEffect; @@ -28,7 +25,7 @@ public class InvigoratingPresence extends Spell { @Override public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){ - List targets = WizardryUtilities.getEntitiesWithinRadius( + List targets = EntityUtils.getEntitiesWithinRadius( getProperty(EFFECT_RADIUS).floatValue() * modifiers.get(WizardryItems.blast_upgrade), caster.posX, caster.posY, caster.posZ, world, EntityPlayer.class); diff --git a/src/main/java/electroblob/wizardry/spell/LifeDrain.java b/src/main/java/electroblob/wizardry/spell/LifeDrain.java index 3d5d9751..64a48104 100644 --- a/src/main/java/electroblob/wizardry/spell/LifeDrain.java +++ b/src/main/java/electroblob/wizardry/spell/LifeDrain.java @@ -1,12 +1,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; @@ -45,13 +42,13 @@ public class LifeDrain extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(ticksInUse % 12 == 0){ float damage = getProperty(DAMAGE).floatValue() * modifiers.get(SpellModifiers.POTENCY); - WizardryUtilities.attackEntityWithoutKnockback(target, MagicDamage.causeDirectMagicDamage(caster, + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeDirectMagicDamage(caster, DamageType.MAGIC), damage); if(caster != null) caster.heal(damage * getProperty(HEAL_FACTOR).floatValue()); diff --git a/src/main/java/electroblob/wizardry/spell/LightningPulse.java b/src/main/java/electroblob/wizardry/spell/LightningPulse.java index f916d0b6..ed72903b 100644 --- a/src/main/java/electroblob/wizardry/spell/LightningPulse.java +++ b/src/main/java/electroblob/wizardry/spell/LightningPulse.java @@ -38,7 +38,7 @@ public class LightningPulse extends Spell { if(caster.onGround){ - List targets = WizardryUtilities.getEntitiesWithinRadius( + List targets = EntityUtils.getEntitiesWithinRadius( getProperty(EFFECT_RADIUS).floatValue() * modifiers.get(WizardryItems.blast_upgrade), caster.posX, caster.posY, caster.posZ, world); @@ -71,7 +71,7 @@ public class LightningPulse extends Spell { if(world.isRemote){ ParticleBuilder.create(Type.LIGHTNING_PULSE).pos(caster.posX, caster.getEntityBoundingBox().minY - + WizardryUtilities.ANTI_Z_FIGHTING_OFFSET, caster.posZ) + + GeometryUtils.ANTI_Z_FIGHTING_OFFSET, caster.posZ) .scale(modifiers.get(WizardryItems.blast_upgrade)).spawn(world); } diff --git a/src/main/java/electroblob/wizardry/spell/LightningRay.java b/src/main/java/electroblob/wizardry/spell/LightningRay.java index 273b4e04..47d7b179 100644 --- a/src/main/java/electroblob/wizardry/spell/LightningRay.java +++ b/src/main/java/electroblob/wizardry/spell/LightningRay.java @@ -1,12 +1,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -43,7 +40,7 @@ public class LightningRay extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(MagicDamage.isEntityImmune(DamageType.SHOCK, target)){ if(!world.isRemote && ticksInUse == 1 && caster instanceof EntityPlayer) @@ -52,7 +49,7 @@ public class LightningRay extends SpellRay { // This now only damages in line with the maxHurtResistantTime. Some mods don't play nicely and fiddle // with this mechanic for their own purposes, so this line makes sure that doesn't affect wizardry. }else if(ticksInUse % ((EntityLivingBase)target).maxHurtResistantTime == 1){ - WizardryUtilities.attackEntityWithoutKnockback(target, + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeDirectMagicDamage(caster, DamageType.SHOCK), getProperty(DAMAGE).floatValue() * modifiers.get(SpellModifiers.POTENCY)); } diff --git a/src/main/java/electroblob/wizardry/spell/LightningWeb.java b/src/main/java/electroblob/wizardry/spell/LightningWeb.java index 5587cba8..c0b95f70 100644 --- a/src/main/java/electroblob/wizardry/spell/LightningWeb.java +++ b/src/main/java/electroblob/wizardry/spell/LightningWeb.java @@ -53,19 +53,19 @@ public class LightningWeb extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ electrocute(world, caster, origin, target, getProperty(PRIMARY_DAMAGE).floatValue() * modifiers.get(SpellModifiers.POTENCY), ticksInUse); // Secondary chaining effect - List secondaryTargets = WizardryUtilities.getEntitiesWithinRadius( + List secondaryTargets = EntityUtils.getEntitiesWithinRadius( getProperty(SECONDARY_RANGE).floatValue(), target.posX, target.posY + target.height / 2, target.posZ, world); secondaryTargets.remove(target); - secondaryTargets.removeIf(e -> !WizardryUtilities.isLiving(e)); + secondaryTargets.removeIf(e -> !EntityUtils.isLiving(e)); secondaryTargets.removeIf(e -> !AllyDesignationSystem.isValidTarget(caster, e)); if(secondaryTargets.size() > getProperty(SECONDARY_MAX_TARGETS).intValue()) secondaryTargets = secondaryTargets.subList(0, getProperty(SECONDARY_MAX_TARGETS).intValue()); @@ -77,13 +77,13 @@ public class LightningWeb extends SpellRay { // Tertiary chaining effect - List tertiaryTargets = WizardryUtilities.getEntitiesWithinRadius( + List tertiaryTargets = EntityUtils.getEntitiesWithinRadius( getProperty(TERTIARY_RANGE).floatValue(), secondaryTarget.posX, secondaryTarget.posY + secondaryTarget.height / 2, secondaryTarget.posZ, world); tertiaryTargets.remove(target); tertiaryTargets.removeAll(secondaryTargets); - tertiaryTargets.removeIf(e -> !WizardryUtilities.isLiving(e)); + tertiaryTargets.removeIf(e -> !EntityUtils.isLiving(e)); tertiaryTargets.removeIf(e -> !AllyDesignationSystem.isValidTarget(caster, e)); if(tertiaryTargets.size() > getProperty(TERTIARY_MAX_TARGETS).intValue()) tertiaryTargets = tertiaryTargets.subList(0, getProperty(TERTIARY_MAX_TARGETS).intValue()); @@ -139,7 +139,7 @@ public class LightningWeb extends SpellRay { ((EntityPlayer)caster).sendStatusMessage(new TextComponentTranslation("spell.resist", target.getName(), this.getNameForTranslationFormatted()), true); }else{ - WizardryUtilities.attackEntityWithoutKnockback(target, + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeDirectMagicDamage(caster, DamageType.SHOCK), damage); } diff --git a/src/main/java/electroblob/wizardry/spell/Metamorphosis.java b/src/main/java/electroblob/wizardry/spell/Metamorphosis.java index a0689642..7e418b0d 100644 --- a/src/main/java/electroblob/wizardry/spell/Metamorphosis.java +++ b/src/main/java/electroblob/wizardry/spell/Metamorphosis.java @@ -5,11 +5,8 @@ import com.google.common.collect.HashBiMap; import electroblob.wizardry.Wizardry; import electroblob.wizardry.entity.living.*; import electroblob.wizardry.item.SpellActions; -import electroblob.wizardry.util.NBTExtras; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -58,7 +55,7 @@ public class Metamorphosis extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ double xPos = target.posX; double yPos = target.posY; diff --git a/src/main/java/electroblob/wizardry/spell/Meteor.java b/src/main/java/electroblob/wizardry/spell/Meteor.java index e26ec67b..10289ce7 100644 --- a/src/main/java/electroblob/wizardry/spell/Meteor.java +++ b/src/main/java/electroblob/wizardry/spell/Meteor.java @@ -3,8 +3,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.entity.EntityMeteor; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; @@ -38,7 +38,7 @@ public class Meteor extends SpellRay { if(!world.isRemote){ EntityMeteor meteor = new EntityMeteor(world, pos.getX(), pos.getY() + 50, pos.getZ(), - modifiers.get(WizardryItems.blast_upgrade), WizardryUtilities.canDamageBlocks(caster, world)); + modifiers.get(WizardryItems.blast_upgrade), EntityUtils.canDamageBlocks(caster, world)); world.spawnEntity(meteor); } diff --git a/src/main/java/electroblob/wizardry/spell/MindControl.java b/src/main/java/electroblob/wizardry/spell/MindControl.java index 7f9d27d2..c658bc63 100644 --- a/src/main/java/electroblob/wizardry/spell/MindControl.java +++ b/src/main/java/electroblob/wizardry/spell/MindControl.java @@ -6,11 +6,8 @@ import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; -import electroblob.wizardry.util.AllyDesignationSystem; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.*; import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.entity.passive.EntitySheep; @@ -50,7 +47,7 @@ public class MindControl extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(!canControl(target)){ if(!world.isRemote){ @@ -71,7 +68,7 @@ public class MindControl extends SpellRay { } if(target instanceof EntitySheep && ((EntitySheep)target).getFleeceColor() == EnumDyeColor.BLUE - && WizardryUtilities.canDamageBlocks(caster, world)){ + && EntityUtils.canDamageBlocks(caster, world)){ if(!world.isRemote) ((EntitySheep)target).setFleeceColor(EnumDyeColor.RED); // Wololo! world.playSound(caster.posX, caster.posY, caster.posZ, SoundEvents.EVOCATION_ILLAGER_PREPARE_WOLOLO, WizardrySounds.SPELLS, 1, 1, false); } @@ -135,7 +132,7 @@ public class MindControl extends SpellRay { // As of 1.1, this now uses the creature's follow range, like normal targeting. It also // no longer lasts until the creature dies; instead it is a potion effect which continues to // set the target until it wears off. - List possibleTargets = WizardryUtilities.getEntitiesWithinRadius( + List possibleTargets = EntityUtils.getEntitiesWithinRadius( target.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).getAttributeValue(), target.posX, target.posY, target.posZ, world); @@ -172,7 +169,7 @@ public class MindControl extends SpellRay { if(entityNBT != null && entityNBT.hasUniqueId(MindControl.NBT_KEY)){ - Entity caster = WizardryUtilities.getEntityByUUID(world, entityNBT.getUniqueId(MindControl.NBT_KEY)); + Entity caster = EntityUtils.getEntityByUUID(world, entityNBT.getUniqueId(MindControl.NBT_KEY)); if(caster instanceof EntityLivingBase){ diff --git a/src/main/java/electroblob/wizardry/spell/MindTrick.java b/src/main/java/electroblob/wizardry/spell/MindTrick.java index 45abead1..6edaa0ec 100644 --- a/src/main/java/electroblob/wizardry/spell/MindTrick.java +++ b/src/main/java/electroblob/wizardry/spell/MindTrick.java @@ -3,10 +3,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -34,7 +34,7 @@ public class MindTrick extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(!world.isRemote){ diff --git a/src/main/java/electroblob/wizardry/spell/Mine.java b/src/main/java/electroblob/wizardry/spell/Mine.java index 93e445de..bd87b0b2 100644 --- a/src/main/java/electroblob/wizardry/spell/Mine.java +++ b/src/main/java/electroblob/wizardry/spell/Mine.java @@ -6,10 +6,8 @@ import electroblob.wizardry.item.ISpellCastingItem; import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; @@ -63,12 +61,12 @@ public class Mine extends SpellRay { if(!world.isRemote){ - if(WizardryUtilities.isBlockUnbreakable(world, pos)) return false; + if(BlockUtils.isBlockUnbreakable(world, pos)) return false; // The mine spell ignores the block damage setting for players, since that's the entire point of the spell // Instead, it triggers block break events at the appropriate points, which protection mods should be able to // pick up and allow/disallow accordingly // For the time being, dispensers respect the mobGriefing gamerule - if(!(caster instanceof EntityPlayer) && !WizardryUtilities.canDamageBlocks(caster, world)) return false; + if(!(caster instanceof EntityPlayer) && !EntityUtils.canDamageBlocks(caster, world)) return false; // Can't mine arcane-locked blocks if(world.getTileEntity(pos) != null && world.getTileEntity(pos).getTileData().hasUniqueId(ArcaneLock.NBT_KEY)) return false; @@ -92,11 +90,11 @@ public class Mine extends SpellRay { // 3 blast upgrades: 5x5 without corners or edges float radius = 0.5f + 0.73f * blastUpgradeCount; - List sphere = WizardryUtilities.getBlockSphere(pos, radius); + List sphere = BlockUtils.getBlockSphere(pos, radius); for(BlockPos pos1 : sphere){ - if(WizardryUtilities.isBlockUnbreakable(world, pos1)) continue; + if(BlockUtils.isBlockUnbreakable(world, pos1)) continue; IBlockState state1 = world.getBlockState(pos1); diff --git a/src/main/java/electroblob/wizardry/spell/Paralysis.java b/src/main/java/electroblob/wizardry/spell/Paralysis.java index 490cac00..607dc422 100644 --- a/src/main/java/electroblob/wizardry/spell/Paralysis.java +++ b/src/main/java/electroblob/wizardry/spell/Paralysis.java @@ -4,12 +4,9 @@ import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardryPotions; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -41,7 +38,7 @@ public class Paralysis extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(world.isRemote){ // Rather neatly, the entity can be set here and if it's null nothing will happen. @@ -74,7 +71,7 @@ public class Paralysis extends SpellRay { if(world.isRemote){ if(world.getBlockState(pos).getMaterial().isSolid()){ - Vec3d vec = hit.add(new Vec3d(side.getDirectionVec()).scale(WizardryUtilities.ANTI_Z_FIGHTING_OFFSET)); + Vec3d vec = hit.add(new Vec3d(side.getDirectionVec()).scale(GeometryUtils.ANTI_Z_FIGHTING_OFFSET)); ParticleBuilder.create(Type.SCORCH).pos(vec).face(side).clr(0.4f, 0.8f, 1).spawn(world); } } diff --git a/src/main/java/electroblob/wizardry/spell/PhaseStep.java b/src/main/java/electroblob/wizardry/spell/PhaseStep.java index 8dbe25df..30f4b40a 100644 --- a/src/main/java/electroblob/wizardry/spell/PhaseStep.java +++ b/src/main/java/electroblob/wizardry/spell/PhaseStep.java @@ -4,9 +4,9 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.constants.Constants; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.RayTracer; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; @@ -64,7 +64,7 @@ public class PhaseStep extends Spell { // Prevents the player from teleporting through unbreakable blocks, so they cannot cheat in other // mods' mazes and dungeons. - if((WizardryUtilities.isBlockUnbreakable(world, pos1) || WizardryUtilities.isBlockUnbreakable(world, pos1.up())) + if((BlockUtils.isBlockUnbreakable(world, pos1) || BlockUtils.isBlockUnbreakable(world, pos1.up())) && !Wizardry.settings.teleportThroughUnbreakableBlocks) break; // Don't return false yet, there are other possible outcomes below now diff --git a/src/main/java/electroblob/wizardry/spell/PlagueOfDarkness.java b/src/main/java/electroblob/wizardry/spell/PlagueOfDarkness.java index fc1e4501..afcb36d2 100644 --- a/src/main/java/electroblob/wizardry/spell/PlagueOfDarkness.java +++ b/src/main/java/electroblob/wizardry/spell/PlagueOfDarkness.java @@ -30,7 +30,7 @@ public class PlagueOfDarkness extends Spell { double radius = getProperty(EFFECT_RADIUS).floatValue() * modifiers.get(WizardryItems.blast_upgrade); - List targets = WizardryUtilities.getEntitiesWithinRadius(radius, caster.posX, caster.posY, caster.posZ, world); + List targets = EntityUtils.getEntitiesWithinRadius(radius, caster.posX, caster.posY, caster.posZ, world); for(EntityLivingBase target : targets){ if(AllyDesignationSystem.isValidTarget(caster, target) @@ -61,7 +61,7 @@ public class PlagueOfDarkness extends Spell { particleX = caster.posX - 1.0d + 2 * world.rand.nextDouble(); particleZ = caster.posZ - 1.0d + 2 * world.rand.nextDouble(); - IBlockState block = WizardryUtilities.getBlockEntityIsStandingOn(caster); + IBlockState block = BlockUtils.getBlockEntityIsStandingOn(caster); if(block != null){ world.spawnParticle(EnumParticleTypes.BLOCK_DUST, particleX, caster.getEntityBoundingBox().minY, diff --git a/src/main/java/electroblob/wizardry/spell/PocketFurnace.java b/src/main/java/electroblob/wizardry/spell/PocketFurnace.java index 8e24e4d6..6ea2c329 100644 --- a/src/main/java/electroblob/wizardry/spell/PocketFurnace.java +++ b/src/main/java/electroblob/wizardry/spell/PocketFurnace.java @@ -3,8 +3,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Settings; import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.SpellActions; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; @@ -46,7 +46,7 @@ public class PocketFurnace extends Spell { if(stack.getCount() <= usesLeft){ ItemStack stack2 = new ItemStack(result.getItem(), stack.getCount(), result.getItemDamage()); - if(WizardryUtilities.doesPlayerHaveItem(caster, result.getItem())){ + if(InventoryUtils.doesPlayerHaveItem(caster, result.getItem())){ caster.inventory.addItemStackToInventory(stack2); caster.inventory.setInventorySlotContents(i, ItemStack.EMPTY); }else{ diff --git a/src/main/java/electroblob/wizardry/spell/Poison.java b/src/main/java/electroblob/wizardry/spell/Poison.java index 48a28e1d..51172b92 100644 --- a/src/main/java/electroblob/wizardry/spell/Poison.java +++ b/src/main/java/electroblob/wizardry/spell/Poison.java @@ -2,12 +2,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -36,7 +33,7 @@ public class Poison extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ // Has no effect on undead or spiders. if(MagicDamage.isEntityImmune(DamageType.POISON, target)){ diff --git a/src/main/java/electroblob/wizardry/spell/Possession.java b/src/main/java/electroblob/wizardry/spell/Possession.java index 305132b6..ce55b450 100644 --- a/src/main/java/electroblob/wizardry/spell/Possession.java +++ b/src/main/java/electroblob/wizardry/spell/Possession.java @@ -17,11 +17,8 @@ import electroblob.wizardry.packet.PacketPossession; import electroblob.wizardry.packet.WizardryPacketHandler; import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.NBTExtras; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.*; @@ -249,7 +246,7 @@ public class Possession extends SpellRay { possessor.getAttributeMap().getAttributeInstance(attribute).applyModifier(new AttributeModifier( INHERITED_ATTRIBUTES.get(attribute), "possessionModifier", targetValue / currentValue, - WizardryUtilities.Operations.MULTIPLY_FLAT)); + EntityUtils.Operations.MULTIPLY_FLAT)); } } @@ -262,7 +259,7 @@ public class Possession extends SpellRay { // Targeting - for(EntityLiving creature : WizardryUtilities.getEntitiesWithinRadius(16, possessor.posX, + for(EntityLiving creature : EntityUtils.getEntitiesWithinRadius(16, possessor.posX, possessor.posY, possessor.posZ, possessor.world, EntityLiving.class)){ // Mobs are dumb, if a player possesses something they're like "Huh?! Where'd you go?" // Of course, this won't last long if the player attacks them, since they'll revenge-target them @@ -607,7 +604,7 @@ public class Possession extends SpellRay { IProjectile projectile = factory.apply(possessor.world); Vec3d look = possessor.getLookVec(); ((Entity)projectile).setPosition(possessor.posX + look.x, possessor.posY + possessor.getEyeHeight() + look.y, possessor.posZ + look.z); - projectile.shoot(look.x, look.y, look.z, 1.6f, WizardryUtilities.getDefaultAimingError(possessor.world.getDifficulty())); + projectile.shoot(look.x, look.y, look.z, 1.6f, EntityUtils.getDefaultAimingError(possessor.world.getDifficulty())); if(projectile instanceof EntityMagicProjectile) ((EntityMagicProjectile)projectile).setCaster(possessor); else if(projectile instanceof EntityMagicArrow) ((EntityMagicArrow)projectile).setCaster(possessor); diff --git a/src/main/java/electroblob/wizardry/spell/RayOfPurification.java b/src/main/java/electroblob/wizardry/spell/RayOfPurification.java index d1262e96..556a65d2 100644 --- a/src/main/java/electroblob/wizardry/spell/RayOfPurification.java +++ b/src/main/java/electroblob/wizardry/spell/RayOfPurification.java @@ -2,12 +2,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -51,7 +48,7 @@ public class RayOfPurification extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ if(MagicDamage.isEntityImmune(DamageType.RADIANT, target)){ if(!world.isRemote && ticksInUse == 1 && caster instanceof EntityPlayer) ((EntityPlayer)caster) @@ -66,7 +63,7 @@ public class RayOfPurification extends SpellRay { damage *= getProperty(UNDEAD_DAMAGE_MULTIPLIER).floatValue(); } // Damage - WizardryUtilities.attackEntityWithoutKnockback(target, + EntityUtils.attackEntityWithoutKnockback(target, MagicDamage.causeDirectMagicDamage(caster, DamageType.RADIANT), damage); // Blindness ((EntityLivingBase)target).addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, diff --git a/src/main/java/electroblob/wizardry/spell/ShadowWard.java b/src/main/java/electroblob/wizardry/spell/ShadowWard.java index 60e42bf2..d3fec9e7 100644 --- a/src/main/java/electroblob/wizardry/spell/ShadowWard.java +++ b/src/main/java/electroblob/wizardry/spell/ShadowWard.java @@ -2,11 +2,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.integration.DamageSafetyChecker; import electroblob.wizardry.registry.Spells; -import electroblob.wizardry.util.IElementalDamage; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; @@ -68,7 +65,7 @@ public class ShadowWard extends Spell { if(event.getSource() != null && event.getSource().getTrueSource() instanceof EntityLivingBase){ - if(WizardryUtilities.isCasting(event.getEntityLiving(), Spells.shadow_ward) && !event.getSource().isUnblockable() + if(EntityUtils.isCasting(event.getEntityLiving(), Spells.shadow_ward) && !event.getSource().isUnblockable() && !(event.getSource() instanceof IElementalDamage && ((IElementalDamage)event.getSource()).isRetaliatory())){ event.setCanceled(true); diff --git a/src/main/java/electroblob/wizardry/spell/Shockwave.java b/src/main/java/electroblob/wizardry/spell/Shockwave.java index a7a0f6e0..9398b7b1 100644 --- a/src/main/java/electroblob/wizardry/spell/Shockwave.java +++ b/src/main/java/electroblob/wizardry/spell/Shockwave.java @@ -37,7 +37,7 @@ public class Shockwave extends Spell { double radius = getProperty(BLAST_RADIUS).floatValue() * modifiers.get(WizardryItems.blast_upgrade); - List targets = WizardryUtilities.getEntitiesWithinRadius(radius, caster.posX, caster.posY, caster.posZ, world); + List targets = EntityUtils.getEntitiesWithinRadius(radius, caster.posX, caster.posY, caster.posZ, world); for(EntityLivingBase target : targets){ @@ -105,7 +105,7 @@ public class Shockwave extends Spell { particleX = caster.posX - 1.0d + 2 * world.rand.nextDouble(); particleZ = caster.posZ - 1.0d + 2 * world.rand.nextDouble(); - IBlockState block = WizardryUtilities.getBlockEntityIsStandingOn(caster); + IBlockState block = BlockUtils.getBlockEntityIsStandingOn(caster); if(block != null){ world.spawnParticle(EnumParticleTypes.BLOCK_DUST, particleX, caster.getEntityBoundingBox().minY, diff --git a/src/main/java/electroblob/wizardry/spell/ShulkerBullet.java b/src/main/java/electroblob/wizardry/spell/ShulkerBullet.java index 69599b6e..167623c3 100644 --- a/src/main/java/electroblob/wizardry/spell/ShulkerBullet.java +++ b/src/main/java/electroblob/wizardry/spell/ShulkerBullet.java @@ -2,9 +2,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.NBTExtras; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -62,7 +62,7 @@ public class ShulkerBullet extends Spell { double range = getProperty(RANGE).floatValue() * modifiers.get(WizardryItems.range_upgrade); - List possibleTargets = WizardryUtilities.getEntitiesWithinRadius(range, x, y, z, world); + List possibleTargets = EntityUtils.getEntitiesWithinRadius(range, x, y, z, world); possibleTargets.remove(caster); possibleTargets.removeIf(t -> t instanceof EntityArmorStand); diff --git a/src/main/java/electroblob/wizardry/spell/Slime.java b/src/main/java/electroblob/wizardry/spell/Slime.java index cae5a7a0..90606a1e 100644 --- a/src/main/java/electroblob/wizardry/spell/Slime.java +++ b/src/main/java/electroblob/wizardry/spell/Slime.java @@ -3,10 +3,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.entity.living.EntityMagicSlime; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntitySlime; @@ -34,7 +34,7 @@ public class Slime extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target) && !(target instanceof EntityMagicSlime)){ + if(EntityUtils.isLiving(target) && !(target instanceof EntityMagicSlime)){ if(target instanceof EntitySlime){ if(!world.isRemote && caster instanceof EntityPlayer) ((EntityPlayer)caster).sendStatusMessage( diff --git a/src/main/java/electroblob/wizardry/spell/Snare.java b/src/main/java/electroblob/wizardry/spell/Snare.java index 71843615..c892ec75 100644 --- a/src/main/java/electroblob/wizardry/spell/Snare.java +++ b/src/main/java/electroblob/wizardry/spell/Snare.java @@ -3,10 +3,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.tileentity.TileEntityPlayerSave; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; @@ -31,7 +31,7 @@ public class Snare extends SpellRay { @Override protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(side == EnumFacing.UP && world.isSideSolid(pos, EnumFacing.UP) && WizardryUtilities.canBlockBeReplaced(world, pos.up())){ + if(side == EnumFacing.UP && world.isSideSolid(pos, EnumFacing.UP) && BlockUtils.canBlockBeReplaced(world, pos.up())){ if(!world.isRemote){ world.setBlockState(pos.up(), WizardryBlocks.snare.getDefaultState()); ((TileEntityPlayerSave)world.getTileEntity(pos.up())).setCaster(caster); diff --git a/src/main/java/electroblob/wizardry/spell/SpectralPathway.java b/src/main/java/electroblob/wizardry/spell/SpectralPathway.java index 9c667462..f86b3291 100644 --- a/src/main/java/electroblob/wizardry/spell/SpectralPathway.java +++ b/src/main/java/electroblob/wizardry/spell/SpectralPathway.java @@ -4,8 +4,8 @@ import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.tileentity.TileEntityTimer; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; @@ -33,8 +33,8 @@ public class SpectralPathway extends Spell { public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){ // Won't work if caster is airborne or if they are already on a bridge (prevents infinite bridges) - if(WizardryUtilities.getBlockEntityIsStandingOn(caster).getBlock() == Blocks.AIR - || WizardryUtilities.getBlockEntityIsStandingOn(caster).getBlock() == WizardryBlocks.spectral_block){ + if(BlockUtils.getBlockEntityIsStandingOn(caster).getBlock() == Blocks.AIR + || BlockUtils.getBlockEntityIsStandingOn(caster).getBlock() == WizardryBlocks.spectral_block){ return false; } @@ -68,7 +68,7 @@ public class SpectralPathway extends Spell { } private boolean placePathwayBlockIfPossible(World world, BlockPos pos, float durationMultiplier){ - if(WizardryUtilities.canBlockBeReplaced(world, pos, true)){ + if(BlockUtils.canBlockBeReplaced(world, pos, true)){ world.setBlockState(pos, WizardryBlocks.spectral_block.getDefaultState()); if(world.getTileEntity(pos) instanceof TileEntityTimer){ ((TileEntityTimer)world.getTileEntity(pos)).setLifetime((int)(getProperty(DURATION).floatValue() * durationMultiplier)); diff --git a/src/main/java/electroblob/wizardry/spell/SpeedTime.java b/src/main/java/electroblob/wizardry/spell/SpeedTime.java index 8caaf5eb..c3f1a50a 100644 --- a/src/main/java/electroblob/wizardry/spell/SpeedTime.java +++ b/src/main/java/electroblob/wizardry/spell/SpeedTime.java @@ -3,9 +3,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -93,7 +93,7 @@ public class SpeedTime extends Spell { if(!world.isRemote){ - List sphere = WizardryUtilities.getBlockSphere(caster.getPosition(), radius); + List sphere = BlockUtils.getBlockSphere(caster.getPosition(), radius); for(BlockPos pos : sphere){ diff --git a/src/main/java/electroblob/wizardry/spell/SpellAreaEffect.java b/src/main/java/electroblob/wizardry/spell/SpellAreaEffect.java index f310ee2f..502a81f3 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellAreaEffect.java +++ b/src/main/java/electroblob/wizardry/spell/SpellAreaEffect.java @@ -3,8 +3,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.util.AllyDesignationSystem; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; @@ -45,7 +45,7 @@ public abstract class SpellAreaEffect extends Spell { @Override public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){ - List targets = WizardryUtilities.getEntitiesWithinRadius(getProperty(EFFECT_RADIUS).floatValue() + List targets = EntityUtils.getEntitiesWithinRadius(getProperty(EFFECT_RADIUS).floatValue() * modifiers.get(WizardryItems.blast_upgrade), caster.posX, caster.posY, caster.posZ, world); targets.removeIf(target -> !AllyDesignationSystem.isValidTarget(caster, target)); diff --git a/src/main/java/electroblob/wizardry/spell/SpellArrow.java b/src/main/java/electroblob/wizardry/spell/SpellArrow.java index 4d967d65..2200b1bb 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellArrow.java +++ b/src/main/java/electroblob/wizardry/spell/SpellArrow.java @@ -6,8 +6,8 @@ import electroblob.wizardry.entity.projectile.EntityMagicArrow; import electroblob.wizardry.entity.projectile.EntityMagicProjectile; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -117,7 +117,7 @@ public class SpellArrow extends Spell { T projectile = arrowFactory.apply(world); // Sets the necessary parameters int aimingError = caster instanceof ISpellCaster ? ((ISpellCaster)caster).getAimingError(world.getDifficulty()) - : WizardryUtilities.getDefaultAimingError(world.getDifficulty()); + : EntityUtils.getDefaultAimingError(world.getDifficulty()); projectile.aim(caster, target, calculateVelocity(projectile, modifiers, caster.getEyeHeight() - (float)EntityMagicProjectile.LAUNCH_Y_OFFSET), aimingError); projectile.damageMultiplier = modifiers.get(SpellModifiers.POTENCY); diff --git a/src/main/java/electroblob/wizardry/spell/SpellConjuration.java b/src/main/java/electroblob/wizardry/spell/SpellConjuration.java index 88034e57..57aa98e6 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellConjuration.java +++ b/src/main/java/electroblob/wizardry/spell/SpellConjuration.java @@ -4,10 +4,10 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.IConjuredItem; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.InventoryUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -86,7 +86,7 @@ public class SpellConjuration extends Spell { IConjuredItem.setDurationMultiplier(stack, modifiers.get(WizardryItems.duration_upgrade)); IConjuredItem.setDamageMultiplier(stack, modifiers.get(SpellModifiers.POTENCY)); - if(WizardryUtilities.doesPlayerHaveItem(caster, item)) return false; + if(InventoryUtils.doesPlayerHaveItem(caster, item)) return false; if(caster.getHeldItemMainhand().isEmpty()){ caster.setHeldItem(EnumHand.MAIN_HAND, stack); diff --git a/src/main/java/electroblob/wizardry/spell/SpellConstruct.java b/src/main/java/electroblob/wizardry/spell/SpellConstruct.java index 4ff0fed7..f5cb08f7 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellConstruct.java +++ b/src/main/java/electroblob/wizardry/spell/SpellConstruct.java @@ -3,8 +3,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.entity.construct.EntityMagicConstruct; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -122,7 +122,7 @@ public class SpellConstruct extends Spell { Integer floor = (int)y; if(requiresFloor){ - floor = WizardryUtilities.getNearestFloor(world, new BlockPos(x, y, z), 1); + floor = BlockUtils.getNearestFloor(world, new BlockPos(x, y, z), 1); direction = EnumFacing.UP; } diff --git a/src/main/java/electroblob/wizardry/spell/SpellConstructRanged.java b/src/main/java/electroblob/wizardry/spell/SpellConstructRanged.java index 2ef4670a..aa788087 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellConstructRanged.java +++ b/src/main/java/electroblob/wizardry/spell/SpellConstructRanged.java @@ -4,9 +4,9 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.entity.construct.EntityMagicConstruct; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.RayTracer; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -149,7 +149,7 @@ public class SpellConstructRanged extends SpellC // If the target is not on the ground but the construct must be placed on the floor, searches for the // floor under the caster and returns false if it does not find one within 3 blocks. if(!target.onGround && requiresFloor){ - Integer floor = WizardryUtilities.getNearestFloor(world, new BlockPos(x, y, z), 3); + Integer floor = BlockUtils.getNearestFloor(world, new BlockPos(x, y, z), 3); if(floor == null) return false; y = floor; side = EnumFacing.UP; diff --git a/src/main/java/electroblob/wizardry/spell/SpellMinion.java b/src/main/java/electroblob/wizardry/spell/SpellMinion.java index bc047627..609326af 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellMinion.java +++ b/src/main/java/electroblob/wizardry/spell/SpellMinion.java @@ -4,9 +4,9 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.entity.living.ISummonedCreature; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; -import electroblob.wizardry.util.WizardryUtilities.Operations; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; @@ -148,7 +148,7 @@ public class SpellMinion extends Spe int range = getProperty(SUMMON_RADIUS).intValue(); // Try and find a nearby floor space - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(caster, range, range*2); + BlockPos pos = BlockUtils.findNearbyFloorSpace(caster, range, range*2); if(flying){ if(pos != null){ @@ -174,10 +174,10 @@ public class SpellMinion extends Spe minion.setLifetime((int)(getProperty(MINION_LIFETIME).floatValue() * modifiers.get(WizardryItems.duration_upgrade))); IAttributeInstance attribute = minion.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); if(attribute != null) attribute.applyModifier( // Apparently some things don't have an attack damage - new AttributeModifier(POTENCY_ATTRIBUTE_MODIFIER, modifiers.get(SpellModifiers.POTENCY) - 1, Operations.MULTIPLY_CUMULATIVE)); + new AttributeModifier(POTENCY_ATTRIBUTE_MODIFIER, modifiers.get(SpellModifiers.POTENCY) - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); // This is only used for artefacts, but it's a nice example of custom spell modifiers minion.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier( - new AttributeModifier(HEALTH_MODIFIER, modifiers.get(HEALTH_MODIFIER) - 1, Operations.MULTIPLY_CUMULATIVE)); + new AttributeModifier(HEALTH_MODIFIER, modifiers.get(HEALTH_MODIFIER) - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); minion.setHealth(minion.getMaxHealth()); // Need to set this because we may have just modified the value this.addMinionExtras(minion, pos, caster, modifiers, i); diff --git a/src/main/java/electroblob/wizardry/spell/SpellProjectile.java b/src/main/java/electroblob/wizardry/spell/SpellProjectile.java index 21624770..16d8402f 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellProjectile.java +++ b/src/main/java/electroblob/wizardry/spell/SpellProjectile.java @@ -5,8 +5,8 @@ import electroblob.wizardry.entity.living.ISpellCaster; import electroblob.wizardry.entity.projectile.EntityBomb; import electroblob.wizardry.entity.projectile.EntityMagicProjectile; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -128,7 +128,7 @@ public class SpellProjectile extends Spell { T projectile = projectileFactory.apply(world); // Sets the necessary parameters int aimingError = caster instanceof ISpellCaster ? ((ISpellCaster)caster).getAimingError(world.getDifficulty()) - : WizardryUtilities.getDefaultAimingError(world.getDifficulty()); + : EntityUtils.getDefaultAimingError(world.getDifficulty()); projectile.aim(caster, target, calculateVelocity(projectile, modifiers, caster.getEyeHeight() - (float)EntityMagicProjectile.LAUNCH_Y_OFFSET), aimingError); projectile.damageMultiplier = modifiers.get(SpellModifiers.POTENCY); diff --git a/src/main/java/electroblob/wizardry/spell/SpellRay.java b/src/main/java/electroblob/wizardry/spell/SpellRay.java index 123b655c..49aac7b3 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellRay.java +++ b/src/main/java/electroblob/wizardry/spell/SpellRay.java @@ -2,9 +2,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.RayTracer; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -178,7 +178,7 @@ public abstract class SpellRay extends Spell { Vec3d origin = new Vec3d(caster.posX, caster.getEntityBoundingBox().minY + caster.getEyeHeight() - Y_OFFSET, caster.posZ); Vec3d targetPos = null; - if(!ignoreLivingEntities || !WizardryUtilities.isLiving(target)){ + if(!ignoreLivingEntities || !EntityUtils.isLiving(target)){ targetPos = new Vec3d(target.posX, target.getEntityBoundingBox().minY + target.height / 2, target.posZ); }else{ @@ -261,7 +261,7 @@ public abstract class SpellRay extends Spell { // Change the filter depending on whether living entities are ignored or not RayTraceResult rayTrace = RayTracer.rayTrace(world, origin, endpoint, aimAssist, hitLiquids, - ignoreUncollidables, false, Entity.class, ignoreLivingEntities ? WizardryUtilities::isLiving + ignoreUncollidables, false, Entity.class, ignoreLivingEntities ? EntityUtils::isLiving : RayTracer.ignoreEntityFilter(caster)); boolean flag = false; diff --git a/src/main/java/electroblob/wizardry/spell/SpellThrowable.java b/src/main/java/electroblob/wizardry/spell/SpellThrowable.java index d3145dd6..7f3b0338 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellThrowable.java +++ b/src/main/java/electroblob/wizardry/spell/SpellThrowable.java @@ -3,8 +3,8 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.entity.living.ISpellCaster; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -93,7 +93,7 @@ public class SpellThrowable extends Spell { float velocity = calculateVelocity(modifiers, caster.getEyeHeight() - LAUNCH_Y_OFFSET); T projectile = projectileFactory.apply(world, caster); int aimingError = caster instanceof ISpellCaster ? ((ISpellCaster)caster).getAimingError(world.getDifficulty()) - : WizardryUtilities.getDefaultAimingError(world.getDifficulty()); + : EntityUtils.getDefaultAimingError(world.getDifficulty()); aim(projectile, caster, target, velocity, aimingError); addProjectileExtras(projectile, caster, modifiers); world.spawnEntity(projectile); diff --git a/src/main/java/electroblob/wizardry/spell/SummonIronGolem.java b/src/main/java/electroblob/wizardry/spell/SummonIronGolem.java index fc7329f4..a93c57b8 100644 --- a/src/main/java/electroblob/wizardry/spell/SummonIronGolem.java +++ b/src/main/java/electroblob/wizardry/spell/SummonIronGolem.java @@ -1,10 +1,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.monster.EntityIronGolem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumHand; @@ -22,7 +22,7 @@ public class SummonIronGolem extends Spell { @Override public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){ - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(caster, getProperty(SpellMinion.SUMMON_RADIUS).intValue(), + BlockPos pos = BlockUtils.findNearbyFloorSpace(caster, getProperty(SpellMinion.SUMMON_RADIUS).intValue(), getProperty(SpellMinion.SUMMON_RADIUS).intValue()); if(pos == null) return false; diff --git a/src/main/java/electroblob/wizardry/spell/SummonSnowGolem.java b/src/main/java/electroblob/wizardry/spell/SummonSnowGolem.java index 67b5abe5..c383fe68 100644 --- a/src/main/java/electroblob/wizardry/spell/SummonSnowGolem.java +++ b/src/main/java/electroblob/wizardry/spell/SummonSnowGolem.java @@ -2,10 +2,10 @@ package electroblob.wizardry.spell; import electroblob.wizardry.Wizardry; import electroblob.wizardry.item.SpellActions; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.monster.EntitySnowman; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumHand; @@ -23,7 +23,7 @@ public class SummonSnowGolem extends Spell { @Override public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){ - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(caster, 2, 4); + BlockPos pos = BlockUtils.findNearbyFloorSpace(caster, 2, 4); if(pos == null) return false; if(!world.isRemote){ diff --git a/src/main/java/electroblob/wizardry/spell/SummonSpiritHorse.java b/src/main/java/electroblob/wizardry/spell/SummonSpiritHorse.java index 8e775f51..b43a16e5 100644 --- a/src/main/java/electroblob/wizardry/spell/SummonSpiritHorse.java +++ b/src/main/java/electroblob/wizardry/spell/SummonSpiritHorse.java @@ -5,9 +5,9 @@ import electroblob.wizardry.data.Persistence; import electroblob.wizardry.data.WizardData; import electroblob.wizardry.entity.living.EntitySpiritHorse; import electroblob.wizardry.item.SpellActions; +import electroblob.wizardry.util.BlockUtils; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; -import electroblob.wizardry.util.WizardryUtilities.Operations; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; @@ -54,11 +54,11 @@ public class SummonSpiritHorse extends Spell { if(!world.isRemote){ - Entity oldHorse = WizardryUtilities.getEntityByUUID(world, data.getVariable(UUID_KEY)); + Entity oldHorse = EntityUtils.getEntityByUUID(world, data.getVariable(UUID_KEY)); if(oldHorse != null) oldHorse.setDead(); - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(caster, 2, 4); + BlockPos pos = BlockUtils.findNearbyFloorSpace(caster, 2, 4); if(pos == null) return false; EntitySpiritHorse horse = new EntitySpiritHorse(world); @@ -68,10 +68,10 @@ public class SummonSpiritHorse extends Spell { world.spawnEntity(horse); horse.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).applyModifier( - new AttributeModifier(POTENCY_ATTRIBUTE_MODIFIER, modifiers.get(SpellModifiers.POTENCY) - 1, Operations.MULTIPLY_CUMULATIVE)); + new AttributeModifier(POTENCY_ATTRIBUTE_MODIFIER, modifiers.get(SpellModifiers.POTENCY) - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); // Jump strength increases ridiculously fast, so we're reducing the effect of the modifier by 75% horse.getEntityAttribute(JUMP_STRENGTH).applyModifier(new AttributeModifier(POTENCY_ATTRIBUTE_MODIFIER, - modifiers.amplified(SpellModifiers.POTENCY, 0.25f) - 1, Operations.MULTIPLY_CUMULATIVE)); + modifiers.amplified(SpellModifiers.POTENCY, 0.25f) - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); data.setVariable(UUID_KEY, horse.getUniqueID()); } diff --git a/src/main/java/electroblob/wizardry/spell/SummonSpiritWolf.java b/src/main/java/electroblob/wizardry/spell/SummonSpiritWolf.java index 59c7286c..70a13c6d 100644 --- a/src/main/java/electroblob/wizardry/spell/SummonSpiritWolf.java +++ b/src/main/java/electroblob/wizardry/spell/SummonSpiritWolf.java @@ -5,9 +5,9 @@ import electroblob.wizardry.data.Persistence; import electroblob.wizardry.data.WizardData; import electroblob.wizardry.entity.living.EntitySpiritWolf; import electroblob.wizardry.item.SpellActions; +import electroblob.wizardry.util.BlockUtils; +import electroblob.wizardry.util.EntityUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; -import electroblob.wizardry.util.WizardryUtilities.Operations; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; @@ -44,11 +44,11 @@ public class SummonSpiritWolf extends Spell { if(!world.isRemote){ - Entity oldWolf = WizardryUtilities.getEntityByUUID(world, data.getVariable(UUID_KEY)); + Entity oldWolf = EntityUtils.getEntityByUUID(world, data.getVariable(UUID_KEY)); if(oldWolf != null) oldWolf.setDead(); - BlockPos pos = WizardryUtilities.findNearbyFloorSpace(caster, 2, 4); + BlockPos pos = BlockUtils.findNearbyFloorSpace(caster, 2, 4); if(pos == null) return false; EntitySpiritWolf wolf = new EntitySpiritWolf(world); @@ -57,9 +57,9 @@ public class SummonSpiritWolf extends Spell { wolf.setOwnerId(caster.getUniqueID()); // Potency gives the wolf more strength AND more health wolf.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).applyModifier( - new AttributeModifier(POTENCY_ATTRIBUTE_MODIFIER, modifiers.get(SpellModifiers.POTENCY) - 1, Operations.MULTIPLY_CUMULATIVE)); + new AttributeModifier(POTENCY_ATTRIBUTE_MODIFIER, modifiers.get(SpellModifiers.POTENCY) - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); wolf.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier( - new AttributeModifier(POTENCY_ATTRIBUTE_MODIFIER, modifiers.amplified(SpellModifiers.POTENCY, 1.5f) - 1, Operations.MULTIPLY_CUMULATIVE)); + new AttributeModifier(POTENCY_ATTRIBUTE_MODIFIER, modifiers.amplified(SpellModifiers.POTENCY, 1.5f) - 1, EntityUtils.Operations.MULTIPLY_CUMULATIVE)); wolf.setHealth(wolf.getMaxHealth()); world.spawnEntity(wolf); diff --git a/src/main/java/electroblob/wizardry/spell/Thunderstorm.java b/src/main/java/electroblob/wizardry/spell/Thunderstorm.java index 4b5bd2a6..9c0314dc 100644 --- a/src/main/java/electroblob/wizardry/spell/Thunderstorm.java +++ b/src/main/java/electroblob/wizardry/spell/Thunderstorm.java @@ -63,7 +63,7 @@ public class Thunderstorm extends Spell { double x = caster.posX + radius * MathHelper.cos(angle); double z = caster.posZ + radius * MathHelper.sin(angle); - Integer y = WizardryUtilities.getNearestFloor(world, new BlockPos(x, caster.posY, z), (int)maxRadius); + Integer y = BlockUtils.getNearestFloor(world, new BlockPos(x, caster.posY, z), (int)maxRadius); if(y != null){ @@ -77,7 +77,7 @@ public class Thunderstorm extends Spell { // entityNBT.setInteger("summoningPlayer", entityplayer.entityId); // Secondary chaining effect - List secondaryTargets = WizardryUtilities.getEntitiesWithinRadius( + List secondaryTargets = EntityUtils.getEntitiesWithinRadius( getProperty(SECONDARY_RANGE).doubleValue(), x, y + 1, z, world); for(int j = 0; j < Math.min(secondaryTargets.size(), getProperty(SECONDARY_MAX_TARGETS).intValue()); j++){ @@ -102,7 +102,7 @@ public class Thunderstorm extends Spell { // Tertiary chaining effect - List tertiaryTargets = WizardryUtilities.getEntitiesWithinRadius( + List tertiaryTargets = EntityUtils.getEntitiesWithinRadius( getProperty(TERTIARY_RANGE).doubleValue(), secondaryTarget.posX, secondaryTarget.posY + secondaryTarget.height / 2, secondaryTarget.posZ, world); diff --git a/src/main/java/electroblob/wizardry/spell/Transportation.java b/src/main/java/electroblob/wizardry/spell/Transportation.java index 2992b06c..c5f57c9c 100644 --- a/src/main/java/electroblob/wizardry/spell/Transportation.java +++ b/src/main/java/electroblob/wizardry/spell/Transportation.java @@ -9,10 +9,7 @@ import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.packet.PacketTransportation; import electroblob.wizardry.packet.WizardryPacketHandler; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.Location; -import electroblob.wizardry.util.NBTExtras; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.*; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.MobEffects; import net.minecraft.nbt.NBTTagList; @@ -128,7 +125,7 @@ public class Transportation extends Spell { public static boolean isLocationAimedAt(EntityPlayer player, BlockPos pos, float partialTicks){ Vec3d origin = player.getPositionEyes(partialTicks); - Vec3d centre = WizardryUtilities.getCentre(pos); + Vec3d centre = GeometryUtils.getCentre(pos); Vec3d direction = centre.subtract(origin); double distance = direction.length(); @@ -139,7 +136,7 @@ public class Transportation extends Spell { Vec3d origin = player.getPositionEyes(partialTicks); Vec3d look = player.getLook(partialTicks); - Vec3d centre = WizardryUtilities.getCentre(pos); + Vec3d centre = GeometryUtils.getCentre(pos); Vec3d direction = centre.subtract(origin); double distance = direction.length(); diff --git a/src/main/java/electroblob/wizardry/spell/WallOfFrost.java b/src/main/java/electroblob/wizardry/spell/WallOfFrost.java index 8bdc50a7..2e8b7b82 100644 --- a/src/main/java/electroblob/wizardry/spell/WallOfFrost.java +++ b/src/main/java/electroblob/wizardry/spell/WallOfFrost.java @@ -5,10 +5,8 @@ import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryItems; import electroblob.wizardry.registry.WizardrySounds; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -63,11 +61,11 @@ public class WallOfFrost extends SpellRay { @Override protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(!world.isRemote && WizardryUtilities.canDamageBlocks(caster, world)){ + if(!world.isRemote && EntityUtils.canDamageBlocks(caster, world)){ // Stops the ice being placed floating above snow and grass. Directions other than up included for // completeness. - if(WizardryUtilities.canBlockBeReplaced(world, pos)){ + if(BlockUtils.canBlockBeReplaced(world, pos)){ // Moves the blockpos back into the block pos = pos.offset(side.getOpposite()); } @@ -79,7 +77,7 @@ public class WallOfFrost extends SpellRay { int duration = (int)(getProperty(DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade)); - if(WizardryUtilities.canBlockBeReplaced(world, pos)){ + if(BlockUtils.canBlockBeReplaced(world, pos)){ world.setBlockState(pos, WizardryBlocks.dry_frosted_ice.getDefaultState()); world.scheduleUpdate(pos.toImmutable(), WizardryBlocks.dry_frosted_ice, duration); } @@ -88,7 +86,7 @@ public class WallOfFrost extends SpellRay { if(side == EnumFacing.UP){ pos = pos.offset(side); - if(WizardryUtilities.canBlockBeReplaced(world, pos)){ + if(BlockUtils.canBlockBeReplaced(world, pos)){ world.setBlockState(pos, WizardryBlocks.dry_frosted_ice.getDefaultState()); world.scheduleUpdate(pos.toImmutable(), WizardryBlocks.dry_frosted_ice, duration); } diff --git a/src/main/java/electroblob/wizardry/spell/Wither.java b/src/main/java/electroblob/wizardry/spell/Wither.java index 0b1667b0..a50c64f1 100644 --- a/src/main/java/electroblob/wizardry/spell/Wither.java +++ b/src/main/java/electroblob/wizardry/spell/Wither.java @@ -2,12 +2,9 @@ package electroblob.wizardry.spell; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; -import electroblob.wizardry.util.MagicDamage; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.MagicDamage.DamageType; -import electroblob.wizardry.util.ParticleBuilder; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -30,7 +27,7 @@ public class Wither extends SpellRay { @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ - if(WizardryUtilities.isLiving(target)){ + if(EntityUtils.isLiving(target)){ // Has no effect on withers or wither skeletons. if(MagicDamage.isEntityImmune(DamageType.WITHER, target)){ diff --git a/src/main/java/electroblob/wizardry/spell/ZombieApocalypse.java b/src/main/java/electroblob/wizardry/spell/ZombieApocalypse.java index aa94ebe1..26415079 100644 --- a/src/main/java/electroblob/wizardry/spell/ZombieApocalypse.java +++ b/src/main/java/electroblob/wizardry/spell/ZombieApocalypse.java @@ -4,9 +4,8 @@ import electroblob.wizardry.entity.construct.EntityZombieSpawner; import electroblob.wizardry.item.ItemArtefact; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryItems; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.SpellModifiers; -import electroblob.wizardry.util.WizardryUtilities; -import electroblob.wizardry.util.WizardryUtilities.SurfaceCriteria; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumFacing; @@ -37,8 +36,8 @@ public class ZombieApocalypse extends SpellConstruct { @Override protected boolean spawnConstruct(World world, double x, double y, double z, EnumFacing side, @Nullable EntityLivingBase caster, SpellModifiers modifiers){ - Integer ceiling = WizardryUtilities.getNearestSurface(world, new BlockPos(x, y + MIN_SPAWNER_HEIGHT, z), - EnumFacing.UP, SPAWNER_HEIGHT - MIN_SPAWNER_HEIGHT, false, SurfaceCriteria.COLLIDABLE.flip()); + Integer ceiling = BlockUtils.getNearestSurface(world, new BlockPos(x, y + MIN_SPAWNER_HEIGHT, z), + EnumFacing.UP, SPAWNER_HEIGHT - MIN_SPAWNER_HEIGHT, false, BlockUtils.SurfaceCriteria.COLLIDABLE.flip()); if(ceiling == null) y += SPAWNER_HEIGHT; else y = ceiling - 0.5; diff --git a/src/main/java/electroblob/wizardry/tileentity/TileEntityPlayerSave.java b/src/main/java/electroblob/wizardry/tileentity/TileEntityPlayerSave.java index 37fd6470..2cb0fa43 100644 --- a/src/main/java/electroblob/wizardry/tileentity/TileEntityPlayerSave.java +++ b/src/main/java/electroblob/wizardry/tileentity/TileEntityPlayerSave.java @@ -1,7 +1,7 @@ package electroblob.wizardry.tileentity; import electroblob.wizardry.Wizardry; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.EntityUtils; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; @@ -52,7 +52,7 @@ public class TileEntityPlayerSave extends TileEntity { @Nullable public EntityLivingBase getCaster(){ - Entity entity = WizardryUtilities.getEntityByUUID(world, casterUUID); + Entity entity = EntityUtils.getEntityByUUID(world, casterUUID); if(entity != null && !(entity instanceof EntityLivingBase)){ // Should never happen Wizardry.logger.warn("{} has a non-living owner!", this); diff --git a/src/main/java/electroblob/wizardry/tileentity/TileEntityShrineCore.java b/src/main/java/electroblob/wizardry/tileentity/TileEntityShrineCore.java index f34a834b..6bde7079 100644 --- a/src/main/java/electroblob/wizardry/tileentity/TileEntityShrineCore.java +++ b/src/main/java/electroblob/wizardry/tileentity/TileEntityShrineCore.java @@ -11,10 +11,8 @@ import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.registry.WizardrySounds; import electroblob.wizardry.spell.ArcaneLock; -import electroblob.wizardry.util.NBTExtras; -import electroblob.wizardry.util.ParticleBuilder; +import electroblob.wizardry.util.*; import electroblob.wizardry.util.ParticleBuilder.Type; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -54,7 +52,7 @@ public class TileEntityShrineCore extends TileEntity implements ITickable { private void initContainmentField(BlockPos pos){ float r = PotionContainment.getContainmentDistance(0); - this.containmentField = new AxisAlignedBB(-r, -r, -r, r, r, r).offset(WizardryUtilities.getCentre(pos)); + this.containmentField = new AxisAlignedBB(-r, -r, -r, r, r, r).offset(GeometryUtils.getCentre(pos)); } public void linkContainer(TileEntity container){ @@ -94,7 +92,7 @@ public class TileEntityShrineCore extends TileEntity implements ITickable { float angle = world.rand.nextFloat() * 2 * (float)Math.PI; double x1 = this.pos.getX() + 0.5 + 5 * MathHelper.sin(angle); double z1 = this.pos.getZ() + 0.5 + 5 * MathHelper.cos(angle); - Integer y1 = WizardryUtilities.getNearestFloor(world, new BlockPos(x1, this.pos.getY(), z1), 8); + Integer y1 = BlockUtils.getNearestFloor(world, new BlockPos(x1, this.pos.getY(), z1), 8); if(y1 == null){ // Fallback to the position of the shrine core if it failed to find a position (unlikely) x1 = this.pos.getX() + 1; // Offset it so the wizard isn't inside the block @@ -128,7 +126,7 @@ public class TileEntityShrineCore extends TileEntity implements ITickable { private boolean areWizardsDead(){ for(UUID uuid : linkedWizards){ - Entity entity = WizardryUtilities.getEntityByUUID(world, uuid); + Entity entity = EntityUtils.getEntityByUUID(world, uuid); if(entity instanceof EntityEvilWizard && entity.isEntityAlive()) return false; } diff --git a/src/main/java/electroblob/wizardry/tileentity/TileEntityStatue.java b/src/main/java/electroblob/wizardry/tileentity/TileEntityStatue.java index 4f07e8e1..e1e07719 100644 --- a/src/main/java/electroblob/wizardry/tileentity/TileEntityStatue.java +++ b/src/main/java/electroblob/wizardry/tileentity/TileEntityStatue.java @@ -1,7 +1,7 @@ package electroblob.wizardry.tileentity; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.NBTExtras; -import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.block.Block; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLiving; @@ -108,7 +108,7 @@ public class TileEntityStatue extends TileEntity implements ITickable { // Breaks the block at light levels of 7 or below, with a higher chance the lower the light level. // The chance is (8 - light level)/12, so at light 0 the chance is 3/4 and at light 7 the chance is 1/12. if(!this.world.isRemote && this.timer % 200 == 0 && this.timer > lifetime && !this.isIce && this.position == 1){ - if(WizardryUtilities.getLightLevel(world, pos) < this.world.rand.nextInt(12) - 3){ + if(BlockUtils.getLightLevel(world, pos) < this.world.rand.nextInt(12) - 3){ // This is all that is needed because destroyBlock invokes the breakBlock function in // BlockPetrifiedStone // and that function handles all the spawning and stuff. diff --git a/src/main/java/electroblob/wizardry/util/AllyDesignationSystem.java b/src/main/java/electroblob/wizardry/util/AllyDesignationSystem.java index b2f8175d..248b3193 100644 --- a/src/main/java/electroblob/wizardry/util/AllyDesignationSystem.java +++ b/src/main/java/electroblob/wizardry/util/AllyDesignationSystem.java @@ -14,7 +14,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; /** * Contains some useful static methods for interacting with the ally designation system. Also handles the friendly fire - * setting. This was split off from {@link WizardryUtilities} as of wizardry 4.2 in an effort to make the code easier to + * setting. This was split off from {@link JavaUtils} as of wizardry 4.2 in an effort to make the code easier to * navigate. */ @Mod.EventBusSubscriber @@ -144,7 +144,7 @@ public final class AllyDesignationSystem { NBTTagCompound entityNBT = target.getEntityData(); if(entityNBT != null && entityNBT.hasUniqueId(MindControl.NBT_KEY)){ - if(attacker == WizardryUtilities.getEntityByUUID(target.world, + if(attacker == EntityUtils.getEntityByUUID(target.world, entityNBT.getUniqueId(MindControl.NBT_KEY))){ return false; } @@ -177,7 +177,7 @@ public final class AllyDesignationSystem { if(entityNBT != null && entityNBT.hasKey(MindControl.NBT_KEY)){ - Entity controller = WizardryUtilities.getEntityByUUID(target.world, entityNBT.getUniqueId(MindControl.NBT_KEY)); + Entity controller = EntityUtils.getEntityByUUID(target.world, entityNBT.getUniqueId(MindControl.NBT_KEY)); if(controller instanceof EntityPlayer && WizardData.get((EntityPlayer)attacker).isPlayerAlly((EntityPlayer)controller)){ return false; diff --git a/src/main/java/electroblob/wizardry/util/BlockUtils.java b/src/main/java/electroblob/wizardry/util/BlockUtils.java new file mode 100644 index 00000000..675d5336 --- /dev/null +++ b/src/main/java/electroblob/wizardry/util/BlockUtils.java @@ -0,0 +1,474 @@ +package electroblob.wizardry.util; + +import electroblob.wizardry.Settings; +import electroblob.wizardry.Wizardry; +import net.minecraft.block.*; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; +import net.minecraft.init.Blocks; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiPredicate; +import java.util.function.Predicate; + +/** + * Contains useful static methods for interacting with blocks and block states. These methods used to be part of + * {@code WizardryUtilities}. + * @see GeometryUtils + * @see EntityUtils + * @author Electroblob + * @since Wizardry 4.3 + */ +public final class BlockUtils { + + private BlockUtils(){} // No instances! + + // General + // =============================================================================================================== + + /** + * Returns a block state for the given block, with all properties set to the values from the given source state. + * The source block state must have exactly the same properties as the destination block will allow or an + * {@link IllegalArgumentException} will be thrown. + *

+ * This method allows, for example, an oak door block to be replaced with a spruce one whilst keeping the same + * orientation, door half, open/closed state, etc. + * @param block The new block type + * @param source The block state to copy property values from + * @return The resulting block state + */ + @SuppressWarnings({"unchecked", "rawtypes"}) // Don't complain to me about Mojang's code design... + public static IBlockState copyState(Block block, IBlockState source){ + + IBlockState state = block.getDefaultState(); + + for(IProperty property : source.getPropertyKeys()){ + // It ain't pretty but it works + state = state.withProperty(property, (Comparable)source.getProperties().get(property)); + } + + return state; + } + + /** + * Returns the actual light level at the given position, taking natural light (skylight) and artificial light + * (block light) into account. This uses the same logic as mob spawning. + * @param world The world the position is in + * @param pos The position to query + * @return The light level, from 0 (pitch darkness) to 15 (full daylight/at a torch). + */ + public static int getLightLevel(World world, BlockPos pos){ + + int i = world.getLightFromNeighbors(pos); + + if(world.isThundering()){ + int j = world.getSkylightSubtracted(); + world.setSkylightSubtracted(10); + i = world.getLightFromNeighbors(pos); + world.setSkylightSubtracted(j); + } + + return i; + } + + /** + * Returns whether the block at the given position can be replaced by another one (works as if a block is being + * placed by a player). True for air, vines, tall grass and snow layers but not for flowers, signs etc. + * This is a shortcut for world.getBlockState(pos).getMaterial().isReplaceable(), with a few extra bits. + * + * @param world The world the block is in. + * @param pos The position of the block. + * @param excludeLiquids True to treat liquids as non-replaceable, false to treat liquids as replaceable. + * + * @see BlockUtils#canBlockBeReplaced(World, BlockPos) + */ + public static boolean canBlockBeReplaced(World world, BlockPos pos, boolean excludeLiquids){ + return (world.isAirBlock(new BlockPos(pos)) || world.getBlockState(pos).getMaterial().isReplaceable()) + && (!excludeLiquids || !world.getBlockState(pos).getMaterial().isLiquid()); + } + + /** + * Returns whether the block at the given position can be replaced by another one (works as if a block is being + * placed by a player). True for air, liquids, vines, tall grass and snow layers but not for flowers, signs etc. + * This is a shorthand version of {@link BlockUtils#canBlockBeReplaced(World, BlockPos, boolean)}; + * excludeLiquids defaults to false. + * + * @param world The world the block is in. + * @param pos The position of the block. + */ + public static boolean canBlockBeReplaced(World world, BlockPos pos){ + return canBlockBeReplaced(world, pos, false); + } + + /** + * Returns whether the block at the given coordinates is unbreakable in survival mode. In vanilla this is true for + * bedrock and end portal frame, for example. This is a shortcut for:

+ * {@code world.getBlockState(pos).getBlockHardness(world, pos) == -1.0f} + */ + public static boolean isBlockUnbreakable(World world, BlockPos pos){ + return !world.isAirBlock(new BlockPos(pos)) && world.getBlockState(pos).getBlockHardness(world, pos) == -1.0f; + } + + /** + * Gets the blockstate of the block the specified entity is standing on. Uses + * {@link MathHelper#floor(double)} because casting to int will not return the correct coordinate when x or z + * is negative. + */ + public static IBlockState getBlockEntityIsStandingOn(Entity entity){ + BlockPos pos = new BlockPos(MathHelper.floor(entity.posX), (int)entity.getEntityBoundingBox().minY - 1, + MathHelper.floor(entity.posZ)); + return entity.world.getBlockState(pos); + } + + /** + * Generates a sphere of block positions centred on the given position, with the given radius. This is an efficient + * implementation - rather than simply generating a cube and cutting the rest out, it works as follows: + *

+ * 1. Step through all x offsets within the specified radius
+ * 2. For each x offset, check the maximum y offset within the radius using Pythagoras
+ * 3. Step through the resulting valid y offsets
+ * 4. For each y offset, check the maximum z offset within the radius using Pythagoras
+ * 5. Step through the resulting valid z offsets + * @return A list of BlockPos objects in a sphere. This list will be ordered negative to positive, with axes + * nested in order (i.e. blocks in a line on the z axis will be consecutive in the list). + */ + public static List getBlockSphere(BlockPos centre, double radius){ + + // Extra efficiency by assigning enough capacity for a cube of side length r + List sphere = new ArrayList<>((int)Math.pow(radius, 3)); + + for(int i=-(int)radius; i<=radius; i++){ + + float r1 = MathHelper.sqrt(radius*radius - i*i); + + for(int j=-(int)r1; j<=r1; j++){ + + float r2 = MathHelper.sqrt(radius*radius - i*i - j*j); + + for(int k=-(int)r2; k<=r2; k++){ + sphere.add(centre.add(i, j, k)); + } + } + } + + return sphere; + } + + // Specific blocks + // =============================================================================================================== + + /** + * Returns true if the block at the given position is a tree block (or other 'solid' vegetation, such as cacti). + * Used for structure generation. + * @param world The world the block is in + * @param pos The position of the block to be tested + * @return True if the given block is a tree block, false if not. + */ + public static boolean isTreeBlock(World world, BlockPos pos){ + Block block = world.getBlockState(pos).getBlock(); + return block instanceof BlockLog || block instanceof BlockCactus + || block.isLeaves(world.getBlockState(pos), world, pos) || block.isFoliage(world, pos) + || Settings.containsMetaBlock(Wizardry.settings.treeBlocks, world.getBlockState(pos)); + } + + /** + * Given the position of one half of a double chest, returns the position of the other half of that double chest. + * @param world The world in which the chest is located + * @param pos The position of one half of the double chest + * @return The position of the other half of the double chest, or null if the given position is not part of a + * double chest. + */ + public static BlockPos getConnectedChest(World world, BlockPos pos){ + + Block block = world.getBlockState(pos).getBlock(); + + if(block instanceof BlockChest){ + for(EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL){ + BlockPos pos1 = pos.offset(enumfacing); + if(world.getBlockState(pos1).getBlock() == block){ + return pos1; + } + } + } + + return null; + } + + /** + * Returns true if the given block is a water source block (specifically, water or flowing water with a level of 0). + * @param state The block state to query + * @return True if the given block state is a water source block, false otherwise. + */ + public static boolean isWaterSource(IBlockState state){ + return state.getMaterial() == Material.WATER && (state.getBlock() == Blocks.WATER || state.getBlock() == Blocks.FLOWING_WATER) && state.getValue(BlockLiquid.LEVEL) == 0; + } + + /** + * Returns true if the given block is a lava source block (specifically, lava or flowing lava with a level of 0). + * @param state The block state to query + * @return True if the given block state is a lava source block, false otherwise. + */ + public static boolean isLavaSource(IBlockState state){ + return state.getMaterial() == Material.LAVA && (state.getBlock() == Blocks.LAVA || state.getBlock() == Blocks.FLOWING_LAVA) && state.getValue(BlockLiquid.LEVEL) == 0; + } + + /** + * Freezes the given block, either by turning water to ice, lava to obsidian/cobblestone or by placing snow on top + * of it if possible. + * @param world The world the block is in + * @param pos The position of the block to freeze + * @param freezeLava True to freeze lava into obsidian or cobblestone, false to leave it unchanged + * @return True if any blocks were changed, false if not. + */ + public static boolean freeze(World world, BlockPos pos, boolean freezeLava){ + + IBlockState state = world.getBlockState(pos); + Block block = state.getBlock(); + + if(isWaterSource(state)){ + world.setBlockState(pos, Blocks.ICE.getDefaultState()); + }else if(freezeLava && isLavaSource(state)){ + world.setBlockState(pos, Blocks.OBSIDIAN.getDefaultState()); + }else if(freezeLava && (block == Blocks.LAVA || block == Blocks.FLOWING_LAVA)){ + world.setBlockState(pos, Blocks.COBBLESTONE.getDefaultState()); + }else if(block.isReplaceable(world, pos.up()) && Blocks.SNOW_LAYER.canPlaceBlockAt(world, pos.up())){ + world.setBlockState(pos.up(), Blocks.SNOW_LAYER.getDefaultState()); + }else{ + return false; + } + + return true; + } + + // Floor finding + // =============================================================================================================== + + /** + * Finds the nearest surface (according to the given criteria) in the given direction from the given position, + * within the range specified. This is a generalised replacement for the old {@code getNearestFloorLevel} methods; + * overloads and predefined surface criteria that replicate the old behaviours are available. + * + * @param world The world to search in + * @param pos The position to search from + * @param direction The direction to search in; also defines the direction the surface must face. + * @param range The maximum distance from the given y coordinate to search. + * @param doubleSided True to also search in the opposite direction, false to only search in the given direction. + * @param criteria A {@link SurfaceCriteria} representing the criteria defining a surface. See that class for + * available predefined criteria. + * @return The x, y, or z coordinate of the closest surface, or null if no surface was found. This represents the + * exact position of the block boundary that forms the surface (and therefore it may correspond to the coordinate + * of the inside or outside block of the surface depending on the direction). + */ + @Nullable + public static Integer getNearestSurface(World world, BlockPos pos, EnumFacing direction, int range, + boolean doubleSided, SurfaceCriteria criteria){ + + // This is a neat trick that allows a default 'not found' return value for integers where all possible integer + // values could, in theory, be returned. The alternative is to use a double and have NaN as the default, but + // that would introduce extra casting, and since NaN can be calculated with, it could produce strange results + // when unaccounted for. Using an Integer means it'll immediately throw an NPE instead. + Integer surface = null; + int currentBest = Integer.MAX_VALUE; + + for(int i = doubleSided ? -range : 0; i <= range && i < currentBest; i++){ // Now short-circuits for efficiency + + BlockPos testPos = pos.offset(direction, i); + + if(criteria.test(world, testPos, direction)){ + // Because the loop now short-circuits, this must be closer than the previous surface found + surface = (int)GeometryUtils.component(GeometryUtils.getFaceCentre(testPos, direction), direction.getAxis()); + currentBest = Math.abs(i); + } + } + + return surface; + } + + /** + * Finds the nearest floor level in the given direction from the given position, + * within the range specified. This is a shorthand for + * {@link BlockUtils#getNearestSurface(World, BlockPos, EnumFacing, int, boolean, SurfaceCriteria)}; + * {@code doubleSided} defaults to true, {@code direction} defaults to {@code EnumFacing.UP}, and + * {@code criteria} defaults to {@link SurfaceCriteria#COLLIDABLE}. + */ + @Nullable + public static Integer getNearestFloor(World world, BlockPos pos, int range){ + return getNearestSurface(world, pos, EnumFacing.UP, range, true, SurfaceCriteria.COLLIDABLE); + } + + /** + * Gets a random position on the ground near the given entity within the specified horizontal and vertical ranges. + * Used to find a position to spawn entities in summoning spells. + * + * @param entity The entity around which to search. + * @param horizontalRange The maximum number of blocks on the x or z axis the returned position can be from the + * given entity. The number of operations performed by this method is proportional to the square of this + * parameter, so for performance reasons it is recommended that it does not exceed around 10. + * @param verticalRange The maximum number of blocks on the y axis the returned position can be from the given + * entity. + * @return A BlockPos with the coordinates of the block directly above the ground at the position found, or null if + * none were found within range. Importantly, since this method checks all possible positions within + * range (i.e. randomness only occurs when deciding between the possible positions), if it returns null once + * then it will always return null given the same circumstances and parameters. What this means is that you + * can (and should) immediately stop trying to cast a summoning spell if this returns null. + */ + @Nullable + public static BlockPos findNearbyFloorSpace(Entity entity, int horizontalRange, int verticalRange){ + + World world = entity.world; + BlockPos origin = new BlockPos(entity); + return findNearbyFloorSpace(world, origin, horizontalRange, verticalRange); + } + + /** + * Gets a random position on the ground near the given BlockPos within the specified horizontal and vertical ranges. + * Used to find a position to spawn entities in summoning spells. + * + * @param world The world in which to search. + * @param origin The BlockPos around which to search. + * @param horizontalRange The maximum number of blocks on the x or z axis the returned position can be from the + * given position. The number of operations performed by this method is proportional to the square of this + * parameter, so for performance reasons it is recommended that it does not exceed around 10. + * @param verticalRange The maximum number of blocks on the y axis the returned position can be from the given + * position. + * @return A BlockPos with the coordinates of the block directly above the ground at the position found, or null if + * none were found within range. Importantly, since this method checks all possible positions within + * range (i.e. randomness only occurs when deciding between the possible positions), if it returns null once + * then it will always return null given the same circumstances and parameters. What this means is that you + * can (and should) immediately stop trying to cast a summoning spell if this returns null. + */ + @Nullable + public static BlockPos findNearbyFloorSpace(World world, BlockPos origin, int horizontalRange, int verticalRange){ + return findNearbyFloorSpace(world, origin, horizontalRange, verticalRange, true); + } + + /** + * Gets a random position on the ground near the given BlockPos within the specified horizontal and vertical ranges. + * Used to find a position to spawn entities in summoning spells. + * + * @param world The world in which to search. + * @param origin The BlockPos around which to search. + * @param horizontalRange The maximum number of blocks on the x or z axis the returned position can be from the + * given position. The number of operations performed by this method is proportional to the square of this + * parameter, so for performance reasons it is recommended that it does not exceed around 10. + * @param verticalRange The maximum number of blocks on the y axis the returned position can be from the given + * position. + * @param lineOfSight Whether to require line-of-sight from the origin to the returned position. + * @return A BlockPos with the coordinates of the block directly above the ground at the position found, or null if + * none were found within range. Importantly, since this method checks all possible positions within + * range (i.e. randomness only occurs when deciding between the possible positions), if it returns null once + * then it will always return null given the same circumstances and parameters. What this means is that you + * can (and should) immediately stop trying to cast a summoning spell if this returns null. + */ + @Nullable + public static BlockPos findNearbyFloorSpace(World world, BlockPos origin, int horizontalRange, int verticalRange, boolean lineOfSight){ + + List possibleLocations = new ArrayList<>(); + + final Vec3d centre = GeometryUtils.getCentre(origin); + + for(int x = -horizontalRange; x <= horizontalRange; x++){ + for(int z = -horizontalRange; z <= horizontalRange; z++){ + + Integer y = getNearestFloor(world, origin.add(x, 0, z), verticalRange); + + if(y != null){ + + BlockPos location = new BlockPos(origin.getX() + x, y, origin.getZ() + z); + + if(lineOfSight){ + // Since we're only using finding collidable surfaces, it doesn't make much sense to include + // non-collidable blocks here! + RayTraceResult rayTrace = world.rayTraceBlocks(centre, GeometryUtils.getCentre(location), + false, true, false); + if(rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.BLOCK) continue; + } + + possibleLocations.add(location); + } + } + } + + if(possibleLocations.isEmpty()){ + return null; + }else{ + return possibleLocations.get(world.rand.nextInt(possibleLocations.size())); + } + } + + /** + * A {@code SurfaceCriteria} object is used to define a 'surface', a boundary between two blocks which differ in + * some way, for use in {@link BlockUtils#getNearestSurface(World, BlockPos, EnumFacing, int, boolean, SurfaceCriteria)}. + * This provides a more flexible replacement for the old {@code getNearestFloorLevel} methods.
+ *
+ * In the context of this class, 'outside' refers to the side of the surface that is in the supplied direction, + * and 'inside' refers to the side which is in the opposite direction. For example, if the direction is {@code UP}, + * the inside of the surface is defined as below it, and the outside is defined as above it. + */ + @FunctionalInterface + public interface SurfaceCriteria { + + /** + * Tests whether the inputs define a valid surface according to this set of criteria. + * @param world The world in which the surface is to be tested. + * @param pos The block coordinates of the inside ('solid' part) of the surface. + * @param side The direction in which the surface must face. + * @return True if the side {@code side} of the block at {@code pos} in {@code world} is a valid surface + * according to this set of criteria, false otherwise. + */ + boolean test(World world, BlockPos pos, EnumFacing side); + + /** Returns a {@code SurfaceCriteria} with the opposite arrangement to this one. */ + default SurfaceCriteria flip(){ + return (world, pos, side) -> this.test(world, pos.offset(side), side.getOpposite()); + } + + /** Returns a {@code SurfaceCriteria} based on the given condition, where the inside of the surface satisfies + * the condition and the outside does not. */ + static SurfaceCriteria basedOn(BiPredicate condition){ + return (world, pos, side) -> condition.test(world, pos) && !condition.test(world, pos.offset(side)); + } + + /** Returns a {@code SurfaceCriteria} based on the given condition, where the inside of the surface satisfies + * the condition and the outside does not. */ + static SurfaceCriteria basedOn(Predicate condition){ + return (world, pos, side) -> condition.test(world.getBlockState(pos)) && !condition.test(world.getBlockState(pos.offset(side))); + } + + /** Surface criterion which defines a surface as the boundary between a block that cannot be moved through and + * a block that can be moved through. This means the surface can be stood on. */ + SurfaceCriteria COLLIDABLE = basedOn(b -> b.getMaterial().blocksMovement()); + + /** Surface criterion which defines a surface as the boundary between a block that is solid on the required side and + * a block that is replaceable. This means the surface can be built on. */ + SurfaceCriteria BUILDABLE = (world, pos, side) -> world.isSideSolid(pos, side) && world.getBlockState(pos.offset(side)).getBlock().isReplaceable(world, pos.offset(side)); + + /** Surface criterion which defines a surface as the boundary between a block that is solid on the required side + * or a liquid, and an air block. Used for freezing water and placing snow. */ + // Was getNearestFloorLevelB + SurfaceCriteria SOLID_LIQUID_TO_AIR = (world, pos, side) -> (world.getBlockState(pos).getMaterial().isLiquid() + || world.isSideSolid(pos, side) && world.isAirBlock(pos.offset(side))); + + /** Surface criterion which defines a surface as the boundary between any non-air block and an air block. + * Used for particles. */ + // Was getNearestFloorLevelC + SurfaceCriteria NOT_AIR_TO_AIR = basedOn(World::isAirBlock).flip(); + + /** Surface criterion which defines a surface as the boundary between a block that cannot be moved through, and + * a block that can be moved through or a tree block (log or leaves). Used for structure generation. */ + SurfaceCriteria COLLIDABLE_IGNORING_TREES = basedOn((world, pos) -> + world.getBlockState(pos).getMaterial().blocksMovement() && !isTreeBlock(world, pos)); + + } + +} diff --git a/src/main/java/electroblob/wizardry/util/EntityUtils.java b/src/main/java/electroblob/wizardry/util/EntityUtils.java new file mode 100644 index 00000000..5f1e1e61 --- /dev/null +++ b/src/main/java/electroblob/wizardry/util/EntityUtils.java @@ -0,0 +1,353 @@ +package electroblob.wizardry.util; + +import electroblob.wizardry.Wizardry; +import electroblob.wizardry.data.WizardData; +import electroblob.wizardry.entity.living.ISpellCaster; +import electroblob.wizardry.item.ISpellCastingItem; +import electroblob.wizardry.spell.Spell; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.item.EntityArmorStand; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.network.datasync.DataParameter; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.DamageSource; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.fml.common.ObfuscationReflectionHelper; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.UUID; + +/** + * Contains useful static methods for retrieving and interacting with players, mobs and other entities. These methods + * used to be part of {@code WizardryUtilities}. + * @see BlockUtils + * @see MagicDamage + * @see AllyDesignationSystem + * @author Electroblob + * @since Wizardry 4.3 + */ +public final class EntityUtils { + + private EntityUtils(){} // No instances! + + /** Changed to a constant in wizardry 2.1, since this is a lot more efficient. */ + private static final DataParameter POWERED; + + static { + // Null is passed in deliberately since POWERED is a static field. + POWERED = ObfuscationReflectionHelper.getPrivateValue(EntityCreeper.class, null, "field_184714_b"); + } + + /** Stores constant values for attribute modifier operations (and javadoc for what they actually do!) */ + // I'm fed up with remembering these... + public static final class Operations { + + private Operations(){} // No instances! + + /** Adds the attribute modifier amount to the base value. */ + public static final int ADD = 0; + /** Multiplies the base value by 1 plus the attribute modifier amount. Multiple modifiers are processed in + * parallel, i.e. the calculation is based on the base value and does not depend on previous modifiers. */ + public static final int MULTIPLY_FLAT = 1; + /** Multiplies the base value by 1 plus the attribute modifier amount. Multiple modifiers are processed in + * series, i.e. the calculation is based on the value after previous modifiers are applied, in the order added. */ + public static final int MULTIPLY_CUMULATIVE = 2; + } + + // Entity retrieval + // =============================================================================================================== + + /** + * Shorthand for {@link EntityUtils#getEntitiesWithinRadius(double, double, double, double, World, Class)} + * with EntityLivingBase as the entity type. This is by far the most common use for that method. + * + * @param radius The search radius + * @param x The x coordinate to search around + * @param y The y coordinate to search around + * @param z The z coordinate to search around + * @param world The world to search in + */ + public static List getEntitiesWithinRadius(double radius, double x, double y, double z, World world){ + return getEntitiesWithinRadius(radius, x, y, z, world, EntityLivingBase.class); + } + + /** + * Returns all entities of the specified type within the specified radius of the given coordinates. This is + * different to using a raw AABB because a raw AABB will search in a cube volume rather than a sphere. Note that + * this does not exclude any entities; if any specific entities are to be excluded this must be checked when + * iterating through the list. + * + * @see EntityUtils#getEntitiesWithinRadius(double, double, double, double, World) + * @param radius The search radius + * @param x The x coordinate to search around + * @param y The y coordinate to search around + * @param z The z coordinate to search around + * @param world The world to search in + * @param entityType The class of entity to search for; pass in Entity.class for all entities + */ + public static List getEntitiesWithinRadius(double radius, double x, double y, double z, World world, Class entityType){ + AxisAlignedBB aabb = new AxisAlignedBB(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius); + List entityList = world.getEntitiesWithinAABB(entityType, aabb); + for(int i = 0; i < entityList.size(); i++){ + if(entityList.get(i).getDistance(x, y, z) > radius){ + entityList.remove(i); + break; + } + } + return entityList; + } + + /** + * Gets an entity from its UUID. If the UUID is known to belong to an {@code EntityPlayer}, use the more efficient + * {@link World#getPlayerEntityByUUID(UUID)} instead. + * + * @param world The world the entity is in + * @param id The entity's UUID + * @return The Entity that has the given UUID, or null if no such entity exists in the specified world. + */ + @Nullable + public static Entity getEntityByUUID(World world, @Nullable UUID id){ + + if(id == null) return null; // It would return null eventually but there's no point even looking + + for(Entity entity : world.loadedEntityList){ + // This is a perfect example of where you need to use .equals() and not ==. For most applications, + // this was unnoticeable until world reload because the UUID instance or entity instance is stored. + // Fixed now though. + if(entity != null && entity.getUniqueID() != null && entity.getUniqueID().equals(id)){ + return entity; + } + } + return null; + } + + /** + * Returns the entity riding the given entity, or null if there is none. Allows for neater code now that entities + * have a list of passengers, because it is necessary to check that the list is not empty first. + */ + @Nullable + public static Entity getRider(Entity entity){ + return !entity.getPassengers().isEmpty() ? entity.getPassengers().get(0) : null; + } + + // Motion + // =============================================================================================================== + + /** + * Undoes 1 tick's worth of velocity change due to gravity for the given entity. If the entity has no gravity, + * this method does nothing. This method is intended to be used in situations where entity gravity needs to be + * turned on and off and it is not practical to use {@link Entity#setNoGravity(boolean)}, usually if there is no + * easy way to get a reference to the entity to turn gravity back on. + * + * @param entity The entity to undo gravity for. + */ + public static void undoGravity(Entity entity){ + if(!entity.hasNoGravity()){ + double gravity = 0.04; + if(entity instanceof EntityThrowable) gravity = 0.03; + else if(entity instanceof EntityArrow) gravity = 0.05; + else if(entity instanceof EntityLivingBase) gravity = 0.08; + entity.motionY += gravity; + } + } + + /** + * Applies the standard (non-enchanted) amount of knockback to the given target, using the same calculation as + * {@link EntityLivingBase#attackEntityFrom(DamageSource, float)}. Use in conjunction with + * {@link EntityUtils#attackEntityWithoutKnockback(Entity, DamageSource, float)} to change the source of + * knockback for an attack. + * + * @param attacker The entity that caused the knockback; the target will be pushed away from this entity. + * @param target The entity to be knocked back. + */ + public static void applyStandardKnockback(Entity attacker, EntityLivingBase target){ + double dx = attacker.posX - target.posX; + double dz; + for(dz = attacker.posZ - target.posZ; dx * dx + dz * dz < 1.0E-4D; dz = (Math.random() - Math.random()) + * 0.01D){ + dx = (Math.random() - Math.random()) * 0.01D; + } + target.knockBack(attacker, 0.4f, dx, dz); + } + + // Damage + // =============================================================================================================== + + /** + * Attacks the given entity with the given damage source and amount, but preserving the entity's original velocity + * instead of applying knockback, as would happen with + * {@link EntityLivingBase#attackEntityFrom(DamageSource, float)} (More accurately, calls that method as normal + * and then resets the entity's velocity to what it was before). Handy for when you need to damage an entity + * repeatedly in a short space of time. + * + * @param entity The entity to attack + * @param source The source of the damage + * @param amount The amount of damage to apply + * @return True if the attack succeeded, false if not. + */ + public static boolean attackEntityWithoutKnockback(Entity entity, DamageSource source, float amount){ + double vx = entity.motionX; + double vy = entity.motionY; + double vz = entity.motionZ; + boolean succeeded = entity.attackEntityFrom(source, amount); + entity.motionX = vx; + entity.motionY = vy; + entity.motionZ = vz; + return succeeded; + } + + /** + * Returns whether the given {@link DamageSource} is melee damage. This method makes a best guess as to whether + * the damage was from a melee attack; there is no way of testing this properly. + * @param source The damage source to be tested. + * @return True if the given damage source is melee damage, false otherwise. + */ + public static boolean isMeleeDamage(DamageSource source){ + + // With the exception of minions, melee damage always has the same entity for immediate/true source + if(!(source instanceof MinionDamage) && source.getImmediateSource() != source.getTrueSource()) return false; + if(source.isProjectile()) return false; // Projectile damage obviously isn't melee damage + if(source.isUnblockable()) return false; // Melee damage should always be blockable + if(!(source instanceof MinionDamage) && source instanceof IElementalDamage) return false; + if(!(source.getTrueSource() instanceof EntityLivingBase)) return false; // Only living things can melee! + + if(source.getTrueSource() instanceof EntityPlayer && source.getDamageLocation() != null + && source.getDamageLocation().distanceTo(source.getTrueSource().getPositionVector()) > ((EntityLivingBase)source + .getTrueSource()).getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue()){ + return false; // Out of melee reach for players + } + + // If it got through all that, chances are it's melee damage + return true; + } + + // Boolean checks + // =============================================================================================================== + + /** + * Returns true if the given entity is an EntityLivingBase and not an armour stand; makes the code a bit neater. + * This was added because armour stands are a subclass of EntityLivingBase, but shouldn't necessarily be treated + * as living entities - this depends on the situation. The given entity can safely be cast to EntityLivingBase + * if this method returns true. + */ + // In my opinion, it's a bad design choice to have armour stands extend EntityLivingBase directly - it would be + // better to make a parent class which is extended by both armour stands and EntityLivingBase and contains only + // the code required by both. + public static boolean isLiving(Entity entity){ + return entity instanceof EntityLivingBase && !(entity instanceof EntityArmorStand); + } + + /** + * Checks if the given player is opped on the given server. If the server is a singleplayer or LAN server, this + * means they have cheats enabled. + */ + public static boolean isPlayerOp(EntityPlayer player, MinecraftServer server){ + return server.getPlayerList().getOppedPlayers().getEntry(player.getGameProfile()) != null; + } + + /** Checks that the given entity is allowed to damage blocks in the given world. If the entity is a player, this + * checks the player block damage config setting, otherwise it posts a mob griefing event and returns the result. */ + public static boolean canDamageBlocks(EntityLivingBase entity, World world){ + if(entity instanceof EntityPlayer) return Wizardry.settings.playerBlockDamage; + return ForgeEventFactory.getMobGriefingEvent(world, entity); + } + + /** + * Returns true if the given caster is currently casting the given spell by any means. This method is intended to + * eliminate the long and cumbersome wand use checking in event handlers, which often missed out spells cast by + * means other than wands. + * @param caster The potential spell caster, which may be a player or an {@link ISpellCaster}. Any other entity will + * cause this method to always return false. + * @param spell The spell to check for. The spell must be continuous or this method will always return false. + * @return True if the caster is currently casting the given spell through any means, false otherwise. + */ + // The reason this is a boolean check is that actually returning a spell presents a problem: players can cast two + // continuous spells at once, one via commands and one via an item, so which do you choose? Since the main point was + // to check for specific spells, it seems more useful to do it this way. + public static boolean isCasting(EntityLivingBase caster, Spell spell){ + + if(!spell.isContinuous) return false; + + if(caster instanceof EntityPlayer){ + + WizardData data = WizardData.get((EntityPlayer)caster); + + if(data != null && data.currentlyCasting() == spell) return true; + + if(caster.isHandActive() && caster.getItemInUseMaxCount() >= spell.getChargeup()){ + + ItemStack stack = caster.getHeldItem(caster.getActiveHand()); + + if(stack.getItem() instanceof ISpellCastingItem && ((ISpellCastingItem)stack.getItem()).getCurrentSpell(stack) == spell){ + // Don't do this, it interferes with stuff! We effectively already tested this with caster.isHandActive() anyway +// && ((ISpellCastingItem)stack.getItem()).canCast(stack, spell, (EntityPlayer)caster, +// EnumHand.MAIN_HAND, 0, new SpellModifiers())){ + return true; + } + } + + }else if(caster instanceof ISpellCaster){ + if(((ISpellCaster)caster).getContinuousSpell() == spell) return true; + } + + return false; + } + + // Misc + // =============================================================================================================== + + /** Returns the default aiming arror used by skeletons for the given difficulty. For reference, these are: Easy - 10, + * Normal - 6, Hard - 2, Peaceful - 10 (rarely used). */ + public static int getDefaultAimingError(EnumDifficulty difficulty){ + switch(difficulty){ + case EASY: return 10; + case NORMAL: return 6; + case HARD: return 2; + default: return 10; // Peaceful counts as easy; the only time this is used is when a player attacks a (good) wizard. + } + } + + /** + * Turns the given creeper into a charged creeper. In 1.10, this requires reflection since the DataManager keys are + * private. (You could call {@link EntityCreeper#onStruckByLightning(EntityLightningBolt)} and then heal it + * and extinguish it, but that's a bit awkward, and it'll trigger events and stuff...) + */ + // The reflection here only gets done once to initialise the POWERED field, so it's not a performance issue at all. + public static void chargeCreeper(EntityCreeper creeper){ + creeper.getDataManager().set(POWERED, true); + } + + // No point allowing anything other than players for these methods since other entities can use Entity#playSound. + + /** + * Shortcut for + * {@link World#playSound(EntityPlayer, double, double, double, SoundEvent, SoundCategory, float, float)} where the + * player is null but the x, y and z coordinates are those of the passed in player. Use in preference to + * {@link EntityPlayer#playSound(SoundEvent, float, float)} if there are client-server discrepancies. + */ + public static void playSoundAtPlayer(EntityPlayer player, SoundEvent sound, SoundCategory category, float volume, + float pitch){ + player.world.playSound(null, player.posX, player.posY, player.posZ, sound, category, volume, pitch); + } + + /** + * See {@link EntityUtils#playSoundAtPlayer(EntityPlayer, SoundEvent, SoundCategory, float, float)}. Category + * defaults to {@link SoundCategory#PLAYERS}. + */ + public static void playSoundAtPlayer(EntityPlayer player, SoundEvent sound, float volume, float pitch){ + player.world.playSound(null, player.posX, player.posY, player.posZ, sound, SoundCategory.PLAYERS, volume, pitch); + } + +} diff --git a/src/main/java/electroblob/wizardry/util/GeometryUtils.java b/src/main/java/electroblob/wizardry/util/GeometryUtils.java new file mode 100644 index 00000000..fe3e5389 --- /dev/null +++ b/src/main/java/electroblob/wizardry/util/GeometryUtils.java @@ -0,0 +1,131 @@ +package electroblob.wizardry.util; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumFacing.Axis; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; +import net.minecraft.world.World; + +/** + * Contains useful static methods for performing geometry operations on vectors, bounding boxes, {@code BlockPos} + * objects, etc. These methods used to be part of {@code WizardryUtilities}. + * @see Vec3d + * @see BlockPos + * @see EnumFacing + * @see RelativeFacing + * @see Location + * @see RayTracer + * @author Electroblob + * @since Wizardry 4.3 + */ +public final class GeometryUtils { + + private GeometryUtils(){} // No instances! + + /** A global offset used for placing/rendering flat things so that they appear to sit flush with the face of blocks + * but do not cause z-fighting at a distance where it is noticeable. */ + // This value is a compromise between flushness and minimum view distance for z-fighting to occur. 0.005 seems to + // be immune to z-fighting until over a hundred blocks away, which is pretty good, and the distance from flat + // surfaces is still indistinguishable. + public static final double ANTI_Z_FIGHTING_OFFSET = 0.005; + + // Why is there a distanceSqToCentre method in Vec3i but not a getCentre method? + + /** + * Returns a {@link Vec3d} of the coordinates at the centre of the given block position (i.e. the block coordinates + * plus 0.5 in x, y, and z). + */ + public static Vec3d getCentre(BlockPos pos){ + return new Vec3d(pos).add(0.5, 0.5, 0.5); + } + + /** + * Returns a {@link Vec3d} of the coordinates at the centre of the given bounding box (The one in {@code AxisAlignedBB} + * itself is client-side only). + */ + public static Vec3d getCentre(AxisAlignedBB box){ + return new Vec3d(box.minX + (box.maxX - box.minX) * 0.5, box.minY + (box.maxY - box.minY) * 0.5, box.minZ + (box.maxZ - box.minZ) * 0.5); + } + + /** + * Returns a {@link Vec3d} of the coordinates at the centre of the given face of the given block position (i.e. the + * centre of the block plus 0.5 in the given direction). + */ + public static Vec3d getFaceCentre(BlockPos pos, EnumFacing face){ + return getCentre(pos).add(new Vec3d(face.getDirectionVec()).scale(0.5)); + } + + /** + * Returns the component of the given {@link Vec3d} corresponding to the given {@link Axis Axis}. + */ + public static double component(Vec3d vec, Axis axis){ + return new double[]{vec.x, vec.y, vec.z}[axis.ordinal()]; // Damn, that's compact. + } + + /** + * Returns the component of the given {@link Vec3i} corresponding to the given {@link Axis Axis}. + */ + public static int component(Vec3i vec, Axis axis){ + return new int[]{vec.getX(), vec.getY(), vec.getZ()}[axis.ordinal()]; + } + + /** + * Returns a new {@link Vec3d} with the component corresponding to the given {@link Axis Axis} replaced by the + * given value. + */ + public static Vec3d replaceComponent(Vec3d vec, Axis axis, double newValue){ + double[] components = {vec.x, vec.y, vec.z}; + components[axis.ordinal()] = newValue; + return new Vec3d(components[0], components[1], components[2]); + } + + /** + * Returns a new {@link Vec3i} with the component corresponding to the given {@link Axis Axis} replaced by the + * given value. + */ + public static Vec3i replaceComponent(Vec3i vec, Axis axis, int newValue){ + int[] components = {vec.getX(), vec.getY(), vec.getZ()}; + components[axis.ordinal()] = newValue; + return new Vec3i(components[0], components[1], components[2]); + } + + /** + * Returns an array of {@code Vec3d} objects representing the vertices of the given bounding box. + * @param box The bounding box whose vertices are to be returned. + * @return The list of vertices, which will contain 8 elements. Using EnumFacing initials, the order is: + * DNW, DNE, DSE, DSW, UNW, UNE, USE, USW. The returned coordinates are absolute (i.e. measured from the world origin). + */ + public static Vec3d[] getVertices(AxisAlignedBB box){ + return new Vec3d[]{ + new Vec3d(box.minX, box.minY, box.minZ), + new Vec3d(box.maxX, box.minY, box.minZ), + new Vec3d(box.maxX, box.minY, box.maxZ), + new Vec3d(box.minX, box.minY, box.maxZ), + new Vec3d(box.minX, box.maxY, box.minZ), + new Vec3d(box.maxX, box.maxY, box.minZ), + new Vec3d(box.maxX, box.maxY, box.maxZ), + new Vec3d(box.minX, box.maxY, box.maxZ) + }; + } + + /** + * Returns an array of {@code Vec3d} objects representing the vertices of the block at the given position. + * @param pos The position of the block whose vertices are to be returned. + * @return The list of vertices, which will contain 8 elements. Using EnumFacing initials, the order is: + * DNW, DNE, DSE, DSW, UNW, UNE, USE, USW. The returned coordinates are absolute (i.e. measured from the world origin). + */ + public static Vec3d[] getVertices(World world, BlockPos pos){ + return getVertices(world.getBlockState(pos).getBoundingBox(world, pos).offset(pos.getX(), pos.getY(), pos.getZ())); + } + + /** + * Returns the pitch angle in degrees of the given {@link EnumFacing}. For some reason {@code EnumFacing} has a get + * yaw method ({@link EnumFacing#getHorizontalAngle()}) but not a get pitch method. + */ + public static float getPitch(EnumFacing facing){ + return facing == EnumFacing.UP ? 90 : facing == EnumFacing.DOWN ? -90 : 0; + } + +} diff --git a/src/main/java/electroblob/wizardry/util/IElementalDamage.java b/src/main/java/electroblob/wizardry/util/IElementalDamage.java index a3d12aeb..db2e84b5 100644 --- a/src/main/java/electroblob/wizardry/util/IElementalDamage.java +++ b/src/main/java/electroblob/wizardry/util/IElementalDamage.java @@ -40,7 +40,7 @@ public interface IElementalDamage { && !((EntityCreeper)event.getEntityLiving()).getPowered() && ((IElementalDamage)event.getSource()).getType() == DamageType.SHOCK){ // Charges creepers when they are hit by shock damage - WizardryUtilities.chargeCreeper((EntityCreeper)event.getEntityLiving()); + EntityUtils.chargeCreeper((EntityCreeper)event.getEntityLiving()); } } } diff --git a/src/main/java/electroblob/wizardry/util/InventoryUtils.java b/src/main/java/electroblob/wizardry/util/InventoryUtils.java new file mode 100644 index 00000000..438458e0 --- /dev/null +++ b/src/main/java/electroblob/wizardry/util/InventoryUtils.java @@ -0,0 +1,145 @@ +package electroblob.wizardry.util; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.inventory.EntityEquipmentSlot.Type; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumHand; +import net.minecraft.util.EnumHandSide; +import net.minecraft.util.NonNullList; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Contains useful static methods for interacting with item stacks and entity inventories. These methods used to be part + * of {@code WizardryUtilities}. + * @author Electroblob + * @since Wizardry 4.3 + */ +public final class InventoryUtils { + + private InventoryUtils(){} // No instances! + + /** Constant which is simply an array of the four armour slots. (Could've sworn this exists somewhere in vanilla, + * but I can't find it anywhere...) */ + public static final EntityEquipmentSlot[] ARMOUR_SLOTS; + + static { + // The list of slots needs to be mutable. + List slots = new ArrayList<>(Arrays.asList(EntityEquipmentSlot.values())); + slots.removeIf(slot -> slot.getSlotType() != Type.ARMOR); + ARMOUR_SLOTS = slots.toArray(new EntityEquipmentSlot[0]); + } + + /** + * Returns a list of the itemstacks in the given player's hotbar. Defined here for convenience and to centralise the + * (unfortunately unavoidable) use of hardcoded numbers to reference the inventory slots. The returned list is a + * modifiable copy of part of the player's inventory stack list; as such, changes to the list are not written + * through to the player's inventory. However, the ItemStack instances themselves are not copied, so changes to any + * of their fields (size, metadata...) will change those in the player's inventory. + * + * @since Wizardry 1.2 + */ + public static List getHotbar(EntityPlayer player){ + NonNullList hotbar = NonNullList.create(); + hotbar.addAll(player.inventory.mainInventory.subList(0, 9)); + return hotbar; + } + + /** + * Returns a list of the itemstacks in the given player's hotbar and offhand, sorted into the following order: main + * hand, offhand, rest of hotbar left-to-right. The returned list is a modifiable shallow copy of part of the player's + * inventory stack list; as such, changes to the list are not written through to the player's inventory. + * However, the ItemStack instances themselves are not copied, so changes to any of their fields (size, metadata...) + * will change those in the player's inventory. + * + * @since Wizardry 1.2 + */ + public static List getPrioritisedHotbarAndOffhand(EntityPlayer player){ + List hotbar = getHotbar(player); + // Adds the offhand item to the beginning of the list so it is processed before the hotbar + hotbar.add(0, player.getHeldItemOffhand()); + // Moves the item in the main hand to the beginning of the list so it is processed first + hotbar.remove(player.getHeldItemMainhand()); + hotbar.add(0, player.getHeldItemMainhand()); + return hotbar; + } + + /** Returns which {@link EnumHandSide} the given {@link EnumHand} is on for the given entity. */ + public static EnumHandSide getSideForHand(EntityLivingBase entity, EnumHand hand){ + return hand == EnumHand.MAIN_HAND ? entity.getPrimaryHand() : entity.getPrimaryHand().opposite(); + } + + /** Returns which {@link EnumHand} is on the given {@link EnumHandSide} for the given entity. */ + public static EnumHand getHandForSide(EntityLivingBase entity, EnumHandSide side){ + return side == entity.getPrimaryHand() ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND; + } + + /** Returns the opposite {@link EnumHand} to the one given. */ + public static EnumHand getOpposite(EnumHand hand){ + return hand == EnumHand.OFF_HAND ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND; + } + + /** + * Tests whether the specified player has any of the specified item in their entire inventory, including armour + * slots and offhand. + */ + public static boolean doesPlayerHaveItem(EntityPlayer player, Item item){ + + for(ItemStack stack : player.inventory.mainInventory){ + if(stack.getItem() == item){ + return true; + } + } + + for(ItemStack stack : player.inventory.armorInventory){ + if(stack.getItem() == item){ + return true; + } + } + + for(ItemStack stack : player.inventory.offHandInventory){ + if(stack.getItem() == item){ + return true; + } + } + + return false; + } + + /** + * Returns a new {@link ItemStack} that is identical to the supplied one, except with the metadata changed to the + * new value given. + * @param toCopy The stack to copy + * @param newMetadata The new metadata value + * @return The resulting {@link ItemStack} + */ + public static ItemStack copyWithMeta(ItemStack toCopy, int newMetadata){ + ItemStack copy = new ItemStack(toCopy.getItem(), toCopy.getCount(), newMetadata); + NBTTagCompound compound = toCopy.getTagCompound(); + if(compound != null) copy.setTagCompound(compound.copy()); + return copy; + } + + /** + * Returns whether the two given item stacks can be merged, i.e. if they both contain the same (stackable) item, + * metadata and NBT. Importantly, the number of items in each stack need not be the same. No actual merging is + * performed by this method; the input stacks will not be modified. + * @param stack1 The first stack to be tested for mergeability + * @param stack2 The second stack to be tested for mergeability (order does not matter) + * @return True if the two stacks can be merged, false if not + */ + public static boolean canMerge(ItemStack stack1, ItemStack stack2){ + return !stack1.isEmpty() && !stack2.isEmpty() + && stack1.isStackable() && stack2.isStackable() + && stack1.getItem() == stack2.getItem() + && (!stack1.getHasSubtypes() || stack1.getMetadata() == stack2.getMetadata()) + && ItemStack.areItemStackTagsEqual(stack1, stack2); + } + +} diff --git a/src/main/java/electroblob/wizardry/util/JavaUtils.java b/src/main/java/electroblob/wizardry/util/JavaUtils.java new file mode 100644 index 00000000..5cf40028 --- /dev/null +++ b/src/main/java/electroblob/wizardry/util/JavaUtils.java @@ -0,0 +1,47 @@ +package electroblob.wizardry.util; + +import java.lang.reflect.Field; +import java.util.*; + +/** + * Contains useful static methods for interacting with Java itself, rather than Minecraft. These methods used to be part + * of {@code WizardryUtilities}. + * + * @author Electroblob + * @since Wizardry 4.3 + */ +public final class JavaUtils { + + /** + * Flattens the given nested collection. The returned collection is an unmodifiable collection of all the elements + * contained within all of the sub-collections of the given nested collection. + * @param collection A nested collection to flatten + * @param The type of elements in the given nested collection + * @return The resulting flattened collection. + */ + public static Collection flatten(Collection> collection){ + Collection result = new ArrayList<>(); + collection.forEach(result::addAll); + return Collections.unmodifiableCollection(result); + } + + // Neat way of getting a random element from a set, wasn't needed in the end but kept here for future reference +// public static E randomElement(Collection collection, Random random){ +// if(collection.isEmpty()) throw new IndexOutOfBoundsException("The given collection must not be empty"); +// Iterator iterator = collection.iterator(); +// for(int n = random.nextInt(collection.size()); n > 0; n--) iterator.next(); +// return iterator.next(); +// } + + /** + * Returns a list of all fields belonging to the given class and all those belonging to all of its superclasses. + * @param c The class to query + * @return The resulting {@link List} of fields + */ + public static List getAllFields(Class c){ + List fields = new ArrayList<>(Arrays.asList(c.getDeclaredFields())); + if(c.getSuperclass() != null) fields.addAll(getAllFields(c.getSuperclass())); + return fields; + } + +} diff --git a/src/main/java/electroblob/wizardry/util/NBTExtras.java b/src/main/java/electroblob/wizardry/util/NBTExtras.java index 8baeb305..c2d439b5 100644 --- a/src/main/java/electroblob/wizardry/util/NBTExtras.java +++ b/src/main/java/electroblob/wizardry/util/NBTExtras.java @@ -10,7 +10,7 @@ import java.util.function.Function; /** * Contains a number of useful static methods for interacting with NBT data, particularly involving collections. - * This was split off from {@link WizardryUtilities} as of wizardry 4.2 in an effort to make the code easier to navigate. + * This was split off from {@link JavaUtils} as of wizardry 4.2 in an effort to make the code easier to navigate. * * @author Electroblob * @since Wizardry 4.2 diff --git a/src/main/java/electroblob/wizardry/util/RayTracer.java b/src/main/java/electroblob/wizardry/util/RayTracer.java index 81516a92..b658026a 100644 --- a/src/main/java/electroblob/wizardry/util/RayTracer.java +++ b/src/main/java/electroblob/wizardry/util/RayTracer.java @@ -14,7 +14,7 @@ import java.util.function.Predicate; /** * Contains a number of static methods that perform raytracing and related functions. This was split off from - * {@link WizardryUtilities} as of wizardry 4.2 in an effort to make the code easier to navigate. + * {@link JavaUtils} as of wizardry 4.2 in an effort to make the code easier to navigate. * * @author Electroblob * @since Wizardry 4.2 @@ -160,7 +160,7 @@ public final class RayTracer { // ring of fire, but doing so will stop forcefields blocking particles //if(!entity.canBeCollidedWith()) continue; - float fuzziness = WizardryUtilities.isLiving(entity) ? aimAssist : 0; // Only living entities have aim assist + float fuzziness = EntityUtils.isLiving(entity) ? aimAssist : 0; // Only living entities have aim assist if(entity instanceof ICustomHitbox){ // Custom hitboxes intercept = ((ICustomHitbox)entity).calculateIntercept(origin, endpoint, fuzziness); diff --git a/src/main/java/electroblob/wizardry/util/WizardryUtilities.java b/src/main/java/electroblob/wizardry/util/WizardryUtilities.java deleted file mode 100644 index 433c10bf..00000000 --- a/src/main/java/electroblob/wizardry/util/WizardryUtilities.java +++ /dev/null @@ -1,1066 +0,0 @@ -package electroblob.wizardry.util; - -import electroblob.wizardry.CommonProxy; -import electroblob.wizardry.Settings; -import electroblob.wizardry.Wizardry; -import electroblob.wizardry.data.WizardData; -import electroblob.wizardry.entity.living.ISpellCaster; -import electroblob.wizardry.item.ISpellCastingItem; -import electroblob.wizardry.spell.Spell; -import net.minecraft.block.*; -import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.effect.EntityLightningBolt; -import net.minecraft.entity.item.EntityArmorStand; -import net.minecraft.entity.monster.EntityCreeper; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.projectile.EntityArrow; -import net.minecraft.entity.projectile.EntityThrowable; -import net.minecraft.init.Blocks; -import net.minecraft.inventory.EntityEquipmentSlot; -import net.minecraft.inventory.EntityEquipmentSlot.Type; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.*; -import net.minecraft.util.EnumFacing.Axis; -import net.minecraft.util.math.*; -import net.minecraft.world.EnumDifficulty; -import net.minecraft.world.World; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; - -import javax.annotation.Nullable; -import java.lang.reflect.Field; -import java.util.*; -import java.util.function.BiPredicate; -import java.util.function.Predicate; - -/** - * "Where do you put random but useful bits and pieces? {@code WizardryUtilities} of course - the 'stuff that doesn't - * fit anywhere else' class!" - *

- * This class contains some useful static methods for use anywhere - items, entities, spells, events, blocks, etc. - * Broadly speaking, these fall into the following categories: - *

- * - In-world utilities (position calculating, retrieving entities, etc.)
- * - Raytracing
- * - NBT and data storage utilities
- * - Interaction with the ally designation system
- * - Loot and weighting utilities - * - * @see CommonProxy - * @see WandHelper - * @since Wizardry 1.0 - * @author Electroblob - */ -public final class WizardryUtilities { - - /** Constant which is simply an array of the four armour slots. (Could've sworn this exists somewhere in vanilla, - * but I can't find it anywhere...) */ - public static final EntityEquipmentSlot[] ARMOUR_SLOTS; - /** Changed to a constant in wizardry 2.1, since this is a lot more efficient. */ - private static final DataParameter POWERED; -// /** Pointing item action used in various spells. */ -// public static final EnumAction POINT; - - static { - // The list of slots needs to be mutable. - List slots = new ArrayList<>( - Arrays.asList(EntityEquipmentSlot.values())); - slots.removeIf(slot -> slot.getSlotType() != Type.ARMOR); - ARMOUR_SLOTS = slots.toArray(new EntityEquipmentSlot[0]); - - // Null is passed in deliberately since POWERED is a static field. - POWERED = ObfuscationReflectionHelper.getPrivateValue(EntityCreeper.class, null, "field_184714_b"); - - //POINT = EnumHelper.addAction("POINT"); - } - - /** A global offset used for placing/rendering flat things so that they appear to sit flush with the face of blocks - * but do not cause z-fighting at a distance where it is noticeable. */ - // This value is a compromise between flushness and minimum view distance for z-fighting to occur. 0.005 seems to - // be immune to z-fighting until over a hundred blocks away, which is pretty good, and the distance from flat - // surfaces is still indistinguishable. - public static final double ANTI_Z_FIGHTING_OFFSET = 0.005; - - // I'm fed up with remembering these... - /** Stores constant values for attribute modifier operations (and javadoc for what they actually do!) */ - public static final class Operations { - /** Adds the attribute modifier amount to the base value. */ - public static final int ADD = 0; - /** Multiplies the base value by 1 plus the attribute modifier amount. Multiple modifiers are processed in - * parallel, i.e. the calculation is based on the base value and does not depend on previous modifiers. */ - public static final int MULTIPLY_FLAT = 1; - /** Multiplies the base value by 1 plus the attribute modifier amount. Multiple modifiers are processed in - * series, i.e. the calculation is based on the value after previous modifiers are applied, in the order added. */ - public static final int MULTIPLY_CUMULATIVE = 2; - } - - // World, Blocks and Coordinates - // =============================================================================================================== - - /** - * Returns the actual light level, taking natural light (skylight) and artificial light (block light) into account. - * This uses the same logic as mob spawning. - * - * @return The light level, from 0 (pitch darkness) to 15 (full daylight/at a torch). - */ - public static int getLightLevel(World world, BlockPos pos){ - - int i = world.getLightFromNeighbors(pos); - - if(world.isThundering()){ - int j = world.getSkylightSubtracted(); - world.setSkylightSubtracted(10); - i = world.getLightFromNeighbors(pos); - world.setSkylightSubtracted(j); - } - - return i; - } - - /** - * Returns whether the block at the given position can be replaced by another one (works as if a block is being - * placed by a player). True for air, vines, tall grass and snow layers but not for flowers, signs etc. - * This is a shortcut for world.getBlockState(pos).getMaterial().isReplaceable(). - * - * @param world The world the block is in. - * @param pos The position of the block. - * @param excludeLiquids True to treat liquids as non-replaceable, false to treat liquids as replaceable. - * - * @see WizardryUtilities#canBlockBeReplaced(World, BlockPos) - */ - public static boolean canBlockBeReplaced(World world, BlockPos pos, boolean excludeLiquids){ - return (world.isAirBlock(new BlockPos(pos)) || world.getBlockState(pos).getMaterial().isReplaceable()) - && (!excludeLiquids || !world.getBlockState(pos).getMaterial().isLiquid()); - } - - /** - * Returns whether the block at the given position can be replaced by another one (works as if a block is being - * placed by a player). True for air, liquids, vines, tall grass and snow layers but not for flowers, signs etc. - * This is a shorthand version of {@link WizardryUtilities#canBlockBeReplaced(World, BlockPos, boolean)}; - * excludeLiquids defaults to false. - * - * @param world The world the block is in. - * @param pos The position of the block. - */ - public static boolean canBlockBeReplaced(World world, BlockPos pos){ - return canBlockBeReplaced(world, pos, false); - } - - /** - * Returns whether the block at the given coordinates is unbreakable in survival mode. In vanilla this is true for - * bedrock and end portal frame, for example. This is a shortcut for:

- * {@code world.getBlockState(pos).getBlockHardness(world, pos) == -1.0f} - */ - public static boolean isBlockUnbreakable(World world, BlockPos pos){ - return !world.isAirBlock(new BlockPos(pos)) && world.getBlockState(pos).getBlockHardness(world, pos) == -1.0f; - } - - /** - * Returns a block state for the given block, with all properties set to the values from the given source state. - * The source block state must have exactly the same properties as the destination block will allow or an - * {@link IllegalArgumentException} will be thrown. - *

- * This method allows, for example, an oak door block to be replaced with a spruce one whilst keeping the same - * orientation, door half, open/closed state, etc. - * @param block The new block type - * @param source The block state to copy property values from - * @return The resulting block state - */ - @SuppressWarnings({"unchecked", "rawtypes"}) // Don't complain to me about Mojang's code design... - public static IBlockState copyState(Block block, IBlockState source){ - - IBlockState state = block.getDefaultState(); - - for(IProperty property : source.getPropertyKeys()){ - // It ain't pretty but it works - state = state.withProperty(property, (Comparable)source.getProperties().get(property)); - } - - return state; - } - - /** - * Finds the nearest surface (according to the given criteria) in the given direction from the given position, - * within the range specified. This is a generalised replacement for the old {@code getNearestFloorLevel} methods; - * overloads and predefined surface criteria that replicate the old behaviours are available. - * - * @param world The world to search in - * @param pos The position to search from - * @param direction The direction to search in; also defines the direction the surface must face. - * @param range The maximum distance from the given y coordinate to search. - * @param doubleSided True to also search in the opposite direction, false to only search in the given direction. - * @param criteria A {@link SurfaceCriteria} representing the criteria defining a surface. See that class for - * available predefined criteria. - * @return The x, y, or z coordinate of the closest surface, or null if no surface was found. This represents the - * exact position of the block boundary that forms the surface (and therefore it may correspond to the coordinate - * of the inside or outside block of the surface depending on the direction). - */ - @Nullable - public static Integer getNearestSurface(World world, BlockPos pos, EnumFacing direction, int range, - boolean doubleSided, SurfaceCriteria criteria){ - - // This is a neat trick that allows a default 'not found' return value for integers where all possible integer - // values could, in theory, be returned. The alternative is to use a double and have NaN as the default, but - // that would introduce extra casting, and since NaN can be calculated with, it could produce strange results - // when unaccounted for. Using an Integer means it'll immediately throw an NPE instead. - Integer surface = null; - int currentBest = Integer.MAX_VALUE; - - for(int i = doubleSided ? -range : 0; i <= range && i < currentBest; i++){ // Now short-circuits for efficiency - - BlockPos testPos = pos.offset(direction, i); - - if(criteria.test(world, testPos, direction)){ - // Because the loop now short-circuits, this must be closer than the previous surface found - surface = (int)component(getFaceCentre(testPos, direction), direction.getAxis()); - currentBest = Math.abs(i); - } - } - - return surface; - } - - /** - * A {@code SurfaceCriteria} object is used to define a 'surface', a boundary between two blocks which differ in - * some way, for use in {@link WizardryUtilities#getNearestSurface(World, BlockPos, EnumFacing, int, boolean, SurfaceCriteria)}. - * This provides a more flexible replacement for the old {@code getNearestFloorLevel} methods.
- *
- * In the context of this class, 'outside' refers to the side of the surface that is in the supplied direction, - * and 'inside' refers to the side which is in the opposite direction. For example, if the direction is {@code UP}, - * the inside of the surface is defined as below it, and the outside is defined as above it. - */ - @FunctionalInterface - public interface SurfaceCriteria { - - /** - * Tests whether the inputs define a valid surface according to this set of criteria. - * @param world The world in which the surface is to be tested. - * @param pos The block coordinates of the inside ('solid' part) of the surface. - * @param side The direction in which the surface must face. - * @return True if the side {@code side} of the block at {@code pos} in {@code world} is a valid surface - * according to this set of criteria, false otherwise. - */ - boolean test(World world, BlockPos pos, EnumFacing side); - - /** Returns a {@code SurfaceCriteria} with the opposite arrangement to this one. */ - default SurfaceCriteria flip(){ - return (world, pos, side) -> this.test(world, pos.offset(side), side.getOpposite()); - } - - /** Returns a {@code SurfaceCriteria} based on the given condition, where the inside of the surface satisfies - * the condition and the outside does not. */ - static SurfaceCriteria basedOn(BiPredicate condition){ - return (world, pos, side) -> condition.test(world, pos) && !condition.test(world, pos.offset(side)); - } - - /** Returns a {@code SurfaceCriteria} based on the given condition, where the inside of the surface satisfies - * the condition and the outside does not. */ - static SurfaceCriteria basedOn(Predicate condition){ - return (world, pos, side) -> condition.test(world.getBlockState(pos)) && !condition.test(world.getBlockState(pos.offset(side))); - } - - /** Surface criterion which defines a surface as the boundary between a block that cannot be moved through and - * a block that can be moved through. This means the surface can be stood on. */ - SurfaceCriteria COLLIDABLE = basedOn(b -> b.getMaterial().blocksMovement()); - - /** Surface criterion which defines a surface as the boundary between a block that is solid on the required side and - * a block that is replaceable. This means the surface can be built on. */ - SurfaceCriteria BUILDABLE = (world, pos, side) -> world.isSideSolid(pos, side) && world.getBlockState(pos.offset(side)).getBlock().isReplaceable(world, pos.offset(side)); - - /** Surface criterion which defines a surface as the boundary between a block that is solid on the required side - * or a liquid, and an air block. Used for freezing water and placing snow. */ - // Was getNearestFloorLevelB - SurfaceCriteria SOLID_LIQUID_TO_AIR = (world, pos, side) -> (world.getBlockState(pos).getMaterial().isLiquid() - || world.isSideSolid(pos, side) && world.isAirBlock(pos.offset(side))); - - /** Surface criterion which defines a surface as the boundary between any non-air block and an air block. - * Used for particles. */ - // Was getNearestFloorLevelC - SurfaceCriteria NOT_AIR_TO_AIR = basedOn(World::isAirBlock).flip(); - - /** Surface criterion which defines a surface as the boundary between a block that cannot be moved through, and - * a block that can be moved through or a tree block (log or leaves). Used for structure generation. */ - SurfaceCriteria COLLIDABLE_IGNORING_TREES = basedOn((world, pos) -> - world.getBlockState(pos).getMaterial().blocksMovement() && !isTreeBlock(world, pos)); - - } - - /** - * Returns true if the block at the given position is a tree block (or other 'solid' vegetation, such as cacti). - * Used for structure generation. - * @param world The world the block is in - * @param pos The position of the block to be tested - * @return True if the given block is a tree block, false if not. - */ - public static boolean isTreeBlock(World world, BlockPos pos){ - Block block = world.getBlockState(pos).getBlock(); - return block instanceof BlockLog || block instanceof BlockCactus - || block.isLeaves(world.getBlockState(pos), world, pos) || block.isFoliage(world, pos) - || Settings.containsMetaBlock(Wizardry.settings.treeBlocks, world.getBlockState(pos)); - } - - /** - * Given the position of one half of a double chest, returns the position of the other half of that double chest. - * @param world The world in which the chest is located - * @param pos The position of one half of the double chest - * @return The position of the other half of the double chest, or null if the given position is not part of a - * double chest. - */ - public static BlockPos getConnectedChest(World world, BlockPos pos){ - - Block block = world.getBlockState(pos).getBlock(); - - if(block instanceof BlockChest){ - for(EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL){ - BlockPos pos1 = pos.offset(enumfacing); - if(world.getBlockState(pos1).getBlock() == block){ - return pos1; - } - } - } - - return null; - } - - /** - * Returns true if the given block is a water source block (specifically, water or flowing water with a level of 0). - * @param state The block state to query - * @return True if the given block state is a water source block, false otherwise. - */ - public static boolean isWaterSource(IBlockState state){ - return state.getMaterial() == Material.WATER && (state.getBlock() == Blocks.WATER || state.getBlock() == Blocks.FLOWING_WATER) && state.getValue(BlockLiquid.LEVEL) == 0; - } - - /** - * Returns true if the given block is a lava source block (specifically, lava or flowing lava with a level of 0). - * @param state The block state to query - * @return True if the given block state is a lava source block, false otherwise. - */ - public static boolean isLavaSource(IBlockState state){ - return state.getMaterial() == Material.LAVA && (state.getBlock() == Blocks.LAVA || state.getBlock() == Blocks.FLOWING_LAVA) && state.getValue(BlockLiquid.LEVEL) == 0; - } - - /** - * Freezes the given block, either by turning water to ice, lava to obsidian/cobblestone or by placing snow on top - * of it if possible. - * @param world The world the block is in - * @param pos The position of the block to freeze - * @param freezeLava True to freeze lava into obsidian or cobblestone, false to leave it unchanged - * @return True if any blocks were changed, false if not. - */ - public static boolean freeze(World world, BlockPos pos, boolean freezeLava){ - - IBlockState state = world.getBlockState(pos); - Block block = state.getBlock(); - - if(WizardryUtilities.isWaterSource(state)){ - world.setBlockState(pos, Blocks.ICE.getDefaultState()); - }else if(freezeLava && WizardryUtilities.isLavaSource(state)){ - world.setBlockState(pos, Blocks.OBSIDIAN.getDefaultState()); - }else if(freezeLava && (block == Blocks.LAVA || block == Blocks.FLOWING_LAVA)){ - world.setBlockState(pos, Blocks.COBBLESTONE.getDefaultState()); - }else if(block.isReplaceable(world, pos.up()) && Blocks.SNOW_LAYER.canPlaceBlockAt(world, pos.up())){ - world.setBlockState(pos.up(), Blocks.SNOW_LAYER.getDefaultState()); - }else{ - return false; - } - - return true; - } - - /** - * Finds the nearest floor level in the given direction from the given position, - * within the range specified. This is a shorthand for - * {@link WizardryUtilities#getNearestSurface(World, BlockPos, EnumFacing, int, boolean, SurfaceCriteria)}; - * {@code doubleSided} defaults to true, {@code direction} defaults to {@code EnumFacing.UP}, and - * {@code criteria} defaults to {@link SurfaceCriteria#COLLIDABLE}. - */ - @Nullable - public static Integer getNearestFloor(World world, BlockPos pos, int range){ - return getNearestSurface(world, pos, EnumFacing.UP, range, true, SurfaceCriteria.COLLIDABLE); - } - - /** - * Gets a random position on the ground near the given entity within the specified horizontal and vertical ranges. - * Used to find a position to spawn entities in summoning spells. - * - * @param entity The entity around which to search. - * @param horizontalRange The maximum number of blocks on the x or z axis the returned position can be from the - * given entity. The number of operations performed by this method is proportional to the square of this - * parameter, so for performance reasons it is recommended that it does not exceed around 10. - * @param verticalRange The maximum number of blocks on the y axis the returned position can be from the given - * entity. - * @return A BlockPos with the coordinates of the block directly above the ground at the position found, or null if - * none were found within range. Importantly, since this method checks all possible positions within - * range (i.e. randomness only occurs when deciding between the possible positions), if it returns null once - * then it will always return null given the same circumstances and parameters. What this means is that you - * can (and should) immediately stop trying to cast a summoning spell if this returns null. - */ - @Nullable - public static BlockPos findNearbyFloorSpace(Entity entity, int horizontalRange, int verticalRange){ - - World world = entity.world; - BlockPos origin = new BlockPos(entity); - return findNearbyFloorSpace(world, origin, horizontalRange, verticalRange); - } - - /** - * Gets a random position on the ground near the given BlockPos within the specified horizontal and vertical ranges. - * Used to find a position to spawn entities in summoning spells. - * - * @param world The world in which to search. - * @param origin The BlockPos around which to search. - * @param horizontalRange The maximum number of blocks on the x or z axis the returned position can be from the - * given position. The number of operations performed by this method is proportional to the square of this - * parameter, so for performance reasons it is recommended that it does not exceed around 10. - * @param verticalRange The maximum number of blocks on the y axis the returned position can be from the given - * position. - * @return A BlockPos with the coordinates of the block directly above the ground at the position found, or null if - * none were found within range. Importantly, since this method checks all possible positions within - * range (i.e. randomness only occurs when deciding between the possible positions), if it returns null once - * then it will always return null given the same circumstances and parameters. What this means is that you - * can (and should) immediately stop trying to cast a summoning spell if this returns null. - */ - @Nullable - public static BlockPos findNearbyFloorSpace(World world, BlockPos origin, int horizontalRange, int verticalRange){ - return findNearbyFloorSpace(world, origin, horizontalRange, verticalRange, true); - } - - /** - * Gets a random position on the ground near the given BlockPos within the specified horizontal and vertical ranges. - * Used to find a position to spawn entities in summoning spells. - * - * @param world The world in which to search. - * @param origin The BlockPos around which to search. - * @param horizontalRange The maximum number of blocks on the x or z axis the returned position can be from the - * given position. The number of operations performed by this method is proportional to the square of this - * parameter, so for performance reasons it is recommended that it does not exceed around 10. - * @param verticalRange The maximum number of blocks on the y axis the returned position can be from the given - * position. - * @param lineOfSight Whether to require line-of-sight from the origin to the returned position. - * @return A BlockPos with the coordinates of the block directly above the ground at the position found, or null if - * none were found within range. Importantly, since this method checks all possible positions within - * range (i.e. randomness only occurs when deciding between the possible positions), if it returns null once - * then it will always return null given the same circumstances and parameters. What this means is that you - * can (and should) immediately stop trying to cast a summoning spell if this returns null. - */ - @Nullable - public static BlockPos findNearbyFloorSpace(World world, BlockPos origin, int horizontalRange, int verticalRange, boolean lineOfSight){ - - List possibleLocations = new ArrayList(); - - final Vec3d centre = WizardryUtilities.getCentre(origin); - - for(int x = -horizontalRange; x <= horizontalRange; x++){ - for(int z = -horizontalRange; z <= horizontalRange; z++){ - - Integer y = WizardryUtilities.getNearestFloor(world, origin.add(x, 0, z), verticalRange); - - if(y != null){ - - BlockPos location = new BlockPos(origin.getX() + x, y, origin.getZ() + z); - - if(lineOfSight){ - // Since we're only using finding collidable surfaces, it doesn't make much sense to include - // non-collidable blocks here! - RayTraceResult rayTrace = world.rayTraceBlocks(centre, WizardryUtilities.getCentre(location), - false, true, false); - if(rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.BLOCK) continue; - } - - possibleLocations.add(location); - } - } - } - - if(possibleLocations.isEmpty()){ - return null; - }else{ - return possibleLocations.get(world.rand.nextInt(possibleLocations.size())); - } - } - - /** - * Gets the blockstate of the block the specified entity is standing on. Uses - * {@link MathHelper#floor(double)} because casting to int will not return the correct coordinate when x or z - * is negative. - */ - public static IBlockState getBlockEntityIsStandingOn(Entity entity){ - BlockPos pos = new BlockPos(MathHelper.floor(entity.posX), (int)entity.getEntityBoundingBox().minY - 1, - MathHelper.floor(entity.posZ)); - return entity.world.getBlockState(pos); - } - - /** - * Generates a sphere of block positions centred on the given position, with the given radius. This is an efficient - * implementation - rather than simply generating a cube and cutting the rest out, it works as follows: - *

- * 1. Step through all x offsets within the specified radius
- * 2. For each x offset, check the maximum y offset within the radius using Pythagoras
- * 3. Step through the resulting valid y offsets
- * 4. For each y offset, check the maximum z offset within the radius using Pythagoras
- * 5. Step through the resulting valid z offsets - * @return A list of BlockPos objects in a sphere. This list will be ordered negative to positive, with axes - * nested in order (i.e. blocks in a line on the z axis will be consecutive in the list). - */ - public static List getBlockSphere(BlockPos centre, double radius){ - - // Extra efficiency by assigning enough capacity for a cube of side length r - List sphere = new ArrayList<>((int)Math.pow(radius, 3)); - - for(int i=-(int)radius; i<=radius; i++){ - - float r1 = MathHelper.sqrt(radius*radius - i*i); - - for(int j=-(int)r1; j<=r1; j++){ - - float r2 = MathHelper.sqrt(radius*radius - i*i - j*j); - - for(int k=-(int)r2; k<=r2; k++){ - sphere.add(centre.add(i, j, k)); - } - } - } - - return sphere; - } - - /** - * Shorthand for {@link WizardryUtilities#getEntitiesWithinRadius(double, double, double, double, World, Class)} - * with EntityLivingBase as the entity type. This is by far the most common use for that method. - * - * @param radius The search radius - * @param x The x coordinate to search around - * @param y The y coordinate to search around - * @param z The z coordinate to search around - * @param world The world to search in - */ - public static List getEntitiesWithinRadius(double radius, double x, double y, double z, - World world){ - return getEntitiesWithinRadius(radius, x, y, z, world, EntityLivingBase.class); - } - - /** - * Returns all entities of the specified type within the specified radius of the given coordinates. This is - * different to using a raw AABB because a raw AABB will search in a cube volume rather than a sphere. Note that - * this does not exclude any entities; if any specific entities are to be excluded this must be checked when - * iterating through the list. - * - * @see WizardryUtilities#getEntitiesWithinRadius(double, double, double, double, World) - * @param radius The search radius - * @param x The x coordinate to search around - * @param y The y coordinate to search around - * @param z The z coordinate to search around - * @param world The world to search in - * @param entityType The class of entity to search for; pass in Entity.class for all entities - */ - public static List getEntitiesWithinRadius(double radius, double x, double y, double z, - World world, Class entityType){ - AxisAlignedBB aabb = new AxisAlignedBB(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius); - List entityList = world.getEntitiesWithinAABB(entityType, aabb); - for(int i = 0; i < entityList.size(); i++){ - if(entityList.get(i).getDistance(x, y, z) > radius){ - entityList.remove(i); - break; - } - } - return entityList; - } - - // Why is there a distanceSqToCentre method in Vec3i but not a getCentre method? - - /** - * Returns a {@link Vec3d} of the coordinates at the centre of the given block position (i.e. the block coordinates - * plus 0.5 in x, y, and z). - */ - public static Vec3d getCentre(BlockPos pos){ - return new Vec3d(pos).add(0.5, 0.5, 0.5); - } - - /** - * Returns a {@link Vec3d} of the coordinates at the centre of the given bounding box (The one in {@code AxisAlignedBB} - * itself is client-side only). - */ - public static Vec3d getCentre(AxisAlignedBB box){ - return new Vec3d(box.minX + (box.maxX - box.minX) * 0.5, box.minY + (box.maxY - box.minY) * 0.5, box.minZ + (box.maxZ - box.minZ) * 0.5); - } - - /** - * Returns a {@link Vec3d} of the coordinates at the centre of the given face of the given block position (i.e. the - * centre of the block plus 0.5 in the given direction). - */ - public static Vec3d getFaceCentre(BlockPos pos, EnumFacing face){ - return getCentre(pos).add(new Vec3d(face.getDirectionVec()).scale(0.5)); - } - - /** - * Returns the component of the given {@link Vec3d} corresponding to the given {@link Axis Axis}. - */ - public static double component(Vec3d vec, Axis axis){ - return new double[]{vec.x, vec.y, vec.z}[axis.ordinal()]; // Damn, that's compact. - } - - /** - * Returns the component of the given {@link Vec3i} corresponding to the given {@link Axis Axis}. - */ - public static int component(Vec3i vec, Axis axis){ - return new int[]{vec.getX(), vec.getY(), vec.getZ()}[axis.ordinal()]; - } - - /** - * Returns a new {@link Vec3d} with the component corresponding to the given {@link Axis Axis} replaced by the - * given value. - */ - public static Vec3d replaceComponent(Vec3d vec, Axis axis, double newValue){ - double[] components = {vec.x, vec.y, vec.z}; - components[axis.ordinal()] = newValue; - return new Vec3d(components[0], components[1], components[2]); - } - - /** - * Returns a new {@link Vec3i} with the component corresponding to the given {@link Axis Axis} replaced by the - * given value. - */ - public static Vec3i replaceComponent(Vec3i vec, Axis axis, int newValue){ - int[] components = {vec.getX(), vec.getY(), vec.getZ()}; - components[axis.ordinal()] = newValue; - return new Vec3i(components[0], components[1], components[2]); - } - - /** - * Returns an array of {@code Vec3d} objects representing the vertices of the given bounding box. - * @param box The bounding box whose vertices are to be returned. - * @return The list of vertices, which will contain 8 elements. Using EnumFacing initials, the order is: - * DNW, DNE, DSE, DSW, UNW, UNE, USE, USW. The returned coordinates are absolute (i.e. measured from the world origin). - */ - public static Vec3d[] getVertices(AxisAlignedBB box){ - return new Vec3d[]{ - new Vec3d(box.minX, box.minY, box.minZ), - new Vec3d(box.maxX, box.minY, box.minZ), - new Vec3d(box.maxX, box.minY, box.maxZ), - new Vec3d(box.minX, box.minY, box.maxZ), - new Vec3d(box.minX, box.maxY, box.minZ), - new Vec3d(box.maxX, box.maxY, box.minZ), - new Vec3d(box.maxX, box.maxY, box.maxZ), - new Vec3d(box.minX, box.maxY, box.maxZ) - }; - } - - /** - * Returns an array of {@code Vec3d} objects representing the vertices of the block at the given position. - * @param pos The position of the block whose vertices are to be returned. - * @return The list of vertices, which will contain 8 elements. Using EnumFacing initials, the order is: - * DNW, DNE, DSE, DSW, UNW, UNE, USE, USW. The returned coordinates are absolute (i.e. measured from the world origin). - */ - public static Vec3d[] getVertices(World world, BlockPos pos){ - return getVertices(world.getBlockState(pos).getBoundingBox(world, pos).offset(pos.getX(), pos.getY(), pos.getZ())); - } - - /** - * Returns the pitch angle in degrees of the given {@link EnumFacing}. For some reason {@code EnumFacing} has a get - * yaw method ({@link EnumFacing#getHorizontalAngle()}) but not a get pitch method. - */ - public static float getPitch(EnumFacing facing){ - return facing == EnumFacing.UP ? 90 : facing == EnumFacing.DOWN ? -90 : 0; - } - - /** - * Gets an entity from its UUID. If the UUID is known to belong to an {@code EntityPlayer}, use the more efficient - * {@link World#getPlayerEntityByUUID(UUID)} instead. - * - * @param world The world the entity is in - * @param id The entity's UUID - * @return The Entity that has the given UUID, or null if no such entity exists in the specified world. - */ - @Nullable - public static Entity getEntityByUUID(World world, @Nullable UUID id){ - - if(id == null) return null; // It would return null eventually but there's no point even looking - - for(Entity entity : world.loadedEntityList){ - // This is a perfect example of where you need to use .equals() and not ==. For most applications, - // this was unnoticeable until world reload because the UUID instance or entity instance is stored. - // Fixed now though. - if(entity != null && entity.getUniqueID() != null && entity.getUniqueID().equals(id)){ - return entity; - } - } - return null; - } - - // No point allowing anything other than players for these methods since other entities can use Entity#playSound. - - /** - * Shortcut for - * {@link World#playSound(EntityPlayer, double, double, double, SoundEvent, SoundCategory, float, float)} where the - * player is null but the x, y and z coordinates are those of the passed in player. Use in preference to - * {@link EntityPlayer#playSound(SoundEvent, float, float)} if there are client-server discrepancies. - */ - public static void playSoundAtPlayer(EntityPlayer player, SoundEvent sound, SoundCategory category, float volume, - float pitch){ - player.world.playSound(null, player.posX, player.posY, player.posZ, sound, category, volume, pitch); - } - - /** - * See {@link WizardryUtilities#playSoundAtPlayer(EntityPlayer, SoundEvent, SoundCategory, float, float)}. Category - * defaults to {@link SoundCategory#PLAYERS}. - */ - public static void playSoundAtPlayer(EntityPlayer player, SoundEvent sound, float volume, float pitch){ - player.world.playSound(null, player.posX, player.posY, player.posZ, sound, SoundCategory.PLAYERS, volume, pitch); - } - - // Players and Mobs - // =============================================================================================================== - - /** - * Returns the entity riding the given entity, or null if there is none. Allows for neater code now that entities - * have a list of passengers, because it is necessary to check that the list is not empty first. - */ - @Nullable - public static Entity getRider(Entity entity){ - return !entity.getPassengers().isEmpty() ? entity.getPassengers().get(0) : null; - } - - /** - * Attacks the given entity with the given damage source and amount, but preserving the entity's original velocity - * instead of applying knockback, as would happen with - * {@link EntityLivingBase#attackEntityFrom(DamageSource, float)} (More accurately, calls that method as normal - * and then resets the entity's velocity to what it was before). Handy for when you need to damage an entity - * repeatedly in a short space of time. - * - * @param entity The entity to attack - * @param source The source of the damage - * @param amount The amount of damage to apply - * @return True if the attack succeeded, false if not. - */ - public static boolean attackEntityWithoutKnockback(Entity entity, DamageSource source, float amount){ - double vx = entity.motionX; - double vy = entity.motionY; - double vz = entity.motionZ; - boolean succeeded = entity.attackEntityFrom(source, amount); - entity.motionX = vx; - entity.motionY = vy; - entity.motionZ = vz; - return succeeded; - } - - /** - * Applies the standard (non-enchanted) amount of knockback to the given target, using the same calculation as - * {@link EntityLivingBase#attackEntityFrom(DamageSource, float)}. Use in conjunction with - * {@link WizardryUtilities#attackEntityWithoutKnockback(Entity, DamageSource, float)} to change the source of - * knockback for an attack. - * - * @param attacker The entity that caused the knockback; the target will be pushed away from this entity. - * @param target The entity to be knocked back. - */ - public static void applyStandardKnockback(Entity attacker, EntityLivingBase target){ - double dx = attacker.posX - target.posX; - double dz; - for(dz = attacker.posZ - target.posZ; dx * dx + dz * dz < 1.0E-4D; dz = (Math.random() - Math.random()) - * 0.01D){ - dx = (Math.random() - Math.random()) * 0.01D; - } - target.knockBack(attacker, 0.4f, dx, dz); - } - - /** - * Undoes 1 tick's worth of velocity change due to gravity for the given entity. If the entity has no gravity, - * this method does nothing. This method is intended to be used in situations where entity gravity needs to be - * turned on and off and it is not practical to use {@link Entity#setNoGravity(boolean)}, usually if there is no - * easy way to get a reference to the entity to turn gravity back on. - * - * @param entity The entity to undo gravity for. - */ - public static void undoGravity(Entity entity){ - if(!entity.hasNoGravity()){ - double gravity = 0.04; - if(entity instanceof EntityThrowable) gravity = 0.03; - else if(entity instanceof EntityArrow) gravity = 0.05; - else if(entity instanceof EntityLivingBase) gravity = 0.08; - entity.motionY += gravity; - } - } - - /** - * Returns a list of the itemstacks in the given player's hotbar. Defined here for convenience and to centralise the - * (unfortunately unavoidable) use of hardcoded numbers to reference the inventory slots. The returned list is a - * modifiable copy of part of the player's inventory stack list; as such, changes to the list are not written - * through to the player's inventory. However, the ItemStack instances themselves are not copied, so changes to any - * of their fields (size, metadata...) will change those in the player's inventory. - * - * @since Wizardry 1.2 - */ - public static List getHotbar(EntityPlayer player){ - NonNullList hotbar = NonNullList.create(); - hotbar.addAll(player.inventory.mainInventory.subList(0, 9)); - return hotbar; - } - - /** - * Returns a list of the itemstacks in the given player's hotbar and offhand, sorted into the following order: main - * hand, offhand, rest of hotbar left-to-right. The returned list is a modifiable shallow copy of part of the player's - * inventory stack list; as such, changes to the list are not written through to the player's inventory. - * However, the ItemStack instances themselves are not copied, so changes to any of their fields (size, metadata...) - * will change those in the player's inventory. - * - * @since Wizardry 1.2 - */ - public static List getPrioritisedHotbarAndOffhand(EntityPlayer player){ - List hotbar = WizardryUtilities.getHotbar(player); - // Adds the offhand item to the beginning of the list so it is processed before the hotbar - hotbar.add(0, player.getHeldItemOffhand()); - // Moves the item in the main hand to the beginning of the list so it is processed first - hotbar.remove(player.getHeldItemMainhand()); - hotbar.add(0, player.getHeldItemMainhand()); - return hotbar; - } - - /** Returns which {@link EnumHandSide} the given {@link EnumHand} is on for the given entity. */ - public static EnumHandSide getSideForHand(EntityLivingBase entity, EnumHand hand){ - return hand == EnumHand.MAIN_HAND ? entity.getPrimaryHand() : entity.getPrimaryHand().opposite(); - } - - /** Returns which {@link EnumHand} is on the given {@link EnumHandSide} for the given entity. */ - public static EnumHand getHandForSide(EntityLivingBase entity, EnumHandSide side){ - return side == entity.getPrimaryHand() ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND; - } - - /** Returns the opposite {@link EnumHand} to the one given. */ - public static EnumHand getOpposite(EnumHand hand){ - return hand == EnumHand.OFF_HAND ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND; - } - - /** - * Tests whether the specified player has any of the specified item in their entire inventory, including armour - * slots and offhand. - */ - public static boolean doesPlayerHaveItem(EntityPlayer player, Item item){ - - for(ItemStack stack : player.inventory.mainInventory){ - if(stack.getItem() == item){ - return true; - } - } - - for(ItemStack stack : player.inventory.armorInventory){ - if(stack.getItem() == item){ - return true; - } - } - - for(ItemStack stack : player.inventory.offHandInventory){ - if(stack.getItem() == item){ - return true; - } - } - - return false; - } - - /** - * Returns a new {@link ItemStack} that is identical to the supplied one, except with the metadata changed to the - * new value given. - * @param toCopy The stack to copy - * @param newMetadata The new metadata value - * @return The resulting {@link ItemStack} - */ - public static ItemStack copyWithMeta(ItemStack toCopy, int newMetadata){ - ItemStack copy = new ItemStack(toCopy.getItem(), toCopy.getCount(), newMetadata); - NBTTagCompound compound = toCopy.getTagCompound(); - if(compound != null) copy.setTagCompound(compound.copy()); - return copy; - } - - /** - * Returns whether the two given item stacks can be merged, i.e. if they both contain the same (stackable) item, - * metadata and NBT. Importantly, the number of items in each stack need not be the same. No actual merging is - * performed by this method; the input stacks will not be modified. - * @param stack1 The first stack to be tested for mergeability - * @param stack2 The second stack to be tested for mergeability (order does not matter) - * @return True if the two stacks can be merged, false if not - */ - public static boolean canMerge(ItemStack stack1, ItemStack stack2){ - return !stack1.isEmpty() && !stack2.isEmpty() - && stack1.isStackable() && stack2.isStackable() - && stack1.getItem() == stack2.getItem() - && (!stack1.getHasSubtypes() || stack1.getMetadata() == stack2.getMetadata()) - && ItemStack.areItemStackTagsEqual(stack1, stack2); - } - - /** - * Checks if the given player is opped on the given server. If the server is a singleplayer or LAN server, this - * means they have cheats enabled. - */ - public static boolean isPlayerOp(EntityPlayer player, MinecraftServer server){ - return server.getPlayerList().getOppedPlayers().getEntry(player.getGameProfile()) != null; - } - - /** Checks that the given entity is allowed to damage blocks in the given world. If the entity is a player, this - * checks the player block damage config setting, otherwise it posts a mob griefing event and returns the result. */ - public static boolean canDamageBlocks(EntityLivingBase entity, World world){ - if(entity instanceof EntityPlayer) return Wizardry.settings.playerBlockDamage; - return ForgeEventFactory.getMobGriefingEvent(world, entity); - } - - /** Returns the default aiming arror used by skeletons for the given difficulty. For reference, these are: Easy - 10, - * Normal - 6, Hard - 2, Peaceful - 10 (rarely used). */ - public static int getDefaultAimingError(EnumDifficulty difficulty){ - switch(difficulty){ - case EASY: return 10; - case NORMAL: return 6; - case HARD: return 2; - default: return 10; // Peaceful counts as easy; the only time this is used is when a player attacks a (good) wizard. - } - } - - /** - * Returns true if the given entity is an EntityLivingBase and not an armour stand; makes the code a bit neater. - * This was added because armour stands are a subclass of EntityLivingBase, but shouldn't necessarily be treated - * as living entities - this depends on the situation. The given entity can safely be cast to EntityLivingBase - * if this method returns true. - */ - // In my opinion, it's a bad design choice to have armour stands extend EntityLivingBase directly - it would be - // better to make a parent class which is extended by both armour stands and EntityLivingBase and contains only - // the code required by both. - public static boolean isLiving(Entity entity){ - return entity instanceof EntityLivingBase && !(entity instanceof EntityArmorStand); - } - - /** - * Turns the given creeper into a charged creeper. In 1.10, this requires reflection since the DataManager keys are - * private. (You could call {@link EntityCreeper#onStruckByLightning(EntityLightningBolt)} and then heal it - * and extinguish it, but that's a bit awkward, and it'll trigger events and stuff...) - */ - // The reflection here only gets done once to initialise the POWERED field, so it's not a performance issue at all. - public static void chargeCreeper(EntityCreeper creeper){ - creeper.getDataManager().set(POWERED, true); - } - - /** - * Returns true if the given caster is currently casting the given spell by any means. This method is intended to - * eliminate the long and cumbersome wand use checking in event handlers, which often missed out spells cast by - * means other than wands. - * @param caster The potential spell caster, which may be a player or an {@link ISpellCaster}. Any other entity will - * cause this method to always return false. - * @param spell The spell to check for. The spell must be continuous or this method will always return false. - * @return True if the caster is currently casting the given spell through any means, false otherwise. - */ - // The reason this is a boolean check is that actually returning a spell presents a problem: players can cast two - // continuous spells at once, one via commands and one via an item, so which do you choose? Since the main point was - // to check for specific spells, it seems more useful to do it this way. - public static boolean isCasting(EntityLivingBase caster, Spell spell){ - - if(!spell.isContinuous) return false; - - if(caster instanceof EntityPlayer){ - - WizardData data = WizardData.get((EntityPlayer)caster); - - if(data != null && data.currentlyCasting() == spell) return true; - - if(caster.isHandActive() && caster.getItemInUseMaxCount() >= spell.getChargeup()){ - - ItemStack stack = caster.getHeldItem(caster.getActiveHand()); - - if(stack.getItem() instanceof ISpellCastingItem && ((ISpellCastingItem)stack.getItem()).getCurrentSpell(stack) == spell){ - // Don't do this, it interferes with stuff! We effectively already tested this with caster.isHandActive() anyway -// && ((ISpellCastingItem)stack.getItem()).canCast(stack, spell, (EntityPlayer)caster, -// EnumHand.MAIN_HAND, 0, new SpellModifiers())){ - return true; - } - } - - }else if(caster instanceof ISpellCaster){ - if(((ISpellCaster)caster).getContinuousSpell() == spell) return true; - } - - return false; - } - - /** - * Returns whether the given {@link DamageSource} is melee damage. This method makes a best guess as to whether - * the damage was from a melee attack; there is no way of testing this properly. - * @param source The damage source to be tested. - * @return True if the given damage source is melee damage, false otherwise. - */ - public static boolean isMeleeDamage(DamageSource source){ - - // With the exception of minions, melee damage always has the same entity for immediate/true source - if(!(source instanceof MinionDamage) && source.getImmediateSource() != source.getTrueSource()) return false; - if(source.isProjectile()) return false; // Projectile damage obviously isn't melee damage - if(source.isUnblockable()) return false; // Melee damage should always be blockable - if(!(source instanceof MinionDamage) && source instanceof IElementalDamage) return false; - if(!(source.getTrueSource() instanceof EntityLivingBase)) return false; // Only living things can melee! - - if(source.getTrueSource() instanceof EntityPlayer && source.getDamageLocation() != null - && source.getDamageLocation().distanceTo(source.getTrueSource().getPositionVector()) > ((EntityLivingBase)source - .getTrueSource()).getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue()){ - return false; // Out of melee reach for players - } - - // If it got through all that, chances are it's melee damage - return true; - } - - // Miscellaneous - // =============================================================================================================== - - /** - * Flattens the given nested collection. The returned collection is an unmodifiable collection of all the elements - * contained within all of the sub-collections of the given nested collection. - * @param collection A nested collection to flatten - * @param The type of elements in the given nested collection - * @return The resulting flattened collection. - */ - public static Collection flatten(Collection> collection){ - Collection result = new ArrayList<>(); - collection.forEach(result::addAll); - return Collections.unmodifiableCollection(result); - } - - // Neat way of getting a random element from a set, wasn't needed in the end but kept here for future reference -// public static E randomElement(Collection collection, Random random){ -// if(collection.isEmpty()) throw new IndexOutOfBoundsException("The given collection must not be empty"); -// Iterator iterator = collection.iterator(); -// for(int n = random.nextInt(collection.size()); n > 0; n--) iterator.next(); -// return iterator.next(); -// } - - /** - * Returns a list of all fields belonging to the given class and all those belonging to all of its superclasses. - * @param c The class to query - * @return The resulting {@link List} of fields - */ - public static List getAllFields(Class c){ - List fields = new ArrayList<>(Arrays.asList(c.getDeclaredFields())); - if(c.getSuperclass() != null) fields.addAll(getAllFields(c.getSuperclass())); - return fields; - } - - /** - * Calculates a factor between 0 and 1 that results in a smooth, aesthetically-pleasing animation when used to scale - * things. Mainly for rendering, but can be used anywhere since it's just a mathematical formula. - * @param lifetime The lifetime of the thing being animated, in ticks (if this is negative, disappearing is ignored) - * @param ticksExisted The current age of the thing being animated, in ticks - * @param partialTicks The current partial tick time - * @param startLength The length of the appearing animation, in ticks - * @param endLength The length of the disappearing animation, in ticks - * @return A fraction between 0 and 1, with the value at the very start and end being 0 and the constant middle - * section having a value of 1. - */ - public static float smoothScaleFactor(int lifetime, int ticksExisted, float partialTicks, int startLength, int endLength){ - float age = ticksExisted + partialTicks; - float s = MathHelper.clamp(age < startLength || lifetime < 0 ? age/startLength : (lifetime - age) / endLength, 0, 1); - s = (float)Math.pow(s, 0.4); // Smooths the animation - return s; - } - -} diff --git a/src/main/java/electroblob/wizardry/worldgen/WoodTypeTemplateProcessor.java b/src/main/java/electroblob/wizardry/worldgen/WoodTypeTemplateProcessor.java index a900c929..7a340a75 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WoodTypeTemplateProcessor.java +++ b/src/main/java/electroblob/wizardry/worldgen/WoodTypeTemplateProcessor.java @@ -1,6 +1,6 @@ package electroblob.wizardry.worldgen; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.BlockUtils; import net.minecraft.block.Block; import net.minecraft.block.BlockPlanks; import net.minecraft.block.BlockWoodSlab; @@ -75,13 +75,13 @@ public class WoodTypeTemplateProcessor implements ITemplateProcessor { return new Template.BlockInfo(info.pos, info.blockState.withProperty(BlockWoodSlab.VARIANT, woodType), info.tileentityData); // This is a mess, no wonder the flattening happened }else if(DOORS.containsValue(info.blockState.getBlock())){ - return new Template.BlockInfo(info.pos, WizardryUtilities.copyState(DOORS.get(woodType), info.blockState), info.tileentityData); + return new Template.BlockInfo(info.pos, BlockUtils.copyState(DOORS.get(woodType), info.blockState), info.tileentityData); }else if(STAIRS.containsValue(info.blockState.getBlock())){ - return new Template.BlockInfo(info.pos, WizardryUtilities.copyState(STAIRS.get(woodType), info.blockState), info.tileentityData); + return new Template.BlockInfo(info.pos, BlockUtils.copyState(STAIRS.get(woodType), info.blockState), info.tileentityData); }else if(FENCES.containsValue(info.blockState.getBlock())){ - return new Template.BlockInfo(info.pos, WizardryUtilities.copyState(FENCES.get(woodType), info.blockState), info.tileentityData); + return new Template.BlockInfo(info.pos, BlockUtils.copyState(FENCES.get(woodType), info.blockState), info.tileentityData); }else if(FENCE_GATES.containsValue(info.blockState.getBlock())){ - return new Template.BlockInfo(info.pos, WizardryUtilities.copyState(FENCE_GATES.get(woodType), info.blockState), info.tileentityData); + return new Template.BlockInfo(info.pos, BlockUtils.copyState(FENCE_GATES.get(woodType), info.blockState), info.tileentityData); } return info; diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java index 5af256f9..0bbd27b6 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java @@ -3,8 +3,8 @@ package electroblob.wizardry.worldgen; import com.google.common.math.Quantiles; import electroblob.wizardry.Wizardry; import electroblob.wizardry.registry.WizardryAdvancementTriggers; +import electroblob.wizardry.util.BlockUtils; import electroblob.wizardry.util.NBTExtras; -import electroblob.wizardry.util.WizardryUtilities; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minecraft.block.Block; @@ -147,8 +147,8 @@ public abstract class WorldGenSurfaceStructure implements IWorldGenerator { // Check if we're at the top of the world, and if so just randomise the y pos (accounts for 'cavern' dimensions) if(centre.getY() >= world.getActualHeight()) centre = new BlockPos(centre.getX(), random.nextInt(world.getActualHeight()), centre.getZ()); - Integer startingHeight = WizardryUtilities.getNearestSurface(world, centre, EnumFacing.UP, 32, true, - WizardryUtilities.SurfaceCriteria.COLLIDABLE_IGNORING_TREES); + Integer startingHeight = BlockUtils.getNearestSurface(world, centre, EnumFacing.UP, 32, true, + BlockUtils.SurfaceCriteria.COLLIDABLE_IGNORING_TREES); if(startingHeight == null) return null; @@ -167,8 +167,8 @@ public abstract class WorldGenSurfaceStructure implements IWorldGenerator { // exactly what is needed here since it is used for placing villages and stuff, and doesn't include leaves // or other foliage. BlockPos pos = origin.add(i / size.getZ(), 0, i % size.getZ()); - Integer floor = WizardryUtilities.getNearestSurface(world, pos.up(startingHeight), EnumFacing.UP, 32, true, - WizardryUtilities.SurfaceCriteria.COLLIDABLE_IGNORING_TREES); + Integer floor = BlockUtils.getNearestSurface(world, pos.up(startingHeight), EnumFacing.UP, 32, true, + BlockUtils.SurfaceCriteria.COLLIDABLE_IGNORING_TREES); floorHeights[i] = floor == null ? 0 : floor; // Very unlikely that floor is null // ^ That method gets the top solid block. Most non-solid blocks are ok to have around the structure, // with the exception of liquids, so if there are too many the position is deemed unsuitable. @@ -336,7 +336,7 @@ public abstract class WorldGenSurfaceStructure implements IWorldGenerator { Block below = world.getBlockState(pos.down()).getBlock(); if(block instanceof BlockLog){ - if(below != Blocks.GRASS && below != Blocks.DIRT && !WizardryUtilities.isTreeBlock(world, pos.down())){ + if(below != Blocks.GRASS && below != Blocks.DIRT && !BlockUtils.isTreeBlock(world, pos.down())){ world.setBlockToAir(pos); changed = true; } diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenWizardTower.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenWizardTower.java index 64882da9..d971468e 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenWizardTower.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenWizardTower.java @@ -5,7 +5,7 @@ import electroblob.wizardry.Wizardry; import electroblob.wizardry.entity.living.EntityEvilWizard; import electroblob.wizardry.entity.living.EntityWizard; import electroblob.wizardry.integration.antiqueatlas.WizardryAntiqueAtlasIntegration; -import electroblob.wizardry.util.WizardryUtilities; +import electroblob.wizardry.util.GeometryUtils; import net.minecraft.block.BlockPlanks; import net.minecraft.block.BlockStainedHardenedClay; import net.minecraft.block.state.IBlockState; @@ -110,7 +110,7 @@ public class WorldGenWizardTower extends WorldGenSurfaceStructure { for(Map.Entry entry : dataBlocks.entrySet()){ - Vec3d vec = WizardryUtilities.getCentre(entry.getKey()); + Vec3d vec = GeometryUtils.getCentre(entry.getKey()); if(entry.getValue().equals(WIZARD_DATA_BLOCK_TAG)){