net.minecraft.entity.SpawnType Java Examples

The following examples show how to use net.minecraft.entity.SpawnType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkeletonEntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onStruckByLightning(LightningEntity lightning)
{
    if (!this.world.isClient && !this.removed && CarpetExtraSettings.renewableWitherSkeletons)
    {
        WitherSkeletonEntity witherSkelly = new WitherSkeletonEntity(EntityType.WITHER_SKELETON, this.world);
        witherSkelly.refreshPositionAndAngles(this.getX(), this.getY(), this.getZ(), this.yaw, this.pitch);
        witherSkelly.initialize(this.world, this.world.getLocalDifficulty(new BlockPos(witherSkelly)), SpawnType.CONVERSION, (EntityData) null, (CompoundTag) null);
        witherSkelly.setAiDisabled(this.isAiDisabled());
        
        if (this.hasCustomName())
        {
            witherSkelly.setCustomName(this.getCustomName());
            witherSkelly.setCustomNameVisible(this.isCustomNameVisible());
        }
        
        this.world.spawnEntity(witherSkelly);
        this.remove();
    }
    else
    {
        super.onStruckByLightning(lightning);
    }
}
 
Example #2
Source File: GuardianEntityMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public void onStruckByLightning(LightningEntity lightning)
{
    if (!this.world.isClient && !this.removed && CarpetSettings.renewableSponges && !((Object)this instanceof ElderGuardianEntity))
    {
        ElderGuardianEntity elderGuardian = new ElderGuardianEntity(EntityType.ELDER_GUARDIAN ,this.world);
        elderGuardian.refreshPositionAndAngles(this.getX(), this.getY(), this.getZ(), this.yaw, this.pitch);
        elderGuardian.initialize(this.world ,this.world.getLocalDifficulty(elderGuardian.getBlockPos()), SpawnType.CONVERSION, (EntityData)null, (CompoundTag)null);
        elderGuardian.setAiDisabled(this.isAiDisabled());
        
        if (this.hasCustomName())
        {
            elderGuardian.setCustomName(this.getCustomName());
            elderGuardian.setCustomNameVisible(this.isCustomNameVisible());
        }
        
        this.world.spawnEntity(elderGuardian);
        this.remove();
    }
    else
    {
        super.onStruckByLightning(lightning);
    }
}
 
Example #3
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnType) {
	if (entity == null) {
		return Result.DEFAULT;
	}

	LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, spawner, spawnType);
	MinecraftForge.EVENT_BUS.post(event);
	return event.getResult();
}
 
Example #4
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean canEntitySpawnFromSpawner(MobEntity entity, World world, double x, double y, double z, MobSpawnerLogic spawner) {
	Result result = canEntitySpawn(entity, world, x, y, z, spawner, SpawnType.SPAWNER);

	if (result == Result.DEFAULT) {
		// Vanilla logic, but inverted since we're checking if it CAN spawn instead of if it CAN'T
		return entity.canSpawn(world, SpawnType.SPAWNER) && entity.canSpawn(world);
	} else {
		return result == Result.ALLOW;
	}
}
 
Example #5
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean canEntitySpawnNaturally(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnType, double sqDistanceFromPlayer) {
	Result result = canEntitySpawn(entity, world, x, y, z, spawner, spawnType);

	if (result == Result.DEFAULT) {
		// Vanilla logic, but inverted since we're checking if it CAN spawn instead of if it CAN'T
		return !(sqDistanceFromPlayer > 16384.0D && entity.canImmediatelyDespawn(sqDistanceFromPlayer)) && entity.canSpawn(world, SpawnType.NATURAL) && entity.canSpawn(world);
	} else {
		return result == Result.ALLOW;
	}
}
 
Example #6
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;"))
private static EntityData hookSpecialSpawn(MobEntity entity, IWorld world, LocalDifficulty localDifficulty, SpawnType spawnType, EntityData data, CompoundTag tag) {
	if (!EntityEvents.doSpecialSpawn(entity, world, entity.x, entity.y, entity.z, null, spawnType)) {
		return entity.initialize(world, localDifficulty, spawnType, data, tag);
	} else {
		return data;
	}
}
 
