use of net.minecraft.entity.IEntityOwnable in project SpongeCommon by SpongePowered.
the class MixinEntity_Tracker method getTrackedUniqueId.
@Nullable
private UUID getTrackedUniqueId(String nbtKey) {
if (this.creator != null && NbtDataUtil.SPONGE_ENTITY_CREATOR.equals(nbtKey)) {
return this.creator;
} else if (this instanceof IEntityOwnable) {
IEntityOwnable ownable = (IEntityOwnable) this;
final net.minecraft.entity.Entity owner = ownable.getOwner();
if (owner != null && owner instanceof EntityPlayer) {
this.setCreator(owner.getUniqueID());
return owner.getUniqueID();
}
} else if (this.notifier != null && NbtDataUtil.SPONGE_ENTITY_NOTIFIER.equals(nbtKey)) {
return this.notifier;
}
NBTTagCompound nbt = getSpongeData();
if (!nbt.hasKey(nbtKey)) {
return null;
}
NBTTagCompound creatorNbt = nbt.getCompoundTag(nbtKey);
if (!creatorNbt.hasKey(NbtDataUtil.UUID + "Most") && !creatorNbt.hasKey(NbtDataUtil.UUID + "Least")) {
return null;
}
UUID uniqueId = creatorNbt.getUniqueId(NbtDataUtil.UUID);
if (NbtDataUtil.SPONGE_ENTITY_CREATOR.equals(nbtKey)) {
this.creator = uniqueId;
} else if (NbtDataUtil.SPONGE_ENTITY_NOTIFIER.equals(nbtKey)) {
this.notifier = uniqueId;
}
return uniqueId;
}
use of net.minecraft.entity.IEntityOwnable in project BloodMagic by WayofTime.
the class EntityAIHurtByTargetIgnoreTamed method isSuitableTarget.
@Override
public boolean isSuitableTarget(EntityLivingBase target, boolean includeInvincibles) {
if (this.taskOwner instanceof IEntityOwnable && target instanceof IEntityOwnable) {
UUID thisId = ((IEntityOwnable) this.taskOwner).getOwnerId();
UUID targetId = ((IEntityOwnable) target).getOwnerId();
if (thisId != null && targetId != null && thisId.equals(targetId)) {
return false;
}
}
return super.isSuitableTarget(target, includeInvincibles);
}
use of net.minecraft.entity.IEntityOwnable in project SpongeCommon by SpongePowered.
the class PhaseTracker method spawnEntity.
/**
* This is the replacement of {@link WorldServer#spawnEntity(net.minecraft.entity.Entity)}
* where it captures into phases. The causes and relations are processed by the phases.
*
* The difference between {@link #spawnEntityWithCause(World, Entity)} is that it bypasses
* any phases and directly throws a spawn entity event.
*
* @param world The world
* @param entity The entity
* @return True if the entity spawn was successful
*/
public boolean spawnEntity(World world, Entity entity) {
checkNotNull(entity, "Entity cannot be null!");
// Sponge Start - handle construction phases
if (((IMixinEntity) entity).isInConstructPhase()) {
((IMixinEntity) entity).firePostConstructEvents();
}
final net.minecraft.entity.Entity minecraftEntity = EntityUtil.toNative(entity);
final WorldServer minecraftWorld = (WorldServer) world;
final IMixinWorldServer mixinWorldServer = (IMixinWorldServer) minecraftWorld;
final PhaseData phaseData = this.stack.peek();
final IPhaseState<?> phaseState = phaseData.state;
final PhaseContext<?> context = phaseData.context;
final boolean isForced = minecraftEntity.forceSpawn || minecraftEntity instanceof EntityPlayer;
// Certain phases disallow entity spawns (such as block restoration)
if (!isForced && !phaseState.allowEntitySpawns()) {
return false;
}
// Sponge End - continue with vanilla mechanics
final int chunkX = MathHelper.floor(minecraftEntity.posX / 16.0D);
final int chunkZ = MathHelper.floor(minecraftEntity.posZ / 16.0D);
if (!isForced && !mixinWorldServer.isMinecraftChunkLoaded(chunkX, chunkZ, true)) {
return false;
}
if (minecraftEntity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) minecraftEntity;
minecraftWorld.playerEntities.add(entityplayer);
minecraftWorld.updateAllPlayersSleepingFlag();
SpongeImplHooks.firePlayerJoinSpawnEvent((EntityPlayerMP) entityplayer);
} else {
// Sponge start - check for vanilla owner
if (minecraftEntity instanceof IEntityOwnable) {
IEntityOwnable ownable = (IEntityOwnable) entity;
net.minecraft.entity.Entity owner = ownable.getOwner();
if (owner != null && owner instanceof EntityPlayer) {
context.owner = (User) owner;
entity.setCreator(ownable.getOwnerId());
}
} else if (minecraftEntity instanceof EntityThrowable) {
EntityThrowable throwable = (EntityThrowable) minecraftEntity;
EntityLivingBase thrower = throwable.getThrower();
if (thrower != null) {
User user = null;
if (!(thrower instanceof EntityPlayer)) {
user = ((IMixinEntity) thrower).getCreatorUser().orElse(null);
} else {
user = (User) thrower;
}
if (user != null) {
context.owner = user;
entity.setCreator(user.getUniqueId());
}
}
}
// Sponge end
}
// capture all entities until the phase is marked for completion.
if (!isForced) {
try {
return ((IPhaseState) phaseState).spawnEntityOrCapture(context, entity, chunkX, chunkZ);
} catch (Exception | NoClassDefFoundError e) {
// Just in case something really happened, we should print a nice exception for people to
// paste us
this.printExceptionSpawningEntity(context, e);
return false;
}
}
// Sponge end - continue on with the checks.
minecraftWorld.getChunkFromChunkCoords(chunkX, chunkZ).addEntity(minecraftEntity);
minecraftWorld.loadedEntityList.add(minecraftEntity);
// Sponge - Cannot add onEntityAdded to the access transformer because forge makes it public
mixinWorldServer.onSpongeEntityAdded(minecraftEntity);
return true;
}
use of net.minecraft.entity.IEntityOwnable in project SpongeCommon by SpongePowered.
the class MixinEntity_Tracker method getCreatorUser.
@Override
public Optional<User> getCreatorUser() {
if (this.creator != null) {
return getUserForUuid(this.creator);
}
if (this instanceof IEntityOwnable) {
IEntityOwnable ownable = (IEntityOwnable) this;
final net.minecraft.entity.Entity owner = ownable.getOwner();
if (owner != null && owner instanceof EntityPlayer) {
this.setCreator(owner.getUniqueID());
return Optional.of((User) owner);
}
}
return getTrackedPlayer(NbtDataUtil.SPONGE_ENTITY_CREATOR);
}
use of net.minecraft.entity.IEntityOwnable in project Cavern2 by kegare.
the class ItemAxeCavenic method hitEntity.
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
World world = target.world;
int amount = 1;
for (EntityLivingBase entity : world.getEntitiesWithinAABB(EntityLivingBase.class, target.getEntityBoundingBox().grow(2.5D))) {
if (!(entity instanceof IMob)) {
continue;
}
if (entity instanceof IEntityOwnable && ((IEntityOwnable) entity).getOwner() != null) {
continue;
}
double dist = target.getDistanceSq(entity);
Vec3d vec = getSmashVector(attacker, dist <= 2.0D, (itemRand.nextDouble() + 1.0D) * 1.15D, 0.1D);
entity.attackEntityFrom(DamageSource.causeMobDamage(attacker), 4.0F);
entity.addVelocity(vec.x, vec.y, vec.z);
++amount;
}
if (amount > 1) {
world.playSound(null, target.posX, target.posY + 0.85D, target.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F) + 0.25F);
}
stack.damageItem(amount, attacker);
return true;
}
Aggregations