Search in sources :

Example 6 with Block

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

the class EntityMyTraderLlama method updateVisuals.

@Override
public void updateVisuals() {
    this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest());
    this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
    if (getMyPet().hasDecor()) {
        ItemStack is = CraftItemStack.asNMSCopy(getMyPet().getDecor());
        Block block = Block.byItem(is.getItem());
        int color = block instanceof WoolCarpetBlock ? ((WoolCarpetBlock) block).getColor().getId() : 0;
        this.getEntityData().set(COLOR_WATCHER, color);
    } else {
        this.getEntityData().set(COLOR_WATCHER, -1);
    }
    this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant());
}
Also used : WoolCarpetBlock(net.minecraft.world.level.block.WoolCarpetBlock) WoolCarpetBlock(net.minecraft.world.level.block.WoolCarpetBlock) Block(net.minecraft.world.level.block.Block) ItemStack(net.minecraft.world.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)

Example 7 with Block

use of net.minecraft.world.level.block.Block in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showBlockAction.

@Override
public void showBlockAction(Player player, Location location, int action, int state) {
    BlockPos position = new BlockPos(location.getX(), location.getY(), location.getZ());
    Block block = ((CraftWorld) location.getWorld()).getHandle().getBlockState(position).getBlock();
    send(player, new ClientboundBlockEventPacket(position, block, action, state));
}
Also used : FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 8 with Block

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

the class ForgeBlockTagsProvider method addColored.

private void addColored(Consumer<Block> consumer, Tag.Named<Block> group, String pattern) {
    String prefix = group.getName().getPath().toUpperCase(Locale.ENGLISH) + '_';
    for (DyeColor color : DyeColor.values()) {
        ResourceLocation key = new ResourceLocation("minecraft", pattern.replace("{color}", color.getName()));
        Tag.Named<Block> tag = getForgeTag(prefix + color.getName());
        Block block = ForgeRegistries.BLOCKS.getValue(key);
        if (block == null || block == Blocks.AIR)
            throw new IllegalStateException("Unknown vanilla block: " + key.toString());
        tag(tag).add(block);
        consumer.accept(block);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Block(net.minecraft.world.level.block.Block) Tag(net.minecraft.tags.Tag) DyeColor(net.minecraft.world.item.DyeColor)

Example 9 with Block

use of net.minecraft.world.level.block.Block 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 10 with Block

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

the class EntityMyLlama method updateVisuals.

@Override
public void updateVisuals() {
    this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest());
    this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
    if (getMyPet().hasDecor()) {
        ItemStack is = CraftItemStack.asNMSCopy(getMyPet().getDecor());
        Block block = Block.byItem(is.getItem());
        int color = block instanceof WoolCarpetBlock ? ((WoolCarpetBlock) block).getColor().getId() : 0;
        this.getEntityData().set(COLOR_WATCHER, color);
    } else {
        this.getEntityData().set(COLOR_WATCHER, -1);
    }
    this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant());
}
Also used : WoolCarpetBlock(net.minecraft.world.level.block.WoolCarpetBlock) WoolCarpetBlock(net.minecraft.world.level.block.WoolCarpetBlock) Block(net.minecraft.world.level.block.Block) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

Block (net.minecraft.world.level.block.Block)14 Item (net.minecraft.world.item.Item)5 ResourceLocation (net.minecraft.resources.ResourceLocation)4 ItemStack (net.minecraft.world.item.ItemStack)3 WoolCarpetBlock (net.minecraft.world.level.block.WoolCarpetBlock)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)3 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)2 BlockPos (net.minecraft.core.BlockPos)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 Tag (net.minecraft.tags.Tag)2 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)2 ItemStack (org.bukkit.inventory.ItemStack)2 com.google.common.collect (com.google.common.collect)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Pair (com.mojang.datafixers.util.Pair)1 Lifecycle (com.mojang.serialization.Lifecycle)1 Field (java.lang.reflect.Field)1