Example #7
Source File: MixinEntityType.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = SPAWN, at = @At(value = "INVOKE", target = "net/minecraft/world/World.spawnEntity(Lnet/minecraft/entity/Entity;)Z"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void hookMobSpawns(World world, @Nullable CompoundTag itemTag, @Nullable Text name, @Nullable PlayerEntity player, BlockPos pos, SpawnType type, boolean alignPosition, boolean bl, CallbackInfoReturnable<Entity> callback, Entity entity) {
	if (!(entity instanceof MobEntity)) {
		return;
	}

	MobEntity mob = (MobEntity) entity;

	if (EntityEvents.doSpecialSpawn(mob, world, pos.getX(), pos.getY(), pos.getZ(), null, type)) {
		callback.setReturnValue(null);
	}
}
 
Example #8
Source File: SpawnHelperMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/mob/MobEntity;initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;"
))
private static EntityData spawnEntity(MobEntity mobEntity, IWorld iWorld_1, LocalDifficulty localDifficulty_1, SpawnType spawnType_1, EntityData entityData_1, CompoundTag compoundTag_1)
{
    if (!SpawnReporter.mock_spawns)
        return mobEntity.initialize(iWorld_1, localDifficulty_1, spawnType_1, entityData_1, compoundTag_1);
    return null;
}
 
Example #9
Source File: MobEntityMixin.java    From the-hallow with MIT License 4 votes vote down vote up
@Inject(method = "initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;", at = @At("RETURN"))
public void initialize(IWorld iWorld, LocalDifficulty localDifficulty, SpawnType spawnType, EntityData entityData, CompoundTag compoundTag, CallbackInfoReturnable<EntityData> cir) {
	if (((Object) this) instanceof EndermanEntity && HallowedConfig.PumpkinMobs.endermen && MixinHelpers.RANDOM.nextInt(10) == 0) {
		((EndermanEntity) (Object) this).setCarriedBlock((MixinHelpers.RANDOM.nextBoolean() ? Blocks.PUMPKIN : (MixinHelpers.RANDOM.nextBoolean() ? Blocks.CARVED_PUMPKIN : Blocks.JACK_O_LANTERN)).getDefaultState());
	}
}
 
Example #10
Source File: LivingSpawnEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SpawnType getSpawnReason() {
	return type;
}
 
Example #11
Source File: LivingSpawnEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SpawnType getSpawnReason() {
	return type;
}
 
Example #12
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean doSpecialSpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnType) {
	return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, spawner, spawnType));
}
 
Example #13
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/IWorld;Lnet/minecraft/entity/SpawnType;)Z"))
private static boolean hookCheckSpawn(MobEntity entity, IWorld world, SpawnType spawnType) {
	return EntityEvents.canEntitySpawnNaturally(entity, entity.world, entity.x, entity.y, entity.x, null, spawnType, playerDistanceStore);
}
 
Example #14
Source File: MixinMobSpawnerLogic.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Redirect(method = "update", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/IWorld;Lnet/minecraft/entity/SpawnType;)Z"))
private boolean spawnTestRedirect(MobEntity on, IWorld world, SpawnType type) {
	MobSpawnerLogic spawner = (MobSpawnerLogic) (Object) this;

	return EntityEvents.canEntitySpawnFromSpawner(on, (World) world, on.x, on.y, on.z, spawner);
}
 
Example #15
Source File: LivingSpawnEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * CheckSpawn is fired when an Entity is about to be spawned.
 *
 * @param entity the spawning entity
 * @param world the world to spawn in
 * @param x x coordinate
 * @param y y coordinate
 * @param z z coordinate
 * @param spawner the spawner that spawned this entity null if it this spawn is
 *               coming from a world spawn or other non-spawner source
 */
public CheckSpawn(MobEntity entity, IWorld world, double x, double y, double z,
		@Nullable MobSpawnerLogic spawner, SpawnType type) {
	super(entity, world, x, y, z);
	this.spawner = spawner;
	this.type = type;
}
 
Example #16
Source File: LivingSpawnEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * @param entity the spawning entity
 * @param world the world to spawn in
 * @param x x coordinate
 * @param y y coordinate
 * @param z z coordinate
 * @param spawner the spawner that spawned this entity, or null if this spawn is
 *        coming from a world spawn or other non-spawner source
 */
public SpecialSpawn(MobEntity entity, IWorld world, double x, double y, double z,
		@Nullable MobSpawnerLogic spawner, SpawnType type) {
	super(entity, world, x, y, z);
	this.spawner = spawner;
	this.type = type;
}