Search in sources :

Example 1 with BlockBanner

use of net.minecraft.block.BlockBanner in project BetterWithAddons by DaedalusGame.

the class TileEntityBannerDetector method checkBanner.

private boolean checkBanner(BlockPos pos, ItemStack filter, Class type) {
    IBlockState state = world.getBlockState(pos);
    if (type.isInstance(state.getBlock())) {
        BlockBanner bannerblock = (BlockBanner) state.getBlock();
        ItemStack banner = bannerblock.getItem(world, pos, state);
        return BannerUtil.isSameBanner(filter, banner);
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) BlockBanner(net.minecraft.block.BlockBanner)

Example 2 with BlockBanner

use of net.minecraft.block.BlockBanner in project BetterWithAddons by DaedalusGame.

the class AssortedHandler method onBlockInteract.

@SubscribeEvent
public void onBlockInteract(PlayerInteractEvent event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState blockstate = world.getBlockState(pos);
    EntityPlayer player = event.getEntityPlayer();
    if (blockstate.getBlock() instanceof BlockBanner) {
        EnumHand hand = EnumHand.MAIN_HAND;
        ItemStack stack = player.getHeldItemMainhand();
        BlockBanner bannerblock = (BlockBanner) blockstate.getBlock();
        if (stack.isEmpty() && player.isSneaking() && player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty()) {
            ItemStack bannerstack = bannerblock.getItem(world, pos, blockstate);
            player.swingArm(hand);
            world.removeTileEntity(pos);
            world.setBlockToAir(pos);
            player.setItemStackToSlot(EntityEquipmentSlot.HEAD, bannerstack);
            if (!event.getWorld().isRemote) {
                event.setCanceled(true);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) BlockBanner(net.minecraft.block.BlockBanner) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

BlockBanner (net.minecraft.block.BlockBanner)2 IBlockState (net.minecraft.block.state.IBlockState)2 ItemStack (net.minecraft.item.ItemStack)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EnumHand (net.minecraft.util.EnumHand)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1