Search in sources :

Example 41 with BlockPos

use of net.minecraft.core.BlockPos in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelperImpl method applyPhysics.

@Override
public void applyPhysics(Location location) {
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    ((CraftWorld) location.getWorld()).getHandle().updateNeighborsAt(pos, CraftMagicNumbers.getBlock(location.getBlock().getType()));
}
Also used : BlockPos(net.minecraft.core.BlockPos)

Example 42 with BlockPos

use of net.minecraft.core.BlockPos in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelperImpl method doRandomTick.

@Override
public void doRandomTick(Location location) {
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    LevelChunk nmsChunk = ((CraftChunk) location.getChunk()).getHandle();
    net.minecraft.world.level.block.state.BlockState nmsBlock = nmsChunk.getBlockState(pos);
    ServerLevel nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
    if (nmsBlock.isRandomlyTicking()) {
        nmsBlock.randomTick(nmsWorld, pos, nmsWorld.random);
    }
    try {
        // FluidState fluid = nmsBlock.getFluidState();
        // if (fluid.isRandomlyTicking()) {
        // fluid.animateTick(nmsWorld, pos, nmsWorld.random);
        // }
        Object fluid = BLOCKSTATEBASE_GETFLUIDSTATE.invoke(nmsBlock);
        if ((boolean) FLUIDSTATE_ISRANDOMLYTICKING.invoke(fluid)) {
            FLUIDSTATE_ANIMATETICK.invoke(fluid, nmsWorld, pos, nmsWorld.random);
        }
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_18_R1.CraftChunk)

Example 43 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class ModelDataManager method refreshModelData.

private static void refreshModelData(Level world, ChunkPos chunk) {
    cleanCaches(world);
    Set<BlockPos> needUpdate = needModelDataRefresh.remove(chunk);
    if (needUpdate != null) {
        Map<BlockPos, IModelData> data = modelDataCache.computeIfAbsent(chunk, $ -> new ConcurrentHashMap<>());
        for (BlockPos pos : needUpdate) {
            BlockEntity toUpdate = world.getBlockEntity(pos);
            if (toUpdate != null && !toUpdate.isRemoved()) {
                data.put(pos, toUpdate.getModelData());
            } else {
                data.remove(pos);
            }
        }
    }
}
Also used : BlockPos(net.minecraft.core.BlockPos) IModelData(net.minecraftforge.client.model.data.IModelData) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 44 with BlockPos

use of net.minecraft.core.BlockPos 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 45 with BlockPos

use of net.minecraft.core.BlockPos in project MinecraftForge by MinecraftForge.

the class DispenseFluidContainer method fillContainer.

/**
 * Picks up fluid in front of a Dispenser and fills a container with it.
 */
@Nonnull
private ItemStack fillContainer(@Nonnull BlockSource source, @Nonnull ItemStack stack) {
    Level world = source.getLevel();
    Direction dispenserFacing = source.getBlockState().getValue(DispenserBlock.FACING);
    BlockPos blockpos = source.getPos().relative(dispenserFacing);
    FluidActionResult actionResult = FluidUtil.tryPickUpFluid(stack, null, world, blockpos, dispenserFacing.getOpposite());
    ItemStack resultStack = actionResult.getResult();
    if (!actionResult.isSuccess() || resultStack.isEmpty()) {
        return super.execute(source, stack);
    }
    if (stack.getCount() == 1) {
        return resultStack;
    } else if (((DispenserBlockEntity) source.getEntity()).addItem(resultStack) < 0) {
        this.dispenseBehavior.dispense(source, resultStack);
    }
    ItemStack stackCopy = stack.copy();
    stackCopy.shrink(1);
    return stackCopy;
}
Also used : DispenserBlockEntity(net.minecraft.world.level.block.entity.DispenserBlockEntity) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) Nonnull(javax.annotation.Nonnull)

Aggregations

BlockPos (net.minecraft.core.BlockPos)54 BlockState (net.minecraft.world.level.block.state.BlockState)10 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)8 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)8 Level (net.minecraft.world.level.Level)7 Direction (net.minecraft.core.Direction)6 Vec3 (net.minecraft.world.phys.Vec3)6 Nonnull (javax.annotation.Nonnull)5 ResourceLocation (net.minecraft.resources.ResourceLocation)5 ItemStack (net.minecraft.world.item.ItemStack)5 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)4 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)4 Nullable (javax.annotation.Nullable)3 GameTest (net.minecraft.gametest.framework.GameTest)3 ChunkPos (net.minecraft.world.level.ChunkPos)3 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)3 BlockLight (com.denizenscript.denizen.nms.abstracts.BlockLight)2 CompoundTagBuilder (com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder)2 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2