Search in sources :

Example 21 with WorldBridge

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

the class BoatEntityMixin method arclight$updateVehicle.

@Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/BoatEntity;updateRocking()V"))
private void arclight$updateVehicle(CallbackInfo ci) {
    final org.bukkit.World bworld = ((WorldBridge) this.world).bridge$getWorld();
    final Location to = new Location(bworld, this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
    final Vehicle vehicle = (Vehicle) this.getBukkitEntity();
    Bukkit.getPluginManager().callEvent(new VehicleUpdateEvent(vehicle));
    if (this.lastLocation != null && !this.lastLocation.equals(to)) {
        final VehicleMoveEvent event = new VehicleMoveEvent(vehicle, this.lastLocation, to);
        Bukkit.getPluginManager().callEvent(event);
    }
    this.lastLocation = vehicle.getLocation();
}
Also used : Vehicle(org.bukkit.entity.Vehicle) VehicleUpdateEvent(org.bukkit.event.vehicle.VehicleUpdateEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) VehicleMoveEvent(org.bukkit.event.vehicle.VehicleMoveEvent) Location(org.bukkit.Location) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 22 with WorldBridge

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

the class EndPortalBlockMixin method arclight$enterPortal.

@Inject(method = "onEntityCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;changeDimension(Lnet/minecraft/world/dimension/DimensionType;)Lnet/minecraft/entity/Entity;"))
public void arclight$enterPortal(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);
    if (entityIn instanceof ServerPlayerEntity) {
        ((ServerPlayerEntityBridge) entityIn).bridge$changeDimension(worldIn.dimension.getType() == DimensionType.THE_END ? DimensionType.OVERWORLD : DimensionType.THE_END, PlayerTeleportEvent.TeleportCause.END_PORTAL);
        ci.cancel();
    }
}
Also used : EntityPortalEnterEvent(org.bukkit.event.entity.EntityPortalEnterEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Location(org.bukkit.Location) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 23 with WorldBridge

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

the class NetherPortalBlock_SizeMixin method createPortal.

public boolean createPortal() {
    CraftWorld craftWorld = ((WorldBridge) this.world.getWorld()).bridge$getWorld();
    for (int i = 0; i < this.width; ++i) {
        BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i);
        for (int j = 0; j < this.height; ++j) {
            BlockPos blockPos = blockpos.up(j);
            CraftBlockState blockState = CraftBlockState.getBlockState(this.world.getWorld(), blockPos, 18);
            blockState.setData(Blocks.NETHER_PORTAL.getDefaultState().with(NetherPortalBlock.AXIS, this.axis));
            blocks.add(blockState);
        }
    }
    PortalCreateEvent event = new PortalCreateEvent(blocks, craftWorld, null, PortalCreateEvent.CreateReason.FIRE);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return false;
    }
    this.placePortalBlocks();
    return true;
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld)

Example 24 with WorldBridge

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

the class TeleporterMixin_1_15 method createPortal.

