Search in sources :

Example 66 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.

the class ForgeEventFactory method onMultiBlockPlace.

public static boolean onMultiBlockPlace(@Nullable Entity entity, List<BlockSnapshot> blockSnapshots, Direction direction) {
    BlockSnapshot snap = blockSnapshots.get(0);
    BlockState placedAgainst = snap.getLevel().getBlockState(snap.getPos().relative(direction.getOpposite()));
    EntityMultiPlaceEvent event = new EntityMultiPlaceEvent(blockSnapshots, placedAgainst, entity);
    return MinecraftForge.EVENT_BUS.post(event);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) EntityMultiPlaceEvent(net.minecraftforge.event.world.BlockEvent.EntityMultiPlaceEvent)

Example 67 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.

the class ForgeEventFactory method fireSleepingLocationCheck.

public static boolean fireSleepingLocationCheck(LivingEntity player, BlockPos sleepingLocation) {
    SleepingLocationCheckEvent evt = new SleepingLocationCheckEvent(player, sleepingLocation);
    MinecraftForge.EVENT_BUS.post(evt);
    Result canContinueSleep = evt.getResult();
    if (canContinueSleep == Result.DEFAULT) {
        return player.getSleepingPos().map(pos -> {
            BlockState state = player.level.getBlockState(pos);
            return state.getBlock().isBed(state, player.level, pos, player);
        }).orElse(false);
    } else
        return canContinueSleep == Result.ALLOW;
}
Also used : EntityTeleportEvent(net.minecraftforge.event.entity.EntityTeleportEvent) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ProjectileImpactEvent(net.minecraftforge.event.entity.ProjectileImpactEvent) GameProfile(com.mojang.authlib.GameProfile) FurnaceFuelBurnTimeEvent(net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent) UseHoeEvent(net.minecraftforge.event.entity.player.UseHoeEvent) PlayerList(net.minecraft.server.players.PlayerList) Dist(net.minecraftforge.api.distmarker.Dist) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Zombie(net.minecraft.world.entity.monster.Zombie) Pose(net.minecraft.world.entity.Pose) MobSpawnSettings(net.minecraft.world.level.biome.MobSpawnSettings) CapabilityDispatcher(net.minecraftforge.common.capabilities.CapabilityDispatcher) EntityPlaceEvent(net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent) Projectile(net.minecraft.world.entity.projectile.Projectile) PreparableReloadListener(net.minecraft.server.packs.resources.PreparableReloadListener) FillBucketEvent(net.minecraftforge.event.entity.player.FillBucketEvent) BonemealEvent(net.minecraftforge.event.entity.player.BonemealEvent) OverlayType(net.minecraftforge.client.event.RenderBlockOverlayEvent.OverlayType) RecipeType(net.minecraft.world.item.crafting.RecipeType) EntityItemPickupEvent(net.minecraftforge.event.entity.player.EntityItemPickupEvent) RenderBlockOverlayEvent(net.minecraftforge.client.event.RenderBlockOverlayEvent) LogicalSide(net.minecraftforge.fml.LogicalSide) PlayerEvent(net.minecraftforge.event.entity.player.PlayerEvent) LivingHealEvent(net.minecraftforge.event.entity.living.LivingHealEvent) BlockEvent(net.minecraftforge.event.world.BlockEvent) ThrownEnderpearl(net.minecraft.world.entity.projectile.ThrownEnderpearl) InteractionResult(net.minecraft.world.InteractionResult) LivingConversionEvent(net.minecraftforge.event.entity.living.LivingConversionEvent) BaseSpawner(net.minecraft.world.level.BaseSpawner) ItemTooltipEvent(net.minecraftforge.event.entity.player.ItemTooltipEvent) PistonEvent(net.minecraftforge.event.world.PistonEvent) ItemStack(net.minecraft.world.item.ItemStack) SoundSource(net.minecraft.sounds.SoundSource) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) CommandSourceStack(net.minecraft.commands.CommandSourceStack) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) EntityType(net.minecraft.world.entity.EntityType) SleepingLocationCheckEvent(net.minecraftforge.event.entity.player.SleepingLocationCheckEvent) BlockState(net.minecraft.world.level.block.state.BlockState) ArrowLooseEvent(net.minecraftforge.event.entity.player.ArrowLooseEvent) EntityMobGriefingEvent(net.minecraftforge.event.entity.EntityMobGriefingEvent) CreateFluidSourceEvent(net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent) ServerPlayer(net.minecraft.server.level.ServerPlayer) Container(net.minecraft.world.Container) ClientChatEvent(net.minecraftforge.client.event.ClientChatEvent) ToolAction(net.minecraftforge.common.ToolAction) PlaySoundAtEntityEvent(net.minecraftforge.event.entity.PlaySoundAtEntityEvent) PlayerDestroyItemEvent(net.minecraftforge.event.entity.player.PlayerDestroyItemEvent) UseOnContext(net.minecraft.world.item.context.UseOnContext) Nullable(javax.annotation.Nullable) ExplosionEvent(net.minecraftforge.event.world.ExplosionEvent) LightningBolt(net.minecraft.world.entity.LightningBolt) Component(net.minecraft.network.chat.Component) PlayerSetSpawnEvent(net.minecraftforge.event.entity.player.PlayerSetSpawnEvent) Animal(net.minecraft.world.entity.animal.Animal) LivingDestroyBlockEvent(net.minecraftforge.event.entity.living.LivingDestroyBlockEvent) File(java.io.File) SaplingGrowTreeEvent(net.minecraftforge.event.world.SaplingGrowTreeEvent) ArrowNockEvent(net.minecraftforge.event.entity.player.ArrowNockEvent) ChunkPos(net.minecraft.world.level.ChunkPos) MinecraftForge(net.minecraftforge.common.MinecraftForge) Result(net.minecraftforge.eventbus.api.Event.Result) AnimalTameEvent(net.minecraftforge.event.entity.living.AnimalTameEvent) EntityDimensions(net.minecraft.world.entity.EntityDimensions) TooltipFlag(net.minecraft.world.item.TooltipFlag) AllowDespawn(net.minecraftforge.event.entity.living.LivingSpawnEvent.AllowDespawn) InteractionHand(net.minecraft.world.InteractionHand) EntityEvent(net.minecraftforge.event.entity.EntityEvent) Mob(net.minecraft.world.entity.Mob) ResourceLocation(net.minecraft.resources.ResourceLocation) LivingEntity(net.minecraft.world.entity.LivingEntity) PlayerWakeUpEvent(net.minecraftforge.event.entity.player.PlayerWakeUpEvent) InteractionResultHolder(net.minecraft.world.InteractionResultHolder) Direction(net.minecraft.core.Direction) ItemExpireEvent(net.minecraftforge.event.entity.item.ItemExpireEvent) MinecraftForgeClient(net.minecraftforge.client.MinecraftForgeClient) PortalShape(net.minecraft.world.level.portal.PortalShape) LootTables(net.minecraft.world.level.storage.loot.LootTables) NeighborNotifyEvent(net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent) PlayerDataStorage(net.minecraft.world.level.storage.PlayerDataStorage) LivingExperienceDropEvent(net.minecraftforge.event.entity.living.LivingExperienceDropEvent) PlayerSleepInBedEvent(net.minecraftforge.event.entity.player.PlayerSleepInBedEvent) Event(net.minecraftforge.eventbus.api.Event) NonNullList(net.minecraft.core.NonNullList) LivingPackSizeEvent(net.minecraftforge.event.entity.living.LivingPackSizeEvent) WorldEvent(net.minecraftforge.event.world.WorldEvent) PlayerFlyableFallEvent(net.minecraftforge.event.entity.player.PlayerFlyableFallEvent) Commands(net.minecraft.commands.Commands) BedSleepingProblem(net.minecraft.world.entity.player.Player.BedSleepingProblem) GameRules(net.minecraft.world.level.GameRules) PermissionsChangedEvent(net.minecraftforge.event.entity.player.PermissionsChangedEvent) ChatType(net.minecraft.network.chat.ChatType) LevelReader(net.minecraft.world.level.LevelReader) Player(net.minecraft.world.entity.player.Player) Blocks(net.minecraft.world.level.block.Blocks) PotionBrewEvent(net.minecraftforge.event.brewing.PotionBrewEvent) ItemEntity(net.minecraft.world.entity.item.ItemEntity) SoundEvent(net.minecraft.sounds.SoundEvent) BlockPos(net.minecraft.core.BlockPos) BlockToolInteractEvent(net.minecraftforge.event.world.BlockEvent.BlockToolInteractEvent) LevelAccessor(net.minecraft.world.level.LevelAccessor) ClientChatReceivedEvent(net.minecraftforge.client.event.ClientChatReceivedEvent) Level(net.minecraft.world.level.Level) SummonAidEvent(net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent) MobSpawnType(net.minecraft.world.entity.MobSpawnType) ServerLevelData(net.minecraft.world.level.storage.ServerLevelData) ServerLevel(net.minecraft.server.level.ServerLevel) EntityMountEvent(net.minecraftforge.event.entity.EntityMountEvent) PoseStack(com.mojang.blaze3d.vertex.PoseStack) MobCategory(net.minecraft.world.entity.MobCategory) LivingEntityUseItemEvent(net.minecraftforge.event.entity.living.LivingEntityUseItemEvent) LootTable(net.minecraft.world.level.storage.loot.LootTable) ServerResources(net.minecraft.server.ServerResources) SleepingTimeCheckEvent(net.minecraftforge.event.entity.player.SleepingTimeCheckEvent) Nonnull(javax.annotation.Nonnull) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) EntityMultiPlaceEvent(net.minecraftforge.event.world.BlockEvent.EntityMultiPlaceEvent) ResourceKey(net.minecraft.resources.ResourceKey) Explosion(net.minecraft.world.level.Explosion) EntityStruckByLightningEvent(net.minecraftforge.event.entity.EntityStruckByLightningEvent) Consumer(java.util.function.Consumer) HitResult(net.minecraft.world.phys.HitResult) Entity(net.minecraft.world.entity.Entity) LivingSpawnEvent(net.minecraftforge.event.entity.living.LivingSpawnEvent) SleepFinishedTimeEvent(net.minecraftforge.event.world.SleepFinishedTimeEvent) PlayerBrewedPotionEvent(net.minecraftforge.event.brewing.PlayerBrewedPotionEvent) ChunkWatchEvent(net.minecraftforge.event.world.ChunkWatchEvent) BlockState(net.minecraft.world.level.block.state.BlockState) SleepingLocationCheckEvent(net.minecraftforge.event.entity.player.SleepingLocationCheckEvent) InteractionResult(net.minecraft.world.InteractionResult) Result(net.minecraftforge.eventbus.api.Event.Result) HitResult(net.minecraft.world.phys.HitResult)

