Search in sources :

Example 1 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class NetherPortalBlockMixin method arclight$portalEnter.

@Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPortal(Lnet/minecraft/util/math/BlockPos;)V"))
public void arclight$portalEnter(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) {
    EntityPortalEnterEvent event = new EntityPortalEnterEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), new Location(((WorldBridge) worldIn).bridge$getWorld(), pos.getX(), pos.getY(), pos.getZ()));
    Bukkit.getPluginManager().callEvent(event);
}
Also used : EntityPortalEnterEvent(org.bukkit.event.entity.EntityPortalEnterEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) Location(org.bukkit.Location) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class SlimeEntityMixin method remove.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite(remap = false)
@Override
public void remove(boolean keepData) {
    int i = this.getSlimeSize();
    if (!this.world.isRemote && i > 1 && this.getHealth() <= 0.0f) {
        int j = 2 + this.rand.nextInt(3);
        SlimeSplitEvent event = new SlimeSplitEvent((Slime) this.getBukkitEntity(), j);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled() || event.getCount() <= 0) {
            super.remove(keepData);
            return;
        }
        j = event.getCount();
        List<LivingEntity> slimes = new ArrayList<>(j);
        for (int k = 0; k < j; ++k) {
            float f = (k % 2 - 0.5f) * i / 4.0f;
            float f2 = (k / 2 - 0.5f) * i / 4.0f;
            SlimeEntity entityslime = this.getType().create(this.world);
            if (this.hasCustomName()) {
                entityslime.setCustomName(this.getCustomName());
            }
            if (this.isNoDespawnRequired()) {
                entityslime.enablePersistence();
            }
            entityslime.setInvulnerable(this.isInvulnerable());
            entityslime.setSlimeSize(i / 2, true);
            entityslime.setLocationAndAngles(this.posX + f, this.posY + 0.5, this.posZ + f2, this.rand.nextFloat() * 360.0f, 0.0f);
            slimes.add(entityslime);
        }
        if (CraftEventFactory.callEntityTransformEvent((SlimeEntity) (Object) this, slimes, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) {
            return;
        }
        for (LivingEntity living : slimes) {
            ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SLIME_SPLIT);
            this.world.addEntity(living);
        }
    }
    super.remove(keepData);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) ArrayList(java.util.ArrayList) SlimeSplitEvent(org.bukkit.event.entity.SlimeSplitEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class PlayerEntityMixin_1_15 method arclight$wakeup.

@Inject(method = "stopSleepInBed", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;sleepTimer:I"))
private void arclight$wakeup(boolean flag, boolean flag1, CallbackInfo ci) {
    BlockPos blockPos = this.getBedPosition().orElse(null);
    if (this.bridge$getBukkitEntity() instanceof Player) {
        Player player = (Player) this.bridge$getBukkitEntity();
        Block bed;
        if (blockPos != null) {
            bed = CraftBlock.at(this.world, blockPos);
        } else {
            bed = ((WorldBridge) this.world).bridge$getWorld().getBlockAt(player.getLocation());
        }
        PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed, true);
        Bukkit.getPluginManager().callEvent(event);
    }
}
Also used : Player(org.bukkit.entity.Player) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) BlockPos(net.minecraft.util.math.BlockPos) PlayerBedLeaveEvent(org.bukkit.event.player.PlayerBedLeaveEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class EggEntityMixin method onImpact.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected void onImpact(final RayTraceResult movingobjectposition) {
    if (movingobjectposition.getType() == RayTraceResult.Type.ENTITY) {
        ((EntityRayTraceResult) movingobjectposition).getEntity().attackEntityFrom(DamageSource.causeThrownDamage((EggEntity) (Object) this, this.getThrower()), 0.0f);
    }
    if (!this.world.isRemote) {
        boolean hatching = this.rand.nextInt(8) == 0;
        byte b0 = 1;
        if (this.rand.nextInt(32) == 0) {
            b0 = 4;
        }
        if (!hatching) {
            b0 = 0;
        }
        org.bukkit.entity.EntityType hatchingType = org.bukkit.entity.EntityType.CHICKEN;
        final Entity shooter = this.getThrower();
        if (shooter instanceof ServerPlayerEntity) {
            final PlayerEggThrowEvent event = new PlayerEggThrowEvent(((ServerPlayerEntityBridge) shooter).bridge$getBukkitEntity(), (Egg) this.getBukkitEntity(), hatching, b0, hatchingType);
            Bukkit.getPluginManager().callEvent(event);
            b0 = event.getNumHatches();
            hatching = event.isHatching();
            hatchingType = event.getHatchingType();
        }
        if (hatching) {
            for (int i = 0; i < b0; ++i) {
                Entity entity = ((CraftEntity) ((WorldBridge) this.world).bridge$getWorld().spawnEntity(new Location(((WorldBridge) this.world).bridge$getWorld(), this.posX, this.posY, this.posZ, this.rotationYaw, 0.0f), hatchingType)).getHandle();
                if (((EntityBridge) entity).bridge$getBukkitEntity() instanceof Ageable) {
                    ((Ageable) ((EntityBridge) entity).bridge$getBukkitEntity()).setBaby();
                }
                ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.EGG);
                this.world.getWorld().addEntity(entity);
            }
        }
        this.world.setEntityState((EggEntity) (Object) this, (byte) 3);
        this.remove();
    }
}
Also used : Entity(net.minecraft.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Ageable(org.bukkit.entity.Ageable) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) PlayerEggThrowEvent(org.bukkit.event.player.PlayerEggThrowEvent) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 5 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class ServerChunkProviderMixin method tickChunks.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private void tickChunks() {
    long i = this.world.getGameTime();
    long j = i - this.lastGameTime;
    this.lastGameTime = i;
    WorldInfo worldinfo = this.world.getWorldInfo();
    boolean flag = worldinfo.getGenerator() == WorldType.DEBUG_ALL_BLOCK_STATES;
    boolean flag1 = this.world.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING) && !this.world.getPlayers().isEmpty();
    if (!flag) {
        this.world.getProfiler().startSection("pollingChunks");
        int k = this.world.getGameRules().getInt(GameRules.RANDOM_TICK_SPEED);
        BlockPos blockpos = this.world.getSpawnPoint();
        boolean spawnAnimal = ((WorldBridge) this.world).bridge$ticksPerAnimalSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerAnimalSpawns() == 0;
        boolean spawnMonster = ((WorldBridge) this.world).bridge$ticksPerMonsterSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerMonsterSpawns() == 0;
        boolean spawnWater = ((WorldBridge) this.world).bridge$ticksPerWaterSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerWaterSpawns() == 0;
        boolean spawnAmbient = ((WorldBridge) this.world).bridge$ticksPerAmbientSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerAmbientSpawns() == 0;
        boolean flag2 = spawnAnimal;
        this.world.getProfiler().startSection("naturalSpawnCount");
        int l = this.ticketManager.getSpawningChunksCount();
        EntityClassification[] aentityclassification = EntityClassification.values();
        Object2IntMap<EntityClassification> object2intmap = this.world.countEntities();
        this.world.getProfiler().endSection();
        ((ChunkManagerBridge) this.chunkManager).bridge$getLoadedChunksIterable().forEach((p_223434_10_) -> {
            Optional<Chunk> optional = p_223434_10_.getEntityTickingFuture().getNow(ChunkHolder.UNLOADED_CHUNK).left();
            if (optional.isPresent()) {
                Chunk chunk = optional.get();
                this.world.getProfiler().startSection("broadcast");
                p_223434_10_.sendChanges(chunk);
                this.world.getProfiler().endSection();
                ChunkPos chunkpos = p_223434_10_.getPosition();
                if (!((ChunkManagerBridge) this.chunkManager).bridge$isOutsideSpawningRadius(chunkpos)) {
                    chunk.setInhabitedTime(chunk.getInhabitedTime() + j);
                    if (flag1 && (this.spawnHostiles || this.spawnPassives) && this.world.getWorldBorder().contains(chunk.getPos())) {
                        this.world.getProfiler().startSection("spawner");
                        for (EntityClassification entityclassification : aentityclassification) {
                            boolean spawnThisTick = true;
                            int limit = entityclassification.getMaxNumberOfCreature();
                            switch(entityclassification) {
                                case MONSTER:
                                    spawnThisTick = spawnMonster;
                                    limit = ((WorldBridge) world).bridge$getWorld().getMonsterSpawnLimit();
                                    break;
                                case CREATURE:
                                    spawnThisTick = spawnAnimal;
                                    limit = ((WorldBridge) world).bridge$getWorld().getAnimalSpawnLimit();
                                    break;
                                case WATER_CREATURE:
                                    spawnThisTick = spawnWater;
                                    limit = ((WorldBridge) world).bridge$getWorld().getWaterAnimalSpawnLimit();
                                    break;
                                case AMBIENT:
                                    spawnThisTick = spawnAmbient;
                                    limit = ((WorldBridge) world).bridge$getWorld().getAmbientSpawnLimit();
                                    break;
                            }
                            if (!spawnThisTick || limit == 0) {
                                continue;
                            }
                            if (entityclassification != EntityClassification.MISC && (!entityclassification.getPeacefulCreature() || this.spawnPassives) && (entityclassification.getPeacefulCreature() || this.spawnHostiles) && (!entityclassification.getAnimal() || flag2)) {
                                int i1 = limit * l / field_217238_b;
                                if (object2intmap.getInt(entityclassification) <= i1) {
                                    this.bridge$worldNaturalSpawn(entityclassification, this.world, chunk, blockpos);
                                }
                            }
                        }
                        this.world.getProfiler().endSection();
                    }
                    this.world.tickEnvironment(chunk, k);
                }
            }
        });
        this.world.getProfiler().startSection("customSpawners");
        if (flag1) {
            this.generator.spawnMobs(this.world, this.spawnHostiles, this.spawnPassives);
        }
        this.world.getProfiler().endSection();
        this.world.getProfiler().endSection();
    }
    ((ChunkManagerBridge) this.chunkManager).bridge$tickEntityTracker();
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) IChunk(net.minecraft.world.chunk.IChunk) ChunkManagerBridge(io.izzel.arclight.common.bridge.world.server.ChunkManagerBridge) EntityClassification(net.minecraft.entity.EntityClassification) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)24 BlockPos (net.minecraft.util.math.BlockPos)12 Location (org.bukkit.Location)11 Overwrite (org.spongepowered.asm.mixin.Overwrite)9 Inject (org.spongepowered.asm.mixin.injection.Inject)7 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)6 ServerWorld (net.minecraft.world.server.ServerWorld)6 DimensionTypeBridge (io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge)4 WorldInfo (net.minecraft.world.storage.WorldInfo)4 Player (org.bukkit.entity.Player)4 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)3 SChangeGameStatePacket (net.minecraft.network.play.server.SChangeGameStatePacket)3 SServerDifficultyPacket (net.minecraft.network.play.server.SServerDifficultyPacket)3 EffectInstance (net.minecraft.potion.EffectInstance)3 ChunkPos (net.minecraft.util.math.ChunkPos)3 Vec3d (net.minecraft.util.math.Vec3d)3 DimensionType (net.minecraft.world.dimension.DimensionType)3 CraftWorld (org.bukkit.craftbukkit.v.CraftWorld)3 PlayerChangedWorldEvent (org.bukkit.event.player.PlayerChangedWorldEvent)3 PortalCreateEvent (org.bukkit.event.world.PortalCreateEvent)3