Added a corruption handler so that blocks can be corrupted by a wide variety of processes.

This commit is contained in:
WayofTime 2016-09-18 10:07:02 -04:00
parent e12b1a7042
commit f7ff728c0d
3 changed files with 130 additions and 10 deletions

View file

@ -3,12 +3,14 @@ package WayofTime.bloodmagic.entity.mob;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.gson.Serializers;
public class EntityAspectedDemonBase extends EntityDemonBase
public abstract class EntityAspectedDemonBase extends EntityDemonBase
{
protected static final DataParameter<EnumDemonWillType> TYPE = EntityDataManager.<EnumDemonWillType>createKey(EntityAspectedDemonBase.class, Serializers.WILL_TYPE_SERIALIZER);
@ -24,6 +26,47 @@ public class EntityAspectedDemonBase extends EntityDemonBase
this.dataManager.register(TYPE, EnumDemonWillType.DEFAULT);
}
public double getMeleeResist()
{
return 0;
}
public double getProjectileResist()
{
return 0;
}
public double getMagicResist()
{
return 0;
}
@Override
public boolean attackEntityFrom(DamageSource source, float amount)
{
if (this.isEntityInvulnerable(source))
{
return false;
} else
{
float newAmount = amount;
if (source.isProjectile())
{
newAmount *= MathHelper.clamp_double(1 - getProjectileResist(), 0, 1);
} else
{
newAmount *= MathHelper.clamp_double(1 - getMeleeResist(), 0, 1);
}
if (source.isMagicDamage())
{
newAmount *= MathHelper.clamp_double(1 - getMagicResist(), 0, 1);
}
return super.attackEntityFrom(source, newAmount);
}
}
public EnumDemonWillType getType()
{
return this.dataManager.get(TYPE);

View file

@ -96,8 +96,19 @@ public class EntityCorruptedSheep extends EntityAspectedDemonBase implements ISh
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(8.0D);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D);
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(30);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.25);
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(6);
}
public double getMeleeResist()
{
return 0.2;
}
public double getProjectileResist()
{
return 0.6;
}
@Override
@ -120,13 +131,6 @@ public class EntityCorruptedSheep extends EntityAspectedDemonBase implements ISh
}
}
@Override
//TODO: Add fun stuff for when interacted with - explode?
public boolean processInteract(EntityPlayer player, EnumHand hand, ItemStack stack)
{
return super.processInteract(player, hand, stack);
}
@SideOnly(Side.CLIENT)
public float getHeadRotationPointY(float partialTick)
{
@ -180,6 +184,12 @@ public class EntityCorruptedSheep extends EntityAspectedDemonBase implements ISh
return SoundEvents.ENTITY_SHEEP_DEATH;
}
@Override
protected float getSoundPitch()
{
return super.getSoundPitch() * 0.5f;
}
@Override
protected void playStepSound(BlockPos pos, Block blockIn)
{

View file

@ -0,0 +1,67 @@
package WayofTime.bloodmagic.inversion;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
public class CorruptionHandler
{
public static Map<Pair<Block, Integer>, Map<EnumDemonWillType, IBlockState>> corruptBlockMap = new HashMap<Pair<Block, Integer>, Map<EnumDemonWillType, IBlockState>>();
public static void registerBlockCorruption(EnumDemonWillType type, Block block, int meta, IBlockState corruptedState)
{
Pair<Block, Integer> pair = Pair.of(block, meta);
if (corruptBlockMap.containsKey(pair))
{
Map<EnumDemonWillType, IBlockState> stateMap = corruptBlockMap.get(pair);
stateMap.put(type, corruptedState);
} else
{
Map<EnumDemonWillType, IBlockState> stateMap = new HashMap<EnumDemonWillType, IBlockState>();
stateMap.put(type, corruptedState);
corruptBlockMap.put(pair, stateMap);
}
}
public static boolean isBlockCorruptible(World world, EnumDemonWillType type, BlockPos pos, IBlockState state, Block block)
{
int meta = block.getMetaFromState(state);
Pair<Block, Integer> pair = Pair.of(block, meta);
if (corruptBlockMap.containsKey(pair))
{
Map<EnumDemonWillType, IBlockState> stateMap = corruptBlockMap.get(pair);
return stateMap.containsKey(type);
}
return false;
}
public static boolean corruptBlock(World world, EnumDemonWillType type, BlockPos pos, IBlockState state, Block block)
{
int meta = block.getMetaFromState(state);
Pair<Block, Integer> pair = Pair.of(block, meta);
if (corruptBlockMap.containsKey(pair))
{
Map<EnumDemonWillType, IBlockState> stateMap = corruptBlockMap.get(pair);
if (stateMap.containsKey(type))
{
return world.setBlockState(pos, stateMap.get(type));
}
}
return false;
}
public static boolean corruptSurroundingBlocks(World world, EnumDemonWillType type, BlockPos centerPos, int radius)
{
return false;
}
}