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();
}
}
}
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();
}
}
}
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;
}
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());
}
}
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());
}
}
}
Aggregations