Search in sources :

Example 1 with CraftBlock

use of org.bukkit.craftbukkit.v.block.CraftBlock in project Arclight by IzzelAliz.

the class RedstoneTorchBlockMixin method arclight$blockRedstone1.

@Inject(method = "update", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private static void arclight$blockRedstone1(BlockState state, World worldIn, BlockPos pos, Random random, boolean flag, CallbackInfo ci) {
    int oldCurrent = state.get(RedstoneTorchBlock.LIT) ? 15 : 0;
    if (oldCurrent != 0) {
        CraftBlock block = CraftBlock.at(worldIn, pos);
        BlockRedstoneEvent event = new BlockRedstoneEvent(block, oldCurrent, 0);
        Bukkit.getPluginManager().callEvent(event);
        if (event.getNewCurrent() != 0) {
            ci.cancel();
        }
    }
}
Also used : BlockRedstoneEvent(org.bukkit.event.block.BlockRedstoneEvent) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with CraftBlock

use of org.bukkit.craftbukkit.v.block.CraftBlock in project Arclight by IzzelAliz.

the class RedstoneTorchBlockMixin method arclight$blockRedstone2.

@Inject(method = "update", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private static void arclight$blockRedstone2(BlockState state, World worldIn, BlockPos pos, Random random, boolean flag, CallbackInfo ci) {
    int oldCurrent = state.get(RedstoneTorchBlock.LIT) ? 15 : 0;
    if (oldCurrent != 15) {
        CraftBlock block = CraftBlock.at(worldIn, pos);
        BlockRedstoneEvent event = new BlockRedstoneEvent(block, oldCurrent, 15);
        Bukkit.getPluginManager().callEvent(event);
        if (event.getNewCurrent() != 15) {
            ci.cancel();
        }
    }
}
Also used : BlockRedstoneEvent(org.bukkit.event.block.BlockRedstoneEvent) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with CraftBlock

use of org.bukkit.craftbukkit.v.block.CraftBlock in project Arclight by IzzelAliz.

the class EnderDragonEntityMixin method destroyBlocksInAABB.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private boolean destroyBlocksInAABB(final AxisAlignedBB axisalignedbb) {
    final int i = MathHelper.floor(axisalignedbb.minX);
    final int j = MathHelper.floor(axisalignedbb.minY);
    final int k = MathHelper.floor(axisalignedbb.minZ);
    final int l = MathHelper.floor(axisalignedbb.maxX);
    final int i2 = MathHelper.floor(axisalignedbb.maxY);
    final int j2 = MathHelper.floor(axisalignedbb.maxZ);
    boolean flag = false;
    boolean flag2 = false;
    final List<org.bukkit.block.Block> destroyedBlocks = new ArrayList<>();
    for (int k2 = i; k2 <= l; ++k2) {
        for (int l2 = j; l2 <= i2; ++l2) {
            for (int i3 = k; i3 <= j2; ++i3) {
                final BlockPos blockposition = new BlockPos(k2, l2, i3);
                final BlockState iblockdata = this.world.getBlockState(blockposition);
                final net.minecraft.block.Block block = iblockdata.getBlock();
                if (!iblockdata.isAir() && iblockdata.getMaterial() != Material.FIRE) {
                    if (net.minecraftforge.common.ForgeHooks.canEntityDestroy(this.world, blockposition, (EnderDragonEntity) (Object) this) && !BlockTags.DRAGON_IMMUNE.contains(block)) {
                        flag2 = true;
                        destroyedBlocks.add(CraftBlock.at(this.world, blockposition));
                    } else {
                        flag = true;
                    }
                }
            }
        }
    }
    if (!flag2) {
        return flag;
    }
    final org.bukkit.entity.Entity bukkitEntity = this.getBukkitEntity();
    final EntityExplodeEvent event = new EntityExplodeEvent(bukkitEntity, bukkitEntity.getLocation(), destroyedBlocks, 0.0f);
    bukkitEntity.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return flag;
    }
    if (event.getYield() == 0.0f) {
        for (final org.bukkit.block.Block block2 : event.blockList()) {
            this.world.removeBlock(new BlockPos(block2.getX(), block2.getY(), block2.getZ()), false);
        }
    } else {
        for (final org.bukkit.block.Block block2 : event.blockList()) {
            final org.bukkit.Material blockId = block2.getType();
            if (blockId.isAir()) {
                continue;
            }
            final CraftBlock craftBlock = (CraftBlock) block2;
            final BlockPos blockposition2 = craftBlock.getPosition();
            final net.minecraft.block.Block nmsBlock = craftBlock.getNMS().getBlock();
            if (nmsBlock.canDropFromExplosion(this.explosionSource)) {
                final TileEntity tileentity = nmsBlock.hasTileEntity() ? this.world.getTileEntity(blockposition2) : null;
                final LootContext.Builder loottableinfo_builder = new LootContext.Builder((ServerWorld) this.world).withRandom(this.world.rand).withParameter(LootParameters.POSITION, blockposition2).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withParameter(LootParameters.EXPLOSION_RADIUS, 1.0f / event.getYield()).withNullableParameter(LootParameters.BLOCK_ENTITY, tileentity);
                for (ItemStack stack : craftBlock.getNMS().getDrops(loottableinfo_builder)) {
                    Block.spawnAsEntity(this.world, blockposition2, stack);
                }
                craftBlock.getNMS().spawnAdditionalDrops(this.world, blockposition2, ItemStack.EMPTY);
            // net.minecraft.block.Block.spawnDrops(craftBlock.getNMS(), loottableinfo_builder);
            }
            nmsBlock.onExplosionDestroy(this.world, blockposition2, this.explosionSource);
            this.world.removeBlock(blockposition2, false);
        }
    }
    if (flag2) {
        final BlockPos blockposition3 = new BlockPos(i + this.rand.nextInt(l - i + 1), j + this.rand.nextInt(i2 - j + 1), k + this.rand.nextInt(j2 - k + 1));
        this.world.playEvent(2008, blockposition3, 0);
    }
    return flag;
}
Also used : EntityExplodeEvent(org.bukkit.event.entity.EntityExplodeEvent) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) LootContext(net.minecraft.world.storage.loot.LootContext) ArrayList(java.util.ArrayList) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) TileEntity(net.minecraft.tileentity.TileEntity) ServerWorld(net.minecraft.world.server.ServerWorld) BlockState(net.minecraft.block.BlockState) Block(net.minecraft.block.Block) Block(net.minecraft.block.Block) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with CraftBlock

