forked from TAIGA/TAIGA
changed trait haunted together with AIPanic
This commit is contained in:
@@ -8,7 +8,6 @@ import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import slimeknights.tconstruct.library.traits.AbstractTrait;
|
||||
import slimeknights.tconstruct.library.utils.ToolHelper;
|
||||
|
||||
@@ -19,7 +18,6 @@ public class TraitDark extends AbstractTrait {
|
||||
|
||||
public TraitDark() {
|
||||
super("dark", TextFormatting.DARK_GRAY);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,14 +1,12 @@
|
||||
package com.sosnitzka.ztic_addon.traits;
|
||||
|
||||
import com.sosnitzka.ztic_addon.util.EntityPanic;
|
||||
import net.minecraft.entity.EntityCreature;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.EntityAIAttackMelee;
|
||||
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
|
||||
import net.minecraft.entity.ai.EntityAIPanic;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.passive.EntityCow;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import slimeknights.tconstruct.library.traits.AbstractTrait;
|
||||
|
||||
/**
|
||||
@@ -18,23 +16,23 @@ public class TraitHaunted extends AbstractTrait {
|
||||
|
||||
public TraitHaunted() {
|
||||
super("haunted", TextFormatting.DARK_GRAY);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean isCritical) {
|
||||
if (target instanceof EntityCow) {
|
||||
EntityCow cow = (EntityCow) target;
|
||||
cow.tasks.addTask(2, new EntityAIAttackMelee(cow, 1.50D, false));
|
||||
cow.targetTasks.addTask(2, new EntityAINearestAttackableTarget(cow, player.getClass(), false, true));
|
||||
cow.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(3.0D);
|
||||
cow.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(16.0D);
|
||||
cow.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D);
|
||||
}
|
||||
if (target instanceof EntityMob) {
|
||||
EntityMob mob = (EntityMob) target;
|
||||
mob.tasks.addTask(1, new EntityAIPanic(mob, 3.0D));
|
||||
if (target instanceof EntityLiving) {
|
||||
//((EntityLiving) target).tasks.addTask(0, new EntityAIAvoidEntity((EntityCreature) target, EntityPlayer.class,16f, 2.0d, 2.4D));
|
||||
((EntityLiving) target).tasks.addTask(0, new EntityPanic((EntityCreature) target, 2.0D));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*@SubscribeEvent
|
||||
public void onDamage(LivingAttackEvent e){
|
||||
System.out.println(e.getEntity() + " " + e.getSource());
|
||||
}*/
|
||||
|
||||
}
|
||||
|
102
src/main/java/com/sosnitzka/ztic_addon/util/EntityPanic.java
Normal file
102
src/main/java/com/sosnitzka/ztic_addon/util/EntityPanic.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package com.sosnitzka.ztic_addon.util;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityCreature;
|
||||
import net.minecraft.entity.ai.EntityAIBase;
|
||||
import net.minecraft.entity.ai.RandomPositionGenerator;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EntityPanic extends EntityAIBase {
|
||||
private EntityCreature theEntityCreature;
|
||||
protected double speed;
|
||||
private double randPosX;
|
||||
private double randPosY;
|
||||
private double randPosZ;
|
||||
|
||||
public EntityPanic(EntityCreature creature, double speedIn) {
|
||||
this.theEntityCreature = creature;
|
||||
this.speed = speedIn;
|
||||
this.setMutexBits(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the EntityAIBase should begin execution.
|
||||
*/
|
||||
public boolean shouldExecute() {
|
||||
if (this.theEntityCreature.getAITarget() == null && !this.theEntityCreature.isBurning()) {
|
||||
return false;
|
||||
} else {
|
||||
Vec3d vec3d = RandomPositionGenerator.findRandomTarget(this.theEntityCreature, 15, 4);
|
||||
|
||||
if (vec3d == null) {
|
||||
return false;
|
||||
} else {
|
||||
this.randPosX = vec3d.xCoord;
|
||||
this.randPosY = vec3d.yCoord;
|
||||
this.randPosZ = vec3d.zCoord;
|
||||
|
||||
if (this.theEntityCreature.isBurning()) {
|
||||
BlockPos blockpos = this.getRandPos(this.theEntityCreature.worldObj, this.theEntityCreature, 15, 4);
|
||||
|
||||
if (blockpos != null) {
|
||||
this.randPosX = (double) blockpos.getX();
|
||||
this.randPosY = (double) blockpos.getY();
|
||||
this.randPosZ = (double) blockpos.getZ();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a one shot task or start executing a continuous task
|
||||
*/
|
||||
public void startExecuting() {
|
||||
this.theEntityCreature.getNavigator().tryMoveToXYZ(this.randPosX, this.randPosY, this.randPosZ, this.speed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an in-progress EntityAIBase should continue executing
|
||||
*/
|
||||
public boolean continueExecuting() {
|
||||
return !this.theEntityCreature.getNavigator().noPath();
|
||||
}
|
||||
|
||||
private BlockPos getRandPos(World worldIn, Entity entityIn, int horizontalRange, int verticalRange) {
|
||||
BlockPos blockpos = new BlockPos(entityIn);
|
||||
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
||||
int i = blockpos.getX();
|
||||
int j = blockpos.getY();
|
||||
int k = blockpos.getZ();
|
||||
float f = (float) (horizontalRange * horizontalRange * verticalRange * 2);
|
||||
BlockPos blockpos1 = null;
|
||||
|
||||
for (int l = i - horizontalRange; l <= i + horizontalRange; ++l) {
|
||||
for (int i1 = j - verticalRange; i1 <= j + verticalRange; ++i1) {
|
||||
for (int j1 = k - horizontalRange; j1 <= k + horizontalRange; ++j1) {
|
||||
blockpos$mutableblockpos.setPos(l, i1, j1);
|
||||
IBlockState iblockstate = worldIn.getBlockState(blockpos$mutableblockpos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) {
|
||||
float f1 = (float) ((l - i) * (l - i) + (i1 - j) * (i1 - j) + (j1 - k) * (j1 - k));
|
||||
|
||||
if (f1 < f) {
|
||||
f = f1;
|
||||
blockpos1 = new BlockPos(blockpos$mutableblockpos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return blockpos1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user