Skip to content

Commit

Permalink
fix: Fixed optional dependency on Ancient Spellcraft causing a crash …
Browse files Browse the repository at this point in the history
…if AS is not present. Fixes #5
  • Loading branch information
WinDanesz committed Feb 25, 2024
1 parent 22c9c30 commit 4eb6961
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.golems.main.ExtraGolems;
import com.golems.util.GolemConfigSet;
import com.windanesz.ancientspellcraft.spell.FairyRing;
import com.windanesz.wizardrygolems.integration.ASIntegration;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.util.SpellModifiers;
Expand Down Expand Up @@ -95,7 +94,7 @@ public void onDeath(DamageSource cause) {
if (rand.nextBoolean() && ASIntegration.isLoaded()) {
SpellModifiers m = new SpellModifiers();
m.set(WizardryItems.blast_upgrade, 0.5f, false);
FairyRing.summonMushroomRing(world, this.getOwner() instanceof EntityPlayer ? (EntityPlayer) this.getOwner() : this, this.getPosition(), m);
ASIntegration.summonFairyRing(world, this.getOwner() instanceof EntityPlayer ? (EntityPlayer) this.getOwner() : this, this.getPosition(), m);
}
super.onDeath(cause);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.windanesz.wizardrygolems.entity.living;

import com.windanesz.ancientspellcraft.entity.projectile.EntitySafeIceShard;
import com.windanesz.wizardrygolems.WizardryGolems;
import com.windanesz.wizardrygolems.integration.ASIntegration;
import electroblob.wizardry.entity.living.EntityAIAttackSpell;
import electroblob.wizardry.entity.living.ISpellCaster;
import electroblob.wizardry.entity.projectile.EntityIceShard;
import electroblob.wizardry.event.SpellCastEvent;
import electroblob.wizardry.packet.PacketCastSpell;
import electroblob.wizardry.packet.WizardryPacketHandler;
Expand Down Expand Up @@ -116,7 +117,7 @@ public void onUpdate() {

for(int i = 0; i < 1; ++i) {
BlockPos currPos = list.get(world.rand.nextInt(list.size()));
EntitySafeIceShard iceShard = new EntitySafeIceShard(world);
EntityIceShard iceShard = ASIntegration.getIceShard(world);
iceShard.setCaster(this);
iceShard.setPosition((float)currPos.getX() + world.rand.nextFloat(), (float)currPos.getY() + world.rand.nextFloat(), (float)currPos.getZ() + world.rand.nextFloat());
iceShard.motionY = -0.5;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package com.windanesz.wizardrygolems.integration;

import com.windanesz.ancientspellcraft.entity.projectile.EntitySafeIceShard;
import com.windanesz.ancientspellcraft.registry.ASBlocks;
import com.windanesz.ancientspellcraft.spell.FairyRing;
import com.windanesz.ancientspellcraft.tileentity.TileEntityLightningBlock;
import electroblob.wizardry.entity.projectile.EntityIceShard;
import electroblob.wizardry.util.SpellModifiers;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Loader;

public class LightingBlockHandler {
public class ASDependencies {

public static boolean loaded = Loader.isModLoaded("ancientspellcraft");

private LightingBlockHandler() {}
private ASDependencies() {}

public static void setTileProperties(TileEntity tile, EntityLivingBase owner, int duration) {
if (loaded && tile instanceof TileEntityLightningBlock) {
Expand All @@ -24,4 +30,13 @@ public static void setTileProperties(TileEntity tile, EntityLivingBase owner, in
public static IBlockState getLightningBlock() {
return ASBlocks.lightning_block.getDefaultState();
}

public static EntityIceShard getIceShard(World world) {
return new EntitySafeIceShard(world);
}

public static void summonFairyRing(World world, EntityLivingBase owner, BlockPos pos, SpellModifiers modifiers) {
FairyRing.summonMushroomRing(world, owner, pos, modifiers);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.windanesz.wizardrygolems.integration;

import electroblob.wizardry.entity.projectile.EntityIceShard;
import electroblob.wizardry.util.SpellModifiers;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Loader;

public final class ASIntegration {
Expand All @@ -16,11 +20,22 @@ public static void init() {
}

public static void setLightningTileProperties(TileEntity tile, EntityLivingBase owner, int duration) {
if (loaded) LightingBlockHandler.setTileProperties(tile,owner,duration);
if (loaded) {ASDependencies.setTileProperties(tile, owner, duration);}
}

public static IBlockState getLightningBlockState() {
return LightingBlockHandler.getLightningBlock();
return ASDependencies.getLightningBlock();
}

public static boolean isLoaded() {return loaded;}

public static EntityIceShard getIceShard(World world) {
return loaded ? ASDependencies.getIceShard(world) : new EntityIceShard(world);
}

public static void summonFairyRing(World world, EntityLivingBase owner, BlockPos pos, SpellModifiers modifiers) {
if (loaded) {
ASDependencies.summonFairyRing(world, owner, pos, modifiers);
}
}
}

0 comments on commit 4eb6961

Please sign in to comment.