use of net.minecraft.entity.passive.EntityWolf in project VanillaTeleporter by dyeo.
the class BlockTeleporter method onEntityWalk.
@Override
public void onEntityWalk(World world, BlockPos pos, Entity entity) {
TeleporterNode destinationNode = null;
IBlockState state = world.getBlockState(pos);
EnumType type = EnumType.byMetadata(getMetaFromState(state));
if (entity instanceof EntityLivingBase && entity.hasCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null)) {
ITeleportHandler teleportHandler = entity.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null);
if (!world.isRemote) {
if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
teleportHandler.setOnTeleporter(entity.getPosition().distanceSq(pos) <= 1);
teleportHandler.setDimension(entity.dimension);
if (teleportHandler.getOnTeleporter()) {
boolean isHostile = (entity instanceof EntityMob) || (entity instanceof EntityWolf && ((EntityWolf) entity).isAngry());
boolean isPassive = (entity instanceof EntityAnimal);
if ((isHostile == false || isHostile == ModConfiguration.teleportHostileMobs) && (isPassive == false || isPassive == ModConfiguration.teleportPassiveMobs)) {
destinationNode = TeleporterUtility.teleport((EntityLivingBase) entity, pos);
}
}
}
}
if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
TileEntityTeleporter tEnt = (TileEntityTeleporter) world.getTileEntity(pos);
if (tEnt != null) {
tEnt.spawnParticles();
}
}
if (type.isRecall() && entity instanceof EntityPlayerMP && destinationNode != null) {
WorldServer nextWorld = world.getMinecraftServer().worldServerForDimension(destinationNode.dimension);
breakBlockRecall(world, nextWorld, pos, destinationNode.pos, state, (EntityPlayerMP) entity);
}
}
}
use of net.minecraft.entity.passive.EntityWolf in project SpongeCommon by SpongePowered.
the class MixinEntityLivingBase method attackEntityFrom.
/**
* @author bloodmc - November 22, 2015
* @author gabizou - Updated April 11th, 2016 - Update for 1.9 changes
* @author Aaron1011 - Updated Nov 11th, 2016 - Update for 1.11 changes
*
* @reason Reroute damageEntity calls to our hook in order to prevent damage.
*/
@Override
@Overwrite
public boolean attackEntityFrom(DamageSource source, float amount) {
// Sponge start - Add certain hooks for necessities
this.lastDamageSource = source;
if (source == null) {
Thread.dumpStack();
}
// Sponge - This hook is for forge use mainly
if (!hookModAttack((EntityLivingBase) (Object) this, source, amount))
return false;
// Sponge end
if (this.isEntityInvulnerable(source)) {
return false;
} else if (this.world.isRemote) {
return false;
} else {
this.idleTime = 0;
// has already been set to zero if Keys#HEALTH or SpongeHealthData is set to zero.
if (this.getHealth() <= 0.0F && source != DamageSourceRegistryModule.IGNORED_DAMAGE_SOURCE) {
return false;
} else if (source.isFireDamage() && this.isPotionActive(MobEffects.FIRE_RESISTANCE)) {
return false;
} else {
// Sponge - ignore as this is handled in our damageEntityHookge
// if (false && (source == DamageSource.anvil || source == DamageSource.fallingBlock)
// && this.getEquipmentInSlot(4) != null) {
// this.getEquipmentInSlot(4).damageItem((int) (amount * 4.0F + this.rand.nextFloat() * amount * 2.0F),
// (EntityLivingBase) (Object) this);
// amount *= 0.75F;
// }
// Sponge End
// Sponge - set the 'shield blocking ran' flag to the proper value, since
// we comment out the logic below
boolean flag = amount > 0.0F && this.canBlockDamageSource(source);
// Sponge start - this is handled in our damageEntityHook
/*boolean flag = false;
if (amount > 0.0F && this.canBlockDamageSource(source)) {
this.damageShield(amount);
if (!source.isProjectile())
{
Entity entity = source.getSourceOfDamage();
if (entity instanceof EntityLivingBase)
{
this.blockUsingShield((EntityLivingBase)entity);
}
}
flag = true;
}*/
// Sponge end
this.limbSwingAmount = 1.5F;
boolean flag1 = true;
if ((float) this.hurtResistantTime > (float) this.maxHurtResistantTime / 2.0F) {
if (amount <= this.lastDamage) {
// Technically, this is wrong since 'amount' won't be 0 if a shield is used. However, we need damageEntityHook so that we process the shield, so we leave it as-is
return false;
}
// Sponge start - reroute to our damage hook
if (!this.damageEntityHook(source, amount - this.lastDamage)) {
return false;
}
// Sponge end
this.lastDamage = amount;
flag1 = false;
} else {
// Sponge start - reroute to our damage hook
if (!this.damageEntityHook(source, amount)) {
return false;
}
this.lastDamage = amount;
this.hurtResistantTime = this.maxHurtResistantTime;
// this.damageEntity(source, amount); // handled above
// Sponge end
this.hurtTime = this.maxHurtTime = 10;
}
this.attackedAtYaw = 0.0F;
net.minecraft.entity.Entity entity = source.getTrueSource();
if (entity != null) {
if (entity instanceof EntityLivingBase) {
this.setRevengeTarget((EntityLivingBase) entity);
}
if (entity instanceof EntityPlayer) {
this.recentlyHit = 100;
this.attackingPlayer = (EntityPlayer) entity;
} else if (entity instanceof EntityWolf) {
EntityWolf entityWolf = (EntityWolf) entity;
if (entityWolf.isTamed()) {
this.recentlyHit = 100;
this.attackingPlayer = null;
}
}
}
if (flag1) {
if (flag) {
this.world.setEntityState((EntityLivingBase) (Object) this, (byte) 29);
} else if (source instanceof net.minecraft.util.EntityDamageSource && ((net.minecraft.util.EntityDamageSource) source).getIsThornsDamage()) {
this.world.setEntityState((EntityLivingBase) (Object) this, (byte) 33);
} else {
this.world.setEntityState((EntityLivingBase) (Object) this, (byte) 2);
}
if (source != DamageSource.DROWN && !flag) {
// Sponge - remove 'amount > 0.0F' - it's redundant in Vanilla, and breaks our handling of shields
this.markVelocityChanged();
}
if (entity != null) {
double d1 = entity.posX - this.posX;
double d0;
for (d0 = entity.posZ - this.posZ; d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D) {
d1 = (Math.random() - Math.random()) * 0.01D;
}
this.attackedAtYaw = (float) (MathHelper.atan2(d0, d1) * 180.0D / Math.PI - (double) this.rotationYaw);
this.knockBack(entity, 0.4F, d1, d0);
} else {
this.attackedAtYaw = (float) ((Math.random() * 2.0D) * 180);
}
}
if (this.getHealth() <= 0.0F) {
if (!this.checkTotemDeathProtection(source)) {
SoundEvent soundevent = this.getDeathSound();
if (flag1 && soundevent != null) {
this.playSound(soundevent, this.getSoundVolume(), this.getSoundPitch());
}
// Sponge Start - notify the cause tracker
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
final boolean enterDeathPhase = !phaseTracker.getCurrentState().tracksEntityDeaths();
if (enterDeathPhase) {
Sponge.getCauseStackManager().pushCause(this);
}
try (final PhaseContext<?> context = !enterDeathPhase ? null : EntityPhase.State.DEATH.createPhaseContext().source(this).setDamageSource((org.spongepowered.api.event.cause.entity.damage.source.DamageSource) source).owner(this::getCreatorUser).notifier(this::getNotifierUser).buildAndSwitch()) {
this.onDeath(source);
}
}
}
// Sponge End
} else if (flag1) {
this.playHurtSound(source);
}
if (// Sponge - remove 'amount > 0.0F'
!flag) {
this.lastDamageSource = source;
this.lastDamageStamp = this.world.getTotalWorldTime();
}
// Sponge - remove 'amount > 0.0F'
return !flag;
}
}
}
use of net.minecraft.entity.passive.EntityWolf in project pvp-mode by VulcanForge.
the class PvPEventHandler method getMaster.
/**
* Returns the player that this entity is associated with, if possible.
*/
public EntityPlayerMP getMaster(Entity entity) {
if (entity == null)
return null;
if (entity instanceof EntityPlayerMP)
return (EntityPlayerMP) entity;
if (entity instanceof EntityWolf)
return (EntityPlayerMP) ((EntityWolf) entity).getOwner();
// LOTR patch begins.
Class entityClass = entity.getClass();
try {
// Only Dumbledore and I are capable of this kind of magic.
// And even then it requires a silken hand and a subtle touch.
Field hiredUnitInfo = entityClass.getField("hiredNPCInfo");
Class hiredClass = hiredUnitInfo.getType();
Method getHiringPlayer = hiredClass.getMethod("getHiringPlayer", new Class[] {});
Object o = getHiringPlayer.invoke(hiredUnitInfo.get(entity), new Object[] {});
if (o instanceof EntityPlayerMP)
return (EntityPlayerMP) o;
return null;
} catch (NoSuchFieldException ex) {
// This entity is not a LOTR unit.
return null;
} catch (NoSuchMethodException ex) {
// Something changed with the LOTR mod.
return null;
} catch (IllegalAccessException ex) {
// Hopefully impossible since I am only accessing public
// fields/methods.
FMLLog.info("Security exception in PvPEventHandler at " + entityClass, null);
return null;
} catch (InvocationTargetException ex) {
// No idea why this would occur.
FMLLog.info("InvocationTargetException thrown: " + ex.getCause().getMessage(), null);
return null;
}
}
use of net.minecraft.entity.passive.EntityWolf in project takumicraft by TNTModders.
the class EntityWolfCreeper method takumiExplode.
@Override
public void takumiExplode() {
if (!this.world.isRemote) {
int r = this.getPowered() ? 5 : 2;
for (int t = 0; t < r * 1.5; t++) {
EntityWolf wolf = new EntityWolf(this.world);
wolf.setPosition(this.posX, this.posY, this.posZ);
wolf.setAttackTarget(this.getAttackTarget());
wolf.setAngry(true);
wolf.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.65);
this.world.spawnEntity(wolf);
}
}
}
use of net.minecraft.entity.passive.EntityWolf in project VanillaTeleporter by dyeo.
the class TeleporterUtility method tryTeleport.
public static void tryTeleport(World world, BlockPos pos, Entity entity) {
if (!world.isRemote) {
if (entity instanceof EntityLivingBase && entity.hasCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null)) {
ITeleportHandler handler = entity.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null);
if (handler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
handler.setOnTeleporter(entity.getPosition().distanceSq(pos) <= 1);
handler.setDimension(entity.dimension);
if (handler.getOnTeleporter()) {
boolean isHostile = (entity instanceof EntityMob) || (entity instanceof EntityWolf && ((EntityWolf) entity).isAngry());
boolean isPassive = (entity instanceof EntityAnimal);
if ((!isHostile || ModConfiguration.teleportHostileMobs) && (!isPassive || ModConfiguration.teleportPassiveMobs)) {
teleport((EntityLivingBase) entity, pos);
}
}
}
if (handler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
double width = 0.25;
double height = 0.25;
double mx = world.rand.nextGaussian() * 0.2d;
double my = world.rand.nextGaussian() * 0.2d;
double mz = world.rand.nextGaussian() * 0.2d;
world.spawnParticle(EnumParticleTypes.PORTAL, pos.getX() + 0.5 + world.rand.nextFloat() * width * 2.0F - width, pos.getY() + 1.5 + world.rand.nextFloat() * height, pos.getZ() + 0.5 + world.rand.nextFloat() * width * 2.0F - width, mx, my, mz);
}
}
}
}
Aggregations