Search in sources :

Example 21 with BlockPos

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

the class WorldHelperImpl method getLocalDifficulty.

@Override
public float getLocalDifficulty(Location location) {
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    DifficultyInstance scaler = ((CraftWorld) location.getWorld()).getHandle().getCurrentDifficultyAt(pos);
    return scaler.getEffectiveDifficulty();
}
Also used : DifficultyInstance(net.minecraft.world.DifficultyInstance) BlockPos(net.minecraft.core.BlockPos)

Example 22 with BlockPos

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

the class PacketHelperImpl method showDebugTestMarker.

@Override
public void showDebugTestMarker(Player player, Location location, ColorTag color, int alpha, String name, int time) {
    ResourceLocation packetKey = new ResourceLocation("minecraft", "debug/game_test_add_marker");
    FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
    buf.writeBlockPos(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
    int colorInt = color.getColor().getBlue() | (color.getColor().getGreen() << 8) | (color.getColor().getRed() << 16) | (alpha << 24);
    buf.writeInt(colorInt);
    buf.writeByteArray(name.getBytes(StandardCharsets.UTF_8));
    buf.writeInt(time);
    ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(packetKey, buf);
    send(player, packet);
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ResourceLocation(net.minecraft.resources.ResourceLocation) BlockPos(net.minecraft.core.BlockPos)

Example 23 with BlockPos

use of net.minecraft.core.BlockPos in project MyPet by xXKeyleXx.

the class EntityMyStrider method ride.

// Special riding for Lava
@Override
protected void ride(double motionSideways, double motionForward, double motionUpwards, float speedModifier) {
    float speed;
    if (this.specialFloat()) {
        // This already has the floating/walking on Lava logic -> Now we just ride it like it's solid
        double minY;
        minY = this.getBoundingBox().minY;
        float friction = 0.91F;
        if (this.onGround) {
            friction = this.level.getBlockState(new BlockPos(Mth.floor(this.getX()), Mth.floor(minY) - 1, Mth.floor(this.getZ()))).getBlock().getFriction() * 0.91F;
        }
        speed = speedModifier * (0.16277136F / (friction * friction * friction));
        this.moveRelative(speed, new Vec3(motionSideways, motionUpwards, motionForward));
        double motX = this.getDeltaMovement().x();
        double motY = this.getDeltaMovement().y();
        double motZ = this.getDeltaMovement().z();
        Vec3 mot = new Vec3(motX, motY, motZ);
        this.move(MoverType.SELF, mot);
        if (this.horizontalCollision && this.onClimbable()) {
            motY = 0.2D;
        }
        motY -= 0.08D;
        motY *= 0.9800000190734863D;
        motX *= friction;
        motZ *= friction;
        this.setDeltaMovement(motX, motY, motZ);
        this.startRiding(this, false);
    } else {
        // Call normal riding when not in lava aka when specialFloat returned false
        super.ride(motionSideways, motionForward, motionUpwards, speedModifier);
    }
}
Also used : Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos)

Example 24 with BlockPos

use of net.minecraft.core.BlockPos in project MyPet by xXKeyleXx.

the class EatGrass method tick.

@Override
public void tick() {
    if (--this.eatTicks == 0) {
        int blockLocX = Mth.floor(this.entityMySheep.getX());
        int blockLocY = Mth.floor(this.entityMySheep.getY());
        int blockLocZ = Mth.floor(this.entityMySheep.getZ());
        BlockPos blockAt = new BlockPos(blockLocX, blockLocY, blockLocZ);
        if (GRASS.test(this.world.getBlockState(blockAt))) {
            if (!CraftEventFactory.callEntityChangeBlockEvent(this.entityMySheep, blockAt, Blocks.AIR.defaultBlockState(), !this.world.getWorld().getGameRuleValue(GameRule.MOB_GRIEFING)).isCancelled()) {
                this.world.destroyBlock(blockAt, false);
            }
            entityMySheep.getMyPet().setSheared(false);
        } else {
            BlockPos blockUnder = blockAt.down();
            if (this.world.getBlockState(blockUnder).getBlock() == Blocks.GRASS) {
                if (!CraftEventFactory.callEntityChangeBlockEvent(this.entityMySheep, blockAt, Blocks.AIR.defaultBlockState(), !this.world.getWorld().getGameRuleValue(GameRule.MOB_GRIEFING)).isCancelled()) {
                    this.world.levelEvent(2001, blockUnder, Block.getId(Blocks.GRASS_BLOCK.defaultBlockState()));
                    this.world.setBlock(blockUnder, Blocks.DIRT.defaultBlockState(), 2);
                }
                entityMySheep.getMyPet().setSheared(false);
            }
        }
    }
}
Also used : BlockPos(net.minecraft.core.BlockPos)

Example 25 with BlockPos

use of net.minecraft.core.BlockPos in project MyPet by xXKeyleXx.

the class PlatformHelper method getBlockBBsInBB.

public List getBlockBBsInBB(net.minecraft.world.level.Level world, AABB axisalignedbb) {
    UnsafeList unsafeList = new UnsafeList();
    int minX = Mth.floor(axisalignedbb.minX);
    int maxX = (int) Math.ceil(axisalignedbb.maxX);
    int minY = Mth.floor(axisalignedbb.minY);
    int maxY = (int) Math.ceil(axisalignedbb.maxY);
    int minZ = Mth.floor(axisalignedbb.minZ);
    int maxZ = (int) Math.ceil(axisalignedbb.maxZ);
    VoxelShape vec3d;
    boolean isEmpty;
    for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
            if (((ServerChunkCache) world.getChunkSource()).hasChunk(x >> 4, z >> 4)) {
                for (int y = minY - 1; y <= maxY; y++) {
                    BlockPos bp = new BlockPos(x, y, z);
                    BlockState blockData = world.getBlockState(bp);
                    if (blockData != null && blockData.getMaterial().isSolid()) {
                        vec3d = blockData.getCollisionShape(world, bp);
                        isEmpty = vec3d.isEmpty();
                        if (!isEmpty) {
                            for (AABB bb : vec3d.toAabbs()) {
                                if (bb.move(bp).intersects(axisalignedbb)) {
                                    unsafeList.add(bb);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return unsafeList;
}
Also used : VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) UnsafeList(org.bukkit.craftbukkit.v1_18_R1.util.UnsafeList) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) AABB(net.minecraft.world.phys.AABB)

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