public boolean createPortal(Entity entity, BlockPos createPosition, int createRadius) {
    boolean flag = true;
    double d0 = -1.0;
    int i = createPosition.getX();
    int j = createPosition.getY();
    int k = createPosition.getZ();
    int l = i;
    int i2 = j;
    int j2 = k;
    int k2 = 0;
    int l2 = this.random.nextInt(4);
    BlockPos.Mutable blockposition_mutableblockposition = new BlockPos.Mutable();
    for (int i3 = i - createRadius; i3 <= i + createRadius; ++i3) {
        double d2 = i3 + 0.5 - createPosition.getX();
        for (int j3 = k - createRadius; j3 <= k + createRadius; ++j3) {
            double d3 = j3 + 0.5 - createPosition.getZ();
            Label_0439: for (int k3 = this.world.getActualHeight() - 1; k3 >= 0; --k3) {
                if (this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3, j3))) {
                    while (k3 > 0 && this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3 - 1, j3))) {
                        --k3;
                    }
                    for (int i4 = l2; i4 < l2 + 4; ++i4) {
                        int l3 = i4 % 2;
                        int j4 = 1 - l3;
                        if (i4 % 4 >= 2) {
                            l3 = -l3;
                            j4 = -j4;
                        }
                        for (int l4 = 0; l4 < 3; ++l4) {
                            for (int i5 = 0; i5 < 4; ++i5) {
                                for (int k4 = -1; k4 < 4; ++k4) {
                                    int k5 = i3 + (i5 - 1) * l3 + l4 * j4;
                                    int j5 = k3 + k4;
                                    int l5 = j3 + (i5 - 1) * j4 - l4 * l3;
                                    blockposition_mutableblockposition.setPos(k5, j5, l5);
                                    if (k4 < 0 && !this.world.getBlockState(blockposition_mutableblockposition).getMaterial().isSolid()) {
                                        continue Label_0439;
                                    }
                                    if (k4 >= 0 && !this.world.isAirBlock(blockposition_mutableblockposition)) {
                                        continue Label_0439;
                                    }
                                }
                            }
                        }
                        double d4 = k3 + 0.5 - entity.getPosY();
                        double d5 = d2 * d2 + d4 * d4 + d3 * d3;
                        if (d0 < 0.0 || d5 < d0) {
                            d0 = d5;
                            l = i3;
                            i2 = k3;
                            j2 = j3;
                            k2 = i4 % 4;
                        }
                    }
                }
            }
        }
    }
    if (d0 < 0.0) {
        for (int i3 = i - createRadius; i3 <= i + createRadius; ++i3) {
            double d2 = i3 + 0.5 - createPosition.getX();
            for (int j3 = k - createRadius; j3 <= k + createRadius; ++j3) {
                double d3 = j3 + 0.5 - createPosition.getZ();
                Label_0812: for (int k3 = this.world.getActualHeight() - 1; k3 >= 0; --k3) {
                    if (this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3, j3))) {
                        while (k3 > 0 && this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3 - 1, j3))) {
                            --k3;
                        }
                        for (int i4 = l2; i4 < l2 + 2; ++i4) {
                            int l3 = i4 % 2;
                            int j4 = 1 - l3;
                            for (int l4 = 0; l4 < 4; ++l4) {
                                for (int i5 = -1; i5 < 4; ++i5) {
                                    int k4 = i3 + (l4 - 1) * l3;
                                    int k5 = k3 + i5;
                                    int j5 = j3 + (l4 - 1) * j4;
                                    blockposition_mutableblockposition.setPos(k4, k5, j5);
                                    if (i5 < 0 && !this.world.getBlockState(blockposition_mutableblockposition).getMaterial().isSolid()) {
                                        continue Label_0812;
                                    }
                                    if (i5 >= 0 && !this.world.isAirBlock(blockposition_mutableblockposition)) {
                                        continue Label_0812;
                                    }
                                }
                            }
                            double d4 = k3 + 0.5 - entity.getPosY();
                            double d5 = d2 * d2 + d4 * d4 + d3 * d3;
                            if (d0 < 0.0 || d5 < d0) {
                                d0 = d5;
                                l = i3;
                                i2 = k3;
                                j2 = j3;
                                k2 = i4 % 2;
                            }
                        }
                    }
                }
            }
        }
    }
    int i6 = l;
    int j6 = i2;
    int j3 = j2;
    int k6 = k2 % 2;
    int l6 = 1 - k6;
    if (k2 % 4 >= 2) {
        k6 = -k6;
        l6 = -l6;
    }
    BlockStateListPopulator blockList = new BlockStateListPopulator(this.world);
    if (d0 < 0.0) {
        i2 = (j6 = MathHelper.clamp(i2, 70, this.world.getActualHeight() - 10));
        for (int k3 = -1; k3 <= 1; ++k3) {
            for (int i4 = 1; i4 < 3; ++i4) {
                for (int l3 = -1; l3 < 3; ++l3) {
                    int j4 = i6 + (i4 - 1) * k6 + k3 * l6;
                    int l4 = j6 + l3;
                    int i5 = j3 + (i4 - 1) * l6 - k3 * k6;
                    boolean flag2 = l3 < 0;
                    blockposition_mutableblockposition.setPos(j4, l4, i5);
                    blockList.setBlockState(blockposition_mutableblockposition, flag2 ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState(), 3);
                }
            }
        }
    }
    for (int k3 = -1; k3 < 3; ++k3) {
        for (int i4 = -1; i4 < 4; ++i4) {
            if (k3 == -1 || k3 == 2 || i4 == -1 || i4 == 3) {
                blockposition_mutableblockposition.setPos(i6 + k3 * k6, j6 + i4, j3 + k3 * l6);
                blockList.setBlockState(blockposition_mutableblockposition, Blocks.OBSIDIAN.getDefaultState(), 3);
            }
        }
    }
    BlockState iblockdata = (Blocks.NETHER_PORTAL.getDefaultState()).with(NetherPortalBlock.AXIS, (k6 == 0) ? Direction.Axis.Z : Direction.Axis.X);
    for (int i4 = 0; i4 < 2; ++i4) {
        for (int l3 = 0; l3 < 3; ++l3) {
            blockposition_mutableblockposition.setPos(i6 + i4 * k6, j6 + l3, j3 + i4 * l6);
            blockList.setBlockState(blockposition_mutableblockposition, iblockdata, 18);
        }
    }
    org.bukkit.World bworld = ((WorldBridge) this.world).bridge$getWorld();
    PortalCreateEvent event = new PortalCreateEvent((List) blockList.getList(), bworld, ((EntityBridge) entity).bridge$getBukkitEntity(), PortalCreateEvent.CreateReason.NETHER_PAIR);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        blockList.updateList();
    }
    return true;
}
Also used : BlockState(net.minecraft.block.BlockState) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) BlockPos(net.minecraft.util.math.BlockPos) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator)

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