Search in sources :

Example 1 with MobEntityBridge

use of io.izzel.arclight.common.bridge.entity.MobEntityBridge in project Arclight by IzzelAliz.

the class AbstractSpawnerMixin method tick.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void tick() {
    if (!this.isActivated()) {
        this.prevMobRotation = this.mobRotation;
    } else {
        World world = this.getWorld();
        BlockPos blockpos = this.getSpawnerPosition();
        if (world.isRemote) {
            double d3 = (double) blockpos.getX() + (double) world.rand.nextFloat();
            double d4 = (double) blockpos.getY() + (double) world.rand.nextFloat();
            double d5 = (double) blockpos.getZ() + (double) world.rand.nextFloat();
            world.addParticle(ParticleTypes.SMOKE, d3, d4, d5, 0.0D, 0.0D, 0.0D);
            world.addParticle(ParticleTypes.FLAME, d3, d4, d5, 0.0D, 0.0D, 0.0D);
            if (this.spawnDelay > 0) {
                --this.spawnDelay;
            }
            this.prevMobRotation = this.mobRotation;
            this.mobRotation = (this.mobRotation + (double) (1000.0F / ((float) this.spawnDelay + 200.0F))) % 360.0D;
        } else {
            if (this.spawnDelay == -1) {
                this.resetTimer();
            }
            if (this.spawnDelay > 0) {
                --this.spawnDelay;
                return;
            }
            boolean flag = false;
            for (int i = 0; i < this.spawnCount; ++i) {
                CompoundNBT compoundnbt = this.spawnData.getNbt();
                Optional<EntityType<?>> optional = EntityType.readEntityType(compoundnbt);
                if (!optional.isPresent()) {
                    this.resetTimer();
                    return;
                }
                ListNBT listnbt = compoundnbt.getList("Pos", 6);
                int j = listnbt.size();
                double d0 = j >= 1 ? listnbt.getDouble(0) : (double) blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) this.spawnRange + 0.5D;
                double d1 = j >= 2 ? listnbt.getDouble(1) : (double) (blockpos.getY() + world.rand.nextInt(3) - 1);
                double d2 = j >= 3 ? listnbt.getDouble(2) : (double) blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) this.spawnRange + 0.5D;
                if (world.hasNoCollisions(optional.get().getBoundingBoxWithSizeApplied(d0, d1, d2)) && EntitySpawnPlacementRegistry.func_223515_a(optional.get(), world.getWorld(), SpawnReason.SPAWNER, new BlockPos(d0, d1, d2), world.getRandom())) {
                    Entity entity = EntityType.loadEntityAndExecute(compoundnbt, world, (p_221408_6_) -> {
                        p_221408_6_.setLocationAndAngles(d0, d1, d2, p_221408_6_.rotationYaw, p_221408_6_.rotationPitch);
                        return p_221408_6_;
                    });
                    if (entity == null) {
                        this.resetTimer();
                        return;
                    }
                    int k = world.getEntitiesWithinAABB(entity.getClass(), (new AxisAlignedBB((double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), (double) (blockpos.getX() + 1), (double) (blockpos.getY() + 1), (double) (blockpos.getZ() + 1))).grow((double) this.spawnRange)).size();
                    if (k >= this.maxNearbyEntities) {
                        this.resetTimer();
                        return;
                    }
                    entity.setLocationAndAngles(entity.getPosX(), entity.getPosY(), entity.getPosZ(), world.rand.nextFloat() * 360.0F, 0.0F);
                    if (entity instanceof MobEntity) {
                        MobEntity mobentity = (MobEntity) entity;
                        if (!ForgeEventFactory.canEntitySpawnSpawner(mobentity, world, (float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), (AbstractSpawner) (Object) this)) {
                            continue;
                        }
                        if (this.spawnData.getNbt().size() == 1 && this.spawnData.getNbt().contains("id", 8)) {
                            ((MobEntity) entity).onInitialSpawn(world, world.getDifficultyForLocation(new BlockPos(entity)), SpawnReason.SPAWNER, (ILivingEntityData) null, (CompoundNBT) null);
                        }
                        if (((WorldBridge) mobentity.world).bridge$spigotConfig().nerfSpawnerMobs) {
                            ((MobEntityBridge) mobentity).bridge$setAware(false);
                        }
                    }
                    if (CraftEventFactory.callSpawnerSpawnEvent(entity, blockpos).isCancelled()) {
                        Entity vehicle = entity.getRidingEntity();
                        if (vehicle != null) {
                            vehicle.removed = true;
                        }
                        for (final Entity passenger : entity.getRecursivePassengers()) {
                            passenger.removed = true;
                        }
                    }
                    this.func_221409_a(entity);
                    world.playEvent(2004, blockpos, 0);
                    if (entity instanceof MobEntity) {
                        ((MobEntity) entity).spawnExplosionParticle();
                    }
                    flag = true;
                }
            }
            if (flag) {
                this.resetTimer();
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) WeightedSpawnerEntity(net.minecraft.util.WeightedSpawnerEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) CompoundNBT(net.minecraft.nbt.CompoundNBT) World(net.minecraft.world.World) MobEntityBridge(io.izzel.arclight.common.bridge.entity.MobEntityBridge) EntityType(net.minecraft.entity.EntityType) ListNBT(net.minecraft.nbt.ListNBT) AbstractSpawner(net.minecraft.world.spawner.AbstractSpawner) BlockPos(net.minecraft.util.math.BlockPos) MobEntity(net.minecraft.entity.MobEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with MobEntityBridge

use of io.izzel.arclight.common.bridge.entity.MobEntityBridge in project Arclight by IzzelAliz.

the class EntityMixin method arclight$read$ReadBukkitValues.

@Inject(method = "read", at = @At(value = "RETURN"))
public void arclight$read$ReadBukkitValues(CompoundNBT compound, CallbackInfo ci) {
    // CraftBukkit start
    if ((Object) this instanceof LivingEntity) {
        LivingEntity entity = (LivingEntity) (Object) this;
        this.ticksExisted = compound.getInt("Spigot.ticksLived");
        // Reset the persistence for tamed animals
        if (entity instanceof TameableEntity && !isLevelAtLeast(compound, 2) && !compound.getBoolean("PersistenceRequired")) {
            MobEntity entityInsentient = (MobEntity) entity;
            ((MobEntityBridge) entityInsentient).bridge$setPersistenceRequired(!entityInsentient.canDespawn(0));
        }
    }
    // CraftBukkit start - Reset world
    if ((Object) this instanceof ServerPlayerEntity) {
        Server server = Bukkit.getServer();
        org.bukkit.World bworld = null;
        String worldName = compound.getString("world");
        if (compound.contains("WorldUUIDMost") && compound.contains("WorldUUIDLeast")) {
            UUID uid = new UUID(compound.getLong("WorldUUIDMost"), compound.getLong("WorldUUIDLeast"));
            bworld = server.getWorld(uid);
        } else {
            bworld = server.getWorld(worldName);
        }
        if (bworld == null) {
            bworld = ((WorldBridge) ((CraftServer) server).getServer().getWorld(DimensionType.OVERWORLD)).bridge$getWorld();
        }
        setWorld(bworld == null ? null : ((CraftWorld) bworld).getHandle());
    }
    this.getBukkitEntity().readBukkitValues(compound);
// CraftBukkit end
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) MinecraftServer(net.minecraft.server.MinecraftServer) Server(org.bukkit.Server) CraftServer(org.bukkit.craftbukkit.v.CraftServer) TameableEntity(net.minecraft.entity.passive.TameableEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) UUID(java.util.UUID) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) MobEntity(net.minecraft.entity.MobEntity) MobEntityBridge(io.izzel.arclight.common.bridge.entity.MobEntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

MobEntityBridge (io.izzel.arclight.common.bridge.entity.MobEntityBridge)2 MobEntity (net.minecraft.entity.MobEntity)2 UUID (java.util.UUID)1 Entity (net.minecraft.entity.Entity)1 EntityType (net.minecraft.entity.EntityType)1 LivingEntity (net.minecraft.entity.LivingEntity)1 TameableEntity (net.minecraft.entity.passive.TameableEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 ListNBT (net.minecraft.nbt.ListNBT)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 WeightedSpawnerEntity (net.minecraft.util.WeightedSpawnerEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 AbstractSpawner (net.minecraft.world.spawner.AbstractSpawner)1 Server (org.bukkit.Server)1 CraftServer (org.bukkit.craftbukkit.v.CraftServer)1 CraftWorld (org.bukkit.craftbukkit.v.CraftWorld)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1