Block protection compat overhaul

- Unifies all block protection checks into helper methods in BlockUtils which trigger all the necessary forge events and vanilla methods
- Implements these checks in all the appropriate places and removes calls to EntityUtils#canDamageBlocks(...) where they are no longer needed
- Changes the mine spell to respect the config settings in line with the rest of the spells
- Fixes earthquake not respecting the settings at all
- Adds a separate config option for dispenser block damage and updates the description for the existing settings to reflect the changes
This commit is contained in:
Electroblob77
2020-09-23 00:57:55 +01:00
parent f49ef7594d
commit 2f91573284
22 changed files with 238 additions and 86 deletions
@@ -45,14 +45,11 @@ public class EntityIceball extends EntityMagicProjectile {
}else{
if(this.getThrower() == null || EntityUtils.canDamageBlocks(this.getThrower(), world)){
BlockPos pos = rayTrace.getBlockPos();
BlockPos pos = rayTrace.getBlockPos();
if(rayTrace.sideHit == EnumFacing.UP && !world.isRemote && world.isSideSolid(pos, EnumFacing.UP)
&& BlockUtils.canBlockBeReplaced(world, pos.up())){
world.setBlockState(pos.up(), Blocks.SNOW_LAYER.getDefaultState());
}
if(rayTrace.sideHit == EnumFacing.UP && !world.isRemote && world.isSideSolid(pos, EnumFacing.UP)
&& BlockUtils.canBlockBeReplaced(world, pos.up()) && BlockUtils.canPlaceBlock(thrower, world, pos)){
world.setBlockState(pos.up(), Blocks.SNOW_LAYER.getDefaultState());
}
}
@@ -51,8 +51,8 @@ public class EntityLargeMagicFireball extends EntityMagicFireball {
protected void onImpact(RayTraceResult rayTrace){
if(!world.isRemote){
boolean flag = this.getThrower() == null || EntityUtils.canDamageBlocks(this.getThrower(), world);
this.world.newExplosion(null, this.posX, this.posY, this.posZ, getExplosionPower() * blastMultiplier, flag, flag);
boolean terrainDamage = EntityUtils.canDamageBlocks(this.getThrower(), world);
this.world.newExplosion(null, this.posX, this.posY, this.posZ, getExplosionPower() * blastMultiplier, terrainDamage, terrainDamage);
}
super.onImpact(rayTrace);
@@ -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.EntityUtils;
import electroblob.wizardry.util.BlockUtils;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.ParticleBuilder;
@@ -84,13 +84,12 @@ public class EntityMagicFireball extends EntityMagicProjectile {
}else{
if(this.getThrower() == null || EntityUtils.canDamageBlocks(this.getThrower(), world)){
BlockPos pos = rayTrace.getBlockPos().offset(rayTrace.sideHit);
BlockPos blockpos = rayTrace.getBlockPos().offset(rayTrace.sideHit);
if(this.world.isAirBlock(blockpos)){
this.world.setBlockState(blockpos, Blocks.FIRE.getDefaultState());
}
// Remember that canPlaceBlock should ALWAYS be the last thing that gets checked, or it risks other mods
// thinking the block was placed even when a later condition prevents it, which may have side-effects
if(this.world.isAirBlock(pos) && BlockUtils.canPlaceBlock(thrower, world, pos)){
this.world.setBlockState(pos, Blocks.FIRE.getDefaultState());
}
}