From 77d9bfc77223162a2a878084ec8fc44fc64dfc9c Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Fri, 23 Oct 2020 13:06:54 +0100 Subject: [PATCH] Blast modifier support for permafrost, plus various fixes and an attempt at slipperiness --- .../wizardry/block/BlockPermafrost.java | 36 +++++++++++- .../wizardry/spell/Permafrost.java | 58 ++++++++++++++++--- 2 files changed, 86 insertions(+), 8 deletions(-) diff --git a/src/main/java/electroblob/wizardry/block/BlockPermafrost.java b/src/main/java/electroblob/wizardry/block/BlockPermafrost.java index 6d3da942..5043cdcb 100644 --- a/src/main/java/electroblob/wizardry/block/BlockPermafrost.java +++ b/src/main/java/electroblob/wizardry/block/BlockPermafrost.java @@ -4,14 +4,15 @@ import electroblob.wizardry.registry.Spells; import electroblob.wizardry.registry.WizardryPotions; import electroblob.wizardry.spell.Spell; import electroblob.wizardry.util.EntityUtils; +import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -43,6 +44,16 @@ public class BlockPermafrost extends BlockDryFrostedIce { return false; } + @Override + public boolean isNormalCube(IBlockState state){ + return false; + } + + @Override + public BlockFaceShape getBlockFaceShape(IBlockAccess world, IBlockState state, BlockPos pos, EnumFacing face){ + return face == EnumFacing.DOWN ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED; + } + @Override public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity){ @@ -53,5 +64,28 @@ public class BlockPermafrost extends BlockDryFrostedIce { int amplifier = Spells.permafrost.getProperty(Spell.EFFECT_STRENGTH).intValue(); ((EntityLivingBase)entity).addPotionEffect(new PotionEffect(WizardryPotions.frost, duration, amplifier)); } + + // EntityLivingBase's slipperiness code doesn't get the block below it properly so slipperiness only works for + // full blocks... + if(entity.onGround){ + + // Not brilliant but it's about the best I can do + entity.motionX *= 1.12 - entity.motionX * entity.motionX; + entity.motionZ *= 1.12 - entity.motionZ * entity.motionZ; + +// if(entity instanceof EntityLivingBase){ +// double maxVel = 0.8; +// double x = entity.motionX; +// double y = entity.motionY; +// double z = entity.motionZ; +// double vel = MathHelper.sqrt(x*x + y*y + z*z); +// double m = vel / maxVel; +// if(m > 1){ +// entity.motionX /= m; +// entity.motionZ /= m; +// } +// } + } + } } diff --git a/src/main/java/electroblob/wizardry/spell/Permafrost.java b/src/main/java/electroblob/wizardry/spell/Permafrost.java index 6176f46a..3bcb3380 100644 --- a/src/main/java/electroblob/wizardry/spell/Permafrost.java +++ b/src/main/java/electroblob/wizardry/spell/Permafrost.java @@ -1,5 +1,6 @@ package electroblob.wizardry.spell; +import electroblob.wizardry.constants.Constants; import electroblob.wizardry.item.SpellActions; import electroblob.wizardry.registry.WizardryBlocks; import electroblob.wizardry.registry.WizardryItems; @@ -10,10 +11,13 @@ import electroblob.wizardry.util.SpellModifiers; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; +import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import java.util.List; + public class Permafrost extends SpellRay { public Permafrost(){ @@ -25,6 +29,21 @@ public class Permafrost extends SpellRay { this.ignoreLivingEntities(true); } + @Override + protected SoundEvent[] createSounds(){ + return this.createContinuousSpellSounds(); + } + + @Override + protected void playSound(World world, EntityLivingBase entity, int ticksInUse, int duration, SpellModifiers modifiers, String... sounds){ + this.playSoundLoop(world, entity, ticksInUse); + } + + @Override + protected void playSound(World world, double x, double y, double z, int ticksInUse, int duration, SpellModifiers modifiers, String... sounds){ + this.playSoundLoop(world, x, y, z, ticksInUse, duration); + } + @Override protected boolean onEntityHit(World world, Entity target, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){ return false; @@ -33,19 +52,44 @@ public class Permafrost 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.getBlockState(pos).isSideSolid(world, pos, EnumFacing.UP) - && BlockUtils.canBlockBeReplaced(world, pos.up())){ + boolean flag = false; + + if(!world.isRemote){ + + int blastUpgradeCount = (int)((modifiers.get(WizardryItems.blast_upgrade) - 1) / Constants.BLAST_RADIUS_INCREASE_PER_LEVEL + 0.5f); + // Results in the following patterns: + // 0 blast upgrades: single block + // 1 blast upgrade: 3x3 without corners or edges + // 2 blast upgrades: 3x3 with corners + // 3 blast upgrades: 5x5 without corners or edges + float radius = 0.5f + 0.73f * blastUpgradeCount; int duration = (int)(getProperty(DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade)); - if(!world.isRemote && BlockUtils.canPlaceBlock(caster, world, pos.up())){ - world.setBlockState(pos.up(), WizardryBlocks.permafrost.getDefaultState()); - world.scheduleUpdate(pos.up().toImmutable(), WizardryBlocks.permafrost, duration); + List sphere = BlockUtils.getBlockSphere(pos.up(), radius); + + for(BlockPos pos1 : sphere){ + flag |= tryToPlaceIce(world, pos1, caster, duration); } - return true; + return flag; + } - + + return true; + + } + + private boolean tryToPlaceIce(World world, BlockPos pos, EntityLivingBase caster, int duration){ + + if(world.getBlockState(pos.down()).isSideSolid(world, pos.down(), EnumFacing.UP) && BlockUtils.canBlockBeReplaced(world, pos)){ + if(BlockUtils.canPlaceBlock(caster, world, pos)){ + world.setBlockState(pos, WizardryBlocks.permafrost.getDefaultState()); + world.scheduleUpdate(pos.toImmutable(), WizardryBlocks.permafrost, duration); + return true; + } + } + return false; }