Example 68 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.

the class FluidUtil method getFluidHandler.

/**
 * Helper method to get an IFluidHandler for at a block position.
 */
public static LazyOptional<IFluidHandler> getFluidHandler(Level world, BlockPos blockPos, @Nullable Direction side) {
    BlockState state = world.getBlockState(blockPos);
    Block block = state.getBlock();
    if (state.hasBlockEntity()) {
        BlockEntity blockEntity = world.getBlockEntity(blockPos);
        if (blockEntity != null) {
            return blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
        }
    }
    return LazyOptional.empty();
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Block(net.minecraft.world.level.block.Block) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 69 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.

the class FluidUtil method destroyBlockOnFluidPlacement.

/**
 * Destroys a block when a fluid is placed in the same position.
 * Modeled after {@link BucketItem#emptyContents(Player, Level, BlockPos, BlockHitResult)}
 *
 * This is a helper method for implementing {@link IFluidBlock#place(Level, BlockPos, FluidStack, IFluidHandler.FluidAction)}.
 *
 * @param world the world that the fluid will be placed in
 * @param pos   the location that the fluid will be placed
 */
public static void destroyBlockOnFluidPlacement(Level world, BlockPos pos) {
    if (!world.isClientSide) {
        BlockState destBlockState = world.getBlockState(pos);
        Material destMaterial = destBlockState.getMaterial();
        boolean isDestNonSolid = !destMaterial.isSolid();
        // TODO: Needs BlockItemUseContext destBlockState.getBlock().isReplaceable(world, pos);
        boolean isDestReplaceable = false;
        if ((isDestNonSolid || isDestReplaceable) && !destMaterial.isLiquid()) {
            world.destroyBlock(pos, true);
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Material(net.minecraft.world.level.material.Material)

Example 70 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project MyPet by xXKeyleXx.

the class EntityMyZombieHorse method playStepSound.

@Override
public void playStepSound(BlockPos blockposition, BlockState blockdata) {
    if (!blockdata.getMaterial().isLiquid()) {
        BlockState blockdataUp = this.level.getBlockState(blockposition.up());
        SoundType soundeffecttype = blockdata.getSoundType();
        if (blockdataUp.getBlock() == Blocks.SNOW) {
            soundeffecttype = blockdata.getSoundType();
        }
        if (this.isVehicle()) {
            ++this.soundCounter;
            if (this.soundCounter > 5 && this.soundCounter % 3 == 0) {
                this.playSound(SoundEvents.HORSE_GALLOP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch());
            } else if (this.soundCounter <= 5) {
                this.playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch());
            }
        } else if (!blockdata.getMaterial().isLiquid()) {
            this.soundCounter += 1;
            playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch());
        } else {
            playSound(SoundEvents.HORSE_STEP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch());
        }
    }
}
Also used : SoundType(net.minecraft.world.level.block.SoundType) BlockState(net.minecraft.world.level.block.state.BlockState)

Aggregations

BlockState (net.minecraft.world.level.block.state.BlockState)141 BlockPos (net.minecraft.core.BlockPos)75 Direction (net.minecraft.core.Direction)18 Level (net.minecraft.world.level.Level)14 Block (net.minecraft.world.level.block.Block)14 ArrayList (java.util.ArrayList)10 ServerLevel (net.minecraft.server.level.ServerLevel)10 SoundType (net.minecraft.world.level.block.SoundType)10 Vec3 (net.minecraft.world.phys.Vec3)10 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)9 Random (java.util.Random)8 ItemStack (net.minecraft.world.item.ItemStack)7 FluidState (net.minecraft.world.level.material.FluidState)7 AABB (net.minecraft.world.phys.AABB)6 BuildBlock (com.wuest.prefab.structures.base.BuildBlock)5 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)5 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)5 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)4 HashMap (java.util.HashMap)4