use of org.bukkit.craftbukkit.v.block.CraftBlock in project Arclight by IzzelAliz.

the class BlockBreakEventDispatcher method onBreakBlock.

@SubscribeEvent(receiveCanceled = true)
public void onBreakBlock(BlockEvent.BreakEvent event) {
    if (!event.getWorld().isRemote()) {
        CraftBlock craftBlock = CraftBlock.at(event.getWorld(), event.getPos());
        BlockBreakEvent breakEvent = new BlockBreakEvent(craftBlock, ((ServerPlayerEntityBridge) event.getPlayer()).bridge$getBukkitEntity());
        ArclightCaptures.captureBlockBreakPlayer(breakEvent);
        breakEvent.setCancelled(event.isCanceled());
        breakEvent.setExpToDrop(event.getExpToDrop());
        Bukkit.getPluginManager().callEvent(breakEvent);
        event.setCanceled(breakEvent.isCancelled());
        event.setExpToDrop(breakEvent.getExpToDrop());
    }
}
Also used : BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 5 with CraftBlock

use of org.bukkit.craftbukkit.v.block.CraftBlock in project Arclight by IzzelAliz.

the class BlockPlaceEventDispatcher method onMultiPlace.

@SubscribeEvent(receiveCanceled = true)
public void onMultiPlace(BlockEvent.EntityMultiPlaceEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof ServerPlayerEntity) {
        ServerPlayerEntity playerEntity = (ServerPlayerEntity) entity;
        Player player = ((CraftServer) Bukkit.getServer()).getPlayer(playerEntity);
        Direction direction = ArclightCaptures.getPlaceEventDirection();
        if (direction != null) {
            Hand hand = ArclightCaptures.getPlaceEventHand(Hand.MAIN_HAND);
            List<BlockState> placedBlocks = new ArrayList<>(event.getReplacedBlockSnapshots().size());
            for (BlockSnapshot snapshot : event.getReplacedBlockSnapshots()) {
                placedBlocks.add(ArclightBlockSnapshot.fromBlockSnapshot(snapshot, true).getState());
            }
            CraftBlock againstBlock = CraftBlock.at(event.getWorld(), event.getPos().offset(direction.getOpposite()));
            ItemStack bukkitStack;
            if (hand == Hand.MAIN_HAND) {
                bukkitStack = player.getInventory().getItemInMainHand();
            } else {
                bukkitStack = player.getInventory().getItemInOffHand();
            }
            BlockPlaceEvent placeEvent = new BlockMultiPlaceEvent(placedBlocks, againstBlock, bukkitStack, player, !event.isCanceled());
            placeEvent.setCancelled(event.isCanceled());
            Bukkit.getPluginManager().callEvent(placeEvent);
            event.setCanceled(placeEvent.isCancelled() || !placeEvent.canBuild());
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Player(org.bukkit.entity.Player) BlockMultiPlaceEvent(org.bukkit.event.block.BlockMultiPlaceEvent) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) ArrayList(java.util.ArrayList) ArclightBlockSnapshot(io.izzel.arclight.common.mod.util.ArclightBlockSnapshot) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) CraftServer(org.bukkit.craftbukkit.v.CraftServer) Direction(net.minecraft.util.Direction) Hand(net.minecraft.util.Hand) BlockState(org.bukkit.block.BlockState) ItemStack(org.bukkit.inventory.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

CraftBlock (org.bukkit.craftbukkit.v.block.CraftBlock)11 Inject (org.spongepowered.asm.mixin.injection.Inject)7 Direction (net.minecraft.util.Direction)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 BlockPos (net.minecraft.util.math.BlockPos)3 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)3 CraftServer (org.bukkit.craftbukkit.v.CraftServer)3 Player (org.bukkit.entity.Player)3 BlockBreakEvent (org.bukkit.event.block.BlockBreakEvent)3 AbstractList (java.util.AbstractList)2 ArrayList (java.util.ArrayList)2 PistonBlock (net.minecraft.block.PistonBlock)2 Entity (net.minecraft.entity.Entity)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 Hand (net.minecraft.util.Hand)2 Block (org.bukkit.block.Block)2 BlockPistonEvent (org.bukkit.event.block.BlockPistonEvent)2 BlockPistonExtendEvent (org.bukkit.event.block.BlockPistonExtendEvent)2 BlockPistonRetractEvent (org.bukkit.event.block.BlockPistonRetractEvent)2 BlockPlaceEvent (org.bukkit.event.block.BlockPlaceEvent)2